summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2009-11-23 21:35:34 -0500
committerMike Frysinger <vapier@gentoo.org>2009-11-23 21:35:34 -0500
commit00673f93826bf1fbde728d202c319a684bb87150 (patch)
tree2918312040781ebf7055ca83321605e7b110002d /libc
parentc5bc75430dccfaef12220311aa4853176a8a911b (diff)
nommu: use MAP_UNINITIALIZE for mallocs
Now that the kernel supports MAP_UNINITIALIZE, have the malloc places use it to get real uninitialized memory on no-mmu systems. This avoids a lot of normally useless overhead involved in zeroing out all of the memory (sometimes multiple times). Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'libc')
-rw-r--r--libc/stdlib/malloc-simple/alloc.c2
-rw-r--r--libc/stdlib/malloc-standard/malloc.h2
-rw-r--r--libc/stdlib/malloc/malloc.c2
-rw-r--r--libc/sysdeps/linux/alpha/bits/mman.h2
-rw-r--r--libc/sysdeps/linux/hppa/bits/mman.h2
-rw-r--r--libc/sysdeps/linux/mips/bits/mman.h2
-rw-r--r--libc/sysdeps/linux/powerpc/bits/mman.h2
-rw-r--r--libc/sysdeps/linux/sparc/bits/mman.h2
-rw-r--r--libc/sysdeps/linux/xtensa/bits/mman.h2
9 files changed, 15 insertions, 3 deletions
diff --git a/libc/stdlib/malloc-simple/alloc.c b/libc/stdlib/malloc-simple/alloc.c
index 36355c1e9..51da14ac8 100644
--- a/libc/stdlib/malloc-simple/alloc.c
+++ b/libc/stdlib/malloc-simple/alloc.c
@@ -36,7 +36,7 @@ void *malloc(size_t size)
#ifdef __ARCH_USE_MMU__
# define MMAP_FLAGS MAP_PRIVATE | MAP_ANONYMOUS
#else
-# define MMAP_FLAGS MAP_SHARED | MAP_ANONYMOUS
+# define MMAP_FLAGS MAP_SHARED | MAP_ANONYMOUS | MAP_UNINITIALIZE
#endif
result = mmap((void *) 0, size + sizeof(size_t), PROT_READ | PROT_WRITE,
diff --git a/libc/stdlib/malloc-standard/malloc.h b/libc/stdlib/malloc-standard/malloc.h
index 90c9fd14d..7a2e66d16 100644
--- a/libc/stdlib/malloc-standard/malloc.h
+++ b/libc/stdlib/malloc-standard/malloc.h
@@ -356,7 +356,7 @@ __UCLIBC_MUTEX_EXTERN(__malloc_lock);
#else
#define MMAP(addr, size, prot) \
- (mmap((addr), (size), (prot), MAP_SHARED|MAP_ANONYMOUS, 0, 0))
+ (mmap((addr), (size), (prot), MAP_SHARED|MAP_ANONYMOUS|MAP_UNINITIALIZE, 0, 0))
#endif
diff --git a/libc/stdlib/malloc/malloc.c b/libc/stdlib/malloc/malloc.c
index f4bbc71a2..337206f09 100644
--- a/libc/stdlib/malloc/malloc.c
+++ b/libc/stdlib/malloc/malloc.c
@@ -124,7 +124,7 @@ __malloc_from_heap (size_t size, struct heap_free_area **heap
MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
#else
block = mmap ((void *)0, block_size, PROT_READ | PROT_WRITE,
- MAP_SHARED | MAP_ANONYMOUS, 0, 0);
+ MAP_SHARED | MAP_ANONYMOUS | MAP_UNINITIALIZE, 0, 0);
#endif
#endif /* MALLOC_USE_SBRK */
diff --git a/libc/sysdeps/linux/alpha/bits/mman.h b/libc/sysdeps/linux/alpha/bits/mman.h
index 2f0e56491..cafad4a24 100644
--- a/libc/sysdeps/linux/alpha/bits/mman.h
+++ b/libc/sysdeps/linux/alpha/bits/mman.h
@@ -71,6 +71,8 @@
# define MAP_NORESERVE 0x10000 /* Don't check for reservations. */
# define MAP_POPULATE 0x20000 /* Populate (prefault) pagetables. */
# define MAP_NONBLOCK 0x40000 /* Do not block on IO. */
+# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#endif
/* Flags to `msync'. */
diff --git a/libc/sysdeps/linux/hppa/bits/mman.h b/libc/sysdeps/linux/hppa/bits/mman.h
index 54531ecf2..7f9bf4ed6 100644
--- a/libc/sysdeps/linux/hppa/bits/mman.h
+++ b/libc/sysdeps/linux/hppa/bits/mman.h
@@ -45,6 +45,8 @@
#define MAP_GROWSDOWN 0x8000 /* stack-like segment */
#define MAP_POPULATE 0x10000 /* populate (prefault) pagetables */
#define MAP_NONBLOCK 0x20000 /* do not block on IO */
+#define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#define MS_SYNC 1 /* synchronous memory sync */
#define MS_ASYNC 2 /* sync memory asynchronously */
diff --git a/libc/sysdeps/linux/mips/bits/mman.h b/libc/sysdeps/linux/mips/bits/mman.h
index 47d33933a..c480be46e 100644
--- a/libc/sysdeps/linux/mips/bits/mman.h
+++ b/libc/sysdeps/linux/mips/bits/mman.h
@@ -66,6 +66,8 @@
# define MAP_LOCKED 0x8000 /* pages are locked */
# define MAP_POPULATE 0x10000 /* populate (prefault) pagetables */
# define MAP_NONBLOCK 0x20000 /* do not block on IO */
+# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#endif
/* Flags to `msync'. */
diff --git a/libc/sysdeps/linux/powerpc/bits/mman.h b/libc/sysdeps/linux/powerpc/bits/mman.h
index e03ab7ff8..2d234c5fc 100644
--- a/libc/sysdeps/linux/powerpc/bits/mman.h
+++ b/libc/sysdeps/linux/powerpc/bits/mman.h
@@ -63,6 +63,8 @@
# define MAP_NORESERVE 0x00040 /* Don't check for reservations. */
# define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables. */
# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#endif
/* Flags to `msync'. */
diff --git a/libc/sysdeps/linux/sparc/bits/mman.h b/libc/sysdeps/linux/sparc/bits/mman.h
index be2b7eb28..74921e4c5 100644
--- a/libc/sysdeps/linux/sparc/bits/mman.h
+++ b/libc/sysdeps/linux/sparc/bits/mman.h
@@ -65,6 +65,8 @@
# define _MAP_NEW 0x80000000 /* Binary compatibility with SunOS. */
# define MAP_POPULATE 0x8000 /* Populate (prefault) pagetables. */
# define MAP_NONBLOCK 0x10000 /* Do not block on IO. */
+# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#endif
/* Flags to `msync'. */
diff --git a/libc/sysdeps/linux/xtensa/bits/mman.h b/libc/sysdeps/linux/xtensa/bits/mman.h
index d3beae6aa..fead3ac20 100644
--- a/libc/sysdeps/linux/xtensa/bits/mman.h
+++ b/libc/sysdeps/linux/xtensa/bits/mman.h
@@ -64,6 +64,8 @@
# define MAP_NORESERVE 0x0400 /* Don't check for reservations. */
# define MAP_POPULATE 0x10000 /* Populate (prefault) pagetables. */
# define MAP_NONBLOCK 0x20000 /* Do not block on IO. */
+# define MAP_UNINITIALIZE 0x4000000 /* For anonymous mmap, memory could
+ be uninitialized. */
#endif
/* Flags to `msync'. */