summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--test/malloc/tst-calloc.c18
-rw-r--r--utils/Makefile.in28
-rw-r--r--utils/bswap.h52
-rw-r--r--utils/chroot_realpath.c18
-rw-r--r--utils/ldconfig.c77
-rw-r--r--utils/ldd.c50
-rw-r--r--utils/mmap-windows.c100
-rw-r--r--utils/porting.h75
-rw-r--r--utils/readsoname2.c12
9 files changed, 256 insertions, 174 deletions
diff --git a/test/malloc/tst-calloc.c b/test/malloc/tst-calloc.c
index b3594c937..eb0059f68 100644
--- a/test/malloc/tst-calloc.c
+++ b/test/malloc/tst-calloc.c
@@ -18,12 +18,12 @@
02111-1307 USA. */
#include <errno.h>
-#include <error.h>
#include <limits.h>
#include <malloc.h>
#include <stdlib.h>
#include <stdio.h>
+static int errors = 0;
/* Number of samples per size. */
#define N 50000
@@ -46,10 +46,11 @@ fixed_test (int size)
for (j = 0; j < size; ++j)
{
- if (ptrs[i][j] != '\0')
- error (EXIT_FAILURE, 0,
- "byte not cleared (size %d, element %d, byte %d)",
+ if (ptrs[i][j] != '\0') {
+ ++errors;
+ printf("byte not cleared (size %d, element %d, byte %d)",
size, i, j);
+ }
ptrs[i][j] = '\xff';
}
}
@@ -79,10 +80,11 @@ random_test (void)
for (j = 0; j < size; ++j)
{
- if (ptrs[i][j] != '\0')
- error (EXIT_FAILURE, 0,
- "byte not cleared (size %d, element %d, byte %d)",
+ if (ptrs[i][j] != '\0') {
+ ++errors;
+ printf("byte not cleared (size %d, element %d, byte %d)",
size, i, j);
+ }
ptrs[i][j] = '\xff';
}
}
@@ -122,5 +124,5 @@ main (void)
null_test ();
- return 0;
+ return errors != 0;
}
diff --git a/utils/Makefile.in b/utils/Makefile.in
index 1c94c41db..446973ea3 100644
--- a/utils/Makefile.in
+++ b/utils/Makefile.in
@@ -9,6 +9,9 @@
CFLAGS-utils := \
$(SSP_ALL_CFLAGS) \
+ -I$(top_srcdir)ldso/include \
+ -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
+ -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
-I$(top_srcdir)/$(KERNEL_HEADERS) \
-DNOT_IN_libc \
-B$(top_builddir)lib \
@@ -20,21 +23,14 @@ else
CFLAGS-utils-shared :=
endif
-CFLAGS-ldconfig := \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO)
+CFLAGS-ldconfig :=
ifeq ($(UCLIBC_STATIC_LDCONFIG),y)
CFLAGS-ldconfig += -static
else
CFLAGS-ldconfig += $(CFLAGS-utils-shared)
endif
-CFLAGS-ldd := \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(CFLAGS-utils-shared)
+CFLAGS-ldd := $(CFLAGS-utils-shared)
# Need CFLAGS-utils explicitly, because the source file is not located in utils
CFLAGS-iconv := $(CFLAGS-utils) \
@@ -50,20 +46,14 @@ ifeq ($(LDSO_CACHE_SUPPORT),y)
LDSO_CACHE_SUPPORT := -D__LDSO_CACHE_SUPPORT__=1
endif
-BUILD_CFLAGS-ldconfig.host := -Wl,-s \
+BUILD_CFLAGS-utils := \
-include $(top_srcdir)include/elf.h \
-I$(top_srcdir)ldso/include \
-DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
-DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(LDSO_CACHE_SUPPORT) \
-
-BUILD_CFLAGS-ldd.host := -Wl,-s \
- -include $(top_srcdir)include/elf.h \
- -I$(top_srcdir)ldso/include \
- -DUCLIBC_RUNTIME_PREFIX=\"$(RUNTIME_PREFIX)\" \
- -DUCLIBC_LDSO=$(UCLIBC_LDSO) \
- $(LDSO_CACHE_SUPPORT) \
-
+ $(LDSO_CACHE_SUPPORT)
+BUILD_CFLAGS-ldconfig.host := $(BUILD_CFLAGS-utils)
+BUILD_CFLAGS-ldd.host := $(BUILD_CFLAGS-utils)
# Rules
diff --git a/utils/bswap.h b/utils/bswap.h
index 666b80a73..0047e4e98 100644
--- a/utils/bswap.h
+++ b/utils/bswap.h
@@ -6,40 +6,6 @@
#ifndef _BSWAP_H
#define _BSWAP_H 1
-#if !defined(__BYTE_ORDER) && defined(BYTE_ORDER)
-# define __BYTE_ORDER BYTE_ORDER
-# if !defined(__BIG_ENDIAN) && defined(BIG_ENDIAN)
-# define __BIG_ENDIAN BIG_ENDIAN
-# endif
-# if !defined(__LITTLE_ENDIAN) && defined(LITTLE_ENDIAN)
-# define __LITTLE_ENDIAN LITTLE_ENDIAN
-# endif
-#endif
-
-#ifndef __BYTE_ORDER
-# ifdef __linux__
-# include <endian.h>
-# else
-# define __LITTLE_ENDIAN 1234 /* least-significant byte first (vax, pc) */
-# define __BIG_ENDIAN 4321 /* most-significant byte first (IBM, net) */
-# define __PDP_ENDIAN 3412 /* LSB first in word, MSW first in long (pdp) */
-
-# if defined(sun386) || defined(i386) || defined(__LITTLE_ENDIAN__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-# endif
-
-# if defined(sparc) || defined(__BIG_ENDIAN__)
-# define __BYTE_ORDER __BIG_ENDIAN
-# endif
-
-# endif /* __linux__ */
-#endif /* __BYTE_ORDER */
-
-
-#ifndef __BYTE_ORDER
-# error "Undefined __BYTE_ORDER"
-#endif
-
#ifdef __linux__
# include <byteswap.h>
#else
@@ -56,6 +22,24 @@ static __inline__ uint32_t bswap_32(uint32_t x)
(((x) & 0x0000ff00) << 8) | \
(((x) & 0x000000ff) << 24));
}
+static __inline__ uint64_t bswap_64(uint64_t x)
+{
+#define _uswap_64(x, sfx) \
+ return ((((x) & 0xff00000000000000##sfx) >> 56) | \
+ (((x) & 0x00ff000000000000##sfx) >> 40) | \
+ (((x) & 0x0000ff0000000000##sfx) >> 24) | \
+ (((x) & 0x000000ff00000000##sfx) >> 8) | \
+ (((x) & 0x00000000ff000000##sfx) << 8) | \
+ (((x) & 0x0000000000ff0000##sfx) << 24) | \
+ (((x) & 0x000000000000ff00##sfx) << 40) | \
+ (((x) & 0x00000000000000ff##sfx) << 56));
+#if defined(__GNUC__)
+ _uswap_64(x, ull)
+#else
+ _uswap_64(x, )
+#endif
+#undef _uswap_64
+}
#endif
#endif
diff --git a/utils/chroot_realpath.c b/utils/chroot_realpath.c
index 87039724d..0be57bf1f 100644
--- a/utils/chroot_realpath.c
+++ b/utils/chroot_realpath.c
@@ -20,23 +20,7 @@
* 2005/09/12: Dan Howell (modified from realpath.c to emulate chroot)
*/
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <string.h>
-#include <strings.h>
-#include <limits.h> /* for PATH_MAX */
-#include <sys/param.h> /* for MAXPATHLEN */
-#include <errno.h>
-#include <sys/stat.h> /* for S_IFLNK */
-
-#ifndef PATH_MAX
-#define PATH_MAX _POSIX_PATH_MAX
-#endif
+#include "porting.h"
#define MAX_READLINKS 32
diff --git a/utils/ldconfig.c b/utils/ldconfig.c
index 6c2362ad2..139b5f9cb 100644
--- a/utils/ldconfig.c
+++ b/utils/ldconfig.c
@@ -26,20 +26,7 @@
* 2005/09/16: Dan Howell (modified for cross-development)
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
-#include <ctype.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <link.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include "bswap.h"
-#include "dl-defs.h"
+#include "porting.h"
#define BUFFER_SIZE 4096
@@ -72,20 +59,6 @@ struct exec {
char *___strtok = NULL;
-/* For SunOS */
-#ifndef PATH_MAX
-#include <limits.h>
-#define PATH_MAX _POSIX_PATH_MAX
-#endif
-
-/* For SunOS */
-#ifndef N_MAGIC
-#define N_MAGIC(exec) ((exec).a_magic & 0xffff)
-#endif
-
-#define EXIT_OK 0
-#define EXIT_FATAL 128
-
char *prog = NULL;
int debug = 0; /* debug mode */
int verbose = 0; /* verbose mode */
@@ -177,7 +150,7 @@ static void *xmalloc(size_t size)
{
void *ptr;
if ((ptr = malloc(size)) == NULL)
- err(EXIT_FATAL, "out of memory");
+ err(EXIT_FAILURE, "out of memory");
return ptr;
}
@@ -185,7 +158,7 @@ static char *xstrdup(const char *str)
{
char *ptr;
if ((ptr = strdup(str)) == NULL)
- err(EXIT_FATAL, "out of memory");
+ err(EXIT_FAILURE, "out of memory");
return ptr;
}
@@ -452,7 +425,7 @@ static void scan_dir(const char *rawname)
/* We need a writable copy of this string */
path = strdup(rawname);
if (!path) {
- err(EXIT_FATAL, "Out of memory!\n");
+ err(EXIT_FAILURE, "Out of memory!\n");
}
/* Eliminate all double //s */
path_n = path;
@@ -678,17 +651,17 @@ void cache_write(void)
return;
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
cachefile, chroot_dir, strerror(errno));
sprintf(tempfile, "%s~", realcachefile);
if (unlink(tempfile) && errno != ENOENT)
- err(EXIT_FATAL, "can't unlink %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't unlink %s~ (%s)", cachefile,
strerror(errno));
if ((cachefd = creat(tempfile, 0644)) < 0)
- err(EXIT_FATAL, "can't create %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't create %s~ (%s)", cachefile,
strerror(errno));
if (byteswap) {
@@ -699,7 +672,7 @@ void cache_write(void)
magic_ptr = &magic;
}
if (write(cachefd, magic_ptr, sizeof(header_t)) != sizeof(header_t))
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
@@ -717,31 +690,31 @@ void cache_write(void)
}
if (write(cachefd, lib_ptr, sizeof(libentry_t)) !=
sizeof(libentry_t))
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
}
for (cur_lib = lib_head; cur_lib != NULL; cur_lib = cur_lib->next) {
if ((size_t)write(cachefd, cur_lib->soname, strlen(cur_lib->soname) + 1)
!= strlen(cur_lib->soname) + 1)
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
if ((size_t)write(cachefd, cur_lib->libname, strlen(cur_lib->libname) + 1)
!= strlen(cur_lib->libname) + 1)
- err(EXIT_FATAL, "can't write %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't write %s~ (%s)", cachefile,
strerror(errno));
}
if (close(cachefd))
- err(EXIT_FATAL, "can't close %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't close %s~ (%s)", cachefile,
strerror(errno));
if (chmod(tempfile, 0644))
- err(EXIT_FATAL, "can't chmod %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't chmod %s~ (%s)", cachefile,
strerror(errno));
if (rename(tempfile, realcachefile))
- err(EXIT_FATAL, "can't rename %s~ (%s)", cachefile,
+ err(EXIT_FAILURE, "can't rename %s~ (%s)", cachefile,
strerror(errno));
}
@@ -756,22 +729,22 @@ void cache_print(void)
char realcachefile[BUFFER_SIZE];
if (!chroot_realpath(chroot_dir, cachefile, realcachefile))
- err(EXIT_FATAL, "can't resolve %s in chroot %s (%s)",
+ err(EXIT_FAILURE, "can't resolve %s in chroot %s (%s)",
cachefile, chroot_dir, strerror(errno));
if (stat(realcachefile, &st) || (fd = open(realcachefile, O_RDONLY)) < 0)
- err(EXIT_FATAL, "can't read %s (%s)", cachefile, strerror(errno));
+ err(EXIT_FAILURE, "can't read %s (%s)", cachefile, strerror(errno));
c = mmap(0, st.st_size, PROT_READ, LDSO_CACHE_MMAP_FLAGS, fd, 0);
if (c == MAP_FAILED)
- err(EXIT_FATAL, "can't map %s (%s)", cachefile, strerror(errno));
+ err(EXIT_FAILURE, "can't map %s (%s)", cachefile, strerror(errno));
close(fd);
if (memcmp(((header_t *) c)->magic, LDSO_CACHE_MAGIC, LDSO_CACHE_MAGIC_LEN))
- err(EXIT_FATAL, "%s cache corrupt", cachefile);
+ err(EXIT_FAILURE, "%s cache corrupt", cachefile);
if (memcmp(((header_t *) c)->version, LDSO_CACHE_VER, LDSO_CACHE_VER_LEN))
- err(EXIT_FATAL, "wrong cache version - expected %s",
+ err(EXIT_FAILURE, "wrong cache version - expected %s",
LDSO_CACHE_VER);
header = (header_t *) c;
@@ -843,7 +816,7 @@ static void attribute_noreturn usage(void)
"\tlib ... :\tlibraries to link\n\n"
#endif
);
- exit(EXIT_FATAL);
+ exit(EXIT_FAILURE);
}
#define DIR_SEP ":, \t\n"
@@ -916,11 +889,11 @@ int main(int argc, char **argv)
if (chroot_dir && *chroot_dir) {
if (chroot(chroot_dir) < 0) {
if (chdir(chroot_dir) < 0)
- err(EXIT_FATAL, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
+ err(EXIT_FAILURE, "couldn't chroot to %s (%s)", chroot_dir, strerror(errno));
chroot_dir = ".";
} else {
if (chdir("/") < 0)
- err(EXIT_FATAL, "couldn't chdir to / (%s)", strerror(errno));
+ err(EXIT_FAILURE, "couldn't chdir to / (%s)", strerror(errno));
chroot_dir = NULL;
}
}
@@ -932,7 +905,7 @@ int main(int argc, char **argv)
if (printcache) {
/* print the cache -- don't you trust me? */
cache_print();
- exit(EXIT_OK);
+ exit(EXIT_SUCCESS);
} else if (libmode) {
/* so you want to do things manually, eh? */
@@ -952,7 +925,7 @@ int main(int argc, char **argv)
/* we'd better do a little bit of checking */
if ((so = is_shlib(dir, cp, &libtype, &islink, LIB_ANY)) == NULL)
- err(EXIT_FATAL, "%s%s%s is not a shared library",
+ err(EXIT_FAILURE, "%s%s%s is not a shared library",
dir, (*dir && strcmp(dir, "/")) ? "/" : "", cp);
/* so far, so good, maybe he knows what he's doing */
@@ -1005,5 +978,5 @@ int main(int argc, char **argv)
cache_write();
}
- exit(EXIT_OK);
+ exit(EXIT_SUCCESS);
}
diff --git a/utils/ldd.c b/utils/ldd.c
index 41da97360..e7a94cbc4 100644
--- a/utils/ldd.c
+++ b/utils/ldd.c
@@ -13,25 +13,7 @@
* Licensed under GPLv2 or later
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#include <string.h>
-#include <unistd.h>
-#include <stdint.h>
-#include <sys/mman.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include "bswap.h"
-#include "link.h"
-#include "dl-defs.h"
-/* makefile will include elf.h for us */
-
-#ifdef DMALLOC
-#include <dmalloc.h>
-#endif
+#include "porting.h"
#if defined(__alpha__)
#define MATCH_MACHINE(x) (x == EM_ALPHA)
@@ -134,16 +116,12 @@
# warning "You really should add a MATCH_MACHINE() macro for your architecture"
#endif
-#if __BYTE_ORDER == __LITTLE_ENDIAN
+#if UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE
#define ELFDATAM ELFDATA2LSB
-#elif __BYTE_ORDER == __BIG_ENDIAN
+#elif UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG
#define ELFDATAM ELFDATA2MSB
#endif
-#ifndef UCLIBC_RUNTIME_PREFIX
-# define UCLIBC_RUNTIME_PREFIX "/"
-#endif
-
struct library {
char *name;
int resolved;
@@ -247,15 +225,13 @@ static int check_elf_header(ElfW(Ehdr) *const ehdr)
/* Check if the target endianness matches the host's endianness */
byteswap = 0;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2MSB)
- byteswap = 1;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- if (ehdr->e_ident[5] == ELFDATA2LSB)
- byteswap = 1;
-#else
-#error Unknown host byte order!
-#endif
+ if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE) {
+ if (ehdr->e_ident[5] == ELFDATA2MSB)
+ byteswap = 1;
+ } else if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG) {
+ if (ehdr->e_ident[5] == ELFDATA2LSB)
+ byteswap = 1;
+ }
/* Be very lazy, and only byteswap the stuff we use */
if (byteswap) {
@@ -363,7 +339,7 @@ static void search_for_named_library(char *name, char *result,
/* We need a writable copy of this string */
path = strdup(path_list);
if (!path) {
- fprintf(stderr, "Out of memory!\n");
+ fprintf(stderr, "%s: Out of memory!\n", __func__);
exit(EXIT_FAILURE);
}
/* Eliminate all double //s */
@@ -412,7 +388,7 @@ static void locate_library_file(ElfW(Ehdr) *ehdr, ElfW(Dyn) *dynamic,
/* We need some elbow room here. Make some room... */
buf = malloc(1024);
if (!buf) {
- fprintf(stderr, "Out of memory!\n");
+ fprintf(stderr, "%s: Out of memory!\n", __func__);
exit(EXIT_FAILURE);
}
@@ -669,7 +645,7 @@ static int find_dependancies(char *filename)
ehdr = mmap(0, statbuf.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fileno(thefile), 0);
if (ehdr == MAP_FAILED) {
fclose(thefile);
- fprintf(stderr, "Out of memory!\n");
+ fprintf(stderr, "mmap(%s) failed: %s\n", filename, strerror(errno));
return -1;
}
diff --git a/utils/mmap-windows.c b/utils/mmap-windows.c
new file mode 100644
index 000000000..1799392f0
--- /dev/null
+++ b/utils/mmap-windows.c
@@ -0,0 +1,100 @@
+/* mmap() replacement for Windows
+ *
+ * Author: Mike Frysinger <vapier@gentoo.org>
+ * Placed into the public domain
+ */
+
+/* References:
+ * CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx
+ * CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx
+ * MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx
+ * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx
+ */
+
+#include <io.h>
+#include <windows.h>
+#include <sys/types.h>
+
+#define PROT_READ 0x1
+#define PROT_WRITE 0x2
+/* This flag is only available in WinXP+ */
+#ifdef FILE_MAP_EXECUTE
+#define PROT_EXEC 0x4
+#else
+#define PROT_EXEC 0x0
+#define FILE_MAP_EXECUTE 0
+#endif
+
+#define MAP_SHARED 0x01
+#define MAP_PRIVATE 0x02
+#define MAP_ANONYMOUS 0x20
+#define MAP_ANON MAP_ANONYMOUS
+#define MAP_FAILED ((void *) -1)
+
+#ifdef __USE_FILE_OFFSET64
+# define DWORD_HI(x) (x >> 32)
+# define DWORD_LO(x) ((x) & 0xffffffff)
+#else
+# define DWORD_HI(x) (0)
+# define DWORD_LO(x) (x)
+#endif
+
+static void *mmap(void *start, size_t length, int prot, int flags, int fd, off_t offset)
+{
+ if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC))
+ return MAP_FAILED;
+ if (fd == -1) {
+ if (!(flags & MAP_ANON) || offset)
+ return MAP_FAILED;
+ } else if (flags & MAP_ANON)
+ return MAP_FAILED;
+
+ DWORD flProtect;
+ if (prot & PROT_WRITE) {
+ if (prot & PROT_EXEC)
+ flProtect = PAGE_EXECUTE_READWRITE;
+ else
+ flProtect = PAGE_READWRITE;
+ } else if (prot & PROT_EXEC) {
+ if (prot & PROT_READ)
+ flProtect = PAGE_EXECUTE_READ;
+ else if (prot & PROT_EXEC)
+ flProtect = PAGE_EXECUTE;
+ } else
+ flProtect = PAGE_READONLY;
+
+ off_t end = length + offset;
+ HANDLE mmap_fd, h;
+ if (fd == -1)
+ mmap_fd = INVALID_HANDLE_VALUE;
+ else
+ mmap_fd = (HANDLE)_get_osfhandle(fd);
+ h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL);
+ if (h == NULL)
+ return MAP_FAILED;
+
+ DWORD dwDesiredAccess;
+ if (prot & PROT_WRITE)
+ dwDesiredAccess = FILE_MAP_WRITE;
+ else
+ dwDesiredAccess = FILE_MAP_READ;
+ if (prot & PROT_EXEC)
+ dwDesiredAccess |= FILE_MAP_EXECUTE;
+ if (flags & MAP_PRIVATE)
+ dwDesiredAccess |= FILE_MAP_COPY;
+ void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length);
+ if (ret == NULL) {
+ CloseHandle(h);
+ ret = MAP_FAILED;
+ }
+ return ret;
+}
+
+static void munmap(void *addr, size_t length)
+{
+ UnmapViewOfFile(addr);
+ /* ruh-ro, we leaked handle from CreateFileMapping() ... */
+}
+
+#undef DWORD_HI
+#undef DWORD_LO
diff --git a/utils/porting.h b/utils/porting.h
new file mode 100644
index 000000000..6bb7fa91f
--- /dev/null
+++ b/utils/porting.h
@@ -0,0 +1,75 @@
+/* Misc system-specific crap */
+
+#ifndef _PORTING_H_
+#define _PORTING_H_
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <ctype.h>
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdarg.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <strings.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef __LDSO_LDD_SUPPORT__
+# include <sys/wait.h>
+#endif
+
+#if defined(_WIN32) || defined(_WINNT)
+# include "mmap-windows.c"
+#else
+# include <sys/mman.h>
+#endif
+
+#include <link.h>
+/* makefile will include elf.h for us */
+
+#include "bswap.h"
+#include "dl-defs.h"
+
+#ifdef DMALLOC
+#include <dmalloc.h>
+#endif
+
+/* For SunOS */
+#ifndef PATH_MAX
+#define PATH_MAX _POSIX_PATH_MAX
+#endif
+
+#ifndef UCLIBC_RUNTIME_PREFIX
+# define UCLIBC_RUNTIME_PREFIX "/"
+#endif
+
+#undef UCLIBC_ENDIAN_HOST
+#define UCLIBC_ENDIAN_LITTLE 1234
+#define UCLIBC_ENDIAN_BIG 4321
+#if defined(BYTE_ORDER)
+# if BYTE_ORDER == LITTLE_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
+# elif BYTE_ORDER == BIG_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
+# endif
+#elif defined(__BYTE_ORDER)
+# if __BYTE_ORDER == __LITTLE_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_LITTLE
+# elif __BYTE_ORDER == __BIG_ENDIAN
+# define UCLIBC_ENDIAN_HOST UCLIBC_ENDIAN_BIG
+# endif
+#endif
+#if !defined(UCLIBC_ENDIAN_HOST)
+# error "Unknown host byte order!"
+#endif
+
+#endif
diff --git a/utils/readsoname2.c b/utils/readsoname2.c
index 6ff136bb7..5cda3318d 100644
--- a/utils/readsoname2.c
+++ b/utils/readsoname2.c
@@ -35,13 +35,11 @@ static char *readsonameXX(char *name, FILE *infile, int expected_type, int *type
if ((char *)(epnt + 1) > (char *)(header + st.st_size))
goto skip;
-#if __BYTE_ORDER == __LITTLE_ENDIAN
- byteswap = (epnt->e_ident[5] == ELFDATA2MSB) ? 1 : 0;
-#elif __BYTE_ORDER == __BIG_ENDIAN
- byteswap = (epnt->e_ident[5] == ELFDATA2LSB) ? 1 : 0;
-#else
-#error Unknown host byte order!
-#endif
+ if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_LITTLE)
+ byteswap = (epnt->e_ident[5] == ELFDATA2MSB) ? 1 : 0;
+ else if (UCLIBC_ENDIAN_HOST == UCLIBC_ENDIAN_BIG)
+ byteswap = (epnt->e_ident[5] == ELFDATA2LSB) ? 1 : 0;
+
/* Be very lazy, and only byteswap the stuff we use */
if (byteswap == 1) {
epnt->e_phoff = bswap_32(epnt->e_phoff);