On Fri, 30 Sep 2022 04:53:51 GMT, David Holmes <dhol...@openjdk.org> wrote:

>> After [JDK-8294314](https://bugs.openjdk.org/browse/JDK-8294314), we would 
>> have signals_posix.cpp excluded with cast-function-type warning:
>
> src/hotspot/os/posix/signals_posix.cpp line 1727:
> 
>> 1725:   // Set up signal handler for suspend/resume
>> 1726:   act.sa_flags = SA_RESTART|SA_SIGINFO;
>> 1727:   act.sa_handler = CAST_FROM_FN_PTR(sa_handler_t, SR_handler);
> 
> The underlying cast in the macro seems a little odd for this situation but if 
> it appeases the compiler then that is fine.

No, don't do this.  The code is just wrong, and should be fixed.

We have a struct sigaction.  We've set the sa_flags member to a value that
includes SA_SIGINFO.  That means the 3 argument sa_sigaction handler is
supposed to be invoked.

We're storing the SR_handler (cast to a value matching the type of the
sa_handler member of the sigaction). This is "working" purely by accident.
Apparently on all POSIX platforms we support, the sa_handler and sa_sigaction
occupy the same memory (being in a union, which is permitted by the spec).

The signature for SR_handler should be changed from
void SR_handler(int, siginfo_t*, ucontext_t*)
to
void SR_handler(int, siginfo_t*, void*)
and adjust the code to deal with the change to the type of the 3rd parameter.

Then we can just assign the sa_sigaction member to SR_handler without any casts.

-------------

PR: https://git.openjdk.org/jdk/pull/10494

Reply via email to