Crash or hang if SIGSEGV+SIGALRM are nested

Christian Franke Christian.Franke@t-online.de
Thu May 29 18:01:31 GMT 2025


Takashi Yano via Cygwin wrote:
> On Thu, 29 May 2025 17:32:19 +0200
> Christian Franke wrote:
> ...
>> I still don't fully understand why a SIGSEGV triggered by an instruction
>> could interrupt a SIGALRM handler.
>> https://sourceware.org/pipermail/cygwin/2025-May/258145.html
>>
>> I guess such behavior is valid from the POSIX point of view, but it is
>> at least unexpected. If the SIGALRM handler is already running, it
>> should have interrupted the thread such that the instruction triggering
>> the segfault is not executed until the SIGALRM handler returns.
> I try to explain what is happing using the figure below.
>
>     <<<<<< Main thread >>>>>>                       < Signal Thread >
>                                              SIGNAL
>    main()   handler1() handler2()             QUEUE    wait_sig()
>      |          .          .                    |          |
>      |          .          .       ALRM         |          |
>      +----------------------------------------->|   ALRM   |
>      |          .          .       SEGV         +--------->|
>      X----------------------------------------->|          |
>      |          .       arm ALRM                |          |
>      +----------+ <----------------------------------------+
>                 |          .                    |   SEGV   |
>                 |          .                    +--------->|
>                 |          .                    |          |
>                 |          .      arm SEGV      |          |
>                 +----------+ <-----------------------------+
>                 .          |                    |          |
>           longjmp()        |                    |          |
>      +---------------------+                    |          |
>      |          .          .                    |          |
>      |          .          .                    |          |
>
> The point is the exception handler does not arm SIGSEGV handler
> directly. It just pushes the SIGSEGV into the signal queue.
> The signal thread reads the queue and process it asynchronously,
> and arms the handler().
>

I see. Thanks for nice explanation!

I created an issue at stress-ng upstream because at least the --mprotect 
test is affected:
https://github.com/ColinIanKing/stress-ng/issues/529

-- 
Regards,
Christian



More information about the Cygwin mailing list