@@ -375,6 +375,82 @@ static void ShowHeapOrGlobalCandidate(uptr untagged_addr, tag_t *candidate,
375
375
}
376
376
}
377
377
378
+ void ReportStats () {}
379
+
380
+ static void PrintTagInfoAroundAddr (tag_t *tag_ptr, uptr num_rows,
381
+ void (*print_tag)(InternalScopedString &s,
382
+ tag_t *tag)) {
383
+ const uptr row_len = 16 ; // better be power of two.
384
+ tag_t *center_row_beg = reinterpret_cast <tag_t *>(
385
+ RoundDownTo (reinterpret_cast <uptr>(tag_ptr), row_len));
386
+ tag_t *beg_row = center_row_beg - row_len * (num_rows / 2 );
387
+ tag_t *end_row = center_row_beg + row_len * ((num_rows + 1 ) / 2 );
388
+ InternalScopedString s;
389
+ for (tag_t *row = beg_row; row < end_row; row += row_len) {
390
+ s.Append (row == center_row_beg ? " =>" : " " );
391
+ s.AppendF (" %p:" , (void *)ShadowToMem (reinterpret_cast <uptr>(row)));
392
+ for (uptr i = 0 ; i < row_len; i++) {
393
+ s.Append (row + i == tag_ptr ? " [" : " " );
394
+ print_tag (s, &row[i]);
395
+ s.Append (row + i == tag_ptr ? " ]" : " " );
396
+ }
397
+ s.AppendF (" \n " );
398
+ }
399
+ Printf (" %s" , s.data ());
400
+ }
401
+
402
+ static void PrintTagsAroundAddr (tag_t *tag_ptr) {
403
+ Printf (
404
+ " Memory tags around the buggy address (one tag corresponds to %zd "
405
+ " bytes):\n " ,
406
+ kShadowAlignment );
407
+ PrintTagInfoAroundAddr (tag_ptr, 17 , [](InternalScopedString &s, tag_t *tag) {
408
+ s.AppendF (" %02x" , *tag);
409
+ });
410
+
411
+ Printf (
412
+ " Tags for short granules around the buggy address (one tag corresponds "
413
+ " to %zd bytes):\n " ,
414
+ kShadowAlignment );
415
+ PrintTagInfoAroundAddr (tag_ptr, 3 , [](InternalScopedString &s, tag_t *tag) {
416
+ if (*tag >= 1 && *tag <= kShadowAlignment ) {
417
+ uptr granule_addr = ShadowToMem (reinterpret_cast <uptr>(tag));
418
+ s.AppendF (" %02x" ,
419
+ *reinterpret_cast <u8 *>(granule_addr + kShadowAlignment - 1 ));
420
+ } else {
421
+ s.AppendF (" .." );
422
+ }
423
+ });
424
+ Printf (
425
+ " See "
426
+ " https://clang.llvm.org/docs/"
427
+ " HardwareAssistedAddressSanitizerDesign.html#short-granules for a "
428
+ " description of short granule tags\n " );
429
+ }
430
+
431
+ static uptr GetTopPc (StackTrace *stack) {
432
+ return stack->size ? StackTrace::GetPreviousInstructionPc (stack->trace [0 ])
433
+ : 0 ;
434
+ }
435
+
436
+ namespace {
437
+ class BaseReport {
438
+ public:
439
+ BaseReport (StackTrace *stack, bool fatal, uptr tagged_addr)
440
+ : scoped_report(fatal),
441
+ stack (stack),
442
+ tagged_addr(tagged_addr),
443
+ untagged_addr(UntagAddr(tagged_addr)),
444
+ ptr_tag(GetTagFromPointer(tagged_addr)) {}
445
+
446
+ protected:
447
+ ScopedReport scoped_report;
448
+ StackTrace *stack;
449
+ uptr tagged_addr;
450
+ uptr untagged_addr;
451
+ tag_t ptr_tag;
452
+ };
453
+
378
454
static void PrintAddressDescription (
379
455
uptr tagged_addr, uptr access_size,
380
456
StackAllocationsRingBuffer *current_stack_allocations) {
@@ -514,81 +590,6 @@ static void PrintAddressDescription(
514
590
}
515
591
}
516
592
517
- void ReportStats () {}
518
-
519
- static void PrintTagInfoAroundAddr (tag_t *tag_ptr, uptr num_rows,
520
- void (*print_tag)(InternalScopedString &s,
521
- tag_t *tag)) {
522
- const uptr row_len = 16 ; // better be power of two.
523
- tag_t *center_row_beg = reinterpret_cast <tag_t *>(
524
- RoundDownTo (reinterpret_cast <uptr>(tag_ptr), row_len));
525
- tag_t *beg_row = center_row_beg - row_len * (num_rows / 2 );
526
- tag_t *end_row = center_row_beg + row_len * ((num_rows + 1 ) / 2 );
527
- InternalScopedString s;
528
- for (tag_t *row = beg_row; row < end_row; row += row_len) {
529
- s.Append (row == center_row_beg ? " =>" : " " );
530
- s.AppendF (" %p:" , (void *)ShadowToMem (reinterpret_cast <uptr>(row)));
531
- for (uptr i = 0 ; i < row_len; i++) {
532
- s.Append (row + i == tag_ptr ? " [" : " " );
533
- print_tag (s, &row[i]);
534
- s.Append (row + i == tag_ptr ? " ]" : " " );
535
- }
536
- s.AppendF (" \n " );
537
- }
538
- Printf (" %s" , s.data ());
539
- }
540
-
541
- static void PrintTagsAroundAddr (tag_t *tag_ptr) {
542
- Printf (
543
- " Memory tags around the buggy address (one tag corresponds to %zd "
544
- " bytes):\n " , kShadowAlignment );
545
- PrintTagInfoAroundAddr (tag_ptr, 17 , [](InternalScopedString &s, tag_t *tag) {
546
- s.AppendF (" %02x" , *tag);
547
- });
548
-
549
- Printf (
550
- " Tags for short granules around the buggy address (one tag corresponds "
551
- " to %zd bytes):\n " ,
552
- kShadowAlignment );
553
- PrintTagInfoAroundAddr (tag_ptr, 3 , [](InternalScopedString &s, tag_t *tag) {
554
- if (*tag >= 1 && *tag <= kShadowAlignment ) {
555
- uptr granule_addr = ShadowToMem (reinterpret_cast <uptr>(tag));
556
- s.AppendF (" %02x" ,
557
- *reinterpret_cast <u8 *>(granule_addr + kShadowAlignment - 1 ));
558
- } else {
559
- s.AppendF (" .." );
560
- }
561
- });
562
- Printf (
563
- " See "
564
- " https://clang.llvm.org/docs/"
565
- " HardwareAssistedAddressSanitizerDesign.html#short-granules for a "
566
- " description of short granule tags\n " );
567
- }
568
-
569
- static uptr GetTopPc (StackTrace *stack) {
570
- return stack->size ? StackTrace::GetPreviousInstructionPc (stack->trace [0 ])
571
- : 0 ;
572
- }
573
-
574
- namespace {
575
- class BaseReport {
576
- public:
577
- BaseReport (StackTrace *stack, bool fatal, uptr tagged_addr)
578
- : scoped_report(fatal),
579
- stack (stack),
580
- tagged_addr(tagged_addr),
581
- untagged_addr(UntagAddr(tagged_addr)),
582
- ptr_tag(GetTagFromPointer(tagged_addr)) {}
583
-
584
- protected:
585
- ScopedReport scoped_report;
586
- StackTrace *stack;
587
- uptr tagged_addr;
588
- uptr untagged_addr;
589
- tag_t ptr_tag;
590
- };
591
-
592
593
class InvalidFreeReport : public BaseReport {
593
594
public:
594
595
InvalidFreeReport (StackTrace *stack, uptr tagged_addr)
0 commit comments