Skip to content

Commit f7830df

Browse files
committed
[Support] Re-raise external signals (llvm#125854)
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 6d9705c commit f7830df

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
@@ -82,7 +82,7 @@
8282

8383
using namespace llvm;
8484

85-
static void SignalHandler(int Sig); // defined below.
85+
static void SignalHandler(int Sig, siginfo_t *Info, void *);
8686
static void InfoSignalHandler(int Sig); // defined below.
8787

8888
using SignalHandlerFunctionType = void (*)();
@@ -311,8 +311,8 @@ static void RegisterHandlers() { // Not signal-safe.
311311

312312
switch (Kind) {
313313
case SignalKind::IsKill:
314-
NewHandler.sa_handler = SignalHandler;
315-
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
314+
NewHandler.sa_sigaction = SignalHandler;
315+
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
316316
break;
317317
case SignalKind::IsInfo:
318318
NewHandler.sa_handler = InfoSignalHandler;
@@ -368,7 +368,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
368368
}
369369

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

415420
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)