From 519abc5d6eb8a2887322de109e27d2c7271ec29e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 9 May 2026 11:15:29 +0000 Subject: [PATCH 1/3] 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. --- CHANGELOG.md | 6 ++++++ stackman/platforms/switch_x86_64_gcc.S | 2 +- stackman/platforms/switch_x86_64_gcc.h | 2 +- tests/test.c | 2 ++ 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf15082..b9443c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [Unreleased] + +### Fixed +- Fixed amd64 (sysv_x86_64 GCC) restore callback stack-pointer argument to pass the active switched stack pointer +- Added assertion coverage in `tests/test.c` to detect incorrect restore callback stack pointer on amd64 + ## [1.2.0] - 2025-11-16 ### Added diff --git a/stackman/platforms/switch_x86_64_gcc.S b/stackman/platforms/switch_x86_64_gcc.S index d4e2191..f4c7ca7 100644 --- a/stackman/platforms/switch_x86_64_gcc.S +++ b/stackman/platforms/switch_x86_64_gcc.S @@ -93,7 +93,7 @@ LABEL(stackman_switch) addq %rax, %rbp # 0 "" 2 #NO_APP - movq %rbx, %rdx + movq %rsp, %rdx movl $1, %esi movq %r15, %rdi call *%r14 diff --git a/stackman/platforms/switch_x86_64_gcc.h b/stackman/platforms/switch_x86_64_gcc.h index 50f566a..6c89514 100644 --- a/stackman/platforms/switch_x86_64_gcc.h +++ b/stackman/platforms/switch_x86_64_gcc.h @@ -67,7 +67,7 @@ void *STACKMAN_SWITCH_INASM_NAME(stackman_cb_t callback, void *context) __asm__ ("movq %[result], %%rsp" :: [result] "r" (stack_pointer2)); __asm__ ("addq %[arg], %%rbp" :: [arg] "r" (diff)); - stack_pointer = callback(context, STACKMAN_OP_RESTORE, stack_pointer); + stack_pointer = callback(context, STACKMAN_OP_RESTORE, stack_pointer2); /* restore non-volatile registers from stack */ __asm__ volatile ( "ldmxcsr %[sr]\n\t" diff --git a/tests/test.c b/tests/test.c index eb3d27f..f8a0057 100644 --- a/tests/test.c +++ b/tests/test.c @@ -102,6 +102,8 @@ void *jmp_cb(void* context, int opcode, void *sp) if (opcode == (int)STACKMAN_OP_SAVE) { return c->stack_near; } else { + /* RESTORE must receive the active switched stack pointer. */ + assert(sp == c->stack_near); restore_stack(c->stack_near, c->buf, c->size); return sp; } From 0734fde28283d028dad7edffcdd58a7ad2501e00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 9 May 2026 11:20:54 +0000 Subject: [PATCH 2/3] 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. --- .github/workflows/buildcommit.yml | 2 +- CHANGELOG.md | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/buildcommit.yml b/.github/workflows/buildcommit.yml index 452c4e4..b6a3713 100644 --- a/.github/workflows/buildcommit.yml +++ b/.github/workflows/buildcommit.yml @@ -128,7 +128,7 @@ jobs: path: lib/${{ matrix.abi }}/libstackman.a build-windows: - runs-on: windows-latest + runs-on: windows-2022 strategy: matrix: platform: [x86, x64, arm64] diff --git a/CHANGELOG.md b/CHANGELOG.md index b9443c6..513221e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed +- CI: pinned Windows runner to `windows-2022` (from `windows-latest`) to keep VS2022 v143 toolset availability stable for ARM64 builds + ### Fixed - Fixed amd64 (sysv_x86_64 GCC) restore callback stack-pointer argument to pass the active switched stack pointer - Added assertion coverage in `tests/test.c` to detect incorrect restore callback stack pointer on amd64 From fbe5ca936ad0f31b1872e5b252b348a4d0c8a798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristj=C3=A1n=20Valur=20J=C3=B3nsson?= Date: Sat, 9 May 2026 11:27:15 +0000 Subject: [PATCH 3/3] Changelog: address PR review notes Use sysv_amd64 naming in Unreleased fix entry and add missing [Unreleased] compare link reference. --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 513221e..ca0c648 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - CI: pinned Windows runner to `windows-2022` (from `windows-latest`) to keep VS2022 v143 toolset availability stable for ARM64 builds ### Fixed -- Fixed amd64 (sysv_x86_64 GCC) restore callback stack-pointer argument to pass the active switched stack pointer +- Fixed amd64 (sysv_amd64 GCC) restore callback stack-pointer argument to pass the active switched stack pointer - Added assertion coverage in `tests/test.c` to detect incorrect restore callback stack pointer on amd64 ## [1.2.0] - 2025-11-16 @@ -108,6 +108,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - GitHub Actions CI for automated building and testing - Visual Studio project files (VS2017, VS2019, VS2022) +[Unreleased]: https://github.com/stackless-dev/stackman/compare/v1.2.0...HEAD [1.2.0]: https://github.com/stackless-dev/stackman/releases/tag/v1.2.0 [1.1.0]: https://github.com/stackless-dev/stackman/releases/tag/v1.1.0 [1.0.1]: https://github.com/stackless-dev/stackman/releases/tag/v1.0.1