[PATCH] D31356: [Support] Avoid concurrency hazard in signal handler registration
Bruno Cardoso Lopes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 24 14:53:38 PDT 2017
bruno created this revision.
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. Since there are a few potentially affected static functions, this patch fix `RegisterHandlers` to use a mutex.
https://reviews.llvm.org/D31356
Files:
lib/Support/Unix/Signals.inc
Index: lib/Support/Unix/Signals.inc
===================================================================
--- lib/Support/Unix/Signals.inc
+++ lib/Support/Unix/Signals.inc
@@ -149,11 +149,7 @@
#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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31356.93012.patch
Type: text/x-patch
Size: 662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170324/31be6260/attachment.bin>
More information about the llvm-commits
mailing list