-
Notifications
You must be signed in to change notification settings - Fork 0
Implement stabilize_sig_stack
#27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: woarm64
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Implements the stabilize_sig_stack routine on AArch64 to mirror the x64 behavior used by setjmp/longjmp.
- Adds AArch64 assembly prologue/epilogue and register saves/restores
- Implements an atomic lock loop,
incy gcounter management, and conditional signal handling - Calls into
call_signal_handlerand handles cleanup before returning the TLS pointer
Comments suppressed due to low confidence (3)
winsup/cygwin/scripts/gendef:450
- This
addinstruction overwrites the TLS pointer in x0 instead of preparing the argument. It should likely beadd x1, x10, x1(or use a fresh register) to compute the address without clobbering x0.
add x0, x0, x1
winsup/cygwin/scripts/gendef:455
- This uses x1 instead of the offset in x11, so the address of
incy gwill be calculated incorrectly. It should readadd x11, x10, x11.
add x11, x10, x1
winsup/cygwin/scripts/gendef:408
- There’s no visible test coverage for the new
stabilize_sig_stackroutine; consider adding a targeted test or integration scenario to validate lock acquisition, signal handling, and stack restoration.
.seh_proc stabilize_sig_stack
7d28934 to
bdf0148
Compare
stabilize_sig_stackstabilize_sig_stack
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Implements the AArch64 version of stabilize_sig_stack to mirror existing x64 logic for use in setjmp/longjmp.
- Adds function prologue/epilogue and per-thread lock around signal processing
- Manages the
incygcounter and invokes the C++-style signal handler in a loop - Returns the TLS base pointer in
x0and releases locks appropriately
Comments suppressed due to low confidence (4)
winsup/cygwin/scripts/gendef:422
- [nitpick] Swapping with the same register for source and destination works but is subtle. For clarity and to avoid surprises, use separate registers for the value to store and the old value (e.g.
mov w8, #1; swp w9, w8, [x11]).
swp w9, w9, [x11] // try to acquire the lock using atomic swap
winsup/cygwin/scripts/gendef:410
- [nitpick] This new AArch64 routine appears untested. Adding unit or integration tests for
stabilize_sig_stackwould help catch regressions and verify signal-handling behavior.
// prologue
winsup/cygwin/scripts/gendef:455
- The comment says "store incremented value back," but this is after decrementing the counter. It should read "store decremented value back."
str w9, [x11] // store incremented value back
winsup/cygwin/scripts/gendef:435
- The addressing mode
ldr w9, [x10, =_cygtls.current_sig]is not valid AArch64 syntax. Use a separate literal load and offset addition (e.g.ldr x11, =_cygtls.current_sig; add x11, x10, x11; ldr w9, [x11]) to compute the correct address.
ldr w9, [x10, =_cygtls.current_sig] // load current value of current_sig
4a6fbc1 to
2e7d7e9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds the AArch64 implementation of the stabilize_sig_stack routine—used by both setjmp and longjmp—to manage TLS-based signal locking and dispatch.
- Introduces a new
stabilize_sig_stackfunction in assembly for ARM64 - Implements a spinlock on
stacklock, increments/decrements theincygcounter, and invokes the signal handler if needed - Pushes/restores callee-saved registers and returns the TLS base in
x0
Comments suppressed due to low confidence (2)
winsup/cygwin/scripts/gendef:414
- [nitpick] The comment could be clearer; consider rephrasing to "Save x13 (scratch) and x14 to maintain stack alignment" to concisely explain why both registers are pushed.
stp\tx13, x14, [sp, #-0x10]!\t\t// save x13 register used next and x14 just to keep stack orientation and alignment
winsup/cygwin/scripts/gendef:471
- The comment says "store incremented value back" but this path actually decrements the counter. Update it to "store decremented value back" for accuracy.
str\tw9, [x11]\t\t// store incremented value back
stabilize_sig_stackstabilize_sig_stack
2e7d7e9 to
58d8814
Compare
58d8814 to
b402a39
Compare
| mov x0, x10 // return TLS address in x0 (return value) | ||
| // epilogue | ||
| .seh_startepilogue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.seh commands are not needed here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thanks. I believe that you know far more about this topic. Could you possibly share link to some documentation where I can learn why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only available documentation is https://learn.microsoft.com/en-us/cpp/build/arm64-exception-handling?view=msvc-170#unwind-codes
and binutils/gcc source code.
in short, for a single instruction like this, not having seh_endepilogue or duplicating seh commands is not changing anything. Both options are acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From this answer I'd deduce that the fact that it has no effect is an implementation detail of GCC/binutils so it makes sense to keep it for consistency with the prologue and accross the compilers (Regardled that Cygwin is build only with GCC, one never know who will copy&paste this code elsewhere).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coming back to this thread, it is worth mentioning again that .seh_startepilogue is not needed here and unwinding should be fully covered by prolog. Current implementation emits duplicated unwinding codes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the stabilize_sig_stack routine for AArch64, mirroring the x64 implementation for improved support in setjmp/longjmp functionality.
- Introduces an assembly implementation for signal stack stabilization.
- Adds atomic operations for lock handling and incyg counter management in the new routine.
b402a39 to
424d171
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the AArch64 version of the stabilize_sig_stack routine used by setjmp/longjmp, following the existing x64 implementation.
- Implements a new signal stack stabilization routine with atomic lock acquisition for thread local storage.
- Includes loop-based lock acquisition with yield and signal handler invocation.
c79dc35 to
7143206
Compare
7143206 to
69e08ec
Compare
69e08ec to
ace3e4e
Compare
ace3e4e to
1ffacac
Compare
1ffacac to
3089c70
Compare
3089c70 to
547be0f
Compare
547be0f to
fac5e8b
Compare
9fc7826 to
af8957d
Compare
af8957d to
f2de0a5
Compare
ccb77cc to
aa712ee
Compare
f2de0a5 to
323c28f
Compare
Implements
stabilize_sig_stackroutine for AArch64 that is used both insetjmpandlongjmproutines implementation. Please, refer to x64 implementation for comparison.Validated by https://github.com/Windows-on-ARM-Experiments/mingw-woarm64-build/actions/runs/15304776330