Skip to content

Commit 77cc939

Browse files
committed
Minor adjustment from reviewer:
1. remove named unused param in `__sanitizer_start_switch_fiber` and `__sanitizer_finish_switch_fiber` 2. code style in `__sanitizer_start_switch_fiber` and `__sanitizer_finish_switch_fiber` 3. fix memory order action in `Thread::FinishSwitchFiber` 4. use `__builtin_frame_address` instead of `char local`
1 parent 612b7e6 commit 77cc939

File tree

2 files changed

+15
-24
lines changed

2 files changed

+15
-24
lines changed

compiler-rt/lib/hwasan/hwasan_interface_internal.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ void *__hwasan_memmove_match_all(void *dest, const void *src, uptr n, u8);
248248
SANITIZER_INTERFACE_ATTRIBUTE
249249
void __hwasan_set_error_report_callback(void (*callback)(const char *));
250250

251-
// hwasan does not need fake stack, so we leave it unused here.
251+
// hwasan does not need fake stack, so we leave it empty here.
252252
SANITIZER_INTERFACE_ATTRIBUTE
253-
void __sanitizer_start_switch_fiber(void **unused, const void *bottom,
253+
void __sanitizer_start_switch_fiber(void **, const void *bottom,
254254
uptr size);
255255
SANITIZER_INTERFACE_ATTRIBUTE
256-
void __sanitizer_finish_switch_fiber(void *unused, const void **bottom_old,
256+
void __sanitizer_finish_switch_fiber(void *, const void **bottom_old,
257257
uptr *size_old);
258258
} // extern "C"
259259

compiler-rt/lib/hwasan/hwasan_thread.cpp

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void Thread::Destroy() {
120120
}
121121

122122
void 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

133133
void 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

287286
extern "C" {
288287
SANITIZER_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

301296
SANITIZER_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

Comments
 (0)