Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 1 | //===-- allocator_interface.h ---------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // Public interface header for allocator used in sanitizers (ASan/TSan/MSan). |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | #ifndef SANITIZER_ALLOCATOR_INTERFACE_H |
| 13 | #define SANITIZER_ALLOCATOR_INTERFACE_H |
| 14 | |
| 15 | #include <stddef.h> |
| 16 | |
| 17 | #ifdef __cplusplus |
| 18 | extern "C" { |
| 19 | #endif |
| 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_get_estimated_allocated_size(size_t size); |
| 25 | |
| 26 | /* Returns true if p was returned by the allocator and |
| 27 | is not yet freed. */ |
| 28 | int __sanitizer_get_ownership(const volatile void *p); |
| 29 | |
| 30 | /* Returns the number of bytes reserved for the pointer p. |
| 31 | Requires (get_ownership(p) == true) or (p == 0). */ |
| 32 | size_t __sanitizer_get_allocated_size(const volatile void *p); |
| 33 | |
| 34 | /* Number of bytes, allocated and not yet freed by the application. */ |
| 35 | size_t __sanitizer_get_current_allocated_bytes(); |
| 36 | |
| 37 | /* Number of bytes, mmaped by the allocator to fulfill allocation requests. |
| 38 | Generally, for request of X bytes, allocator can reserve and add to free |
| 39 | lists a large number of chunks of size X to use them for future requests. |
| 40 | All these chunks count toward the heap size. Currently, allocator never |
| 41 | releases memory to OS (instead, it just puts freed chunks to free |
| 42 | lists). */ |
| 43 | size_t __sanitizer_get_heap_size(); |
| 44 | |
| 45 | /* Number of bytes, mmaped by the allocator, which can be used to fulfill |
| 46 | allocation requests. When a user program frees memory chunk, it can first |
| 47 | fall into quarantine and will count toward __sanitizer_get_free_bytes() |
| 48 | later. */ |
| 49 | size_t __sanitizer_get_free_bytes(); |
| 50 | |
| 51 | /* Number of bytes in unmapped pages, that are released to OS. Currently, |
| 52 | always returns 0. */ |
| 53 | size_t __sanitizer_get_unmapped_bytes(); |
| 54 | |
| 55 | /* Malloc hooks that may be optionally provided by user. |
| 56 | __sanitizer_malloc_hook(ptr, size) is called immediately after |
| 57 | allocation of "size" bytes, which returned "ptr". |
| 58 | __sanitizer_free_hook(ptr) is called immediately before |
| 59 | deallocation of "ptr". */ |
| 60 | void __sanitizer_malloc_hook(const volatile void *ptr, size_t size); |
| 61 | void __sanitizer_free_hook(const volatile void *ptr); |
| 62 | #ifdef __cplusplus |
| 63 | } // extern "C" |
| 64 | #endif |
| 65 | |
| 66 | #endif |