From 6abf46dcd5be687fa1707f07f7f3594c6cbf943d Mon Sep 17 00:00:00 2001 From: Chris Hanson Date: Wed, 15 Aug 2012 22:16:37 -0700 Subject: [PATCH] Fix broken memory allocation on 32-bit OS X. --- src/microcode/ux.c | 18 ++++++++++++++++-- src/microcode/ux.h | 3 +++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/microcode/ux.c b/src/microcode/ux.c index 513c008db..417e45a62 100644 --- a/src/microcode/ux.c +++ b/src/microcode/ux.c @@ -765,6 +765,20 @@ mmap_heap_malloc_try (unsigned long address, unsigned long request, int flags) /* Try to use our low addresses even if the OS has a tendency to choose high ones. (What if we're on a 64-bit system? Why do we care?) */ +#ifdef __x86_64__ +# define MMAP_EXTRA_FLAGS 0 +#else +#ifdef MAP_TRYFIXED +# define MMAP_EXTRA_FLAGS MAP_TRYFIXED +#else +#if defined(USE_MAP_FIXED) && defined(MAP_FIXED) +# define MMAP_EXTRA_FLAGS MAP_FIXED +#else +# define MMAP_EXTRA_FLAGS 0 +#endif +#endif +#endif + static void * mmap_heap_malloc_search (unsigned long request, unsigned long min_result, @@ -772,9 +786,9 @@ mmap_heap_malloc_search (unsigned long request, { (void)max_result; /* ignore */ -#ifdef MAP_TRYFIXED +#if MMAP_EXTRA_FLAGS != 0 { - void * addr = (mmap_heap_malloc_try (min_result, request, MAP_TRYFIXED)); + void * addr = (mmap_heap_malloc_try (min_result, request, MMAP_EXTRA_FLAGS)); return (addr ? addr : (mmap_heap_malloc_try (0, request, 0))); } #else diff --git a/src/microcode/ux.h b/src/microcode/ux.h index 5356b93cf..5c875454c 100644 --- a/src/microcode/ux.h +++ b/src/microcode/ux.h @@ -129,6 +129,9 @@ USA. #ifdef HAVE_SYS_MMAN_H # include #endif +#ifdef __APPLE__ +# define USE_MAP_FIXED 1 +#endif /* GNU C library defines environ if __USE_GNU is defined. */ #ifndef __USE_GNU -- 2.25.1