[compiler-rt] 93afc34 - [dfsan] Clean TLS after signal callbacks
Jianzhou Zhao via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 3 09:22:07 PST 2021
Author: Jianzhou Zhao
Date: 2021-02-03T17:21:28Z
New Revision: 93afc3452cd4ebdb145e309f4d82f82e2f496479
URL: https://github.com/llvm/llvm-project/commit/93afc3452cd4ebdb145e309f4d82f82e2f496479
DIFF: https://github.com/llvm/llvm-project/commit/93afc3452cd4ebdb145e309f4d82f82e2f496479.diff
LOG: [dfsan] Clean TLS after signal callbacks
Similar to https://reviews.llvm.org/D95642, this diff fixes signal.
Reviewed-by: morehouse
Differential Revision: https://reviews.llvm.org/D95896
Added:
Modified:
compiler-rt/lib/dfsan/dfsan_custom.cpp
compiler-rt/lib/dfsan/done_abilist.txt
compiler-rt/test/dfsan/custom.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/dfsan/dfsan_custom.cpp b/compiler-rt/lib/dfsan/dfsan_custom.cpp
index 5ecd5698a215..f90c8e813340 100644
--- a/compiler-rt/lib/dfsan/dfsan_custom.cpp
+++ b/compiler-rt/lib/dfsan/dfsan_custom.cpp
@@ -951,6 +951,29 @@ int __dfsw_sigaction(int signum, const struct sigaction *act,
return ret;
}
+SANITIZER_INTERFACE_ATTRIBUTE
+sighandler_t __dfsw_signal(int signum,
+ void *(*handler_trampoline)(void *, int, dfsan_label,
+ dfsan_label *),
+ sighandler_t handler, dfsan_label signum_label,
+ dfsan_label handler_label, dfsan_label *ret_label) {
+ CHECK_LT(signum, kMaxSignals);
+ SignalSpinLocker lock;
+ uptr old_cb = atomic_load(&sigactions[signum], memory_order_relaxed);
+ if (handler != SIG_IGN && handler != SIG_DFL) {
+ atomic_store(&sigactions[signum], (uptr)handler, memory_order_relaxed);
+ handler = &SignalHandler;
+ }
+
+ sighandler_t ret = signal(signum, handler);
+
+ if (ret == SignalHandler)
+ ret = (sighandler_t)old_cb;
+
+ *ret_label = 0;
+ return ret;
+}
+
SANITIZER_INTERFACE_ATTRIBUTE
int __dfsw_sigaltstack(const stack_t *ss, stack_t *old_ss, dfsan_label ss_label,
dfsan_label old_ss_label, dfsan_label *ret_label) {
diff --git a/compiler-rt/lib/dfsan/done_abilist.txt b/compiler-rt/lib/dfsan/done_abilist.txt
index 6db03b4817c3..1ceabf1cba6c 100644
--- a/compiler-rt/lib/dfsan/done_abilist.txt
+++ b/compiler-rt/lib/dfsan/done_abilist.txt
@@ -253,6 +253,7 @@ fun:sched_getaffinity=custom
fun:select=custom
fun:sigemptyset=custom
fun:sigaction=custom
+fun:signal=custom
fun:gettimeofday=custom
# sprintf-like
diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp
index 48fc9d004218..94ca7a82a825 100644
--- a/compiler-rt/test/dfsan/custom.cpp
+++ b/compiler-rt/test/dfsan/custom.cpp
@@ -853,6 +853,20 @@ void test_sigaction() {
assert(oldact.sa_handler == SignalHandler);
}
+void test_signal() {
+ // Set signal to be SignalHandler, save the previous one into
+ // old_signal_handler.
+ sighandler_t old_signal_handler = signal(SIGHUP, SignalHandler);
+ ASSERT_ZERO_LABEL(old_signal_handler);
+
+ // Set SIG_IGN or SIG_DFL, and check the previous one is expected.
+ assert(SignalHandler == signal(SIGHUP, SIG_DFL));
+ assert(SIG_DFL == signal(SIGHUP, SIG_IGN));
+
+ // Restore signal to old_signal_handler.
+ assert(SIG_IGN == signal(SIGHUP, old_signal_handler));
+}
+
void test_sigaltstack() {
stack_t old_altstack = {};
dfsan_set_label(j_label, &old_altstack, sizeof(old_altstack));
@@ -1323,6 +1337,7 @@ int main(void) {
test_sched_getaffinity();
test_select();
test_sigaction();
+ test_signal();
test_sigaltstack();
test_sigemptyset();
test_snprintf();
More information about the llvm-commits
mailing list