Re: [PATCH] Cygwin: exceptions: Fix AArch64 non-incyg signal handling
Jon Turney <[email protected]> Thu, 2 Jul 2026 00:14:03 +0100
| Newsgroups | gmane.os.cygwin.patches |
|---|---|
| Message-ID | <[email protected]> |
On 12/06/2026 09:02, Máte Dimand wrote: > This patch fixes crashes that occur when a signal interrupts sigfe or > any non-cygwin function that does not preserve the LR register in its Right. So I think I understand how this problem manifests when interrupting a leaf function, but I wonder if you could go into a bit more detail about how it occurs inside sigfe? > prologue/epilogue. This crash was discovered through the "run-heredoc" > testcase in bash's testsuite, which caused bash to call "read" > frequently, leading to a high chance of a signal interrupting sigfe. > > The "sigdelayed" function in gendef clobbers the LR register to return > to the instruction where the thread was interrupted. Picking any other > register for branching back would also clobber said register. Leaf > functions are not guaranteed to be compiled with LR being preserved on > the stack. The solution is to use RtlRestoreContext to restore all > registers without needing to sacrifice any. > > The patch includes a C++ version of sigdelayed, which calls > RtlRestoreContext at the end. The non-incyg signal handling codepath > will change the thread's IP register to this new function instead of > the original sigdelayed function written in assembly. Cygwin functions > interrupted by signals still use the original function. Hmm... so, this looks like a reasonable implementation of the change described to address the problem identified, but... One concern I have is that this adds a single CONTEXT. I'm not entirely sure about the situations in which nested signal interrupts can occur. Is that something you considered? Is there reason to believe that can't happen in these circumstances? I wonder if there's a possible implementation where we maintain a stack of (lr, pc) tuples, and then exit by rotating those onto the top of the stack frame and popping them both? (It might also be worthwhile looking at the aarch64 implementation of RtlRestoreContext - since it must know how to restore all registers without clobbering any of them - which is exactly what we want to do in sigdelayed?) > > Signed-off-by: Máté Dimand <[email protected]> > --- > winsup/cygwin/exceptions.cc | 87 ++++++++++++++++++++++++++- > winsup/cygwin/local_includes/cygtls.h | 13 ++++ > 2 files changed, 98 insertions(+), 2 deletions(-) >