Skip to content

Commit e122a02

Browse files
author
git apple-llvm automerger
committed
Merge commit '89361007aa8a' from llvm.org/main into next
2 parents 1fa85ce + 8936100 commit e122a02

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

compiler-rt/lib/hwasan/hwasan_linux.cpp

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -294,25 +294,6 @@ void InstallAtExitHandler() { atexit(HwasanAtExit); }
294294

295295
// ---------------------- TSD ---------------- {{{1
296296

297-
extern "C" void __hwasan_thread_enter() {
298-
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
299-
}
300-
301-
extern "C" void __hwasan_thread_exit() {
302-
Thread *t = GetCurrentThread();
303-
// Make sure that signal handler can not see a stale current thread pointer.
304-
atomic_signal_fence(memory_order_seq_cst);
305-
if (t) {
306-
// Block async signals on the thread as the handler can be instrumented.
307-
// After this point instrumented code can't access essential data from TLS
308-
// and will crash.
309-
// Bionic already calls __hwasan_thread_exit with blocked signals.
310-
if (SANITIZER_GLIBC)
311-
BlockSignals();
312-
hwasanThreadList().ReleaseThread(t);
313-
}
314-
}
315-
316297
# if HWASAN_WITH_INTERCEPTORS
317298
static pthread_key_t tsd_key;
318299
static bool tsd_key_inited = false;
@@ -561,4 +542,25 @@ void InstallAtExitCheckLeaks() {
561542

562543
} // namespace __hwasan
563544

545+
using namespace __hwasan;
546+
547+
extern "C" void __hwasan_thread_enter() {
548+
hwasanThreadList().CreateCurrentThread()->EnsureRandomStateInited();
549+
}
550+
551+
extern "C" void __hwasan_thread_exit() {
552+
Thread *t = GetCurrentThread();
553+
// Make sure that signal handler can not see a stale current thread pointer.
554+
atomic_signal_fence(memory_order_seq_cst);
555+
if (t) {
556+
// Block async signals on the thread as the handler can be instrumented.
557+
// After this point instrumented code can't access essential data from TLS
558+
// and will crash.
559+
// Bionic already calls __hwasan_thread_exit with blocked signals.
560+
if (SANITIZER_GLIBC)
561+
BlockSignals();
562+
hwasanThreadList().ReleaseThread(t);
563+
}
564+
}
565+
564566
#endif // SANITIZER_FREEBSD || SANITIZER_LINUX || SANITIZER_NETBSD

0 commit comments

Comments
 (0)