Home | History | Annotate | Download | only in allocator
      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
      3 // found in the LICENSE file.
      4 
      5 #ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
      6 #define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
      7 
      8 #include <stddef.h> // for size_t
      9 
     10 #include "base/base_export.h"
     11 #include "build/build_config.h"
     12 
     13 namespace base {
     14 namespace allocator {
     15 
     16 // Callback types for alloc and free.
     17 using AllocHookFunc = void (*)(const void*, size_t);
     18 using FreeHookFunc = void (*)(const void*);
     19 
     20 // Request that the allocator release any free memory it knows about to the
     21 // system.
     22 BASE_EXPORT void ReleaseFreeMemory();
     23 
     24 // Get the named property's |value|. Returns true if the property is known.
     25 // Returns false if the property is not a valid property name for the current
     26 // allocator implementation.
     27 // |name| or |value| cannot be NULL
     28 BASE_EXPORT bool GetNumericProperty(const char* name, size_t* value);
     29 
     30 BASE_EXPORT bool IsHeapProfilerRunning();
     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 
     48 }  // namespace allocator
     49 }  // namespace base
     50 
     51 #endif  // BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H_
     52