Chromium Code Reviews| Index: base/allocator/allocator_extension.h |
| diff --git a/base/allocator/allocator_extension.h b/base/allocator/allocator_extension.h |
| index 64bfd1cc4acaa3fe2a8fc1e8f80ab1fe674f3856..e234f1cf22c87c31e5f1347ecba07efd48639e74 100644 |
| --- a/base/allocator/allocator_extension.h |
| +++ b/base/allocator/allocator_extension.h |
| @@ -7,12 +7,18 @@ |
| #include <stddef.h> // for size_t |
| +#include <type_traits> // for std::add_pointer |
| + |
| #include "base/base_export.h" |
| #include "build/build_config.h" |
| namespace base { |
| namespace allocator { |
| +// Callback types for alloc and free. |
| +using AllocHookFunc = std::add_pointer<void(const void*, size_t)>::type; |
|
Primiano Tucci (use gerrit)
2016/03/01 18:54:37
What is the benefit of std::add_pointer as opposit
|
| +using FreeHookFunc = std::add_pointer<void(const void*)>::type; |
| + |
| // Request that the allocator release any free memory it knows about to the |
| // system. |
| BASE_EXPORT void ReleaseFreeMemory(); |
| @@ -25,6 +31,32 @@ BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value); |
| BASE_EXPORT bool IsHeapProfilerRunning(); |
| +// Register callbacks for alloc and free. Can only store one callback at a time |
| +// for each of alloc and free. Returns the previously stored hook function, or |
| +// nullptr if none was stored. |
| +BASE_EXPORT AllocHookFunc SetSingleAllocHook(AllocHookFunc func); |
|
Primiano Tucci (use gerrit)
2016/03/01 18:54:37
I'd drop Single from the name. The fact that you h
|
| +BASE_EXPORT FreeHookFunc SetSingleFreeHook(FreeHookFunc func); |
| + |
| +// Returns the currently stored alloc/free callbacks that were registered by |
| +// calling SetSingle{Alloc,Free}Hook(). |
| +BASE_EXPORT AllocHookFunc GetSingleAllocHook(); |
| +BASE_EXPORT FreeHookFunc GetSingleFreeHook(); |
| + |
| +// Attempts to unwind the call stack from the current location where this |
| +// function is being called from. Must be called from a hook function registered |
| +// by calling SetSingle{Alloc,Free}Hook, directly or indirectly. |
| +// |
| +// Arguments: |
| +// stack: pointer to a pre-allocated array of void*'s. |
| +// max_stack_size: indicates the size of the array in |stack|. |
| +// skip_count: Indicates how many initial call stack levels to skip before |
|
Primiano Tucci (use gerrit)
2016/03/01 18:54:36
It looks like this is really not used in the .cc f
|
| +// storing the caller of alloc/free. This value might not be |
| +// used, depending on the specific implementation. |
| +// |
| +// Returns the number of call stack frames stored in |stack|, or 0 if no call |
| +// stack information is available. |
| +BASE_EXPORT int GetCallStack(void** stack, int max_stack_size, int skip_count); |
| + |
| } // namespace allocator |
| } // namespace base |