Re: [PATCH v2] exceptions: Fix AArch64 non-incyg signal handling

Máté Dimand <[email protected]> Tue, 4 Aug 2026 14:44:46 +0200
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
Hi, thanks for applying the patch!

> cygtls::sigdelayed_impl could probably be marked with
> __attribute__((noreturn))?
Thanks for spotting that, I agree, it should be marked with it.
> Elsewhere ([1], in the implementation of setcontext), the claim is
> made that RtlRestoreContext() can fail on synthetic contexts (meaning,
> not directly the result of RtlCaptureContext()).
>
> Do you agree? Is there good reason to believe that the manipulations
> we perform on a context here are "safe"?

I took a peek into RtlRestoreContext, and excluding all code that's
related to the optional ExceptionRecord argument (which in our instance
is NULL), the only validation it seems to do is for the stack pointer by
checking:
     1. Sp is between StackBase and StackLimit (TEB members)
     2. if it isn't, and StackLimit !=3D DeallocationStack, then it checks
if Sp is between StackBase and (StackLimit - 0x1000), presumably for
checking if it is in the guard page

If it fails both checks then it uses __fastfail to exit.

RtlCaptureContext on the other hand, is described to fail (in a comment
in cygtls.h at line 189) if the context is not aligned to 16
bytes. Looking into its code however, I didn't see any specific check
for this, maybe it's only there on x86/x64. Either way, on AArch64
Windows enforces that the stack is always 16-byte aligned through the
use of a hardware feature
(https://learn.microsoft.com/en-us/cpp/build/arm64-windows-abi-conventions?=
view=3Dmsvc-170#stack).


Best regards,
M=C3=A1t=C3=A9 Dimand

IMPORTANT NOTICE: The contents of this email and any attachments are confid=
ential and may also be privileged. If you are not the intended recipient, p=
lease notify the sender immediately and do not disclose the contents to any=
 other person, use it for any purpose, or store or copy the information in =
any medium. Thank you.