diff options
Diffstat (limited to 'malloc')
-rw-r--r-- | malloc/Makefile | 2 | ||||
-rw-r--r-- | malloc/malloc.c | 22 | ||||
-rw-r--r-- | malloc/mtrace.pl | 2 |
3 files changed, 18 insertions, 8 deletions
diff --git a/malloc/Makefile b/malloc/Makefile index 7cec63dde4..07acdcf0f7 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -109,7 +109,7 @@ $(objpfx)mtrace: mtrace.pl $(objpfx)memusage: memusage.sh rm -f $@.new sed -e 's|@BASH@|$(BASH)|' -e 's|@VERSION@|$(version)|' \ - -e 's|@LIBDIR@|$(libdir)|' -e 's|@BINDIR@|$(bindir)|' $^ > $@.new \ + -e 's|@LIBDIR@|$(slibdir)|' -e 's|@BINDIR@|$(bindir)|' $^ > $@.new \ && rm -f $@ && mv $@.new $@ && chmod +x $@ diff --git a/malloc/malloc.c b/malloc/malloc.c index af20ca22bf..9ae5b6ef24 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -2013,12 +2013,22 @@ new_heap(size) size_t size; mapping (on Linux, this is the case for all non-writable mappings anyway). */ p1 = (char *)MMAP(0, HEAP_MAX_SIZE<<1, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE); - if(p1 == MAP_FAILED) - return 0; - p2 = (char *)(((unsigned long)p1 + HEAP_MAX_SIZE) & ~(HEAP_MAX_SIZE-1)); - ul = p2 - p1; - munmap(p1, ul); - munmap(p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul); + if(p1 != MAP_FAILED) { + p2 = (char *)(((unsigned long)p1 + HEAP_MAX_SIZE) & ~(HEAP_MAX_SIZE-1)); + ul = p2 - p1; + munmap(p1, ul); + munmap(p2 + HEAP_MAX_SIZE, HEAP_MAX_SIZE - ul); + } else { + /* Try to take the chance that an allocation of only HEAP_MAX_SIZE + is already aligned. */ + p2 = (char *)MMAP(0, HEAP_MAX_SIZE, PROT_NONE, MAP_PRIVATE|MAP_NORESERVE); + if(p2 == MAP_FAILED) + return 0; + if((unsigned long)p2 & (HEAP_MAX_SIZE-1)) { + munmap(p2, HEAP_MAX_SIZE); + return 0; + } + } if(mprotect(p2, size, PROT_READ|PROT_WRITE) != 0) { munmap(p2, HEAP_MAX_SIZE); return 0; diff --git a/malloc/mtrace.pl b/malloc/mtrace.pl index aff04d35c5..8be50f466e 100644 --- a/malloc/mtrace.pl +++ b/malloc/mtrace.pl @@ -69,7 +69,7 @@ if ($#ARGV == 0) { $binary=$ARGV[0]; $data=$ARGV[1]; } else { - die "Wrong number of arguments."; + die "Wrong number of arguments, run $progname --help for help."; } sub location { |