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 1728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1739 #if defined(OS_LINUX) | 1739 #if defined(OS_LINUX) |
1740 extern "C" void* PERFTOOLS_DLL_DECL tc_malloc_skip_new_handler(size_t size) { | 1740 extern "C" void* PERFTOOLS_DLL_DECL tc_malloc_skip_new_handler(size_t size) { |
1741 void* result = do_malloc(size); | 1741 void* result = do_malloc(size); |
1742 MallocHook::InvokeNewHook(result, size); | 1742 MallocHook::InvokeNewHook(result, size); |
1743 return result; | 1743 return result; |
1744 } | 1744 } |
1745 #endif | 1745 #endif |
1746 | 1746 |
1747 #endif // TCMALLOC_USING_DEBUGALLOCATION | 1747 #endif // TCMALLOC_USING_DEBUGALLOCATION |
1748 | 1748 |
1749 #if defined(OS_LINUX) | |
1750 // Alias the weak symbol in chromium to our implementation. | |
1751 extern "C" __attribute__((visibility("default"), alias("tc_malloc_skip_new_handl
er"))) | |
1752 void* tc_malloc_skip_new_handler_weak(size_t size); | |
1753 #endif | |
1754 | |
1755 // --- Validation implementation with an extra mark ---------------------------- | 1749 // --- Validation implementation with an extra mark ---------------------------- |
1756 // We will put a mark at the extreme end of each allocation block. We make | 1750 // We will put a mark at the extreme end of each allocation block. We make |
1757 // sure that we always allocate enough "extra memory" that we can fit in the | 1751 // sure that we always allocate enough "extra memory" that we can fit in the |
1758 // mark, and still provide the requested usable region. If ever that mark is | 1752 // mark, and still provide the requested usable region. If ever that mark is |
1759 // not as expected, then we know that the user is corrupting memory beyond their | 1753 // not as expected, then we know that the user is corrupting memory beyond their |
1760 // request size, or that they have called free a second time without having | 1754 // request size, or that they have called free a second time without having |
1761 // the memory allocated (again). This allows us to spot most double free()s, | 1755 // the memory allocated (again). This allows us to spot most double free()s, |
1762 // but some can "slip by" or confuse our logic if the caller reallocates memory | 1756 // but some can "slip by" or confuse our logic if the caller reallocates memory |
1763 // (for a second use) before performing an evil double-free of a first | 1757 // (for a second use) before performing an evil double-free of a first |
1764 // allocation | 1758 // allocation |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1902 *mark = ~allocated_mark; // Distinctively not allocated. | 1896 *mark = ~allocated_mark; // Distinctively not allocated. |
1903 } | 1897 } |
1904 | 1898 |
1905 static void MarkAllocatedRegion(void* ptr) { | 1899 static void MarkAllocatedRegion(void* ptr) { |
1906 if (ptr == NULL) return; | 1900 if (ptr == NULL) return; |
1907 MarkType* mark = GetMarkLocation(ptr); | 1901 MarkType* mark = GetMarkLocation(ptr); |
1908 *mark = GetMarkValue(ptr, mark); | 1902 *mark = GetMarkValue(ptr, mark); |
1909 } | 1903 } |
1910 | 1904 |
1911 #endif // TCMALLOC_VALIDATION | 1905 #endif // TCMALLOC_VALIDATION |
OLD | NEW |