| OLD | NEW |
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, Google Inc. |
| 2 // All rights reserved. | 2 // All rights reserved. |
| 3 // | 3 // |
| 4 // Redistribution and use in source and binary forms, with or without | 4 // Redistribution and use in source and binary forms, with or without |
| 5 // modification, are permitted provided that the following conditions are | 5 // modification, are permitted provided that the following conditions are |
| 6 // met: | 6 // met: |
| 7 // | 7 // |
| 8 // * Redistributions of source code must retain the above copyright | 8 // * Redistributions of source code must retain the above copyright |
| 9 // notice, this list of conditions and the following disclaimer. | 9 // notice, this list of conditions and the following disclaimer. |
| 10 // * Redistributions in binary form must reproduce the above | 10 // * Redistributions in binary form must reproduce the above |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 void* __libc_memalign(size_t align, size_t s) { return memalign(align, s); } | 346 void* __libc_memalign(size_t align, size_t s) { return memalign(align, s); } |
| 347 void* __libc_valloc(size_t size) { return valloc(size); } | 347 void* __libc_valloc(size_t size) { return valloc(size); } |
| 348 void* __libc_pvalloc(size_t size) { return pvalloc(size); } | 348 void* __libc_pvalloc(size_t size) { return pvalloc(size); } |
| 349 int __posix_memalign(void** r, size_t a, size_t s) { | 349 int __posix_memalign(void** r, size_t a, size_t s) { |
| 350 return posix_memalign(r, a, s); | 350 return posix_memalign(r, a, s); |
| 351 } | 351 } |
| 352 #endif // #ifdef ALIAS | 352 #endif // #ifdef ALIAS |
| 353 } // extern "C" | 353 } // extern "C" |
| 354 #endif // ifdef __GLIBC__ | 354 #endif // ifdef __GLIBC__ |
| 355 | 355 |
| 356 #if defined(__GLIBC__) && defined(HAVE_MALLOC_H) |
| 357 // If we're using glibc, then override glibc malloc hooks to make sure that even |
| 358 // if calls fall through to ptmalloc (due to dlopen() with RTLD_DEEPBIND or what |
| 359 // not), ptmalloc will use TCMalloc. |
| 360 |
| 361 static void* tc_ptmalloc_malloc_hook(size_t size, const void* caller) { |
| 362 return tc_malloc(size); |
| 363 } |
| 364 |
| 365 static void* tc_ptmalloc_realloc_hook( |
| 366 void* ptr, size_t size, const void* caller) { |
| 367 return tc_realloc(ptr, size); |
| 368 } |
| 369 |
| 370 static void tc_ptmalloc_free_hook(void* ptr, const void* caller) { |
| 371 tc_free(ptr); |
| 372 } |
| 373 |
| 374 static void* tc_ptmalloc_memalign_hook( |
| 375 size_t alignment, size_t size, const void* caller) { |
| 376 return tc_memalign(alignment, size); |
| 377 } |
| 378 |
| 379 static void tc_ptmalloc_init_hook() { |
| 380 __malloc_hook = tc_ptmalloc_malloc_hook; |
| 381 __realloc_hook = tc_ptmalloc_realloc_hook; |
| 382 __free_hook = tc_ptmalloc_free_hook; |
| 383 __memalign_hook = tc_ptmalloc_memalign_hook; |
| 384 } |
| 385 |
| 386 void (*__malloc_initialize_hook)() = tc_ptmalloc_init_hook; |
| 387 |
| 388 #endif |
| 389 |
| 356 #endif // #ifndef _WIN32 | 390 #endif // #ifndef _WIN32 |
| 357 #undef ALIAS | 391 #undef ALIAS |
| 358 | 392 |
| 359 #endif // #ifndef(WIN32_DO_PATCHING) && ndef(TCMALLOC_FOR_DEBUGALLOCATION) | 393 #endif // #ifndef(WIN32_DO_PATCHING) && ndef(TCMALLOC_FOR_DEBUGALLOCATION) |
| 360 | 394 |
| 361 | 395 |
| 362 // ----------------------- IMPLEMENTATION ------------------------------- | 396 // ----------------------- IMPLEMENTATION ------------------------------- |
| 363 | 397 |
| 364 static int tc_new_mode = 0; // See tc_set_new_mode(). | 398 static int tc_new_mode = 0; // See tc_set_new_mode(). |
| 365 | 399 |
| (...skipping 1132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1498 __THROW ATTRIBUTE_SECTION(google_malloc); | 1532 __THROW ATTRIBUTE_SECTION(google_malloc); |
| 1499 | 1533 |
| 1500 static void *MemalignOverride(size_t align, size_t size, const void *caller) | 1534 static void *MemalignOverride(size_t align, size_t size, const void *caller) |
| 1501 __THROW { | 1535 __THROW { |
| 1502 void* result = do_memalign_or_cpp_memalign(align, size); | 1536 void* result = do_memalign_or_cpp_memalign(align, size); |
| 1503 MallocHook::InvokeNewHook(result, size); | 1537 MallocHook::InvokeNewHook(result, size); |
| 1504 return result; | 1538 return result; |
| 1505 } | 1539 } |
| 1506 void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride; | 1540 void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride; |
| 1507 #endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION | 1541 #endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION |
| OLD | NEW |