Commit 9580d7f
committed
Cygwin: thread: Fix stack alignment for PTHREAD_CANCEL_ASYNCHRONOUS
The test case winsup/testsuites/winsup.api/pthread/cancel2 fails
on Windows 11 and Windows Server 2025, while it works on Windows 10
and Windows Server 2022. PTHREAD_CANCEL_ASYNCHRONOUS is implemented
by forcing the target thread's instruction pointer (IP) to pthread::
static_cancel_self() using [GS]etThreadContext(). static_cancel_self()
will call Windows API function during thread shutdown. A misaligned
stack will lead to unexpected exceptions.
Previously, the stack pointer was not maintained to 16-byte alignment,
even though this is required by 64-bit Windows ABI. At the start of
the function prologue, the stack is expected to be at an offset of
8 byte from 16-byte boundary (SP % 16 == 8) in x86_64 architecture,
as the call instruction has just pushed the return IP onto the stack.
However, this appears to have been overlooked when cygwin first added
x86_64 support.
This patch fixes this issue by aligning the stack pointer as well as
the instruction pointer in the PTHREAD_CANCEL_ASYNCHRONOUS handling.
Addresses: https://cygwin.com/pipermail/cygwin/2025-December/259117.html
Fixes: 6152219 ("* Merge in cygwin-64bit-branch.")
Reported-by: Takashi Yano <takashi.yano@nifty.ne.jp>
Reviewed-by: Jon Turney <jon.turney@dronecode.org.uk>
Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
(cherry picked from commit b41e3b6)1 parent ac07897 commit 9580d7f
1 file changed
Lines changed: 20 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
629 | 629 | | |
630 | 630 | | |
631 | 631 | | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
632 | 649 | | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
633 | 653 | | |
634 | 654 | | |
635 | 655 | | |
| |||
0 commit comments