Skip to content

[Support] Re-raise external signals #125854

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions llvm/lib/Support/Unix/Signals.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

using namespace llvm;

static void SignalHandler(int Sig); // defined below.
static void SignalHandler(int Sig, siginfo_t *Info, void *);
static void InfoSignalHandler(int Sig); // defined below.

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

switch (Kind) {
case SignalKind::IsKill:
NewHandler.sa_handler = SignalHandler;
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK;
NewHandler.sa_sigaction = SignalHandler;
NewHandler.sa_flags = SA_NODEFER | SA_RESETHAND | SA_ONSTACK | SA_SIGINFO;
break;
case SignalKind::IsInfo:
NewHandler.sa_handler = InfoSignalHandler;
Expand Down Expand Up @@ -370,7 +370,7 @@ void sys::CleanupOnSignal(uintptr_t Context) {
}

// The signal handler that runs.
static void SignalHandler(int Sig) {
static void SignalHandler(int Sig, siginfo_t *Info, void *) {
// Restore the signal behavior to default, so that the program actually
// crashes when we return and the signal reissues. This also ensures that if
// we crash in our signal handler that the program will terminate immediately
Expand Down Expand Up @@ -412,6 +412,11 @@ static void SignalHandler(int Sig) {
if (Sig == SIGILL || Sig == SIGFPE || Sig == SIGTRAP)
raise(Sig);
#endif

// Signal sent from another process, do not assume that continuing the
// execution would re-raise it.
if (Info->si_pid != getpid())
raise(Sig);
}

static void InfoSignalHandler(int Sig) {
Expand Down