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