Skip to content

Commit 3c283ef

Browse files
committed
[tsan] Keep a stack of old signal sets in the signal handler
1 parent 9123520 commit 3c283ef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "sanitizer_common/sanitizer_posix.h"
2828
#include "sanitizer_common/sanitizer_stacktrace.h"
2929
#include "sanitizer_common/sanitizer_tls_get_addr.h"
30+
#include "sanitizer_common/sanitizer_vector.h"
3031
#include "tsan_fd.h"
3132
#include "tsan_interceptors.h"
3233
#include "tsan_interface.h"
@@ -177,7 +178,7 @@ struct ThreadSignalContext {
177178
SignalDesc pending_signals[kSigCount];
178179
// emptyset and oldset are too big for stack.
179180
__sanitizer_sigset_t emptyset;
180-
__sanitizer_sigset_t oldset;
181+
__sanitizer::Vector<__sanitizer_sigset_t> oldset;
181182
};
182183

183184
void EnterBlockingFunc(ThreadState *thr) {
@@ -980,6 +981,7 @@ void PlatformCleanUpThreadState(ThreadState *thr) {
980981
&thr->signal_ctx, memory_order_relaxed);
981982
if (sctx) {
982983
atomic_store(&thr->signal_ctx, 0, memory_order_relaxed);
984+
sctx->oldset.Reset();
983985
UnmapOrDie(sctx, sizeof(*sctx));
984986
}
985987
}
@@ -2176,7 +2178,8 @@ void ProcessPendingSignalsImpl(ThreadState *thr) {
21762178
return;
21772179
atomic_fetch_add(&thr->in_signal_handler, 1, memory_order_relaxed);
21782180
internal_sigfillset(&sctx->emptyset);
2179-
int res = REAL(pthread_sigmask)(SIG_SETMASK, &sctx->emptyset, &sctx->oldset);
2181+
__sanitizer_sigset_t *oldset = sctx->oldset.PushBack();
2182+
int res = REAL(pthread_sigmask)(SIG_SETMASK, &sctx->emptyset, oldset);
21802183
CHECK_EQ(res, 0);
21812184
for (int sig = 0; sig < kSigCount; sig++) {
21822185
SignalDesc *signal = &sctx->pending_signals[sig];
@@ -2186,8 +2189,9 @@ void ProcessPendingSignalsImpl(ThreadState *thr) {
21862189
&signal->ctx);
21872190
}
21882191
}
2189-
res = REAL(pthread_sigmask)(SIG_SETMASK, &sctx->oldset, 0);
2192+
res = REAL(pthread_sigmask)(SIG_SETMASK, oldset, 0);
21902193
CHECK_EQ(res, 0);
2194+
sctx->oldset.PopBack();
21912195
atomic_fetch_add(&thr->in_signal_handler, -1, memory_order_relaxed);
21922196
}
21932197

0 commit comments

Comments
 (0)