|
11 | 11 | #ifndef SANITIZER_ALLOCATOR_INTERFACE_H
|
12 | 12 | #define SANITIZER_ALLOCATOR_INTERFACE_H
|
13 | 13 |
|
| 14 | +#include <sanitizer/common_interface_defs.h> |
14 | 15 | #include <stddef.h>
|
15 | 16 |
|
16 | 17 | #ifdef __cplusplus
|
17 | 18 | extern "C" {
|
18 | 19 | #endif
|
19 |
| - /* Returns the estimated number of bytes that will be reserved by allocator |
20 |
| - for request of "size" bytes. If allocator can't allocate that much |
21 |
| - memory, returns the maximal possible allocation size, otherwise returns |
22 |
| - "size". */ |
23 |
| - size_t __sanitizer_get_estimated_allocated_size(size_t size); |
| 20 | +/* Returns the estimated number of bytes that will be reserved by allocator |
| 21 | + for request of "size" bytes. If allocator can't allocate that much |
| 22 | + memory, returns the maximal possible allocation size, otherwise returns |
| 23 | + "size". */ |
| 24 | +size_t SANITIZER_CDECL __sanitizer_get_estimated_allocated_size(size_t size); |
24 | 25 |
|
25 |
| - /* Returns true if p was returned by the allocator and |
26 |
| - is not yet freed. */ |
27 |
| - int __sanitizer_get_ownership(const volatile void *p); |
| 26 | +/* Returns true if p was returned by the allocator and |
| 27 | + is not yet freed. */ |
| 28 | +int SANITIZER_CDECL __sanitizer_get_ownership(const volatile void *p); |
28 | 29 |
|
29 |
| - /* If a pointer lies within an allocation, it will return the start address |
30 |
| - of the allocation. Otherwise, it returns nullptr. */ |
31 |
| - const void *__sanitizer_get_allocated_begin(const void *p); |
| 30 | +/* If a pointer lies within an allocation, it will return the start address |
| 31 | + of the allocation. Otherwise, it returns nullptr. */ |
| 32 | +const void *SANITIZER_CDECL __sanitizer_get_allocated_begin(const void *p); |
32 | 33 |
|
33 |
| - /* Returns the number of bytes reserved for the pointer p. |
34 |
| - Requires (get_ownership(p) == true) or (p == 0). */ |
35 |
| - size_t __sanitizer_get_allocated_size(const volatile void *p); |
| 34 | +/* Returns the number of bytes reserved for the pointer p. |
| 35 | + Requires (get_ownership(p) == true) or (p == 0). */ |
| 36 | +size_t SANITIZER_CDECL __sanitizer_get_allocated_size(const volatile void *p); |
36 | 37 |
|
37 |
| - /* Returns the number of bytes reserved for the pointer p. |
38 |
| - Requires __sanitizer_get_allocated_begin(p) == p. */ |
39 |
| - size_t __sanitizer_get_allocated_size_fast(const volatile void *p); |
| 38 | +/* Returns the number of bytes reserved for the pointer p. |
| 39 | + Requires __sanitizer_get_allocated_begin(p) == p. */ |
| 40 | +size_t SANITIZER_CDECL |
| 41 | +__sanitizer_get_allocated_size_fast(const volatile void *p); |
40 | 42 |
|
41 |
| - /* Number of bytes, allocated and not yet freed by the application. */ |
42 |
| - size_t __sanitizer_get_current_allocated_bytes(void); |
| 43 | +/* Number of bytes, allocated and not yet freed by the application. */ |
| 44 | +size_t SANITIZER_CDECL __sanitizer_get_current_allocated_bytes(void); |
43 | 45 |
|
44 |
| - /* Number of bytes, mmaped by the allocator to fulfill allocation requests. |
45 |
| - Generally, for request of X bytes, allocator can reserve and add to free |
46 |
| - lists a large number of chunks of size X to use them for future requests. |
47 |
| - All these chunks count toward the heap size. Currently, allocator never |
48 |
| - releases memory to OS (instead, it just puts freed chunks to free |
49 |
| - lists). */ |
50 |
| - size_t __sanitizer_get_heap_size(void); |
| 46 | +/* Number of bytes, mmaped by the allocator to fulfill allocation requests. |
| 47 | + Generally, for request of X bytes, allocator can reserve and add to free |
| 48 | + lists a large number of chunks of size X to use them for future requests. |
| 49 | + All these chunks count toward the heap size. Currently, allocator never |
| 50 | + releases memory to OS (instead, it just puts freed chunks to free |
| 51 | + lists). */ |
| 52 | +size_t SANITIZER_CDECL __sanitizer_get_heap_size(void); |
51 | 53 |
|
52 |
| - /* Number of bytes, mmaped by the allocator, which can be used to fulfill |
53 |
| - allocation requests. When a user program frees memory chunk, it can first |
54 |
| - fall into quarantine and will count toward __sanitizer_get_free_bytes() |
55 |
| - later. */ |
56 |
| - size_t __sanitizer_get_free_bytes(void); |
| 54 | +/* Number of bytes, mmaped by the allocator, which can be used to fulfill |
| 55 | + allocation requests. When a user program frees memory chunk, it can first |
| 56 | + fall into quarantine and will count toward __sanitizer_get_free_bytes() |
| 57 | + later. */ |
| 58 | +size_t SANITIZER_CDECL __sanitizer_get_free_bytes(void); |
57 | 59 |
|
58 |
| - /* Number of bytes in unmapped pages, that are released to OS. Currently, |
59 |
| - always returns 0. */ |
60 |
| - size_t __sanitizer_get_unmapped_bytes(void); |
| 60 | +/* Number of bytes in unmapped pages, that are released to OS. Currently, |
| 61 | + always returns 0. */ |
| 62 | +size_t SANITIZER_CDECL __sanitizer_get_unmapped_bytes(void); |
61 | 63 |
|
62 |
| - /* Malloc hooks that may be optionally provided by user. |
63 |
| - __sanitizer_malloc_hook(ptr, size) is called immediately after |
64 |
| - allocation of "size" bytes, which returned "ptr". |
65 |
| - __sanitizer_free_hook(ptr) is called immediately before |
66 |
| - deallocation of "ptr". */ |
67 |
| - void __sanitizer_malloc_hook(const volatile void *ptr, size_t size); |
68 |
| - void __sanitizer_free_hook(const volatile void *ptr); |
| 64 | +/* Malloc hooks that may be optionally provided by user. |
| 65 | + __sanitizer_malloc_hook(ptr, size) is called immediately after |
| 66 | + allocation of "size" bytes, which returned "ptr". |
| 67 | + __sanitizer_free_hook(ptr) is called immediately before |
| 68 | + deallocation of "ptr". */ |
| 69 | +void SANITIZER_CDECL __sanitizer_malloc_hook(const volatile void *ptr, |
| 70 | + size_t size); |
| 71 | +void SANITIZER_CDECL __sanitizer_free_hook(const volatile void *ptr); |
69 | 72 |
|
70 |
| - /* Installs a pair of hooks for malloc/free. |
71 |
| - Several (currently, 5) hook pairs may be installed, they are executed |
72 |
| - in the order they were installed and after calling |
73 |
| - __sanitizer_malloc_hook/__sanitizer_free_hook. |
74 |
| - Unlike __sanitizer_malloc_hook/__sanitizer_free_hook these hooks can be |
75 |
| - chained and do not rely on weak symbols working on the platform, but |
76 |
| - require __sanitizer_install_malloc_and_free_hooks to be called at startup |
77 |
| - and thus will not be called on malloc/free very early in the process. |
78 |
| - Returns the number of hooks currently installed or 0 on failure. |
79 |
| - Not thread-safe, should be called in the main thread before starting |
80 |
| - other threads. |
81 |
| - */ |
82 |
| - int __sanitizer_install_malloc_and_free_hooks( |
83 |
| - void (*malloc_hook)(const volatile void *, size_t), |
84 |
| - void (*free_hook)(const volatile void *)); |
| 73 | +/* Installs a pair of hooks for malloc/free. |
| 74 | + Several (currently, 5) hook pairs may be installed, they are executed |
| 75 | + in the order they were installed and after calling |
| 76 | + __sanitizer_malloc_hook/__sanitizer_free_hook. |
| 77 | + Unlike __sanitizer_malloc_hook/__sanitizer_free_hook these hooks can be |
| 78 | + chained and do not rely on weak symbols working on the platform, but |
| 79 | + require __sanitizer_install_malloc_and_free_hooks to be called at startup |
| 80 | + and thus will not be called on malloc/free very early in the process. |
| 81 | + Returns the number of hooks currently installed or 0 on failure. |
| 82 | + Not thread-safe, should be called in the main thread before starting |
| 83 | + other threads. |
| 84 | +*/ |
| 85 | +int SANITIZER_CDECL __sanitizer_install_malloc_and_free_hooks( |
| 86 | + void (*SANITIZER_CDECL malloc_hook)(const volatile void *, size_t), |
| 87 | + void (*SANITIZER_CDECL free_hook)(const volatile void *)); |
85 | 88 |
|
86 |
| - /* Drains allocator quarantines (calling thread's and global ones), returns |
87 |
| - freed memory back to OS and releases other non-essential internal allocator |
88 |
| - resources in attempt to reduce process RSS. |
89 |
| - Currently available with ASan only. |
90 |
| - */ |
91 |
| - void __sanitizer_purge_allocator(void); |
| 89 | +/* Drains allocator quarantines (calling thread's and global ones), returns |
| 90 | + freed memory back to OS and releases other non-essential internal allocator |
| 91 | + resources in attempt to reduce process RSS. |
| 92 | + Currently available with ASan only. |
| 93 | +*/ |
| 94 | +void SANITIZER_CDECL __sanitizer_purge_allocator(void); |
92 | 95 | #ifdef __cplusplus
|
93 |
| -} // extern "C" |
| 96 | +} // extern "C" |
94 | 97 | #endif
|
95 | 98 |
|
96 | 99 | #endif
|
0 commit comments