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 1703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1714 return do_mallinfo(); | 1714 return do_mallinfo(); |
1715 } | 1715 } |
1716 #endif | 1716 #endif |
1717 | 1717 |
1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { | 1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { |
1719 return MallocExtension::instance()->GetAllocatedSize(ptr); | 1719 return MallocExtension::instance()->GetAllocatedSize(ptr); |
1720 } | 1720 } |
1721 | 1721 |
1722 #endif // TCMALLOC_USING_DEBUGALLOCATION | 1722 #endif // TCMALLOC_USING_DEBUGALLOCATION |
1723 | 1723 |
| 1724 // Define the strong symbol that overrides tc_malloc_skip_new_handler_weak |
| 1725 // in chromium. |
| 1726 #if defined(OS_LINUX) |
| 1727 extern "C" { |
| 1728 |
| 1729 void* tc_malloc_skip_new_handler(size_t size) { |
| 1730 void* result = do_malloc(size); |
| 1731 MallocHook::InvokeNewHook(result, size); |
| 1732 return result; |
| 1733 } |
| 1734 |
| 1735 __attribute__((visibility("default"), alias("tc_malloc_skip_new_handler"))) |
| 1736 void* tc_malloc_skip_new_handler_weak(size_t size); |
| 1737 |
| 1738 } |
| 1739 #endif |
| 1740 |
1724 // --- Validation implementation with an extra mark ---------------------------- | 1741 // --- Validation implementation with an extra mark ---------------------------- |
1725 // We will put a mark at the extreme end of each allocation block. We make | 1742 // 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 | 1743 // 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 | 1744 // 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 | 1745 // 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 | 1746 // 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, | 1747 // 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 | 1748 // but some can "slip by" or confuse our logic if the caller reallocates memory |
1732 // (for a second use) before performing an evil double-free of a first | 1749 // (for a second use) before performing an evil double-free of a first |
1733 // allocation | 1750 // allocation |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1871 *mark = ~allocated_mark; // Distinctively not allocated. | 1888 *mark = ~allocated_mark; // Distinctively not allocated. |
1872 } | 1889 } |
1873 | 1890 |
1874 static void MarkAllocatedRegion(void* ptr) { | 1891 static void MarkAllocatedRegion(void* ptr) { |
1875 if (ptr == NULL) return; | 1892 if (ptr == NULL) return; |
1876 MarkType* mark = GetMarkLocation(ptr); | 1893 MarkType* mark = GetMarkLocation(ptr); |
1877 *mark = GetMarkValue(ptr, mark); | 1894 *mark = GetMarkValue(ptr, mark); |
1878 } | 1895 } |
1879 | 1896 |
1880 #endif // TCMALLOC_VALIDATION | 1897 #endif // TCMALLOC_VALIDATION |
OLD | NEW |