1 //===-- allocator_interface.h ---------------------------------------------===//
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
6 //===----------------------------------------------------------------------===//
8 // Public interface header for allocator used in sanitizers (ASan/TSan/MSan).
9 //===----------------------------------------------------------------------===//
10 #ifndef SANITIZER_ALLOCATOR_INTERFACE_H
11 #define SANITIZER_ALLOCATOR_INTERFACE_H
18 /* Returns the estimated number of bytes that will be reserved by allocator
19 for request of "size" bytes. If allocator can't allocate that much
20 memory, returns the maximal possible allocation size, otherwise returns
22 size_t __sanitizer_get_estimated_allocated_size(size_t size
);
24 /* Returns true if p was returned by the allocator and
26 int __sanitizer_get_ownership(const volatile void *p
);
28 /* Returns the number of bytes reserved for the pointer p.
29 Requires (get_ownership(p) == true) or (p == 0). */
30 size_t __sanitizer_get_allocated_size(const volatile void *p
);
32 /* Number of bytes, allocated and not yet freed by the application. */
33 size_t __sanitizer_get_current_allocated_bytes();
35 /* Number of bytes, mmaped by the allocator to fulfill allocation requests.
36 Generally, for request of X bytes, allocator can reserve and add to free
37 lists a large number of chunks of size X to use them for future requests.
38 All these chunks count toward the heap size. Currently, allocator never
39 releases memory to OS (instead, it just puts freed chunks to free
41 size_t __sanitizer_get_heap_size();
43 /* Number of bytes, mmaped by the allocator, which can be used to fulfill
44 allocation requests. When a user program frees memory chunk, it can first
45 fall into quarantine and will count toward __sanitizer_get_free_bytes()
47 size_t __sanitizer_get_free_bytes();
49 /* Number of bytes in unmapped pages, that are released to OS. Currently,
51 size_t __sanitizer_get_unmapped_bytes();
53 /* Malloc hooks that may be optionally provided by user.
54 __sanitizer_malloc_hook(ptr, size) is called immediately after
55 allocation of "size" bytes, which returned "ptr".
56 __sanitizer_free_hook(ptr) is called immediately before
57 deallocation of "ptr". */
58 void __sanitizer_malloc_hook(const volatile void *ptr
, size_t size
);
59 void __sanitizer_free_hook(const volatile void *ptr
);
61 /* Installs a pair of hooks for malloc/free.
62 Several (currently, 5) hook pairs may be installed, they are executed
63 in the order they were installed and after calling
64 __sanitizer_malloc_hook/__sanitizer_free_hook.
65 Unlike __sanitizer_malloc_hook/__sanitizer_free_hook these hooks can be
66 chained and do not rely on weak symbols working on the platform, but
67 require __sanitizer_install_malloc_and_free_hooks to be called at startup
68 and thus will not be called on malloc/free very early in the process.
69 Returns the number of hooks currently installed or 0 on failure.
70 Not thread-safe, should be called in the main thread before starting
73 int __sanitizer_install_malloc_and_free_hooks(
74 void (*malloc_hook
)(const volatile void *, size_t),
75 void (*free_hook
)(const volatile void *));