diff options
author | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 22:51:11 +0000 |
---|---|---|
committer | willchan@chromium.org <willchan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 22:51:11 +0000 |
commit | 3d51bb8d552d342896c22a9847eafc594c49f3bd (patch) | |
tree | 6c042358c1fa00b93dbe9b898c4170990618796e /third_party | |
parent | 61a86c4d5644817d291e7f22ffd0b0b5cef56295 (diff) | |
download | chromium_src-3d51bb8d552d342896c22a9847eafc594c49f3bd.zip chromium_src-3d51bb8d552d342896c22a9847eafc594c49f3bd.tar.gz chromium_src-3d51bb8d552d342896c22a9847eafc594c49f3bd.tar.bz2 |
Linux: Make TCMalloc override ptmalloc hooks.
Certain libraries still seem to fall through to ptmalloc. At least one cause seems to be because some libraries dynamically load other libraries via dlopen() invoked with RTLD_DEEPBIND. Therefore, we override ptmalloc's hooks to pass through to TCMalloc. This is suboptimal since it adds an extra function call per malloc()/realloc()/free()/memalign() invocation, but it should catch all cases where the library does not correctly allow for malloc implementation overrides.
BUG=38692
Review URL: http://codereview.chromium.org/1665005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'third_party')
-rw-r--r-- | third_party/tcmalloc/chromium/src/tcmalloc.cc | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/third_party/tcmalloc/chromium/src/tcmalloc.cc b/third_party/tcmalloc/chromium/src/tcmalloc.cc index e48be77..cb45b0e 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 |