Branch: refs/heads/smoke-me/davem/sighandler2
Home: https://github.com/Perl/perl5
Commit: 74b790600d0d6ed72ea7af55d053607ca49a052b
https://github.com/Perl/perl5/commit/74b790600d0d6ed72ea7af55d053607ca49a052b
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M embed.fnc
M iperlsys.h
M mg.c
M perl.h
M proto.h
Log Message:
-----------
add Siginfo_t
>From the code comments:
This is an alias for the OS's siginfo_t, except that where the OS
doesn't support it, declare a dummy version instead. This allows us to
have signal handler functions which always have a Siginfo_t parameter
regardless of platform, (and which will just be passed a NULL value
where the OS doesn't support HAS_SIGACTION).
It doesn't actually do anything useful yet, but will shortly allow
signal handler functions to be rationalised.
Commit: 1f7a47ae1719fceb988c5788ab4b52332f46eb1d
https://github.com/Perl/perl5/commit/1f7a47ae1719fceb988c5788ab4b52332f46eb1d
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M embed.fnc
M embed.h
M iperlsys.h
M mg.c
M perl.h
M proto.h
Log Message:
-----------
add PERL_USE_3ARG_SIGHANDLER macro
There are a bunch of places in core that do
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
to decide whether the C signal handler function should be declared with,
and called with, 1 arg or 3 args.
This commit just adds
#if defined(HAS_SIGACTION) && defined(SA_SIGINFO)
# define PERL_USE_3ARG_SIGHANDLER
#endif
Then uses the new macro in all other places rather than checking
HAS_SIGACTION and SA_SIGINFO. Thus there is no functional change; it just
makes the code more readable.
However, it turns out that all is not well with core's use of 1-arg
versus 3-arg, and the few commits will fix this.
Commit: 533e8f2fea6761b9055fd48d5faa05afd1afe2d9
https://github.com/Perl/perl5/commit/533e8f2fea6761b9055fd48d5faa05afd1afe2d9
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M embed.fnc
M embed.h
M mg.c
M proto.h
Log Message:
-----------
add a new function, Perl_perly_sighandler()
This function implements the body of what used to be Perl_sighandler(),
the latter becoming a thin wrapper round Perl_perly_sighandler().
The main reason for this change is that it allows us to add an extra
arg, 'safe' to the function without breaking backcompat. This arg
indicates whether the function is being called directly from the OS
signal handler (safe==0), or deferred via Perl_despatch_signals()
(safe==1).
This allows an infelicity in the code to be fixed - it was formerly
trying to determine the route it had been called by (and hence whether a
'safe' route) by seeing if either of the sig/uap parameters was
non-null. It turns out that this was highly dogdy, and only worked by
luck. The safe caller did indeed pass NULL args, but due to a bug
(shortly to be fixed), sometimes the kernel thinks its calling a 1-arg
sig handler when its actually calling a 3-arg one. This means that the
sig/uap args are random garbage, and happen to be non-zero only by happy
coincidence on the OS/platforms so far.
Also, it turns out that the call via Perl_csighandler() was getting it
wrong: its explicit (NULL,NULL) args made it look like a safe signal
call. This will be corrected in the next commit, but for this commit the
old wrong behaviour is preserved.
See RT #82040 for details of when/why the original dodgy 'safe' check
was
added.
Commit: 7310588705ee1959ee5af633c94d16d221c2da6b
https://github.com/Perl/perl5/commit/7310588705ee1959ee5af633c94d16d221c2da6b
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M mg.c
Log Message:
-----------
fix unsafe signals under exceptions
The preceding commit flagged up an existing bug, but kept old the buggy
behaviour. This commit fixes the bug. I haven't added a test, since it
seems that the test suite doesn't try with unsafe signals. But this
code:
$SIG{USR1} = sub { $gotit++, die };
eval { kill SIGUSR1, $$ } for 1..2;
print "gotit=$gotit\n";
when run before erroneously gave 1, but now correctly gives 2.
Basically the code that restores the signal mask after a sig handler
dies, should do it only in a direct (unsafe) signal handler: the
deferred (safe) signal handler will have already done it. The bug was
that the inbuilt perl unsafe signal handler was being incorrectly
treated as safe. The code path via POSIX (and for which a test was added
with v5.13.9-531-gc22d665b55) *was* ok.
Commit: a6d13c8f20e5b60300fa717a37f8c3aa9a4a01b1
https://github.com/Perl/perl5/commit/a6d13c8f20e5b60300fa717a37f8c3aa9a4a01b1
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M embed.fnc
M embed.h
M embedvar.h
M intrpvar.h
M iperlsys.h
M mg.c
M perl.c
M perlapi.h
M perlvars.h
M proto.h
M sv.c
Log Message:
-----------
add explicit 1-arg and 3-arg sig handler functions
Currently, whether the OS-level signal handler function is declared as
1-arg or 3-arg depends on the configuration. Add explicit versions of
these functions, principally so that POSIX.xs can call which version of
the handler it wants regardless of configuration: see next commit.
Commit: 2132bf2730274221d6e0a5f331942847d125c7a0
https://github.com/Perl/perl5/commit/2132bf2730274221d6e0a5f331942847d125c7a0
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M ext/POSIX/POSIX.xs
M ext/POSIX/lib/POSIX.pm
Log Message:
-----------
POSIX::sigaction(): use correct sig handler
Depending on whether sigaction() is called with the SA_SIGINFO flag set,
it should be setting either a 1-arg or 3-arg signal handler for the
kernel to call back. In fact it was always passing a 3-arg handler, and
telling the kernel that it was a 1-arg handler, which means that in
1-arg handler situations, the handler was being called with args 2 and 3
containing random garbage.
Instead, use the newly-added explicit-arg handler functions, which take
the specified number of args regardless of OS / configuration.`
There's a temporary hack included in the patch because perl core is
still claiming to use 3-arg handlers while actually supplying 1-arg
ones. This will be fixed shortly and the hack removed.
Commit: 83e8dc948e770aa3d9731b291f7f3ad9a085c438
https://github.com/Perl/perl5/commit/83e8dc948e770aa3d9731b291f7f3ad9a085c438
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M ext/POSIX/POSIX.xs
M perl.h
Log Message:
-----------
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.
Commit: 5dfd1c14605ea642df8ccdb0bf898f03b77443a5
https://github.com/Perl/perl5/commit/5dfd1c14605ea642df8ccdb0bf898f03b77443a5
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M util.c
Log Message:
-----------
remove some redundant sig handler type casts
Commit: 00dd08d4800d4a9f2992e16c37a2670e1bff4e8d
https://github.com/Perl/perl5/commit/00dd08d4800d4a9f2992e16c37a2670e1bff4e8d
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M mg.c
Log Message:
-----------
Perl_perly_sighandler: combine two conditions
The branch is only taken if a number of conditions are true. Combine
them into a single if statement, with the sip test first, so that an
unnecessary call to sigaction() may be skipped if its only going to
immediately fail afterwards because sip isn't true.
Shouldn't be any change in functionality.
Commit: 0356abf1145e921503342ad9bdcd65838348347b
https://github.com/Perl/perl5/commit/0356abf1145e921503342ad9bdcd65838348347b
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M mg.c
Log Message:
-----------
Perl_perly_sighandler: re-indent some code
Fix indentation after previous commits modified scopes; also indent
some nested #if's correctly.
Whitespace-only change
Commit: c228fb8a1ddad74857c9b8e3a7b38f5823df3073
https://github.com/Perl/perl5/commit/c228fb8a1ddad74857c9b8e3a7b38f5823df3073
Author: David Mitchell <[email protected]>
Date: 2019-11-12 (Tue, 12 Nov 2019)
Changed paths:
M mg.c
Log Message:
-----------
Perl_csighandler(): remove forward declaration
There's a forward declaration of this function in mg.c. This should be
redundant in these days of embed.fnc and embed.h, so remove it.
Compare: https://github.com/Perl/perl5/compare/74b790600d0d%5E...c228fb8a1dda