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