@@ -114,24 +114,39 @@ namespace {
114114// example, Printf may call syslog() which can itself be built with hwasan).
115115class SavedStackAllocations {
116116 public:
117- SavedStackAllocations (StackAllocationsRingBuffer *rb) {
117+ SavedStackAllocations () = default ;
118+
119+ explicit SavedStackAllocations (Thread *t) { CopyFrom (t); }
120+
121+ void CopyFrom (Thread *t) {
122+ StackAllocationsRingBuffer *rb = t->stack_allocations ();
118123 uptr size = rb->size () * sizeof (uptr);
119124 void *storage =
120125 MmapAlignedOrDieOnFatalError (size, size * 2 , " saved stack allocations" );
121126 new (&rb_) StackAllocationsRingBuffer (*rb, storage);
127+ thread_id_ = t->unique_id ();
122128 }
123129
124130 ~SavedStackAllocations () {
125- StackAllocationsRingBuffer *rb = get ();
126- UnmapOrDie (rb->StartOfStorage (), rb->size () * sizeof (uptr));
131+ if (rb_) {
132+ StackAllocationsRingBuffer *rb = get ();
133+ UnmapOrDie (rb->StartOfStorage (), rb->size () * sizeof (uptr));
134+ }
135+ }
136+
137+ const StackAllocationsRingBuffer *get () const {
138+ return (const StackAllocationsRingBuffer *)&rb_;
127139 }
128140
129141 StackAllocationsRingBuffer *get () {
130142 return (StackAllocationsRingBuffer *)&rb_;
131143 }
132144
145+ u32 thread_id () const { return thread_id_; }
146+
133147 private:
134- uptr rb_;
148+ uptr rb_ = 0 ;
149+ u32 thread_id_;
135150};
136151
137152class Decorator : public __sanitizer ::SanitizerCommonDecorator {
@@ -737,8 +752,7 @@ class TagMismatchReport : public BaseReport {
737752};
738753
739754TagMismatchReport::~TagMismatchReport () {
740- SavedStackAllocations current_stack_allocations (
741- GetCurrentThread ()->stack_allocations ());
755+ SavedStackAllocations current_stack_allocations (GetCurrentThread ());
742756
743757 Decorator d;
744758 // TODO: when possible, try to print heap-use-after-free, etc.
0 commit comments