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