15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define BASE_ALLOCATOR_ALLOCATOR_EXTENSION_H
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <stddef.h> // for size_t
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/allocator/allocator_extension_thunks.h"
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/base_export.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "build/build_config.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace base {
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace allocator {
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Request the allocator to report value of its waste memory size.
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Waste size corresponds to memory that has been allocated from the OS but
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// not passed up to the application. It e.g. includes memory retained by free
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// lists, internal data, chunks padding, etc.
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// |size| pointer to the returned value, must be not NULL.
232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// Returns true if the value has been returned, false otherwise.
242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)BASE_EXPORT bool GetAllocatorWasteSize(size_t* size);
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Request that the allocator print a human-readable description of the current
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// state of the allocator into a null-terminated string in the memory segment
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// buffer[0,buffer_length-1].
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |buffer| must point to a valid piece of memory
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// |buffer_length| must be > 0.
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT void GetStats(char* buffer, int buffer_length);
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Request that the allocator release any free memory it knows about to the
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// system.
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT void ReleaseFreeMemory();
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// These settings allow specifying a callback used to implement the allocator
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// extension functions.  These are optional, but if set they must only be set
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// once.  These will typically called in an allocator-specific initialization
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// routine.
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// No threading promises are made.  The caller is responsible for making sure
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// these pointers are set before any other threads attempt to call the above
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// functions.
472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)BASE_EXPORT void SetGetAllocatorWasteSizeFunction(
482a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function);
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT void SetGetStatsFunction(
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    thunks::GetStatsFunction get_stats_function);
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)BASE_EXPORT void SetReleaseFreeMemoryFunction(
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    thunks::ReleaseFreeMemoryFunction release_free_memory_function);
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace allocator
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace base
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
60