Skip to content

Commit 22c761c

Browse files
Avoid concurrency hazard in signal handler registration (#5272)
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 Co-authored-by: Bruno Cardoso Lopes <[email protected]>
1 parent fb7043e commit 22c761c

1 file changed

Lines changed: 3 additions & 7 deletions

File tree

lib/Support/Unix/Signals.inc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,8 @@ static void RegisterHandler(int Signal) {
112112
}
113113

114114
static void RegisterHandlers() {
115-
// We need to dereference the signals mutex during handler registration so
116-
// that we force its construction. This is to prevent the first use being
117-
// during handling an actual signal because you can't safely call new in a
118-
// signal handler.
119-
*SignalsMutex;
120-
115+
sys::SmartScopedLock<true> Guard(*SignalsMutex);
116+
121117
// If the handlers are already registered, we're done.
122118
if (NumRegisteredSignals != 0) return;
123119

@@ -164,7 +160,7 @@ static void RemoveFilesToRemove() {
164160
// super-user permissions.
165161
if (!S_ISREG(buf.st_mode))
166162
continue;
167-
163+
168164
// Otherwise, remove the file. We ignore any errors here as there is nothing
169165
// else we can do.
170166
unlink(path);

0 commit comments

Comments
 (0)