1*7c3d14c8STreehugger Robot //===-- asan_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 AddressSanitizer, an address sanity checker. 11*7c3d14c8STreehugger Robot // 12*7c3d14c8STreehugger Robot // This header declares the AddressSanitizer runtime interface functions. 13*7c3d14c8STreehugger Robot // The runtime library has to define these functions so the instrumented program 14*7c3d14c8STreehugger Robot // could call them. 15*7c3d14c8STreehugger Robot // 16*7c3d14c8STreehugger Robot // See also include/sanitizer/asan_interface.h 17*7c3d14c8STreehugger Robot //===----------------------------------------------------------------------===// 18*7c3d14c8STreehugger Robot #ifndef ASAN_INTERFACE_INTERNAL_H 19*7c3d14c8STreehugger Robot #define ASAN_INTERFACE_INTERNAL_H 20*7c3d14c8STreehugger Robot 21*7c3d14c8STreehugger Robot #include "sanitizer_common/sanitizer_internal_defs.h" 22*7c3d14c8STreehugger Robot 23*7c3d14c8STreehugger Robot #include "asan_init_version.h" 24*7c3d14c8STreehugger Robot 25*7c3d14c8STreehugger Robot using __sanitizer::uptr; 26*7c3d14c8STreehugger Robot 27*7c3d14c8STreehugger Robot extern "C" { 28*7c3d14c8STreehugger Robot // This function should be called at the very beginning of the process, 29*7c3d14c8STreehugger Robot // before any instrumented code is executed and before any call to malloc. 30*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_init(); 31*7c3d14c8STreehugger Robot 32*7c3d14c8STreehugger Robot // This function exists purely to get a linker/loader error when using 33*7c3d14c8STreehugger Robot // incompatible versions of instrumentation and runtime library. Please note 34*7c3d14c8STreehugger Robot // that __asan_version_mismatch_check is a macro that is replaced with 35*7c3d14c8STreehugger Robot // __asan_version_mismatch_check_vXXX at compile-time. 36*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_version_mismatch_check(); 37*7c3d14c8STreehugger Robot 38*7c3d14c8STreehugger Robot // This structure is used to describe the source location of a place where 39*7c3d14c8STreehugger Robot // global was defined. 40*7c3d14c8STreehugger Robot struct __asan_global_source_location { 41*7c3d14c8STreehugger Robot const char *filename; 42*7c3d14c8STreehugger Robot int line_no; 43*7c3d14c8STreehugger Robot int column_no; 44*7c3d14c8STreehugger Robot }; 45*7c3d14c8STreehugger Robot 46*7c3d14c8STreehugger Robot // This structure describes an instrumented global variable. 47*7c3d14c8STreehugger Robot struct __asan_global { 48*7c3d14c8STreehugger Robot uptr beg; // The address of the global. 49*7c3d14c8STreehugger Robot uptr size; // The original size of the global. 50*7c3d14c8STreehugger Robot uptr size_with_redzone; // The size with the redzone. 51*7c3d14c8STreehugger Robot const char *name; // Name as a C string. 52*7c3d14c8STreehugger Robot const char *module_name; // Module name as a C string. This pointer is a 53*7c3d14c8STreehugger Robot // unique identifier of a module. 54*7c3d14c8STreehugger Robot uptr has_dynamic_init; // Non-zero if the global has dynamic initializer. 55*7c3d14c8STreehugger Robot __asan_global_source_location *location; // Source location of a global, 56*7c3d14c8STreehugger Robot // or NULL if it is unknown. 57*7c3d14c8STreehugger Robot uptr odr_indicator; // The address of the ODR indicator symbol. 58*7c3d14c8STreehugger Robot }; 59*7c3d14c8STreehugger Robot 60*7c3d14c8STreehugger Robot // These functions can be called on some platforms to find globals in the same 61*7c3d14c8STreehugger Robot // loaded image as `flag' and apply __asan_(un)register_globals to them, 62*7c3d14c8STreehugger Robot // filtering out redundant calls. 63*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 64*7c3d14c8STreehugger Robot void __asan_register_image_globals(uptr *flag); 65*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 66*7c3d14c8STreehugger Robot void __asan_unregister_image_globals(uptr *flag); 67*7c3d14c8STreehugger Robot 68*7c3d14c8STreehugger Robot // These two functions should be called by the instrumented code. 69*7c3d14c8STreehugger Robot // 'globals' is an array of structures describing 'n' globals. 70*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 71*7c3d14c8STreehugger Robot void __asan_register_globals(__asan_global *globals, uptr n); 72*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 73*7c3d14c8STreehugger Robot void __asan_unregister_globals(__asan_global *globals, uptr n); 74*7c3d14c8STreehugger Robot 75*7c3d14c8STreehugger Robot // These two functions should be called before and after dynamic initializers 76*7c3d14c8STreehugger Robot // of a single module run, respectively. 77*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 78*7c3d14c8STreehugger Robot void __asan_before_dynamic_init(const char *module_name); 79*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 80*7c3d14c8STreehugger Robot void __asan_after_dynamic_init(); 81*7c3d14c8STreehugger Robot 82*7c3d14c8STreehugger Robot // These two functions are used by instrumented code in the 83*7c3d14c8STreehugger Robot // use-after-scope mode. They mark memory for local variables as 84*7c3d14c8STreehugger Robot // unaddressable when they leave scope and addressable before the 85*7c3d14c8STreehugger Robot // function exits. 86*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 87*7c3d14c8STreehugger Robot void __asan_poison_stack_memory(uptr addr, uptr size); 88*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 89*7c3d14c8STreehugger Robot void __asan_unpoison_stack_memory(uptr addr, uptr size); 90*7c3d14c8STreehugger Robot 91*7c3d14c8STreehugger Robot // Performs cleanup before a NoReturn function. Must be called before things 92*7c3d14c8STreehugger Robot // like _exit and execl to avoid false positives on stack. 93*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return(); 94*7c3d14c8STreehugger Robot 95*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 96*7c3d14c8STreehugger Robot void __asan_poison_memory_region(void const volatile *addr, uptr size); 97*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 98*7c3d14c8STreehugger Robot void __asan_unpoison_memory_region(void const volatile *addr, uptr size); 99*7c3d14c8STreehugger Robot 100*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 101*7c3d14c8STreehugger Robot int __asan_address_is_poisoned(void const volatile *addr); 102*7c3d14c8STreehugger Robot 103*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 104*7c3d14c8STreehugger Robot uptr __asan_region_is_poisoned(uptr beg, uptr size); 105*7c3d14c8STreehugger Robot 106*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 107*7c3d14c8STreehugger Robot void __asan_describe_address(uptr addr); 108*7c3d14c8STreehugger Robot 109*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 110*7c3d14c8STreehugger Robot int __asan_report_present(); 111*7c3d14c8STreehugger Robot 112*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 113*7c3d14c8STreehugger Robot uptr __asan_get_report_pc(); 114*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 115*7c3d14c8STreehugger Robot uptr __asan_get_report_bp(); 116*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 117*7c3d14c8STreehugger Robot uptr __asan_get_report_sp(); 118*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 119*7c3d14c8STreehugger Robot uptr __asan_get_report_address(); 120*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 121*7c3d14c8STreehugger Robot int __asan_get_report_access_type(); 122*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 123*7c3d14c8STreehugger Robot uptr __asan_get_report_access_size(); 124*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 125*7c3d14c8STreehugger Robot const char * __asan_get_report_description(); 126*7c3d14c8STreehugger Robot 127*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 128*7c3d14c8STreehugger Robot const char * __asan_locate_address(uptr addr, char *name, uptr name_size, 129*7c3d14c8STreehugger Robot uptr *region_address, uptr *region_size); 130*7c3d14c8STreehugger Robot 131*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 132*7c3d14c8STreehugger Robot uptr __asan_get_alloc_stack(uptr addr, uptr *trace, uptr size, 133*7c3d14c8STreehugger Robot u32 *thread_id); 134*7c3d14c8STreehugger Robot 135*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 136*7c3d14c8STreehugger Robot uptr __asan_get_free_stack(uptr addr, uptr *trace, uptr size, 137*7c3d14c8STreehugger Robot u32 *thread_id); 138*7c3d14c8STreehugger Robot 139*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 140*7c3d14c8STreehugger Robot void __asan_get_shadow_mapping(uptr *shadow_scale, uptr *shadow_offset); 141*7c3d14c8STreehugger Robot 142*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 143*7c3d14c8STreehugger Robot void __asan_report_error(uptr pc, uptr bp, uptr sp, 144*7c3d14c8STreehugger Robot uptr addr, int is_write, uptr access_size, u32 exp); 145*7c3d14c8STreehugger Robot 146*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 147*7c3d14c8STreehugger Robot void __asan_set_death_callback(void (*callback)(void)); 148*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 149*7c3d14c8STreehugger Robot void __asan_set_error_report_callback(void (*callback)(const char*)); 150*7c3d14c8STreehugger Robot 151*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 152*7c3d14c8STreehugger Robot /* OPTIONAL */ void __asan_on_error(); 153*7c3d14c8STreehugger Robot 154*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats(); 155*7c3d14c8STreehugger Robot 156*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 157*7c3d14c8STreehugger Robot /* OPTIONAL */ const char* __asan_default_options(); 158*7c3d14c8STreehugger Robot 159*7c3d14c8STreehugger Robot // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return 160*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 161*7c3d14c8STreehugger Robot extern int __asan_option_detect_stack_use_after_return; 162*7c3d14c8STreehugger Robot 163*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 164*7c3d14c8STreehugger Robot extern uptr *__asan_test_only_reported_buggy_pointer; 165*7c3d14c8STreehugger Robot 166*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p); 167*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p); 168*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p); 169*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p); 170*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p); 171*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p); 172*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p); 173*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p); 174*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p); 175*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p); 176*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size); 177*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size); 178*7c3d14c8STreehugger Robot 179*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1_noabort(uptr p); 180*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2_noabort(uptr p); 181*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4_noabort(uptr p); 182*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8_noabort(uptr p); 183*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16_noabort(uptr p); 184*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1_noabort(uptr p); 185*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2_noabort(uptr p); 186*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4_noabort(uptr p); 187*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8_noabort(uptr p); 188*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16_noabort(uptr p); 189*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN_noabort(uptr p, uptr size); 190*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN_noabort(uptr p, uptr size); 191*7c3d14c8STreehugger Robot 192*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load1(uptr p, u32 exp); 193*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load2(uptr p, u32 exp); 194*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load4(uptr p, u32 exp); 195*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load8(uptr p, u32 exp); 196*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load16(uptr p, u32 exp); 197*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store1(uptr p, u32 exp); 198*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store2(uptr p, u32 exp); 199*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store4(uptr p, u32 exp); 200*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store8(uptr p, u32 exp); 201*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store16(uptr p, u32 exp); 202*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_loadN(uptr p, uptr size, 203*7c3d14c8STreehugger Robot u32 exp); 204*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_storeN(uptr p, uptr size, 205*7c3d14c8STreehugger Robot u32 exp); 206*7c3d14c8STreehugger Robot 207*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 208*7c3d14c8STreehugger Robot void* __asan_memcpy(void *dst, const void *src, uptr size); 209*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 210*7c3d14c8STreehugger Robot void* __asan_memset(void *s, int c, uptr n); 211*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 212*7c3d14c8STreehugger Robot void* __asan_memmove(void* dest, const void* src, uptr n); 213*7c3d14c8STreehugger Robot 214*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 215*7c3d14c8STreehugger Robot void __asan_poison_cxx_array_cookie(uptr p); 216*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 217*7c3d14c8STreehugger Robot uptr __asan_load_cxx_array_cookie(uptr *p); 218*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 219*7c3d14c8STreehugger Robot void __asan_poison_intra_object_redzone(uptr p, uptr size); 220*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 221*7c3d14c8STreehugger Robot void __asan_unpoison_intra_object_redzone(uptr p, uptr size); 222*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 223*7c3d14c8STreehugger Robot void __asan_alloca_poison(uptr addr, uptr size); 224*7c3d14c8STreehugger Robot SANITIZER_INTERFACE_ATTRIBUTE 225*7c3d14c8STreehugger Robot void __asan_allocas_unpoison(uptr top, uptr bottom); 226*7c3d14c8STreehugger Robot } // extern "C" 227*7c3d14c8STreehugger Robot 228*7c3d14c8STreehugger Robot #endif // ASAN_INTERFACE_INTERNAL_H 229