@@ -114,24 +114,39 @@ namespace {
114
114
// example, Printf may call syslog() which can itself be built with hwasan).
115
115
class SavedStackAllocations {
116
116
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 ();
118
123
uptr size = rb->size () * sizeof (uptr);
119
124
void *storage =
120
125
MmapAlignedOrDieOnFatalError (size, size * 2 , " saved stack allocations" );
121
126
new (&rb_) StackAllocationsRingBuffer (*rb, storage);
127
+ thread_id_ = t->unique_id ();
122
128
}
123
129
124
130
~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_;
127
139
}
128
140
129
141
StackAllocationsRingBuffer *get () {
130
142
return (StackAllocationsRingBuffer *)&rb_;
131
143
}
132
144
145
+ u32 thread_id () const { return thread_id_; }
146
+
133
147
private:
134
- uptr rb_;
148
+ uptr rb_ = 0 ;
149
+ u32 thread_id_;
135
150
};
136
151
137
152
class Decorator : public __sanitizer ::SanitizerCommonDecorator {
@@ -737,8 +752,7 @@ class TagMismatchReport : public BaseReport {
737
752
};
738
753
739
754
TagMismatchReport::~TagMismatchReport () {
740
- SavedStackAllocations current_stack_allocations (
741
- GetCurrentThread ()->stack_allocations ());
755
+ SavedStackAllocations current_stack_allocations (GetCurrentThread ());
742
756
743
757
Decorator d;
744
758
// TODO: when possible, try to print heap-use-after-free, etc.
0 commit comments