@@ -120,7 +120,7 @@ void Thread::Destroy() {
120120}
121121
122122void Thread::StartSwitchFiber (uptr bottom, uptr size) {
123- if (atomic_load (&stack_switching_, memory_order_relaxed )) {
123+ if (atomic_load (&stack_switching_, memory_order_acquire )) {
124124 Report (" ERROR: starting fiber switch while in fiber switch\n " );
125125 Die ();
126126 }
@@ -131,7 +131,7 @@ void Thread::StartSwitchFiber(uptr bottom, uptr size) {
131131}
132132
133133void Thread::FinishSwitchFiber (uptr *bottom_old, uptr *size_old) {
134- if (!atomic_load (&stack_switching_, memory_order_relaxed )) {
134+ if (!atomic_load (&stack_switching_, memory_order_acquire )) {
135135 Report (" ERROR: finishing a fiber switch that has not started\n " );
136136 Die ();
137137 }
@@ -154,8 +154,7 @@ inline Thread::StackBounds Thread::GetStackBounds() const {
154154 return {0 , 0 };
155155 return {stack_bottom_, stack_top_};
156156 }
157- char local;
158- const uptr cur_stack = (uptr)&local;
157+ const uptr cur_stack = (uptr)__builtin_frame_address (0 );
159158 // Note: need to check next stack first, because FinishSwitchFiber
160159 // may be in process of overwriting stack_top_/bottom_. But in such case
161160 // we are already on the next stack.
@@ -286,28 +285,20 @@ using namespace __hwasan;
286285
287286extern " C" {
288287SANITIZER_INTERFACE_ATTRIBUTE
289- void __sanitizer_start_switch_fiber (void **unused , const void *bottom,
288+ void __sanitizer_start_switch_fiber (void **, const void *bottom,
290289 uptr size) {
291- // this is just a placeholder which make the interface same as ASan
292- (void )unused;
293- auto *t = GetCurrentThread ();
294- if (!t) {
290+ if (auto *t = GetCurrentThread ())
291+ t->StartSwitchFiber ((uptr)bottom, size);
292+ else
295293 VReport (1 , " __hwasan_start_switch_fiber called from unknown thread\n " );
296- return ;
297- }
298- t->StartSwitchFiber ((uptr)bottom, size);
299294}
300295
301296SANITIZER_INTERFACE_ATTRIBUTE
302- void __sanitizer_finish_switch_fiber (void *unused , const void **bottom_old,
297+ void __sanitizer_finish_switch_fiber (void *, const void **bottom_old,
303298 uptr *size_old) {
304- // this is just a placeholder which make the interface same as ASan
305- (void )unused;
306- auto *t = GetCurrentThread ();
307- if (!t) {
299+ if (auto *t = GetCurrentThread ())
300+ t->FinishSwitchFiber ((uptr *)bottom_old, size_old);
301+ else
308302 VReport (1 , " __hwasan_finish_switch_fiber called from unknown thread\n " );
309- return ;
310- }
311- t->FinishSwitchFiber ((uptr *)bottom_old, size_old);
312303}
313- }
304+ }
0 commit comments