1*7c3d14c8STreehugger Robot //===-- msan_interface_internal.h -------------------------------*- C++ -*-===// 2*7c3d14c8STreehugger Robot // 3*7c3d14c8STreehugger Robot // The LLVM Compiler Infrastructure 4*7c3d14c8STreehugger Robot // 5*7c3d14c8STreehugger Robot // This file is distributed under the University of Illinois Open Source 6*7c3d14c8STreehugger Robot // License. See LICENSE.TXT for details. 7*7c3d14c8STreehugger Robot // 8*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 9*7c3d14c8STreehugger Robot // 10*7c3d14c8STreehugger Robot // This file is a part of MemorySanitizer. 11*7c3d14c8STreehugger Robot // 12*7c3d14c8STreehugger Robot // Private MSan interface header. 13*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 14*7c3d14c8STreehugger Robot 15*7c3d14c8STreehugger Robot #ifndef MSAN_INTERFACE_INTERNAL_H 16*7c3d14c8STreehugger Robot #define MSAN_INTERFACE_INTERNAL_H 17*7c3d14c8STreehugger Robot 18*7c3d14c8STreehugger Robot #include "sanitizer_common/sanitizer_internal_defs.h" 19*7c3d14c8STreehugger Robot 20*7c3d14c8STreehugger Robot extern "C" { 21*7c3d14c8STreehugger Robot // FIXME: document all interface functions. 22*7c3d14c8STreehugger Robot 23*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 24*7c3d14c8STreehugger Robot int __msan_get_track_origins(); 25*7c3d14c8STreehugger Robot 26*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 27*7c3d14c8STreehugger Robot void __msan_init(); 28*7c3d14c8STreehugger Robot 29*7c3d14c8STreehugger Robot // Print a warning and maybe return. 30*7c3d14c8STreehugger Robot // This function can die based on common_flags()->exitcode. 31*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 32*7c3d14c8STreehugger Robot void __msan_warning(); 33*7c3d14c8STreehugger Robot 34*7c3d14c8STreehugger Robot // Print a warning and die. 35*7c3d14c8STreehugger Robot // Intrumentation inserts calls to this function when building in "fast" mode 36*7c3d14c8STreehugger Robot // (i.e. -mllvm -msan-keep-going) 37*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn)) 38*7c3d14c8STreehugger Robot void __msan_warning_noreturn(); 39*7c3d14c8STreehugger Robot 40*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 41*7c3d14c8STreehugger Robot void __msan_maybe_warning_1(u8 s, u32 o); 42*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 43*7c3d14c8STreehugger Robot void __msan_maybe_warning_2(u16 s, u32 o); 44*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 45*7c3d14c8STreehugger Robot void __msan_maybe_warning_4(u32 s, u32 o); 46*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 47*7c3d14c8STreehugger Robot void __msan_maybe_warning_8(u64 s, u32 o); 48*7c3d14c8STreehugger Robot 49*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 50*7c3d14c8STreehugger Robot void __msan_maybe_store_origin_1(u8 s, void *p, u32 o); 51*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 52*7c3d14c8STreehugger Robot void __msan_maybe_store_origin_2(u16 s, void *p, u32 o); 53*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 54*7c3d14c8STreehugger Robot void __msan_maybe_store_origin_4(u32 s, void *p, u32 o); 55*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 56*7c3d14c8STreehugger Robot void __msan_maybe_store_origin_8(u64 s, void *p, u32 o); 57*7c3d14c8STreehugger Robot 58*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 59*7c3d14c8STreehugger Robot void __msan_unpoison(const void *a, uptr size); 60*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 61*7c3d14c8STreehugger Robot void __msan_unpoison_string(const char *s); 62*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 63*7c3d14c8STreehugger Robot void __msan_clear_and_unpoison(void *a, uptr size); 64*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 65*7c3d14c8STreehugger Robot void* __msan_memcpy(void *dst, const void *src, uptr size); 66*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 67*7c3d14c8STreehugger Robot void* __msan_memset(void *s, int c, uptr n); 68*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 69*7c3d14c8STreehugger Robot void* __msan_memmove(void* dest, const void* src, uptr n); 70*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 71*7c3d14c8STreehugger Robot void __msan_poison(const void *a, uptr size); 72*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 73*7c3d14c8STreehugger Robot void __msan_poison_stack(void *a, uptr size); 74*7c3d14c8STreehugger Robot 75*7c3d14c8STreehugger Robot // Copy size bytes from src to dst and unpoison the result. 76*7c3d14c8STreehugger Robot // Useful to implement unsafe loads. 77*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 78*7c3d14c8STreehugger Robot void __msan_load_unpoisoned(void *src, uptr size, void *dst); 79*7c3d14c8STreehugger Robot 80*7c3d14c8STreehugger Robot // Returns the offset of the first (at least partially) poisoned byte, 81*7c3d14c8STreehugger Robot // or -1 if the whole range is good. 82*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 83*7c3d14c8STreehugger Robot sptr __msan_test_shadow(const void *x, uptr size); 84*7c3d14c8STreehugger Robot 85*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 86*7c3d14c8STreehugger Robot void __msan_check_mem_is_initialized(const void *x, uptr size); 87*7c3d14c8STreehugger Robot 88*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 89*7c3d14c8STreehugger Robot void __msan_set_origin(const void *a, uptr size, u32 origin); 90*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 91*7c3d14c8STreehugger Robot void __msan_set_alloca_origin(void *a, uptr size, char *descr); 92*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 93*7c3d14c8STreehugger Robot void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc); 94*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 95*7c3d14c8STreehugger Robot u32 __msan_chain_origin(u32 id); 96*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 97*7c3d14c8STreehugger Robot u32 __msan_get_origin(const void *a); 98*7c3d14c8STreehugger Robot 99*7c3d14c8STreehugger Robot // Test that this_id is a descendant of prev_id (or they are simply equal). 100*7c3d14c8STreehugger Robot // "descendant" here means that are part of the same chain, created with 101*7c3d14c8STreehugger Robot // __msan_chain_origin. 102*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 103*7c3d14c8STreehugger Robot int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id); 104*7c3d14c8STreehugger Robot 105*7c3d14c8STreehugger Robot 106*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 107*7c3d14c8STreehugger Robot void __msan_clear_on_return(); 108*7c3d14c8STreehugger Robot 109*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 110*7c3d14c8STreehugger Robot void __msan_set_keep_going(int keep_going); 111*7c3d14c8STreehugger Robot 112*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 113*7c3d14c8STreehugger Robot int __msan_set_poison_in_malloc(int do_poison); 114*7c3d14c8STreehugger Robot 115*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 116*7c3d14c8STreehugger Robot /* OPTIONAL */ const char* __msan_default_options(); 117*7c3d14c8STreehugger Robot 118*7c3d14c8STreehugger Robot // For testing. 119*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 120*7c3d14c8STreehugger Robot void __msan_set_expect_umr(int expect_umr); 121*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 122*7c3d14c8STreehugger Robot void __msan_print_shadow(const void *x, uptr size); 123*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 124*7c3d14c8STreehugger Robot void __msan_dump_shadow(const void *x, uptr size); 125*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 126*7c3d14c8STreehugger Robot int __msan_has_dynamic_component(); 127*7c3d14c8STreehugger Robot 128*7c3d14c8STreehugger Robot // For testing. 129*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 130*7c3d14c8STreehugger Robot u32 __msan_get_umr_origin(); 131*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 132*7c3d14c8STreehugger Robot void __msan_partial_poison(const void* data, void* shadow, uptr size); 133*7c3d14c8STreehugger Robot 134*7c3d14c8STreehugger Robot // Tell MSan about newly allocated memory (ex.: custom allocator). 135*7c3d14c8STreehugger Robot // Memory will be marked uninitialized, with origin at the call site. 136*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 137*7c3d14c8STreehugger Robot void __msan_allocated_memory(const void* data, uptr size); 138*7c3d14c8STreehugger Robot 139*7c3d14c8STreehugger Robot // Tell MSan about newly destroyed memory. Memory will be marked 140*7c3d14c8STreehugger Robot // uninitialized. 141*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 142*7c3d14c8STreehugger Robot void __sanitizer_dtor_callback(const void* data, uptr size); 143*7c3d14c8STreehugger Robot 144*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 145*7c3d14c8STreehugger Robot u16 __sanitizer_unaligned_load16(const uu16 *p); 146*7c3d14c8STreehugger Robot 147*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 148*7c3d14c8STreehugger Robot u32 __sanitizer_unaligned_load32(const uu32 *p); 149*7c3d14c8STreehugger Robot 150*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 151*7c3d14c8STreehugger Robot u64 __sanitizer_unaligned_load64(const uu64 *p); 152*7c3d14c8STreehugger Robot 153*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 154*7c3d14c8STreehugger Robot void __sanitizer_unaligned_store16(uu16 *p, u16 x); 155*7c3d14c8STreehugger Robot 156*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 157*7c3d14c8STreehugger Robot void __sanitizer_unaligned_store32(uu32 *p, u32 x); 158*7c3d14c8STreehugger Robot 159*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 160*7c3d14c8STreehugger Robot void __sanitizer_unaligned_store64(uu64 *p, u64 x); 161*7c3d14c8STreehugger Robot 162*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 163*7c3d14c8STreehugger Robot void __msan_set_death_callback(void (*callback)(void)); 164*7c3d14c8STreehugger Robot 165*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 166*7c3d14c8STreehugger Robot void __msan_copy_shadow(void *dst, const void *src, uptr size); 167*7c3d14c8STreehugger Robot } // extern "C" 168*7c3d14c8STreehugger Robot 169*7c3d14c8STreehugger Robot #endif // MSAN_INTERFACE_INTERNAL_H 170