aboutsummaryrefslogtreecommitdiff
path: root/malloc/arena.c
diff options
context:
space:
mode:
Diffstat (limited to 'malloc/arena.c')
-rw-r--r--malloc/arena.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/malloc/arena.c b/malloc/arena.c
index 00f40971f3..9018a4f0e9 100644
--- a/malloc/arena.c
+++ b/malloc/arena.c
@@ -339,7 +339,16 @@ ptmalloc_init_minimal (void)
mp_.pagesize = malloc_getpagesize;
}
+
#ifdef _LIBC
+# ifdef SHARED
+static void *
+__failing_morecore (ptrdiff_t d)
+{
+ return (void *) MORECORE_FAILURE;
+}
+# endif
+
# if defined SHARED && defined USE_TLS && !USE___THREAD
# include <stdbool.h>
@@ -419,6 +428,14 @@ ptmalloc_init (void)
mutex_init(&main_arena.mutex);
main_arena.next = &main_arena;
+#if defined _LIBC && defined SHARED
+ /* In case this libc copy is in a non-default namespace, never use brk. */
+ Dl_info di;
+ struct link_map *l;
+ if (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0 && l->l_ns != LM_ID_BASE)
+ __morecore = __failing_morecore;
+#endif
+
mutex_init(&list_lock);
tsd_key_create(&arena_key, NULL);
tsd_setspecific(arena_key, (Void_t *)&main_arena);