Skip to content

Commit 060e4f6

Browse files
Fix amd64 restore callback stack pointer (#18)
* Fix amd64 restore callback stack pointer Restore the sysv_amd64 callback stack-pointer fix so STACKMAN_OP_RESTORE receives the active switched stack pointer, not the pre-switch value. Update both the assembly and inline GCC x86_64 paths for consistent callback behavior. Add a regression assertion in tests/test.c and document the fix in CHANGELOG.md under Unreleased. * CI: pin Windows runner to 2022 Pin build-windows to windows-2022 to avoid v143 toolset availability drift on windows-latest, especially for ARM64. Document this CI change in CHANGELOG.md under Unreleased. * Changelog: address PR review notes Use sysv_amd64 naming in Unreleased fix entry and add missing [Unreleased] compare link reference.
1 parent d136f89 commit 060e4f6

5 files changed

Lines changed: 15 additions & 3 deletions

File tree

.github/workflows/buildcommit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ jobs:
128128
path: lib/${{ matrix.abi }}/libstackman.a
129129

130130
build-windows:
131-
runs-on: windows-latest
131+
runs-on: windows-2022
132132
strategy:
133133
matrix:
134134
platform: [x86, x64, arm64]

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [Unreleased]
9+
10+
### Changed
11+
- CI: pinned Windows runner to `windows-2022` (from `windows-latest`) to keep VS2022 v143 toolset availability stable for ARM64 builds
12+
13+
### Fixed
14+
- Fixed amd64 (sysv_amd64 GCC) restore callback stack-pointer argument to pass the active switched stack pointer
15+
- Added assertion coverage in `tests/test.c` to detect incorrect restore callback stack pointer on amd64
16+
817
## [1.2.0] - 2025-11-16
918

1019
### Added
@@ -99,6 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99108
- GitHub Actions CI for automated building and testing
100109
- Visual Studio project files (VS2017, VS2019, VS2022)
101110

111+
[Unreleased]: https://github.com/stackless-dev/stackman/compare/v1.2.0...HEAD
102112
[1.2.0]: https://github.com/stackless-dev/stackman/releases/tag/v1.2.0
103113
[1.1.0]: https://github.com/stackless-dev/stackman/releases/tag/v1.1.0
104114
[1.0.1]: https://github.com/stackless-dev/stackman/releases/tag/v1.0.1

stackman/platforms/switch_x86_64_gcc.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ LABEL(stackman_switch)
9393
addq %rax, %rbp
9494
# 0 "" 2
9595
#NO_APP
96-
movq %rbx, %rdx
96+
movq %rsp, %rdx
9797
movl $1, %esi
9898
movq %r15, %rdi
9999
call *%r14

stackman/platforms/switch_x86_64_gcc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context)
6767
__asm__ ("movq %[result], %%rsp" :: [result] "r" (stack_pointer2));
6868
__asm__ ("addq %[arg], %%rbp" :: [arg] "r" (diff));
6969

70-
stack_pointer = callback(context, STACKMAN_OP_RESTORE, stack_pointer);
70+
stack_pointer = callback(context, STACKMAN_OP_RESTORE, stack_pointer2);
7171
/* restore non-volatile registers from stack */
7272
__asm__ volatile (
7373
"ldmxcsr %[sr]\n\t"

tests/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ void *jmp_cb(void* context, int opcode, void *sp)
102102
if (opcode == (int)STACKMAN_OP_SAVE) {
103103
return c->stack_near;
104104
} else {
105+
/* RESTORE must receive the active switched stack pointer. */
106+
assert(sp == c->stack_near);
105107
restore_stack(c->stack_near, c->buf, c->size);
106108
return sp;
107109
}

0 commit comments

Comments
 (0)