1 //===-- msan_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 // This file is a part of MemorySanitizer. 11 // 12 // Public interface header. 13 //===----------------------------------------------------------------------===// 14 #ifndef MSAN_INTERFACE_H 15 #define MSAN_INTERFACE_H 16 17 #include <sanitizer/common_interface_defs.h> 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 /* Set raw origin for the memory range. */ 23 void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin); 24 25 /* Get raw origin for an address. */ 26 uint32_t __msan_get_origin(const volatile void *a); 27 28 /* Returns non-zero if tracking origins. */ 29 int __msan_get_track_origins(); 30 31 /* Returns the origin id of the latest UMR in the calling thread. */ 32 uint32_t __msan_get_umr_origin(); 33 34 /* Make memory region fully initialized (without changing its contents). */ 35 void __msan_unpoison(const volatile void *a, size_t size); 36 37 /* Make a null-terminated string fully initialized (without changing its 38 contents). */ 39 void __msan_unpoison_string(const volatile char *a); 40 41 /* Make memory region fully uninitialized (without changing its contents). */ 42 void __msan_poison(const volatile void *a, size_t size); 43 44 /* Make memory region partially uninitialized (without changing its contents). 45 */ 46 void __msan_partial_poison(const volatile void *data, void *shadow, 47 size_t size); 48 49 /* Returns the offset of the first (at least partially) poisoned byte in the 50 memory range, or -1 if the whole range is good. */ 51 intptr_t __msan_test_shadow(const volatile void *x, size_t size); 52 53 /* Checks that memory range is fully initialized, and reports an error if it 54 * is not. */ 55 void __msan_check_mem_is_initialized(const volatile void *x, size_t size); 56 57 /* Set exit code when error(s) were detected. 58 Value of 0 means don't change the program exit code. */ 59 void __msan_set_exit_code(int exit_code); 60 61 /* For testing: 62 __msan_set_expect_umr(1); 63 ... some buggy code ... 64 __msan_set_expect_umr(0); 65 The last line will verify that a UMR happened. */ 66 void __msan_set_expect_umr(int expect_umr); 67 68 /* Change the value of keep_going flag. Non-zero value means don't terminate 69 program execution when an error is detected. This will not affect error in 70 modules that were compiled without the corresponding compiler flag. */ 71 void __msan_set_keep_going(int keep_going); 72 73 /* Print shadow and origin for the memory range to stderr in a human-readable 74 format. */ 75 void __msan_print_shadow(const volatile void *x, size_t size); 76 77 /* Print shadow for the memory range to stderr in a minimalistic 78 human-readable format. */ 79 void __msan_dump_shadow(const volatile void *x, size_t size); 80 81 /* Returns true if running under a dynamic tool (DynamoRio-based). */ 82 int __msan_has_dynamic_component(); 83 84 /* Tell MSan about newly allocated memory (ex.: custom allocator). 85 Memory will be marked uninitialized, with origin at the call site. */ 86 void __msan_allocated_memory(const volatile void* data, size_t size); 87 88 /* This function may be optionally provided by user and should return 89 a string containing Msan runtime options. See msan_flags.h for details. */ 90 const char* __msan_default_options(); 91 92 /* Sets the callback to be called right before death on error. 93 Passing 0 will unset the callback. */ 94 void __msan_set_death_callback(void (*callback)(void)); 95 96 /***********************************/ 97 /* Allocator statistics interface. */ 98 99 /* Returns the estimated number of bytes that will be reserved by allocator 100 for request of "size" bytes. If Msan allocator can't allocate that much 101 memory, returns the maximal possible allocation size, otherwise returns 102 "size". */ 103 /* DEPRECATED: Use __sanitizer_get_estimated_allocated_size instead. */ 104 size_t __msan_get_estimated_allocated_size(size_t size); 105 106 /* Returns true if p was returned by the Msan allocator and 107 is not yet freed. */ 108 /* DEPRECATED: Use __sanitizer_get_ownership instead. */ 109 int __msan_get_ownership(const volatile void *p); 110 111 /* Returns the number of bytes reserved for the pointer p. 112 Requires (get_ownership(p) == true) or (p == 0). */ 113 /* DEPRECATED: Use __sanitizer_get_allocated_size instead. */ 114 size_t __msan_get_allocated_size(const volatile void *p); 115 116 /* Number of bytes, allocated and not yet freed by the application. */ 117 /* DEPRECATED: Use __sanitizer_get_current_allocated_bytes instead. */ 118 size_t __msan_get_current_allocated_bytes(); 119 120 /* Number of bytes, mmaped by msan allocator to fulfill allocation requests. 121 Generally, for request of X bytes, allocator can reserve and add to free 122 lists a large number of chunks of size X to use them for future requests. 123 All these chunks count toward the heap size. Currently, allocator never 124 releases memory to OS (instead, it just puts freed chunks to free 125 lists). */ 126 /* DEPRECATED: Use __sanitizer_get_heap_size instead. */ 127 size_t __msan_get_heap_size(); 128 129 /* Number of bytes, mmaped by msan allocator, which can be used to fulfill 130 allocation requests. When a user program frees memory chunk, it can first 131 fall into quarantine and will count toward __msan_get_free_bytes() 132 later. */ 133 /* DEPRECATED: Use __sanitizer_get_free_bytes instead. */ 134 size_t __msan_get_free_bytes(); 135 136 /* Number of bytes in unmapped pages, that are released to OS. Currently, 137 always returns 0. */ 138 /* DEPRECATED: Use __sanitizer_get_unmapped_bytes instead. */ 139 size_t __msan_get_unmapped_bytes(); 140 141 /* Malloc hooks that may be optionally provided by user. 142 __msan_malloc_hook(ptr, size) is called immediately after 143 allocation of "size" bytes, which returned "ptr". 144 __msan_free_hook(ptr) is called immediately before 145 deallocation of "ptr". */ 146 /* DEPRECATED: Use __sanitizer_malloc_hook / __sanitizer_free_hook instead. */ 147 void __msan_malloc_hook(const volatile void *ptr, size_t size); 148 void __msan_free_hook(const volatile void *ptr); 149 150 #ifdef __cplusplus 151 } // extern "C" 152 #endif 153 154 #endif 155