Chromium Code Reviews| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 109 #include <algorithm> // for max, min | 109 #include <algorithm> // for max, min |
| 110 #include <limits> // for numeric_limits | 110 #include <limits> // for numeric_limits |
| 111 #include <new> // for nothrow_t (ptr only), etc | 111 #include <new> // for nothrow_t (ptr only), etc |
| 112 #include <vector> // for vector | 112 #include <vector> // for vector |
| 113 | 113 |
| 114 #include <gperftools/malloc_extension.h> | 114 #include <gperftools/malloc_extension.h> |
| 115 #include <gperftools/malloc_hook.h> // for MallocHook | 115 #include <gperftools/malloc_hook.h> // for MallocHook |
| 116 #include "base/basictypes.h" // for int64 | 116 #include "base/basictypes.h" // for int64 |
| 117 #include "base/commandlineflags.h" // for RegisterFlagValidator, etc | 117 #include "base/commandlineflags.h" // for RegisterFlagValidator, etc |
| 118 #include "base/dynamic_annotations.h" // for RunningOnValgrind | 118 #include "base/dynamic_annotations.h" // for RunningOnValgrind |
| 119 #include "base/process/memory.h" // for UncheckedMalloc | |
| 119 #include "base/spinlock.h" // for SpinLockHolder | 120 #include "base/spinlock.h" // for SpinLockHolder |
| 120 #include "central_freelist.h" // for CentralFreeListPadded | 121 #include "central_freelist.h" // for CentralFreeListPadded |
| 121 #include "common.h" // for StackTrace, kPageShift, etc | 122 #include "common.h" // for StackTrace, kPageShift, etc |
| 122 #include "free_list.h" // for FL_Init | 123 #include "free_list.h" // for FL_Init |
| 123 #include "internal_logging.h" // for ASSERT, TCMalloc_Printer, etc | 124 #include "internal_logging.h" // for ASSERT, TCMalloc_Printer, etc |
| 124 #include "malloc_hook-inl.h" // for MallocHook::InvokeNewHook, etc | 125 #include "malloc_hook-inl.h" // for MallocHook::InvokeNewHook, etc |
| 125 #include "page_heap.h" // for PageHeap, PageHeap::Stats | 126 #include "page_heap.h" // for PageHeap, PageHeap::Stats |
| 126 #include "page_heap_allocator.h" // for PageHeapAllocator | 127 #include "page_heap_allocator.h" // for PageHeapAllocator |
| 127 #include "span.h" // for Span, DLL_Prepend, etc | 128 #include "span.h" // for Span, DLL_Prepend, etc |
| 128 #include "stack_trace_table.h" // for StackTraceTable | 129 #include "stack_trace_table.h" // for StackTraceTable |
| (...skipping 1583 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1712 #ifdef HAVE_STRUCT_MALLINFO | 1713 #ifdef HAVE_STRUCT_MALLINFO |
| 1713 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { | 1714 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { |
| 1714 return do_mallinfo(); | 1715 return do_mallinfo(); |
| 1715 } | 1716 } |
| 1716 #endif | 1717 #endif |
| 1717 | 1718 |
| 1718 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { | 1719 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { |
| 1719 return MallocExtension::instance()->GetAllocatedSize(ptr); | 1720 return MallocExtension::instance()->GetAllocatedSize(ptr); |
| 1720 } | 1721 } |
| 1721 | 1722 |
| 1723 namespace base { | |
|
willchan no longer on Chromium
2013/11/02 21:11:44
Ditto here on the layering violation.
| |
| 1724 | |
| 1725 void* UncheckedMalloc(size_t size) { | |
| 1726 void* result = do_malloc(size); | |
| 1727 MallocHook::InvokeNewHook(result, size); | |
| 1728 return result; | |
| 1729 } | |
| 1730 | |
| 1731 } | |
| 1732 | |
| 1722 #endif // TCMALLOC_USING_DEBUGALLOCATION | 1733 #endif // TCMALLOC_USING_DEBUGALLOCATION |
| 1723 | 1734 |
| 1724 // --- Validation implementation with an extra mark ---------------------------- | 1735 // --- Validation implementation with an extra mark ---------------------------- |
| 1725 // We will put a mark at the extreme end of each allocation block. We make | 1736 // 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 | 1737 // 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 | 1738 // 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 | 1739 // 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 | 1740 // 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, | 1741 // 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 | 1742 // 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. | 1882 *mark = ~allocated_mark; // Distinctively not allocated. |
| 1872 } | 1883 } |
| 1873 | 1884 |
| 1874 static void MarkAllocatedRegion(void* ptr) { | 1885 static void MarkAllocatedRegion(void* ptr) { |
| 1875 if (ptr == NULL) return; | 1886 if (ptr == NULL) return; |
| 1876 MarkType* mark = GetMarkLocation(ptr); | 1887 MarkType* mark = GetMarkLocation(ptr); |
| 1877 *mark = GetMarkValue(ptr, mark); | 1888 *mark = GetMarkValue(ptr, mark); |
| 1878 } | 1889 } |
| 1879 | 1890 |
| 1880 #endif // TCMALLOC_VALIDATION | 1891 #endif // TCMALLOC_VALIDATION |
| OLD | NEW |