1 //===-- hwasan_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 HWAddressSanitizer. 10 // 11 // Private Hwasan interface header. 12 //===----------------------------------------------------------------------===// 13 14 #ifndef HWASAN_INTERFACE_INTERNAL_H 15 #define HWASAN_INTERFACE_INTERNAL_H 16 17 #include "sanitizer_common/sanitizer_internal_defs.h" 18 #include "sanitizer_common/sanitizer_platform_limits_posix.h" 19 #include <link.h> 20 21 extern "C" { 22 23 SANITIZER_INTERFACE_ATTRIBUTE 24 void __hwasan_init_static(); 25 26 SANITIZER_INTERFACE_ATTRIBUTE 27 void __hwasan_init(); 28 29 SANITIZER_INTERFACE_ATTRIBUTE 30 void __hwasan_library_loaded(ElfW(Addr) base, const ElfW(Phdr) * phdr, 31 ElfW(Half) phnum); 32 33 SANITIZER_INTERFACE_ATTRIBUTE 34 void __hwasan_library_unloaded(ElfW(Addr) base, const ElfW(Phdr) * phdr, 35 ElfW(Half) phnum); 36 37 using __sanitizer::uptr; 38 using __sanitizer::sptr; 39 using __sanitizer::uu64; 40 using __sanitizer::uu32; 41 using __sanitizer::uu16; 42 using __sanitizer::u64; 43 using __sanitizer::u32; 44 using __sanitizer::u16; 45 using __sanitizer::u8; 46 47 SANITIZER_INTERFACE_ATTRIBUTE 48 void __hwasan_init_frames(uptr, uptr); 49 50 SANITIZER_INTERFACE_ATTRIBUTE 51 extern uptr __hwasan_shadow_memory_dynamic_address; 52 53 SANITIZER_INTERFACE_ATTRIBUTE 54 void __hwasan_loadN(uptr, uptr); 55 SANITIZER_INTERFACE_ATTRIBUTE 56 void __hwasan_load1(uptr); 57 SANITIZER_INTERFACE_ATTRIBUTE 58 void __hwasan_load2(uptr); 59 SANITIZER_INTERFACE_ATTRIBUTE 60 void __hwasan_load4(uptr); 61 SANITIZER_INTERFACE_ATTRIBUTE 62 void __hwasan_load8(uptr); 63 SANITIZER_INTERFACE_ATTRIBUTE 64 void __hwasan_load16(uptr); 65 66 SANITIZER_INTERFACE_ATTRIBUTE 67 void __hwasan_loadN_noabort(uptr, uptr); 68 SANITIZER_INTERFACE_ATTRIBUTE 69 void __hwasan_load1_noabort(uptr); 70 SANITIZER_INTERFACE_ATTRIBUTE 71 void __hwasan_load2_noabort(uptr); 72 SANITIZER_INTERFACE_ATTRIBUTE 73 void __hwasan_load4_noabort(uptr); 74 SANITIZER_INTERFACE_ATTRIBUTE 75 void __hwasan_load8_noabort(uptr); 76 SANITIZER_INTERFACE_ATTRIBUTE 77 void __hwasan_load16_noabort(uptr); 78 79 SANITIZER_INTERFACE_ATTRIBUTE 80 void __hwasan_storeN(uptr, uptr); 81 SANITIZER_INTERFACE_ATTRIBUTE 82 void __hwasan_store1(uptr); 83 SANITIZER_INTERFACE_ATTRIBUTE 84 void __hwasan_store2(uptr); 85 SANITIZER_INTERFACE_ATTRIBUTE 86 void __hwasan_store4(uptr); 87 SANITIZER_INTERFACE_ATTRIBUTE 88 void __hwasan_store8(uptr); 89 SANITIZER_INTERFACE_ATTRIBUTE 90 void __hwasan_store16(uptr); 91 92 SANITIZER_INTERFACE_ATTRIBUTE 93 void __hwasan_storeN_noabort(uptr, uptr); 94 SANITIZER_INTERFACE_ATTRIBUTE 95 void __hwasan_store1_noabort(uptr); 96 SANITIZER_INTERFACE_ATTRIBUTE 97 void __hwasan_store2_noabort(uptr); 98 SANITIZER_INTERFACE_ATTRIBUTE 99 void __hwasan_store4_noabort(uptr); 100 SANITIZER_INTERFACE_ATTRIBUTE 101 void __hwasan_store8_noabort(uptr); 102 SANITIZER_INTERFACE_ATTRIBUTE 103 void __hwasan_store16_noabort(uptr); 104 105 SANITIZER_INTERFACE_ATTRIBUTE 106 void __hwasan_tag_memory(uptr p, u8 tag, uptr sz); 107 108 SANITIZER_INTERFACE_ATTRIBUTE 109 uptr __hwasan_tag_pointer(uptr p, u8 tag); 110 111 SANITIZER_INTERFACE_ATTRIBUTE 112 void __hwasan_tag_mismatch(uptr addr, u8 ts); 113 114 SANITIZER_INTERFACE_ATTRIBUTE 115 void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame, 116 size_t outsize); 117 118 SANITIZER_INTERFACE_ATTRIBUTE 119 u8 __hwasan_generate_tag(); 120 121 // Returns the offset of the first tag mismatch or -1 if the whole range is 122 // good. 123 SANITIZER_INTERFACE_ATTRIBUTE 124 sptr __hwasan_test_shadow(const void *x, uptr size); 125 126 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 127 /* OPTIONAL */ const char* __hwasan_default_options(); 128 129 SANITIZER_INTERFACE_ATTRIBUTE 130 void __hwasan_print_shadow(const void *x, uptr size); 131 132 SANITIZER_INTERFACE_ATTRIBUTE 133 void __hwasan_handle_longjmp(const void *sp_dst); 134 135 SANITIZER_INTERFACE_ATTRIBUTE 136 void __hwasan_handle_vfork(const void *sp_dst); 137 138 SANITIZER_INTERFACE_ATTRIBUTE 139 u16 __sanitizer_unaligned_load16(const uu16 *p); 140 141 SANITIZER_INTERFACE_ATTRIBUTE 142 u32 __sanitizer_unaligned_load32(const uu32 *p); 143 144 SANITIZER_INTERFACE_ATTRIBUTE 145 u64 __sanitizer_unaligned_load64(const uu64 *p); 146 147 SANITIZER_INTERFACE_ATTRIBUTE 148 void __sanitizer_unaligned_store16(uu16 *p, u16 x); 149 150 SANITIZER_INTERFACE_ATTRIBUTE 151 void __sanitizer_unaligned_store32(uu32 *p, u32 x); 152 153 SANITIZER_INTERFACE_ATTRIBUTE 154 void __sanitizer_unaligned_store64(uu64 *p, u64 x); 155 156 SANITIZER_INTERFACE_ATTRIBUTE 157 void __hwasan_enable_allocator_tagging(); 158 159 SANITIZER_INTERFACE_ATTRIBUTE 160 void __hwasan_disable_allocator_tagging(); 161 162 SANITIZER_INTERFACE_ATTRIBUTE 163 void __hwasan_thread_enter(); 164 165 SANITIZER_INTERFACE_ATTRIBUTE 166 void __hwasan_thread_exit(); 167 168 SANITIZER_INTERFACE_ATTRIBUTE 169 void __hwasan_print_memory_usage(); 170 171 // The compiler will generate this when 172 // `-hwasan-record-stack-history-with-calls` is added as a flag, which will add 173 // frame record information to the stack ring buffer. This is an alternative to 174 // the compiler emitting instructions in the prologue for doing the same thing 175 // by accessing the ring buffer directly. 176 SANITIZER_INTERFACE_ATTRIBUTE 177 void __hwasan_add_frame_record(u64 frame_record_info); 178 179 SANITIZER_INTERFACE_ATTRIBUTE 180 void *__hwasan_memcpy(void *dst, const void *src, uptr size); 181 SANITIZER_INTERFACE_ATTRIBUTE 182 void *__hwasan_memset(void *s, int c, uptr n); 183 SANITIZER_INTERFACE_ATTRIBUTE 184 void *__hwasan_memmove(void *dest, const void *src, uptr n); 185 186 SANITIZER_INTERFACE_ATTRIBUTE 187 void __hwasan_set_error_report_callback(void (*callback)(const char *)); 188 } // extern "C" 189 190 #endif // HWASAN_INTERFACE_INTERNAL_H 191