Skip to content

Commit f84d18a

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 814db6c commit f84d18a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

llvm/lib/Support/Unix/Signals.inc

Lines changed: 11 additions & 6 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
@@ -401,6 +402,11 @@ static void SignalHandler(int Sig) {
401402
}
402403
}
403404

405+
// Signal sent from another process, do not assume that continuing the
406+
// execution would re-raise it.
407+
if (Info->si_pid != getpid())
408+
raise(Sig);
409+
404410
// Otherwise if it is a fault (like SEGV) run any handler.
405411
llvm::sys::RunSignalHandlers();
406412

@@ -468,8 +474,7 @@ void llvm::sys::AddSignalHandler(sys::SignalHandlerCallback FnPtr,
468474

469475
#if ENABLE_BACKTRACES && defined(HAVE_BACKTRACE) && \
470476
(defined(__linux__) || defined(__FreeBSD__) || \
471-
defined(__FreeBSD_kernel__) || defined(__NetBSD__) || \
472-
defined(__OpenBSD__) || defined(__DragonFly__))
477+
defined(__FreeBSD_kernel__) || defined(__NetBSD__))
473478
struct DlIteratePhdrData {
474479
void **StackTrace;
475480
int depth;

0 commit comments

Comments
 (0)