Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Unified Diff: third_party/tcmalloc/chromium/src/tcmalloc.cc

Issue 1665005: Linux: Make TCMalloc override ptmalloc hooks. (Closed)
Patch Set: Update change to new location. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/tcmalloc/chromium/src/tcmalloc.cc
diff --git a/third_party/tcmalloc/chromium/src/tcmalloc.cc b/third_party/tcmalloc/chromium/src/tcmalloc.cc
index e48be775bc65d8fae5d4e86e1d6b0b7800d91280..cb45b0e55026ada7a757bbedc181aa63f91967bf 100644
--- a/third_party/tcmalloc/chromium/src/tcmalloc.cc
+++ b/third_party/tcmalloc/chromium/src/tcmalloc.cc
@@ -353,6 +353,40 @@ extern "C" {
} // extern "C"
#endif // ifdef __GLIBC__
+#if defined(__GLIBC__) && defined(HAVE_MALLOC_H)
+// If we're using glibc, then override glibc malloc hooks to make sure that even
+// if calls fall through to ptmalloc (due to dlopen() with RTLD_DEEPBIND or what
+// not), ptmalloc will use TCMalloc.
+
+static void* tc_ptmalloc_malloc_hook(size_t size, const void* caller) {
+ return tc_malloc(size);
+}
+
+static void* tc_ptmalloc_realloc_hook(
+ void* ptr, size_t size, const void* caller) {
+ return tc_realloc(ptr, size);
+}
+
+static void tc_ptmalloc_free_hook(void* ptr, const void* caller) {
+ tc_free(ptr);
+}
+
+static void* tc_ptmalloc_memalign_hook(
+ size_t alignment, size_t size, const void* caller) {
+ return tc_memalign(alignment, size);
+}
+
+static void tc_ptmalloc_init_hook() {
+ __malloc_hook = tc_ptmalloc_malloc_hook;
+ __realloc_hook = tc_ptmalloc_realloc_hook;
+ __free_hook = tc_ptmalloc_free_hook;
+ __memalign_hook = tc_ptmalloc_memalign_hook;
+}
+
+void (*__malloc_initialize_hook)() = tc_ptmalloc_init_hook;
+
+#endif
+
#endif // #ifndef _WIN32
#undef ALIAS
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698