OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/trace_event/malloc_dump_provider.h" | 5 #include "base/trace_event/malloc_dump_provider.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/allocator/allocator_extension.h" | 9 #include "base/allocator/allocator_extension.h" |
10 #include "base/allocator/allocator_shim.h" | 10 #include "base/allocator/allocator_shim.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 size_t n, | 47 size_t n, |
48 size_t size, | 48 size_t size, |
49 void* context) { | 49 void* context) { |
50 const AllocatorDispatch* const next = self->next; | 50 const AllocatorDispatch* const next = self->next; |
51 void* ptr = next->alloc_zero_initialized_function(next, n, size, context); | 51 void* ptr = next->alloc_zero_initialized_function(next, n, size, context); |
52 if (ptr) | 52 if (ptr) |
53 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, n * size); | 53 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, n * size); |
54 return ptr; | 54 return ptr; |
55 } | 55 } |
56 | 56 |
57 void* HookllocAligned(const AllocatorDispatch* self, | 57 void* HookAllocAligned(const AllocatorDispatch* self, |
58 size_t alignment, | 58 size_t alignment, |
59 size_t size, | 59 size_t size, |
60 void* context) { | 60 void* context) { |
61 const AllocatorDispatch* const next = self->next; | 61 const AllocatorDispatch* const next = self->next; |
62 void* ptr = next->alloc_aligned_function(next, alignment, size, context); | 62 void* ptr = next->alloc_aligned_function(next, alignment, size, context); |
63 if (ptr) | 63 if (ptr) |
64 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size); | 64 MallocDumpProvider::GetInstance()->InsertAllocation(ptr, size); |
65 return ptr; | 65 return ptr; |
66 } | 66 } |
67 | 67 |
68 void* HookRealloc(const AllocatorDispatch* self, | 68 void* HookRealloc(const AllocatorDispatch* self, |
69 void* address, | 69 void* address, |
70 size_t size, | 70 size_t size, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 void* context) { | 122 void* context) { |
123 if (ptr) | 123 if (ptr) |
124 MallocDumpProvider::GetInstance()->RemoveAllocation(ptr); | 124 MallocDumpProvider::GetInstance()->RemoveAllocation(ptr); |
125 const AllocatorDispatch* const next = self->next; | 125 const AllocatorDispatch* const next = self->next; |
126 next->free_definite_size_function(next, ptr, size, context); | 126 next->free_definite_size_function(next, ptr, size, context); |
127 } | 127 } |
128 | 128 |
129 AllocatorDispatch g_allocator_hooks = { | 129 AllocatorDispatch g_allocator_hooks = { |
130 &HookAlloc, /* alloc_function */ | 130 &HookAlloc, /* alloc_function */ |
131 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ | 131 &HookZeroInitAlloc, /* alloc_zero_initialized_function */ |
132 &HookllocAligned, /* alloc_aligned_function */ | 132 &HookAllocAligned, /* alloc_aligned_function */ |
133 &HookRealloc, /* realloc_function */ | 133 &HookRealloc, /* realloc_function */ |
134 &HookFree, /* free_function */ | 134 &HookFree, /* free_function */ |
135 &HookGetSizeEstimate, /* get_size_estimate_function */ | 135 &HookGetSizeEstimate, /* get_size_estimate_function */ |
136 &HookBatchMalloc, /* batch_malloc_function */ | 136 &HookBatchMalloc, /* batch_malloc_function */ |
137 &HookBatchFree, /* batch_free_function */ | 137 &HookBatchFree, /* batch_free_function */ |
138 &HookFreeDefiniteSize, /* free_definite_size_function */ | 138 &HookFreeDefiniteSize, /* free_definite_size_function */ |
139 nullptr, /* next */ | 139 nullptr, /* next */ |
140 }; | 140 }; |
141 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) | 141 #endif // BUILDFLAG(USE_EXPERIMENTAL_ALLOCATOR_SHIM) |
142 | 142 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 tid_dumping_heap_ == PlatformThread::CurrentId()) | 369 tid_dumping_heap_ == PlatformThread::CurrentId()) |
370 return; | 370 return; |
371 AutoLock lock(allocation_register_lock_); | 371 AutoLock lock(allocation_register_lock_); |
372 if (!allocation_register_) | 372 if (!allocation_register_) |
373 return; | 373 return; |
374 allocation_register_->Remove(address); | 374 allocation_register_->Remove(address); |
375 } | 375 } |
376 | 376 |
377 } // namespace trace_event | 377 } // namespace trace_event |
378 } // namespace base | 378 } // namespace base |
OLD | NEW |