Skip to content

Commit a737a57

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 a737a57

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

llvm/lib/Support/Unix/Signals.inc

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

8181
using namespace llvm;
8282

83-
static void SignalHandler(int Sig); // defined below.
83+
static void SignalHandler(int Sig, siginfo_t *Info,
84+
void *Context); // defined below.
8485
static void InfoSignalHandler(int Sig); // defined below.
8586

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

314315
switch (Kind) {
315316
case SignalKind::IsKill:
316-
NewHandler.sa_handler = SignalHandler;
317-
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
317+
NewHandler.sa_sigaction = SignalHandler;
318+
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
318319
break;
319320
case SignalKind::IsInfo:
320321
NewHandler.sa_handler = InfoSignalHandler;
@@ -370,7 +371,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
370371
}
371372

372373
// The signal handler that runs.
373-
static void SignalHandler(int Sig) {
374+
static void SignalHandler(int Sig, siginfo_t *Info, void *Context) {
374375
// Restore the signal behavior to default, so that the program actually
375376
// crashes when we return and the signal reissues. This also ensures that if
376377
// we crash in our signal handler that the program will terminate immediately
@@ -412,6 +413,11 @@ static void SignalHandler(int Sig) {
412413
if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP)
413414
raise(Sig);
414415
#endif
416+
417+
// Signal sent from another process, do not assume that continuing the
418+
// execution would re-raise it.
419+
if (Info->si_pid != getpid())
420+
raise(Sig);
415421
}
416422

417423
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)