[compiler-rt] 083a5cd - Revert "[sanitizer_common] AND signals in BlockSignals instead of deleting (#113443)"
Thurston Dang via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 31 14:08:43 PDT 2024
Author: Thurston Dang
Date: 2024-10-31T21:08:22Z
New Revision: 083a5cdbeab09517d8345868970d4f41170d7ed2
URL: https://github.com/llvm/llvm-project/commit/083a5cdbeab09517d8345868970d4f41170d7ed2
DIFF: https://github.com/llvm/llvm-project/commit/083a5cdbeab09517d8345868970d4f41170d7ed2.diff
LOG: Revert "[sanitizer_common] AND signals in BlockSignals instead of deleting (#113443)"
This reverts commit 25fd366d6a7d40266ff27c134ed8beb0a90cc33b.
Reason: buildbot breakage (https://lab.llvm.org/buildbot/#/builders/186/builds/3642)
Added:
Modified:
compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
Removed:
compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
################################################################################
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
index 82bc21d341a8be..33107eb0b42993 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_linux.cpp
@@ -164,45 +164,33 @@ void SetSigProcMask(__sanitizer_sigset_t *set, __sanitizer_sigset_t *oldset) {
CHECK_EQ(0, internal_sigprocmask(SIG_SETMASK, set, oldset));
}
-// Deletes the specified signal from newset, if it is not present in oldset
-// Equivalently: newset[signum] = newset[signum] & oldset[signum]
-static void KeepUnblocked(__sanitizer_sigset_t &newset,
- __sanitizer_sigset_t &oldset, int signum) {
- if (!internal_sigismember(&oldset, signum))
- internal_sigdelset(&newset, signum);
-}
-
// Block asynchronous signals
void BlockSignals(__sanitizer_sigset_t *oldset) {
- __sanitizer_sigset_t currentset;
- SetSigProcMask(NULL, ¤tset);
-
- __sanitizer_sigset_t newset;
- internal_sigfillset(&newset);
+ __sanitizer_sigset_t set;
+ internal_sigfillset(&set);
# if SANITIZER_LINUX && !SANITIZER_ANDROID
// Glibc uses SIGSETXID signal during setuid call. If this signal is blocked
// on any thread, setuid call hangs.
// See test/sanitizer_common/TestCases/Linux/setuid.c.
- KeepUnblocked(newset, currentset, 33);
+ internal_sigdelset(&set, 33);
# endif
# if SANITIZER_LINUX
// Seccomp-BPF-sandboxed processes rely on SIGSYS to handle trapped syscalls.
// If this signal is blocked, such calls cannot be handled and the process may
// hang.
- KeepUnblocked(newset, currentset, 31);
+ internal_sigdelset(&set, 31);
// Don't block synchronous signals
- // but also don't unblock signals that the user had deliberately blocked.
- KeepUnblocked(newset, currentset, SIGSEGV);
- KeepUnblocked(newset, currentset, SIGBUS);
- KeepUnblocked(newset, currentset, SIGILL);
- KeepUnblocked(newset, currentset, SIGTRAP);
- KeepUnblocked(newset, currentset, SIGABRT);
- KeepUnblocked(newset, currentset, SIGFPE);
- KeepUnblocked(newset, currentset, SIGPIPE);
+ internal_sigdelset(&set, SIGSEGV);
+ internal_sigdelset(&set, SIGBUS);
+ internal_sigdelset(&set, SIGILL);
+ internal_sigdelset(&set, SIGTRAP);
+ internal_sigdelset(&set, SIGABRT);
+ internal_sigdelset(&set, SIGFPE);
+ internal_sigdelset(&set, SIGPIPE);
# endif
- SetSigProcMask(&newset, oldset);
+ SetSigProcMask(&set, oldset);
}
ScopedBlockSignals::ScopedBlockSignals(__sanitizer_sigset_t *copy) {
diff --git a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
index fef8bb772e0e0d..2b4c15125263a9 100644
--- a/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
+++ b/compiler-rt/lib/sanitizer_common/tests/CMakeLists.txt
@@ -15,7 +15,6 @@ set(SANITIZER_UNITTESTS
sanitizer_array_ref_test.cpp
sanitizer_atomic_test.cpp
sanitizer_bitvector_test.cpp
- sanitizer_block_signals.cpp
sanitizer_bvgraph_test.cpp
sanitizer_chained_origin_depot_test.cpp
sanitizer_common_test.cpp
diff --git a/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp b/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
deleted file mode 100644
index 17791c1494ca7d..00000000000000
--- a/compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
+++ /dev/null
@@ -1,76 +0,0 @@
-//===-- sanitizer_block_signals.cpp ---------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of sanitizer_common unit tests.
-//
-//===----------------------------------------------------------------------===//
-#include <signal.h>
-#include <stdio.h>
-
-#include "gtest/gtest.h"
-#include "sanitizer_common/sanitizer_linux.h"
-
-namespace __sanitizer {
-
-#if SANITIZER_LINUX
-volatile int received_sig = -1;
-
-void signal_handler(int signum) { received_sig = signum; }
-
-TEST(SanitizerCommon, NoBlockSignals) {
- // No signals blocked
- signal(SIGUSR1, signal_handler);
- raise(SIGUSR1);
- EXPECT_EQ(received_sig, SIGUSR1);
-
- received_sig = -1;
- signal(SIGPIPE, signal_handler);
- raise(SIGPIPE);
- EXPECT_EQ(received_sig, SIGPIPE);
-}
-
-TEST(SanitizerCommon, BlockSignalsPlain) {
- // ScopedBlockSignals; SIGUSR1 should be blocked but not SIGPIPE
- {
- __sanitizer_sigset_t sigset = {};
- ScopedBlockSignals block(&sigset);
-
- received_sig = -1;
- signal(SIGUSR1, signal_handler);
- raise(SIGUSR1);
- EXPECT_EQ(received_sig, -1);
-
- received_sig = -1;
- signal(SIGPIPE, signal_handler);
- raise(SIGPIPE);
- EXPECT_EQ(received_sig, SIGPIPE);
- }
- EXPECT_EQ(received_sig, SIGUSR1);
-}
-
-TEST(SanitizerCommon, BlockSignalsExceptPipe) {
- // Manually block SIGPIPE; ScopedBlockSignals should not unblock this
- sigset_t block_sigset;
- sigemptyset(&block_sigset);
- sigaddset(&block_sigset, SIGPIPE);
- sigprocmask(SIG_BLOCK, &block_sigset, NULL);
- {
- __sanitizer_sigset_t sigset = {};
- ScopedBlockSignals block(&sigset);
-
- received_sig = -1;
- signal(SIGPIPE, signal_handler);
- raise(SIGPIPE);
- EXPECT_EQ(received_sig, -1);
- }
- sigprocmask(SIG_UNBLOCK, &block_sigset, NULL);
- EXPECT_EQ(received_sig, SIGPIPE);
-}
-#endif // SANITIZER_LINUX
-
-} // namespace __sanitizer
More information about the llvm-commits
mailing list