forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sanitizer_common] AND signals in BlockSignals instead of deleting (l…
…lvm#113443) My earlier patch llvm#98200 caused a regression because it unconditionally unblocked synchronous signals, even if the user program had deliberately blocked them. This patch fixes the issue by checking the current signal mask, as suggested by Vitaly. It also adds tests. Fixes llvm#113385 --------- Co-authored-by: Vitaly Buka <vitalybuka@gmail.com>
- Loading branch information
1 parent
030ce43
commit 1e547fc
Showing
3 changed files
with
101 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
compiler-rt/lib/sanitizer_common/tests/sanitizer_block_signals.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//===-- 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 |