aboutsummaryrefslogtreecommitdiff
path: root/malloc
diff options
context:
space:
mode:
Diffstat (limited to 'malloc')
-rw-r--r--malloc/arena.c17
-rw-r--r--malloc/malloc.c6
2 files changed, 22 insertions, 1 deletions
diff --git a/malloc/arena.c b/malloc/arena.c
index 00f4097..9018a4f 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);
diff --git a/malloc/malloc.c b/malloc/malloc.c
index ad6009a..2e91952 100644
--- a/malloc/malloc.c
+++ b/malloc/malloc.c
@@ -289,9 +289,13 @@ extern "C" {
/* For writev and struct iovec. */
#include <sys/uio.h>
- /* For syslog. */
+/* For syslog. */
#include <sys/syslog.h>
+/* For various dynamic linking things. */
+#include <dlfcn.h>
+
+
/*
Debugging: