1*a7c257b0Skamil //===-- msan_interface.h --------------------------------------------------===// 2*a7c257b0Skamil // 3*a7c257b0Skamil // The LLVM Compiler Infrastructure 4*a7c257b0Skamil // 5*a7c257b0Skamil // This file is distributed under the University of Illinois Open Source 6*a7c257b0Skamil // License. See LICENSE.TXT for details. 7*a7c257b0Skamil // 8*a7c257b0Skamil //===----------------------------------------------------------------------===// 9*a7c257b0Skamil // 10*a7c257b0Skamil // This file is a part of MemorySanitizer. 11*a7c257b0Skamil // 12*a7c257b0Skamil // Public interface header. 13*a7c257b0Skamil //===----------------------------------------------------------------------===// 14*a7c257b0Skamil #ifndef MSAN_INTERFACE_H 15*a7c257b0Skamil #define MSAN_INTERFACE_H 16*a7c257b0Skamil 17*a7c257b0Skamil #include <sanitizer/common_interface_defs.h> 18*a7c257b0Skamil 19*a7c257b0Skamil #ifdef __cplusplus 20*a7c257b0Skamil extern "C" { 21*a7c257b0Skamil #endif 22*a7c257b0Skamil /* Set raw origin for the memory range. */ 23*a7c257b0Skamil void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin); 24*a7c257b0Skamil 25*a7c257b0Skamil /* Get raw origin for an address. */ 26*a7c257b0Skamil uint32_t __msan_get_origin(const volatile void *a); 27*a7c257b0Skamil 28*a7c257b0Skamil /* Test that this_id is a descendant of prev_id (or they are simply equal). 29*a7c257b0Skamil * "descendant" here means they are part of the same chain, created with 30*a7c257b0Skamil * __msan_chain_origin. */ 31*a7c257b0Skamil int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id); 32*a7c257b0Skamil 33*a7c257b0Skamil /* Returns non-zero if tracking origins. */ 34*a7c257b0Skamil int __msan_get_track_origins(void); 35*a7c257b0Skamil 36*a7c257b0Skamil /* Returns the origin id of the latest UMR in the calling thread. */ 37*a7c257b0Skamil uint32_t __msan_get_umr_origin(void); 38*a7c257b0Skamil 39*a7c257b0Skamil /* Make memory region fully initialized (without changing its contents). */ 40*a7c257b0Skamil void __msan_unpoison(const volatile void *a, size_t size); 41*a7c257b0Skamil 42*a7c257b0Skamil /* Make a null-terminated string fully initialized (without changing its 43*a7c257b0Skamil contents). */ 44*a7c257b0Skamil void __msan_unpoison_string(const volatile char *a); 45*a7c257b0Skamil 46*a7c257b0Skamil /* Make memory region fully uninitialized (without changing its contents). 47*a7c257b0Skamil This is a legacy interface that does not update origin information. Use 48*a7c257b0Skamil __msan_allocated_memory() instead. */ 49*a7c257b0Skamil void __msan_poison(const volatile void *a, size_t size); 50*a7c257b0Skamil 51*a7c257b0Skamil /* Make memory region partially uninitialized (without changing its contents). 52*a7c257b0Skamil */ 53*a7c257b0Skamil void __msan_partial_poison(const volatile void *data, void *shadow, 54*a7c257b0Skamil size_t size); 55*a7c257b0Skamil 56*a7c257b0Skamil /* Returns the offset of the first (at least partially) poisoned byte in the 57*a7c257b0Skamil memory range, or -1 if the whole range is good. */ 58*a7c257b0Skamil intptr_t __msan_test_shadow(const volatile void *x, size_t size); 59*a7c257b0Skamil 60*a7c257b0Skamil /* Checks that memory range is fully initialized, and reports an error if it 61*a7c257b0Skamil * is not. */ 62*a7c257b0Skamil void __msan_check_mem_is_initialized(const volatile void *x, size_t size); 63*a7c257b0Skamil 64*a7c257b0Skamil /* For testing: 65*a7c257b0Skamil __msan_set_expect_umr(1); 66*a7c257b0Skamil ... some buggy code ... 67*a7c257b0Skamil __msan_set_expect_umr(0); 68*a7c257b0Skamil The last line will verify that a UMR happened. */ 69*a7c257b0Skamil void __msan_set_expect_umr(int expect_umr); 70*a7c257b0Skamil 71*a7c257b0Skamil /* Change the value of keep_going flag. Non-zero value means don't terminate 72*a7c257b0Skamil program execution when an error is detected. This will not affect error in 73*a7c257b0Skamil modules that were compiled without the corresponding compiler flag. */ 74*a7c257b0Skamil void __msan_set_keep_going(int keep_going); 75*a7c257b0Skamil 76*a7c257b0Skamil /* Print shadow and origin for the memory range to stderr in a human-readable 77*a7c257b0Skamil format. */ 78*a7c257b0Skamil void __msan_print_shadow(const volatile void *x, size_t size); 79*a7c257b0Skamil 80*a7c257b0Skamil /* Print shadow for the memory range to stderr in a minimalistic 81*a7c257b0Skamil human-readable format. */ 82*a7c257b0Skamil void __msan_dump_shadow(const volatile void *x, size_t size); 83*a7c257b0Skamil 84*a7c257b0Skamil /* Returns true if running under a dynamic tool (DynamoRio-based). */ 85*a7c257b0Skamil int __msan_has_dynamic_component(void); 86*a7c257b0Skamil 87*a7c257b0Skamil /* Tell MSan about newly allocated memory (ex.: custom allocator). 88*a7c257b0Skamil Memory will be marked uninitialized, with origin at the call site. */ 89*a7c257b0Skamil void __msan_allocated_memory(const volatile void* data, size_t size); 90*a7c257b0Skamil 91*a7c257b0Skamil /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */ 92*a7c257b0Skamil void __sanitizer_dtor_callback(const volatile void* data, size_t size); 93*a7c257b0Skamil 94*a7c257b0Skamil /* This function may be optionally provided by user and should return 95*a7c257b0Skamil a string containing Msan runtime options. See msan_flags.h for details. */ 96*a7c257b0Skamil const char* __msan_default_options(void); 97*a7c257b0Skamil 98*a7c257b0Skamil /* Deprecated. Call __sanitizer_set_death_callback instead. */ 99*a7c257b0Skamil void __msan_set_death_callback(void (*callback)(void)); 100*a7c257b0Skamil 101*a7c257b0Skamil /* Update shadow for the application copy of size bytes from src to dst. 102*a7c257b0Skamil Src and dst are application addresses. This function does not copy the 103*a7c257b0Skamil actual application memory, it only updates shadow and origin for such 104*a7c257b0Skamil copy. Source and destination regions can overlap. */ 105*a7c257b0Skamil void __msan_copy_shadow(const volatile void *dst, const volatile void *src, 106*a7c257b0Skamil size_t size); 107*a7c257b0Skamil 108*a7c257b0Skamil /* Disables uninitialized memory checks in interceptors. */ 109*a7c257b0Skamil void __msan_scoped_disable_interceptor_checks(void); 110*a7c257b0Skamil 111*a7c257b0Skamil /* Re-enables uninitialized memory checks in interceptors after a previous 112*a7c257b0Skamil call to __msan_scoped_disable_interceptor_checks. */ 113*a7c257b0Skamil void __msan_scoped_enable_interceptor_checks(void); 114*a7c257b0Skamil 115*a7c257b0Skamil #ifdef __cplusplus 116*a7c257b0Skamil } // extern "C" 117*a7c257b0Skamil #endif 118*a7c257b0Skamil 119*a7c257b0Skamil #endif 120