Skip to content

Commit 1d83024

Browse files
authored
Merge pull request #10988 from bulbazord/20240723-signal-handler
[Support] Don't re-raise signals sent from kernel (llvm#145759)
2 parents 77936b9 + 9346d8d commit 1d83024

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

llvm/lib/Support/Unix/Signals.inc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@
8080
#endif
8181
#endif
8282

83+
#if defined(__linux__)
84+
#include <sys/syscall.h>
85+
#endif
86+
8387
using namespace llvm;
8488

8589
static void SignalHandler(int Sig, siginfo_t *Info, void *);
@@ -411,10 +415,21 @@ static void SignalHandler(int Sig, siginfo_t *Info, void *) {
411415
raise(Sig);
412416
#endif
413417

414-
// Signal sent from another process, do not assume that continuing the
415-
// execution would re-raise it.
416-
if (Info->si_pid != getpid())
418+
#if defined(__linux__)
419+
// Re-raising a signal via `raise` loses the original siginfo. Recent
420+
// versions of linux (>= 3.9) support processes sending a signal to itself
421+
// with arbitrary signal information using a syscall. If this syscall is
422+
// unsupported, errno will be set to EPERM and `raise` will be used instead.
423+
int retval =
424+
syscall(SYS_rt_tgsigqueueinfo, getpid(), syscall(SYS_gettid), Sig, Info);
425+
if (retval != 0 && errno == EPERM)
417426
raise(Sig);
427+
#else
428+
// Signal sent from another userspace process, do not assume that continuing
429+
// the execution would re-raise it.
430+
if (Info->si_pid != getpid() && Info->si_pid != 0)
431+
raise(Sig);
432+
#endif
418433
}
419434

420435
static void InfoSignalHandler(int Sig) {

0 commit comments

Comments
 (0)