[compiler-rt] [msan] Use `pthread_atfork` instead of interceptor (PR #75398)
Vitaly Buka via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 13 14:51:27 PST 2023
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/75398
>From 4d81ef26367fc6745bb3a8eac4fee9d213c2b7c6 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 13 Dec 2023 14:49:18 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
=?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
[skip ci]
---
compiler-rt/lib/hwasan/hwasan_linux.cpp | 16 ++++++++++++++--
compiler-rt/lib/hwasan/hwasan_thread.cpp | 1 +
.../TestCases/Posix/fork_threaded.c | 2 --
3 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/compiler-rt/lib/hwasan/hwasan_linux.cpp b/compiler-rt/lib/hwasan/hwasan_linux.cpp
index f01fa42764134..3271a955e7ed1 100644
--- a/compiler-rt/lib/hwasan/hwasan_linux.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_linux.cpp
@@ -523,12 +523,24 @@ uptr TagMemoryAligned(uptr p, uptr size, tag_t tag) {
void HwasanInstallAtForkHandler() {
auto before = []() {
- HwasanAllocatorLock();
+ if (CAN_SANITIZE_LEAKS) {
+ __lsan::LockGlobal();
+ }
+ // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and lock the
+ // stuff we need.
+ __lsan::LockThreads();
+ __lsan::LockAllocator();
StackDepotLockAll();
};
auto after = []() {
StackDepotUnlockAll();
- HwasanAllocatorUnlock();
+ // `_lsan` functions defined regardless of `CAN_SANITIZE_LEAKS` and unlock
+ // the stuff we need.
+ __lsan::UnlockAllocator();
+ __lsan::UnlockThreads();
+ if (CAN_SANITIZE_LEAKS) {
+ __lsan::UnlockGlobal();
+ }
};
pthread_atfork(before, after, after);
}
diff --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp
index ce36547580e6e..3e14a718513d7 100644
--- a/compiler-rt/lib/hwasan/hwasan_thread.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp
@@ -68,6 +68,7 @@ void Thread::Init(uptr stack_buffer_start, uptr stack_buffer_size,
}
Print("Creating : ");
}
+ ClearShadowForThreadStackAndTLS();
}
void Thread::InitStackRingBuffer(uptr stack_buffer_start,
diff --git a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
index 673d35346ba83..1b4a0ad6140db 100644
--- a/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
+++ b/compiler-rt/test/sanitizer_common/TestCases/Posix/fork_threaded.c
@@ -1,7 +1,5 @@
// RUN: %clang -O0 %s -o %t && %env_tool_opts=die_after_fork=0 %run %t
-// UNSUPPORTED: hwasan
-
// The test uses pthread barriers which are not available on Darwin.
// UNSUPPORTED: darwin
More information about the llvm-commits
mailing list