48 lines
1.6 KiB
Diff
48 lines
1.6 KiB
Diff
|
From: Karl Tomlinson <mozbugz@karlt.net>
|
||
|
Subject: jemalloc integration cause crashes when libraries or plugins dlopen with RTLD_DEEPBIND
|
||
|
References:
|
||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=493541
|
||
|
https://bugzilla.novell.com/show_bug.cgi?id=503151
|
||
|
|
||
|
diff --git a/memory/jemalloc/jemalloc.c b/memory/jemalloc/jemalloc.c
|
||
|
--- a/memory/jemalloc/jemalloc.c
|
||
|
+++ b/memory/jemalloc/jemalloc.c
|
||
|
@@ -7225,8 +7225,37 @@ jemalloc_darwin_init(void)
|
||
|
* default zone.
|
||
|
*/
|
||
|
assert(malloc_num_zones > 1);
|
||
|
memmove(&malloc_zones[1], &malloc_zones[0],
|
||
|
sizeof(malloc_zone_t *) * (malloc_num_zones - 1));
|
||
|
malloc_zones[0] = &zone;
|
||
|
}
|
||
|
#endif
|
||
|
+
|
||
|
+#ifdef HAVE_LIBDL
|
||
|
+# include <dlfcn.h>
|
||
|
+/*
|
||
|
+ * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
|
||
|
+ * to inconsistently reference libc's malloc(3)-compatible functions
|
||
|
+ * (bug 493541).
|
||
|
+ *
|
||
|
+ * XXX On systems that support RTLD_GROUP or DF_1_GROUP, do their
|
||
|
+ * implementations permit similar inconsistencies? Should STV_SINGLETON
|
||
|
+ * visibility be used for interposition where available?
|
||
|
+ */
|
||
|
+# ifdef RTLD_DEEPBIND
|
||
|
+# if defined(__GLIBC__) && !defined(__UCLIBC__)
|
||
|
+
|
||
|
+/*
|
||
|
+ * These interpose hooks in glibc. They are actually passed an extra
|
||
|
+ * argument for the caller return address, which will be ignored.
|
||
|
+ */
|
||
|
+void (*__free_hook)(void *ptr) = free;
|
||
|
+void *(*__malloc_hook)(size_t size) = malloc;
|
||
|
+void *(*__realloc_hook)(void *ptr, size_t size) = realloc;
|
||
|
+void *(*__memalign_hook)(size_t alignment, size_t size) = memalign;
|
||
|
+
|
||
|
+# elif !defined(malloc)
|
||
|
+# error "Interposing malloc is unsafe on this system without libc malloc hooks."
|
||
|
+# endif
|
||
|
+# endif
|
||
|
+#endif
|