allocator_interface.h revision 276851
1169689Skan//===-- allocator_interface.h ---------------------------------------------===//
2122180Skan//
3132718Skan//                     The LLVM Compiler Infrastructure
4122180Skan//
5132718Skan// This file is distributed under the University of Illinois Open Source
6122180Skan// License. See LICENSE.TXT for details.
7122180Skan//
8122180Skan//===----------------------------------------------------------------------===//
9122180Skan//
10132718Skan// Public interface header for allocator used in sanitizers (ASan/TSan/MSan).
11122180Skan//===----------------------------------------------------------------------===//
12122180Skan#ifndef SANITIZER_ALLOCATOR_INTERFACE_H
13122180Skan#define SANITIZER_ALLOCATOR_INTERFACE_H
14122180Skan
15122180Skan#include <stddef.h>
16132718Skan
17169689Skan#ifdef __cplusplus
18169689Skanextern "C" {
19122180Skan#endif
20122180Skan  /* Returns the estimated number of bytes that will be reserved by allocator
21122180Skan     for request of "size" bytes. If allocator can't allocate that much
22122180Skan     memory, returns the maximal possible allocation size, otherwise returns
23122180Skan     "size". */
24122180Skan  size_t __sanitizer_get_estimated_allocated_size(size_t size);
25122180Skan
26122180Skan  /* Returns true if p was returned by the allocator and
27122180Skan     is not yet freed. */
28169689Skan  int __sanitizer_get_ownership(const volatile void *p);
29122180Skan
30122180Skan  /* Returns the number of bytes reserved for the pointer p.
31122180Skan     Requires (get_ownership(p) == true) or (p == 0). */
32122180Skan  size_t __sanitizer_get_allocated_size(const volatile void *p);
33122180Skan
34122180Skan  /* Number of bytes, allocated and not yet freed by the application. */
35122180Skan  size_t __sanitizer_get_current_allocated_bytes();
36122180Skan
37169689Skan  /* Number of bytes, mmaped by the allocator to fulfill allocation requests.
38169689Skan     Generally, for request of X bytes, allocator can reserve and add to free
39169689Skan     lists a large number of chunks of size X to use them for future requests.
40169689Skan     All these chunks count toward the heap size. Currently, allocator never
41169689Skan     releases memory to OS (instead, it just puts freed chunks to free
42122180Skan     lists). */
43169689Skan  size_t __sanitizer_get_heap_size();
44169689Skan
45169689Skan  /* Number of bytes, mmaped by the allocator, which can be used to fulfill
46169689Skan     allocation requests. When a user program frees memory chunk, it can first
47169689Skan     fall into quarantine and will count toward __sanitizer_get_free_bytes()
48122180Skan     later. */
49122180Skan  size_t __sanitizer_get_free_bytes();
50122180Skan
51122180Skan  /* Number of bytes in unmapped pages, that are released to OS. Currently,
52169689Skan     always returns 0. */
53169689Skan  size_t __sanitizer_get_unmapped_bytes();
54169689Skan
55169689Skan  /* Malloc hooks that may be optionally provided by user.
56169689Skan     __sanitizer_malloc_hook(ptr, size) is called immediately after
57169689Skan       allocation of "size" bytes, which returned "ptr".
58122180Skan     __sanitizer_free_hook(ptr) is called immediately before
59169689Skan       deallocation of "ptr". */
60169689Skan  void __sanitizer_malloc_hook(const volatile void *ptr, size_t size);
61169689Skan  void __sanitizer_free_hook(const volatile void *ptr);
62122180Skan#ifdef __cplusplus
63169689Skan}  // extern "C"
64122180Skan#endif
65122180Skan
66169689Skan#endif
67169689Skan