llvm.org GIT mirror llvm / fa92ec8
[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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298871 91177308-0d34-0410-b5e6-96231b3b80d8 Bruno Cardoso Lopes 3 years ago
1 changed file(s) with 1 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
148148 #endif
149149
150150 static void RegisterHandlers() {
151 // We need to dereference the signals mutex during handler registration so
152 // that we force its construction. This is to prevent the first use being
153 // during handling an actual signal because you can't safely call new in a
154 // signal handler.
155 *SignalsMutex;
151 sys::SmartScopedLock Guard(*SignalsMutex);
156152
157153 // If the handlers are already registered, we're done.
158154 if (NumRegisteredSignals != 0) return;