Skip to content

Commit 3162a7f

Browse files
committed
[Support] Re-raise external signals
Otherwise, the handler "swallows" the signal and the process continues to execute. While this use case is peculiar, ignoring these signals entirely seems more odd.
1 parent ccd92ec commit 3162a7f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

llvm/lib/Support/Unix/Signals.inc

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
using namespace llvm;
8282

83-
static void SignalHandler(int Sig); // defined below.
83+
static void SignalHandler(int Sig, siginfo_t *Info, void *); // defined below.
8484
static void InfoSignalHandler(int Sig); // defined below.
8585

8686
using SignalHandlerFunctionType = void (*)();
@@ -313,8 +313,8 @@ static void RegisterHandlers() { // Not signal-safe.
313313

314314
switch (Kind) {
315315
case SignalKind::IsKill:
316-
NewHandler.sa_handler = SignalHandler;
317-
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
316+
NewHandler.sa_sigaction = SignalHandler;
317+
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
318318
break;
319319
case SignalKind::IsInfo:
320320
NewHandler.sa_handler = InfoSignalHandler;
@@ -370,7 +370,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
370370
}
371371

372372
// The signal handler that runs.
373-
static void SignalHandler(int Sig) {
373+
static void SignalHandler(int Sig, siginfo_t *Info, void *) {
374374
// Restore the signal behavior to default, so that the program actually
375375
// crashes when we return and the signal reissues. This also ensures that if
376376
// we crash in our signal handler that the program will terminate immediately
@@ -412,6 +412,11 @@ static void SignalHandler(int Sig) {
412412
if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP)
413413
raise(Sig);
414414
#endif
415+
416+
// Signal sent from another process, do not assume that continuing the
417+
// execution would re-raise it.
418+
if (Info->si_pid != getpid())
419+
raise(Sig);
415420
}
416421

417422
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)