From fa92ec8e9e59d57a1556ec7b2024de94001485ae Mon Sep 17 00:00:00 2001 From: Bruno Cardoso Lopes Date: Mon, 27 Mar 2017 18:21:31 +0000 Subject: [PATCH] [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 --- lib/Support/Unix/Signals.inc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/Support/Unix/Signals.inc b/lib/Support/Unix/Signals.inc index 081b2fe33a6..68be010ff5c 100644 --- a/lib/Support/Unix/Signals.inc +++ b/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 Guard(*SignalsMutex); // If the handlers are already registered, we're done. if (NumRegisteredSignals != 0) return; -- 2.50.1