xref: /freebsd/contrib/llvm-project/compiler-rt/lib/hwasan/hwasan_interface_internal.h (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
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_loadN_match_all(uptr, uptr, u8);
81 SANITIZER_INTERFACE_ATTRIBUTE
82 void __hwasan_load1_match_all(uptr, u8);
83 SANITIZER_INTERFACE_ATTRIBUTE
84 void __hwasan_load2_match_all(uptr, u8);
85 SANITIZER_INTERFACE_ATTRIBUTE
86 void __hwasan_load4_match_all(uptr, u8);
87 SANITIZER_INTERFACE_ATTRIBUTE
88 void __hwasan_load8_match_all(uptr, u8);
89 SANITIZER_INTERFACE_ATTRIBUTE
90 void __hwasan_load16_match_all(uptr, u8);
91 
92 SANITIZER_INTERFACE_ATTRIBUTE
93 void __hwasan_loadN_match_all_noabort(uptr, uptr, u8);
94 SANITIZER_INTERFACE_ATTRIBUTE
95 void __hwasan_load1_match_all_noabort(uptr, u8);
96 SANITIZER_INTERFACE_ATTRIBUTE
97 void __hwasan_load2_match_all_noabort(uptr, u8);
98 SANITIZER_INTERFACE_ATTRIBUTE
99 void __hwasan_load4_match_all_noabort(uptr, u8);
100 SANITIZER_INTERFACE_ATTRIBUTE
101 void __hwasan_load8_match_all_noabort(uptr, u8);
102 SANITIZER_INTERFACE_ATTRIBUTE
103 void __hwasan_load16_match_all_noabort(uptr, u8);
104 
105 SANITIZER_INTERFACE_ATTRIBUTE
106 void __hwasan_storeN(uptr, uptr);
107 SANITIZER_INTERFACE_ATTRIBUTE
108 void __hwasan_store1(uptr);
109 SANITIZER_INTERFACE_ATTRIBUTE
110 void __hwasan_store2(uptr);
111 SANITIZER_INTERFACE_ATTRIBUTE
112 void __hwasan_store4(uptr);
113 SANITIZER_INTERFACE_ATTRIBUTE
114 void __hwasan_store8(uptr);
115 SANITIZER_INTERFACE_ATTRIBUTE
116 void __hwasan_store16(uptr);
117 
118 SANITIZER_INTERFACE_ATTRIBUTE
119 void __hwasan_storeN_noabort(uptr, uptr);
120 SANITIZER_INTERFACE_ATTRIBUTE
121 void __hwasan_store1_noabort(uptr);
122 SANITIZER_INTERFACE_ATTRIBUTE
123 void __hwasan_store2_noabort(uptr);
124 SANITIZER_INTERFACE_ATTRIBUTE
125 void __hwasan_store4_noabort(uptr);
126 SANITIZER_INTERFACE_ATTRIBUTE
127 void __hwasan_store8_noabort(uptr);
128 SANITIZER_INTERFACE_ATTRIBUTE
129 void __hwasan_store16_noabort(uptr);
130 
131 SANITIZER_INTERFACE_ATTRIBUTE
132 void __hwasan_storeN_match_all(uptr, uptr, u8);
133 SANITIZER_INTERFACE_ATTRIBUTE
134 void __hwasan_store1_match_all(uptr, u8);
135 SANITIZER_INTERFACE_ATTRIBUTE
136 void __hwasan_store2_match_all(uptr, u8);
137 SANITIZER_INTERFACE_ATTRIBUTE
138 void __hwasan_store4_match_all(uptr, u8);
139 SANITIZER_INTERFACE_ATTRIBUTE
140 void __hwasan_store8_match_all(uptr, u8);
141 SANITIZER_INTERFACE_ATTRIBUTE
142 void __hwasan_store16_match_all(uptr, u8);
143 
144 SANITIZER_INTERFACE_ATTRIBUTE
145 void __hwasan_storeN_match_all_noabort(uptr, uptr, u8);
146 SANITIZER_INTERFACE_ATTRIBUTE
147 void __hwasan_store1_match_all_noabort(uptr, u8);
148 SANITIZER_INTERFACE_ATTRIBUTE
149 void __hwasan_store2_match_all_noabort(uptr, u8);
150 SANITIZER_INTERFACE_ATTRIBUTE
151 void __hwasan_store4_match_all_noabort(uptr, u8);
152 SANITIZER_INTERFACE_ATTRIBUTE
153 void __hwasan_store8_match_all_noabort(uptr, u8);
154 SANITIZER_INTERFACE_ATTRIBUTE
155 void __hwasan_store16_match_all_noabort(uptr, u8);
156 
157 SANITIZER_INTERFACE_ATTRIBUTE
158 void __hwasan_tag_memory(uptr p, u8 tag, uptr sz);
159 
160 SANITIZER_INTERFACE_ATTRIBUTE
161 uptr __hwasan_tag_pointer(uptr p, u8 tag);
162 
163 SANITIZER_INTERFACE_ATTRIBUTE
164 void __hwasan_tag_mismatch(uptr addr, u8 ts);
165 
166 SANITIZER_INTERFACE_ATTRIBUTE
167 void __hwasan_tag_mismatch4(uptr addr, uptr access_info, uptr *registers_frame,
168                             size_t outsize);
169 
170 SANITIZER_INTERFACE_ATTRIBUTE
171 u8 __hwasan_generate_tag();
172 
173 // Returns the offset of the first tag mismatch or -1 if the whole range is
174 // good.
175 SANITIZER_INTERFACE_ATTRIBUTE
176 sptr __hwasan_test_shadow(const void *x, uptr size);
177 
178 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
179 /* OPTIONAL */ const char* __hwasan_default_options();
180 
181 SANITIZER_INTERFACE_ATTRIBUTE
182 void __hwasan_print_shadow(const void *x, uptr size);
183 
184 SANITIZER_INTERFACE_ATTRIBUTE
185 void __hwasan_handle_longjmp(const void *sp_dst);
186 
187 SANITIZER_INTERFACE_ATTRIBUTE
188 void __hwasan_handle_vfork(const void *sp_dst);
189 
190 SANITIZER_INTERFACE_ATTRIBUTE
191 u16 __sanitizer_unaligned_load16(const uu16 *p);
192 
193 SANITIZER_INTERFACE_ATTRIBUTE
194 u32 __sanitizer_unaligned_load32(const uu32 *p);
195 
196 SANITIZER_INTERFACE_ATTRIBUTE
197 u64 __sanitizer_unaligned_load64(const uu64 *p);
198 
199 SANITIZER_INTERFACE_ATTRIBUTE
200 void __sanitizer_unaligned_store16(uu16 *p, u16 x);
201 
202 SANITIZER_INTERFACE_ATTRIBUTE
203 void __sanitizer_unaligned_store32(uu32 *p, u32 x);
204 
205 SANITIZER_INTERFACE_ATTRIBUTE
206 void __sanitizer_unaligned_store64(uu64 *p, u64 x);
207 
208 SANITIZER_INTERFACE_ATTRIBUTE
209 void __hwasan_enable_allocator_tagging();
210 
211 SANITIZER_INTERFACE_ATTRIBUTE
212 void __hwasan_disable_allocator_tagging();
213 
214 SANITIZER_INTERFACE_ATTRIBUTE
215 void __hwasan_thread_enter();
216 
217 SANITIZER_INTERFACE_ATTRIBUTE
218 void __hwasan_thread_exit();
219 
220 SANITIZER_INTERFACE_ATTRIBUTE
221 void __hwasan_print_memory_usage();
222 
223 // The compiler will generate this when
224 // `-hwasan-record-stack-history-with-calls` is added as a flag, which will add
225 // frame record information to the stack ring buffer. This is an alternative to
226 // the compiler emitting instructions in the prologue for doing the same thing
227 // by accessing the ring buffer directly.
228 SANITIZER_INTERFACE_ATTRIBUTE
229 void __hwasan_add_frame_record(u64 frame_record_info);
230 
231 SANITIZER_INTERFACE_ATTRIBUTE
232 void *__hwasan_memcpy(void *dst, const void *src, uptr size);
233 SANITIZER_INTERFACE_ATTRIBUTE
234 void *__hwasan_memset(void *s, int c, uptr n);
235 SANITIZER_INTERFACE_ATTRIBUTE
236 void *__hwasan_memmove(void *dest, const void *src, uptr n);
237 
238 SANITIZER_INTERFACE_ATTRIBUTE
239 void *__hwasan_memcpy_match_all(void *dst, const void *src, uptr size, u8);
240 SANITIZER_INTERFACE_ATTRIBUTE
241 void *__hwasan_memset_match_all(void *s, int c, uptr n, u8);
242 SANITIZER_INTERFACE_ATTRIBUTE
243 void *__hwasan_memmove_match_all(void *dest, const void *src, uptr n, u8);
244 
245 SANITIZER_INTERFACE_ATTRIBUTE
246 void __hwasan_set_error_report_callback(void (*callback)(const char *));
247 }  // extern "C"
248 
249 #endif  // HWASAN_INTERFACE_INTERNAL_H
250