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

Side by Side Diff: third_party/tcmalloc/chromium/src/tcmalloc.cc

Issue 2830035: tc_malloc_usable_size impl (Closed)
Patch Set: ok Created 10 years, 5 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 void* memalign(size_t align, size_t s) __THROW ALIAS("tc_memalign"); 275 void* memalign(size_t align, size_t s) __THROW ALIAS("tc_memalign");
276 void* valloc(size_t size) __THROW ALIAS("tc_valloc"); 276 void* valloc(size_t size) __THROW ALIAS("tc_valloc");
277 void* pvalloc(size_t size) __THROW ALIAS("tc_pvalloc"); 277 void* pvalloc(size_t size) __THROW ALIAS("tc_pvalloc");
278 int posix_memalign(void** r, size_t a, size_t s) __THROW 278 int posix_memalign(void** r, size_t a, size_t s) __THROW
279 ALIAS("tc_posix_memalign"); 279 ALIAS("tc_posix_memalign");
280 void malloc_stats(void) __THROW ALIAS("tc_malloc_stats"); 280 void malloc_stats(void) __THROW ALIAS("tc_malloc_stats");
281 int mallopt(int cmd, int value) __THROW ALIAS("tc_mallopt"); 281 int mallopt(int cmd, int value) __THROW ALIAS("tc_mallopt");
282 #ifdef HAVE_STRUCT_MALLINFO 282 #ifdef HAVE_STRUCT_MALLINFO
283 struct mallinfo mallinfo(void) __THROW ALIAS("tc_mallinfo"); 283 struct mallinfo mallinfo(void) __THROW ALIAS("tc_mallinfo");
284 #endif 284 #endif
285 size_t malloc_usable_size(void* ptr) __THROW ALIAS("tc_malloc_usable_size");
285 } // extern "C" 286 } // extern "C"
286 #else // #if defined(__GNUC__) && !defined(__MACH__) 287 #else // #if defined(__GNUC__) && !defined(__MACH__)
287 // Portable wrappers 288 // Portable wrappers
288 void* operator new(size_t size) { return tc_new(size); } 289 void* operator new(size_t size) { return tc_new(size); }
289 void operator delete(void* p) __THROW { tc_delete(p); } 290 void operator delete(void* p) __THROW { tc_delete(p); }
290 void* operator new[](size_t size) { return tc_newarray(size); } 291 void* operator new[](size_t size) { return tc_newarray(size); }
291 void operator delete[](void* p) __THROW { tc_deletearray(p); } 292 void operator delete[](void* p) __THROW { tc_deletearray(p); }
292 void* operator new(size_t size, const std::nothrow_t& nt) __THROW { 293 void* operator new(size_t size, const std::nothrow_t& nt) __THROW {
293 return tc_new_nothrow(size, nt); 294 return tc_new_nothrow(size, nt);
294 } 295 }
(...skipping 16 matching lines...) Expand all
311 void* valloc(size_t s) __THROW { return tc_valloc(s); } 312 void* valloc(size_t s) __THROW { return tc_valloc(s); }
312 void* pvalloc(size_t s) __THROW { return tc_pvalloc(s); } 313 void* pvalloc(size_t s) __THROW { return tc_pvalloc(s); }
313 int posix_memalign(void** r, size_t a, size_t s) __THROW { 314 int posix_memalign(void** r, size_t a, size_t s) __THROW {
314 return tc_posix_memalign(r, a, s); 315 return tc_posix_memalign(r, a, s);
315 } 316 }
316 void malloc_stats(void) __THROW { tc_malloc_stats(); } 317 void malloc_stats(void) __THROW { tc_malloc_stats(); }
317 int mallopt(int cmd, int v) __THROW { return tc_mallopt(cmd, v); } 318 int mallopt(int cmd, int v) __THROW { return tc_mallopt(cmd, v); }
318 #ifdef HAVE_STRUCT_MALLINFO 319 #ifdef HAVE_STRUCT_MALLINFO
319 struct mallinfo mallinfo(void) __THROW { return tc_mallinfo(); } 320 struct mallinfo mallinfo(void) __THROW { return tc_mallinfo(); }
320 #endif 321 #endif
322 size_t malloc_usable_size(void* p) __THROW {
323 return tc_malloc_usable_size(p);
324 }
321 } // extern "C" 325 } // extern "C"
322 #endif // #if defined(__GNUC__) 326 #endif // #if defined(__GNUC__)
323 327
324 // Some library routines on RedHat 9 allocate memory using malloc() 328 // Some library routines on RedHat 9 allocate memory using malloc()
325 // and free it using __libc_free() (or vice-versa). Since we provide 329 // and free it using __libc_free() (or vice-versa). Since we provide
326 // our own implementations of malloc/free, we need to make sure that 330 // our own implementations of malloc/free, we need to make sure that
327 // the __libc_XXX variants (defined as part of glibc) also point to 331 // the __libc_XXX variants (defined as part of glibc) also point to
328 // the same implementations. 332 // the same implementations.
329 #ifdef __GLIBC__ // only glibc defines __libc_* 333 #ifdef __GLIBC__ // only glibc defines __libc_*
330 extern "C" { 334 extern "C" {
(...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 extern "C" PERFTOOLS_DLL_DECL int tc_mallopt(int cmd, int value) __THROW { 1522 extern "C" PERFTOOLS_DLL_DECL int tc_mallopt(int cmd, int value) __THROW {
1519 return do_mallopt(cmd, value); 1523 return do_mallopt(cmd, value);
1520 } 1524 }
1521 1525
1522 #ifdef HAVE_STRUCT_MALLINFO 1526 #ifdef HAVE_STRUCT_MALLINFO
1523 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { 1527 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW {
1524 return do_mallinfo(); 1528 return do_mallinfo();
1525 } 1529 }
1526 #endif 1530 #endif
1527 1531
1532 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_usable_size(void* ptr) __THROW {
1533 return GetSizeWithCallback(ptr, &InvalidGetAllocatedSize);
1534 }
1535
1528 // This function behaves similarly to MSVC's _set_new_mode. 1536 // This function behaves similarly to MSVC's _set_new_mode.
1529 // If flag is 0 (default), calls to malloc will behave normally. 1537 // If flag is 0 (default), calls to malloc will behave normally.
1530 // If flag is 1, calls to malloc will behave like calls to new, 1538 // If flag is 1, calls to malloc will behave like calls to new,
1531 // and the std_new_handler will be invoked on failure. 1539 // and the std_new_handler will be invoked on failure.
1532 // Returns the previous mode. 1540 // Returns the previous mode.
1533 extern "C" PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW { 1541 extern "C" PERFTOOLS_DLL_DECL int tc_set_new_mode(int flag) __THROW {
1534 int old_mode = tc_new_mode; 1542 int old_mode = tc_new_mode;
1535 tc_new_mode = flag; 1543 tc_new_mode = flag;
1536 return old_mode; 1544 return old_mode;
1537 } 1545 }
(...skipping 11 matching lines...) Expand all
1549 __THROW ATTRIBUTE_SECTION(google_malloc); 1557 __THROW ATTRIBUTE_SECTION(google_malloc);
1550 1558
1551 static void *MemalignOverride(size_t align, size_t size, const void *caller) 1559 static void *MemalignOverride(size_t align, size_t size, const void *caller)
1552 __THROW { 1560 __THROW {
1553 void* result = do_memalign_or_cpp_memalign(align, size); 1561 void* result = do_memalign_or_cpp_memalign(align, size);
1554 MallocHook::InvokeNewHook(result, size); 1562 MallocHook::InvokeNewHook(result, size);
1555 return result; 1563 return result;
1556 } 1564 }
1557 void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride; 1565 void *(*__memalign_hook)(size_t, size_t, const void *) = MemalignOverride;
1558 #endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION 1566 #endif // #ifndef TCMALLOC_FOR_DEBUGALLOCATION
OLDNEW
« 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