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 23 #if __has_feature(memory_sanitizer) 24 /* Returns a string describing a stack origin. 25 Return NULL if the origin is invalid, or is not a stack origin. */ 26 const char *__msan_get_origin_descr_if_stack(uint32_t id); 27 28 29 /* Set raw origin for the memory range. */ 30 void __msan_set_origin(void *a, size_t size, uint32_t origin); 31 32 /* Get raw origin for an address. */ 33 uint32_t __msan_get_origin(void *a); 34 35 /* Returns non-zero if tracking origins. */ 36 int __msan_get_track_origins(); 37 38 /* Returns the origin id of the latest UMR in the calling thread. */ 39 uint32_t __msan_get_umr_origin(); 40 41 /* Make memory region fully initialized (without changing its contents). */ 42 void __msan_unpoison(void *a, size_t size); 43 44 /* Make memory region fully uninitialized (without changing its contents). */ 45 void __msan_poison(void *a, size_t size); 46 47 /* Make memory region partially uninitialized (without changing its contents). 48 */ 49 void __msan_partial_poison(void* data, void* shadow, size_t size); 50 51 /* Returns the offset of the first (at least partially) poisoned byte in the 52 memory range, or -1 if the whole range is good. */ 53 intptr_t __msan_test_shadow(const void *x, size_t size); 54 55 /* Set exit code when error(s) were detected. 56 Value of 0 means don't change the program exit code. */ 57 void __msan_set_exit_code(int exit_code); 58 59 /* For testing: 60 __msan_set_expect_umr(1); 61 ... some buggy code ... 62 __msan_set_expect_umr(0); 63 The last line will verify that a UMR happened. */ 64 void __msan_set_expect_umr(int expect_umr); 65 66 /* Print shadow and origin for the memory range to stdout in a human-readable 67 format. */ 68 void __msan_print_shadow(const void *x, size_t size); 69 70 /* Print current function arguments shadow and origin to stdout in a 71 human-readable format. */ 72 void __msan_print_param_shadow(); 73 74 /* Returns true if running under a dynamic tool (DynamoRio-based). */ 75 int __msan_has_dynamic_component(); 76 77 /* Tell MSan about newly allocated memory (ex.: custom allocator). 78 Memory will be marked uninitialized, with origin at the call site. */ 79 void __msan_allocated_memory(void* data, size_t size); 80 81 #else // __has_feature(memory_sanitizer) 82 83 #define __msan_get_origin_descr_if_stack(id) ((const char*)0) 84 #define __msan_set_origin(a, size, origin) 85 #define __msan_get_origin(a) ((uint32_t)-1) 86 #define __msan_get_track_origins() (0) 87 #define __msan_get_umr_origin() ((uint32_t)-1) 88 #define __msan_unpoison(a, size) 89 #define __msan_poison(a, size) 90 #define __msan_partial_poison(data, shadow, size) 91 #define __msan_test_shadow(x, size) ((intptr_t)-1) 92 #define __msan_set_exit_code(exit_code) 93 #define __msan_set_expect_umr(expect_umr) 94 #define __msan_print_shadow(x, size) 95 #define __msan_print_param_shadow() 96 #define __msan_has_dynamic_component() (0) 97 #define __msan_allocated_memory(data, size) 98 99 #endif // __has_feature(memory_sanitizer) 100 101 #ifdef __cplusplus 102 } // extern "C" 103 #endif 104 105 #endif 106