summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2017-03-27 18:21:31 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2017-03-27 18:21:31 +0000
commit1856ceed8271162e7ee6c0655de693840472cf7a (patch)
treef9688d9e2591d8d8583134e4a3956c457de01670 /llvm/lib/Support/Unix
parent70d8ca9276510103beb947b8ba7b365a69a2b863 (diff)
downloadbcm5719-llvm-1856ceed8271162e7ee6c0655de693840472cf7a.tar.gz
bcm5719-llvm-1856ceed8271162e7ee6c0655de693840472cf7a.zip
[Support] Avoid concurrency hazard in signal handler registration
Several static functions from the signal API can be invoked simultaneously; RemoveFileOnSignal for instance can be called indirectly by multiple parallel loadModule() invocations, which might lead to the assertion: Assertion failed: (NumRegisteredSignals < array_lengthof(RegisteredSignalInfo) && "Out of space for signal handlers!"), function RegisterHandler, file /llvm/lib/Support/Unix/Signals.inc, line 105. RemoveFileOnSignal calls RegisterHandlers(), which isn't currently mutex protected, leading to the behavior above. This potentially affect a few other users of RegisterHandlers() too. rdar://problem/30381224 llvm-svn: 298871
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r--llvm/lib/Support/Unix/Signals.inc6
1 files changed, 1 insertions, 5 deletions
diff --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 081b2fe33a6..68be010ff5c 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -149,11 +149,7 @@ static void CreateSigAltStack() {}
#endif
static void RegisterHandlers() {
- // We need to dereference the signals mutex during handler registration so
- // that we force its construction. This is to prevent the first use being
- // during handling an actual signal because you can't safely call new in a
- // signal handler.
- *SignalsMutex;
+ sys::SmartScopedLock<true> Guard(*SignalsMutex);
// If the handlers are already registered, we're done.
if (NumRegisteredSignals != 0) return;
OpenPOWER on IntegriCloud