OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ | 5 #ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ |
6 #define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ | 6 #define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ |
7 | 7 |
8 #include <stddef.h> // for size_t | 8 #include <stddef.h> // for size_t |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 namespace allocator { | 14 namespace allocator { |
15 | 15 |
| 16 // Callback types for alloc and free. |
| 17 using AllocHookFunc = void (*)(const void*, size_t); |
| 18 using FreeHookFunc = void (*)(const void*); |
| 19 |
16 // Request that the allocator release any free memory it knows about to the | 20 // Request that the allocator release any free memory it knows about to the |
17 // system. | 21 // system. |
18 BASE_EXPORT void ReleaseFreeMemory(); | 22 BASE_EXPORT void ReleaseFreeMemory(); |
19 | 23 |
20 // Get the named property's |value|. Returns true if the property is known. | 24 // Get the named property's |value|. Returns true if the property is known. |
21 // Returns false if the property is not a valid property name for the current | 25 // Returns false if the property is not a valid property name for the current |
22 // allocator implementation. | 26 // allocator implementation. |
23 // |name| or |value| cannot be NULL | 27 // |name| or |value| cannot be NULL |
24 BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value); | 28 BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value); |
25 | 29 |
26 BASE_EXPORT bool IsHeapProfilerRunning(); | 30 BASE_EXPORT bool IsHeapProfilerRunning(); |
27 | 31 |
| 32 // Register callbacks for alloc and free. Can only store one callback at a time |
| 33 // for each of alloc and free. |
| 34 BASE_EXPORT void SetHooks(AllocHookFunc alloc_hook, FreeHookFunc free_hook); |
| 35 |
| 36 // Attempts to unwind the call stack from the current location where this |
| 37 // function is being called from. Must be called from a hook function registered |
| 38 // by calling SetSingle{Alloc,Free}Hook, directly or indirectly. |
| 39 // |
| 40 // Arguments: |
| 41 // stack: pointer to a pre-allocated array of void*'s. |
| 42 // max_stack_size: indicates the size of the array in |stack|. |
| 43 // |
| 44 // Returns the number of call stack frames stored in |stack|, or 0 if no call |
| 45 // stack information is available. |
| 46 BASE_EXPORT int GetCallStack(void** stack, int max_stack_size); |
| 47 |
28 } // namespace allocator | 48 } // namespace allocator |
29 } // namespace base | 49 } // namespace base |
30 | 50 |
31 #endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ | 51 #endif // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_ |
OLD | NEW |