summaryrefslogtreecommitdiff
path: root/libc/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdlib')
-rw-r--r--libc/stdlib/malloc-simple/alloc.c4
-rw-r--r--libc/stdlib/malloc-standard/malloc.c4
-rw-r--r--libc/stdlib/malloc-standard/malloc.h13
-rw-r--r--libc/stdlib/malloc/malloc.c7
4 files changed, 21 insertions, 7 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index c0f702676..68cd77665 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -33,14 +33,14 @@ void *malloc(size_t size)
#ifdef __ARCH_HAS_MMU__
result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
if (result == MAP_FAILED)
return 0;
* (size_t *) result = size;
return(result + sizeof(size_t));
#else
result = mmap((void *) 0, size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+ MAP_SHARED | MAP_ANONYMOUS, 0, 0);
if (result == MAP_FAILED)
return 0;
return(result);
diff --git a/libc/stdlib/malloc-standard/malloc.c b/libc/stdlib/malloc-standard/malloc.c
index 8d132a43e..51e02a240 100644
--- a/libc/stdlib/malloc-standard/malloc.c
+++ b/libc/stdlib/malloc-standard/malloc.c
@@ -406,7 +406,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* Don't try if size wraps around 0 */
if ((unsigned long)(size) > (unsigned long)(nb)) {
- mm = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
+ mm = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
if (mm != (char*)(MORECORE_FAILURE)) {
@@ -526,7 +526,7 @@ static void* __malloc_alloc(size_t nb, mstate av)
/* Don't try if size wraps around 0 */
if ((unsigned long)(size) > (unsigned long)(nb)) {
- brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE));
+ brk = (char*)(MMAP(0, size, PROT_READ|PROT_WRITE));
if (brk != (char*)(MORECORE_FAILURE)) {
diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h
index 46858332d..0b8bbef31 100644
--- a/libc/stdlib/malloc-standard/malloc.h
+++ b/libc/stdlib/malloc-standard/malloc.h
@@ -350,8 +350,17 @@ extern pthread_mutex_t __malloc_lock;
#define MAP_ANONYMOUS MAP_ANON
#endif
-#define MMAP(addr, size, prot, flags) \
- (mmap((addr), (size), (prot), (flags)|MAP_ANONYMOUS, -1, 0))
+#ifdef __ARCH_HAS_MMU__
+
+#define MMAP(addr, size, prot) \
+ (mmap((addr), (size), (prot), MAP_PRIVATE|MAP_ANONYMOUS, 0, 0))
+
+#else
+
+#define MMAP(addr, size, prot) \
+ (mmap((addr), (size), (prot), MAP_SHARED|MAP_ANONYMOUS, 0, 0))
+
+#endif
/* ----------------------- Chunk representations ----------------------- */
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index 5ba552d25..e4523adb2 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -103,8 +103,13 @@ malloc_from_heap (size_t size, struct heap *heap)
#else /* !MALLOC_USE_SBRK */
/* Otherwise, use mmap. */
- block = mmap (0, block_size, PROT_READ | PROT_WRITE,
+#ifdef __ARCH_HAS_MMU__
+ block = mmap ((void *)0, block_size, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
+#else
+ block = mmap ((void *)0, block_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+#endif
#endif /* MALLOC_USE_SBRK */