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 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 ATTRIBUTE_SECTION(google_malloc); | 262 ATTRIBUTE_SECTION(google_malloc); |
263 | 263 |
264 // Some non-standard extensions that we support. | 264 // Some non-standard extensions that we support. |
265 | 265 |
266 // This is equivalent to | 266 // This is equivalent to |
267 // OS X: malloc_size() | 267 // OS X: malloc_size() |
268 // glibc: malloc_usable_size() | 268 // glibc: malloc_usable_size() |
269 // Windows: _msize() | 269 // Windows: _msize() |
270 size_t tc_malloc_size(void* p) __THROW | 270 size_t tc_malloc_size(void* p) __THROW |
271 ATTRIBUTE_SECTION(google_malloc); | 271 ATTRIBUTE_SECTION(google_malloc); |
| 272 |
| 273 void* tc_malloc_skip_new_handler(size_t size) __THROW |
| 274 ATTRIBUTE_SECTION(google_malloc); |
272 } // extern "C" | 275 } // extern "C" |
273 | 276 |
274 | 277 |
275 // ----------------------- IMPLEMENTATION ------------------------------- | 278 // ----------------------- IMPLEMENTATION ------------------------------- |
276 | 279 |
277 static int tc_new_mode = 0; // See tc_set_new_mode(). | 280 static int tc_new_mode = 0; // See tc_set_new_mode(). |
278 | 281 |
279 // Routines such as free() and realloc() catch some erroneous pointers | 282 // Routines such as free() and realloc() catch some erroneous pointers |
280 // passed to them, and invoke the below when they do. (An erroneous pointer | 283 // passed to them, and invoke the below when they do. (An erroneous pointer |
281 // won't be caught if it's within a valid span or a stale span for which | 284 // won't be caught if it's within a valid span or a stale span for which |
(...skipping 1430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 #ifdef HAVE_STRUCT_MALLINFO | 1715 #ifdef HAVE_STRUCT_MALLINFO |
1713 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { | 1716 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { |
1714 return do_mallinfo(); | 1717 return do_mallinfo(); |
1715 } | 1718 } |
1716 #endif | 1719 #endif |
1717 | 1720 |
1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { | 1721 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { |
1719 return MallocExtension::instance()->GetAllocatedSize(ptr); | 1722 return MallocExtension::instance()->GetAllocatedSize(ptr); |
1720 } | 1723 } |
1721 | 1724 |
| 1725 extern "C" PERFTOOLS_DLL_DECL void* tc_malloc_skip_new_handler(size_t size) |
| 1726 __THROW { |
| 1727 void* result = do_malloc(size); |
| 1728 MallocHook::InvokeNewHook(result, size); |
| 1729 return result; |
| 1730 } |
| 1731 |
1722 #endif // TCMALLOC_USING_DEBUGALLOCATION | 1732 #endif // TCMALLOC_USING_DEBUGALLOCATION |
1723 | 1733 |
1724 // --- Validation implementation with an extra mark ---------------------------- | 1734 // --- Validation implementation with an extra mark ---------------------------- |
1725 // We will put a mark at the extreme end of each allocation block. We make | 1735 // We will put a mark at the extreme end of each allocation block. We make |
1726 // sure that we always allocate enough "extra memory" that we can fit in the | 1736 // sure that we always allocate enough "extra memory" that we can fit in the |
1727 // mark, and still provide the requested usable region. If ever that mark is | 1737 // mark, and still provide the requested usable region. If ever that mark is |
1728 // not as expected, then we know that the user is corrupting memory beyond their | 1738 // not as expected, then we know that the user is corrupting memory beyond their |
1729 // request size, or that they have called free a second time without having | 1739 // request size, or that they have called free a second time without having |
1730 // the memory allocated (again). This allows us to spot most double free()s, | 1740 // the memory allocated (again). This allows us to spot most double free()s, |
1731 // but some can "slip by" or confuse our logic if the caller reallocates memory | 1741 // but some can "slip by" or confuse our logic if the caller reallocates memory |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 *mark = ~allocated_mark; // Distinctively not allocated. | 1881 *mark = ~allocated_mark; // Distinctively not allocated. |
1872 } | 1882 } |
1873 | 1883 |
1874 static void MarkAllocatedRegion(void* ptr) { | 1884 static void MarkAllocatedRegion(void* ptr) { |
1875 if (ptr == NULL) return; | 1885 if (ptr == NULL) return; |
1876 MarkType* mark = GetMarkLocation(ptr); | 1886 MarkType* mark = GetMarkLocation(ptr); |
1877 *mark = GetMarkValue(ptr, mark); | 1887 *mark = GetMarkValue(ptr, mark); |
1878 } | 1888 } |
1879 | 1889 |
1880 #endif // TCMALLOC_VALIDATION | 1890 #endif // TCMALLOC_VALIDATION |
OLD | NEW |