summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Evans <je@fb.com>2012-02-29 18:37:27 (GMT)
committerJason Evans <je@fb.com>2012-02-29 18:37:27 (GMT)
commit4bb09830133ffa8b27a95bc3727558007722c152 (patch)
tree12c17283304c231e3cced2acae24f5ad8271f29c /src
parent5965631636c620fba2eb33698accee75fd207aab (diff)
downloadjemalloc-4bb09830133ffa8b27a95bc3727558007722c152.zip
jemalloc-4bb09830133ffa8b27a95bc3727558007722c152.tar.gz
jemalloc-4bb09830133ffa8b27a95bc3727558007722c152.tar.bz2
Use glibc allocator hooks.
When jemalloc is used as a libc malloc replacement (i.e. not prefixed), some particular setups may end up inconsistently calling malloc from libc and free from jemalloc, or the other way around. glibc provides hooks to make its functions use alternative implementations. Use them. Submitted by Karl Tomlinson and Mike Hommey.
Diffstat (limited to 'src')
-rw-r--r--src/jemalloc.c24
-rw-r--r--src/mutex.c4
2 files changed, 28 insertions, 0 deletions
diff --git a/src/jemalloc.c b/src/jemalloc.c
index 535efaa..ccc3a20 100644
--- a/src/jemalloc.c
+++ b/src/jemalloc.c
@@ -1272,6 +1272,30 @@ JEMALLOC_P(valloc)(size_t size)
}
#endif
+#if defined(__GLIBC__) && !defined(__UCLIBC__)
+/*
+ * glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible
+ * to inconsistently reference libc's malloc(3)-compatible functions
+ * (https://bugzilla.mozilla.org/show_bug.cgi?id=493541).
+ *
+ * These definitions interpose hooks in glibc.  The functions are actually
+ * passed an extra argument for the caller return address, which will be
+ * ignored.
+ */
+JEMALLOC_ATTR(visibility("default"))
+void (* const __free_hook)(void *ptr) = JEMALLOC_P(free);
+
+JEMALLOC_ATTR(visibility("default"))
+void *(* const __malloc_hook)(size_t size) = JEMALLOC_P(malloc);
+
+JEMALLOC_ATTR(visibility("default"))
+void *(* const __realloc_hook)(void *ptr, size_t size) = JEMALLOC_P(realloc);
+
+JEMALLOC_ATTR(visibility("default"))
+void *(* const __memalign_hook)(size_t alignment, size_t size) =
+ JEMALLOC_P(memalign);
+#endif
+
#endif /* JEMALLOC_PREFIX */
/*
* End non-standard override functions.
diff --git a/src/mutex.c b/src/mutex.c
index ca89ef1..0e09060 100644
--- a/src/mutex.c
+++ b/src/mutex.c
@@ -1,6 +1,10 @@
#define JEMALLOC_MUTEX_C_
#include "jemalloc/internal/jemalloc_internal.h"
+#ifdef JEMALLOC_LAZY_LOCK
+#include <dlfcn.h>
+#endif
+
/******************************************************************************/
/* Data. */