Skip to content

Commit c99d8cd

Browse files
committed
declare perl core's sig handler as 1-arg
First some background: UNIXy OSes support two types of signal handler function: Signal_t handler1(int sig); Signal_t handler3(int sig, siginfo_t *info, void *uap); The original one-argument handler was set using the signal(2) system call. The newer sigaction(2) system call allows either a 1-arg or 3-arg handler to be specified: act.sa_handler = handler1; sigaction(sig, act, NULL); act.sa_sigaction = handler3; act.sa_sa_flags |= SA_SIGINFO; sigaction(sig, act, NULL); The current behaviour in perl core is that, in the presence of HAS_SIGACTION and SA_SIGINFO, the signal handler type and function are both declared as 3-arg, but perl still tells the kernel that the supplied signal handler function takes one arg. This means that whenever the kernel calls the handler, args 2 and 3 are whatever garbage the OS and architecture cause them to happen to be. Note that POSIX.xs *does* allow a 3-arg signal handler to be specified by passing the SA_SIGINFO flag, and a couple of tests check for this. Recently, gcc-8 has (quite reasonably) been warning that we're passing around 3-arg function pointers where a 1-arg function pointer is expected. After the groundwork laid down by the previous commits in this branch, this commit flips things over so that the perl core now declares its handlers and handler type as being 1-arg, thus reflecting the reality that the core has actually being using 1-arg handlers. This makes a whole bunch of compiler noise like this go away: perl.h:2825:51: warning: cast between incompatible function types from ‘__sighandler_t’ {aka ‘void (*)(int)’} to ‘void (*)(int, siginfo_t *, void *)’ {aka ‘void (*)(int, struct <anonymous> *, void *)’} [-Wcast-function-type] In theory this should make no functional difference. It might cause 3rd-party XS modules to emit compiler warnings now if they are relying on things like Sighandler_t to represent a 3-arg function - this commit flips it to being 1-arg.
1 parent 19c9c2e commit c99d8cd

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

ext/POSIX/POSIX.xs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3096,7 +3096,6 @@ sigaction(sig, optaction, oldaction = 0)
30963096
#endif
30973097
)
30983098
: ( oact.sa_handler == PL_csighandler1p
3099-
|| oact.sa_handler == PL_csighandlerp /* XXX tmp */
31003099
#ifndef PERL_USE_3ARG_SIGHANDLER
31013100
|| oact.sa_handler == PL_csighandlerp
31023101
#endif

perl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2795,7 +2795,13 @@ typedef struct padname PADNAME;
27952795

27962796

27972797
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
2798-
# define PERL_USE_3ARG_SIGHANDLER
2798+
/* having sigaction(2) means that the OS supports both 1-arg and 3-arg
2799+
* signal handlers. But the perl core itself only fully supports 1-arg
2800+
* handlers, so don't enable for now.
2801+
* NB: POSIX::sigaction() supports both.
2802+
*
2803+
* # define PERL_USE_3ARG_SIGHANDLER
2804+
*/
27992805
#endif
28002806

28012807
/* Siginfo_t:

0 commit comments

Comments
 (0)