@@ -252,40 +252,112 @@ static void SigIll() {
252
252
// __builtin_unreachable();
253
253
}
254
254
255
- template <bool IsStore, unsigned LogSize>
256
- __attribute__ ((always_inline, nodebug))
257
- static void CheckAddress(uptr p) {
255
+ enum class ErrorAction { Abort, Recover };
256
+ enum class AccessType { Load, Store };
257
+
258
+ template <ErrorAction EA, AccessType AT, unsigned LogSize>
259
+ __attribute__ ((always_inline, nodebug)) static void CheckAddress(uptr p) {
258
260
tag_t ptr_tag = GetTagFromPointer (p);
259
261
uptr ptr_raw = p & ~kAddressTagMask ;
260
262
tag_t mem_tag = *(tag_t *)MEM_TO_SHADOW (ptr_raw);
261
- if (UNLIKELY (ptr_tag != mem_tag)) SigIll<0x100 + 0x10 * IsStore + LogSize>();
263
+ if (UNLIKELY (ptr_tag != mem_tag)) {
264
+ SigIll<0x100 + 0x20 * (EA == ErrorAction::Recover) +
265
+ 0x10 * (AT == AccessType::Store) + LogSize>();
266
+ if (EA == ErrorAction::Abort) __builtin_unreachable ();
267
+ }
262
268
}
263
269
264
- template < bool IsStore >
265
- __attribute__ ((always_inline, nodebug))
266
- static void CheckAddressSized(uptr p, uptr sz) {
270
+ template <ErrorAction EA, AccessType AT >
271
+ __attribute__ ((always_inline, nodebug)) static void CheckAddressSized(uptr p,
272
+ uptr sz) {
267
273
CHECK_NE (0 , sz);
268
274
tag_t ptr_tag = GetTagFromPointer (p);
269
275
uptr ptr_raw = p & ~kAddressTagMask ;
270
276
tag_t *shadow_first = (tag_t *)MEM_TO_SHADOW (ptr_raw);
271
277
tag_t *shadow_last = (tag_t *)MEM_TO_SHADOW (ptr_raw + sz - 1 );
272
278
for (tag_t *t = shadow_first; t <= shadow_last; ++t)
273
- if (UNLIKELY (ptr_tag != *t)) SigIll<0x100 + 0x10 * IsStore + 0xf >();
274
- }
275
-
276
- void __hwasan_load (uptr p, uptr sz) { CheckAddressSized<false >(p, sz); }
277
- void __hwasan_load1 (uptr p) { CheckAddress<false , 0 >(p); }
278
- void __hwasan_load2 (uptr p) { CheckAddress<false , 1 >(p); }
279
- void __hwasan_load4 (uptr p) { CheckAddress<false , 2 >(p); }
280
- void __hwasan_load8 (uptr p) { CheckAddress<false , 3 >(p); }
281
- void __hwasan_load16 (uptr p) { CheckAddress<false , 4 >(p); }
282
-
283
- void __hwasan_store (uptr p, uptr sz) { CheckAddressSized<true >(p, sz); }
284
- void __hwasan_store1 (uptr p) { CheckAddress<true , 0 >(p); }
285
- void __hwasan_store2 (uptr p) { CheckAddress<true , 1 >(p); }
286
- void __hwasan_store4 (uptr p) { CheckAddress<true , 2 >(p); }
287
- void __hwasan_store8 (uptr p) { CheckAddress<true , 3 >(p); }
288
- void __hwasan_store16 (uptr p) { CheckAddress<true , 4 >(p); }
279
+ if (UNLIKELY (ptr_tag != *t)) {
280
+ SigIll<0x100 + 0x20 * (EA == ErrorAction::Recover) +
281
+ 0x10 * (AT == AccessType::Store) + 0xf >();
282
+ if (EA == ErrorAction::Abort) __builtin_unreachable ();
283
+ }
284
+ }
285
+
286
+ void __hwasan_load (uptr p, uptr sz) {
287
+ CheckAddressSized<ErrorAction::Abort, AccessType::Load>(p, sz);
288
+ }
289
+ void __hwasan_load1 (uptr p) {
290
+ CheckAddress<ErrorAction::Abort, AccessType::Load, 0 >(p);
291
+ }
292
+ void __hwasan_load2 (uptr p) {
293
+ CheckAddress<ErrorAction::Abort, AccessType::Load, 1 >(p);
294
+ }
295
+ void __hwasan_load4 (uptr p) {
296
+ CheckAddress<ErrorAction::Abort, AccessType::Load, 2 >(p);
297
+ }
298
+ void __hwasan_load8 (uptr p) {
299
+ CheckAddress<ErrorAction::Abort, AccessType::Load, 3 >(p);
300
+ }
301
+ void __hwasan_load16 (uptr p) {
302
+ CheckAddress<ErrorAction::Abort, AccessType::Load, 4 >(p);
303
+ }
304
+
305
+ void __hwasan_load_noabort (uptr p, uptr sz) {
306
+ CheckAddressSized<ErrorAction::Recover, AccessType::Load>(p, sz);
307
+ }
308
+ void __hwasan_load1_noabort (uptr p) {
309
+ CheckAddress<ErrorAction::Recover, AccessType::Load, 0 >(p);
310
+ }
311
+ void __hwasan_load2_noabort (uptr p) {
312
+ CheckAddress<ErrorAction::Recover, AccessType::Load, 1 >(p);
313
+ }
314
+ void __hwasan_load4_noabort (uptr p) {
315
+ CheckAddress<ErrorAction::Recover, AccessType::Load, 2 >(p);
316
+ }
317
+ void __hwasan_load8_noabort (uptr p) {
318
+ CheckAddress<ErrorAction::Recover, AccessType::Load, 3 >(p);
319
+ }
320
+ void __hwasan_load16_noabort (uptr p) {
321
+ CheckAddress<ErrorAction::Recover, AccessType::Load, 4 >(p);
322
+ }
323
+
324
+ void __hwasan_store (uptr p, uptr sz) {
325
+ CheckAddressSized<ErrorAction::Abort, AccessType::Store>(p, sz);
326
+ }
327
+ void __hwasan_store1 (uptr p) {
328
+ CheckAddress<ErrorAction::Abort, AccessType::Store, 0 >(p);
329
+ }
330
+ void __hwasan_store2 (uptr p) {
331
+ CheckAddress<ErrorAction::Abort, AccessType::Store, 1 >(p);
332
+ }
333
+ void __hwasan_store4 (uptr p) {
334
+ CheckAddress<ErrorAction::Abort, AccessType::Store, 2 >(p);
335
+ }
336
+ void __hwasan_store8 (uptr p) {
337
+ CheckAddress<ErrorAction::Abort, AccessType::Store, 3 >(p);
338
+ }
339
+ void __hwasan_store16 (uptr p) {
340
+ CheckAddress<ErrorAction::Abort, AccessType::Store, 4 >(p);
341
+ }
342
+
343
+ void __hwasan_store_noabort (uptr p, uptr sz) {
344
+ CheckAddressSized<ErrorAction::Recover, AccessType::Store>(p, sz);
345
+ }
346
+ void __hwasan_store1_noabort (uptr p) {
347
+ CheckAddress<ErrorAction::Recover, AccessType::Store, 0 >(p);
348
+ }
349
+ void __hwasan_store2_noabort (uptr p) {
350
+ CheckAddress<ErrorAction::Recover, AccessType::Store, 1 >(p);
351
+ }
352
+ void __hwasan_store4_noabort (uptr p) {
353
+ CheckAddress<ErrorAction::Recover, AccessType::Store, 2 >(p);
354
+ }
355
+ void __hwasan_store8_noabort (uptr p) {
356
+ CheckAddress<ErrorAction::Recover, AccessType::Store, 3 >(p);
357
+ }
358
+ void __hwasan_store16_noabort (uptr p) {
359
+ CheckAddress<ErrorAction::Recover, AccessType::Store, 4 >(p);
360
+ }
289
361
290
362
#if !SANITIZER_SUPPORTS_WEAK_HOOKS
291
363
extern " C" {
0 commit comments