purego: support RegisterFunc and typed callbacks on Windows 386#478
purego: support RegisterFunc and typed callbacks on Windows 386#478nekohasekai wants to merge 4 commits into
Conversation
|
Can you create an issue to track this change? |
24c96da to
e84a25f
Compare
|
Update README.md too |
|
The README is already updated in this PR — the platform table now lists Windows 386 with footnote 2 (structs supported as arguments/return values in calls, but not in callbacks), replacing the previous footnotes 3 and 6. Let me know if you'd like it documented differently. |
|
Ah sorry, I missed that |
There was a problem hiding this comment.
Pull request overview
Extends PureGo’s Windows/386 support beyond SyscallN/NewCallback by implementing the ABI handling needed for typed RegisterFunc/RegisterLibFunc calls, typed callbacks (including cdecl/stdcall cleanup), 64-bit scalar splitting/reconstruction, and x87 float returns, and adds dedicated Windows/386 ABI and callback test coverage plus CI updates.
Changes:
- Adds Windows/386 callback trampoline/dispatch path and x87 return handling to support typed callbacks and float/int64 returns.
- Adds Windows/386 struct-by-value support for direct calls and updates existing struct tests accordingly.
- Introduces comprehensive Windows/386 ABI tests and updates CI to exercise Windows/386 (cgo + non-cgo, optimized + unoptimized).
Reviewed changes
Copilot reviewed 18 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| zcallback_386.s | Expands callback trampoline table build coverage to include windows/386. |
| windows_386_test.go | Adds Windows/386 ABI + callback + concurrency/reentrancy + x87 edge-case tests. |
| wincallback.go | Updates generated assembly build constraints to include windows/386. |
| testdata/structtest/struct_test.c | Fixes register-sum computation to be width-safe across architectures. |
| testdata/abitest/abi_test.c | Adds Windows/386-specific ABI/callback test helpers implemented in C. |
| syscall_windows.go | Routes NewCallback through an internal newCallback to enable custom windows/386 behavior. |
| syscall_32bit.go | Adds floatReturn control field used by the 386 bridge to capture x87 results safely. |
| sys_windows_386.s | Implements windows/386 callback trampoline part that restores integer/x87 return conventions. |
| sys_arm.s | Updates struct layout commentary to reflect renamed field. |
| sys_386.s | Enables syscall bridge on windows/386 and adds guarded x87 return capture logic. |
| struct_windows_386.go | Implements windows/386 struct argument packing and struct return reconstruction. |
| struct_test.go | Enables struct tests on windows/386 and fixes type-width expectations. |
| struct_other.go | Excludes windows/386 from “no-struct-support” fallback implementation. |
| README.md | Updates Windows/386 support tier notes to reflect added struct support for direct calls. |
| func.go | Implements windows/386 slot accounting, 64-bit return reconstruction, and x87 float-return modes. |
| func_test.go | Removes windows/386 skips now that CI/tooling is expected to support building test DLLs. |
| callback_windows_other.go | Keeps stdlib-backed callbacks on non-386 Windows. |
| callback_windows_386.go | Adds typed callback decoding/encoding for windows/386 using a stdlib-compatible bridge. |
| .github/workflows/test.yml | Adds MSYS2-based Windows/386 toolchain setup and windows/386 test runs. |
Files not reviewed (1)
- wincallback.go: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
What issue is this addressing?
There is no existing issue. This expands the Windows/386 support currently described in the platform support table.
What type of issue is this addressing?
feature
What this PR does | solves
Windows/386 previously only officially supported
SyscallNandNewCallback. The partialRegisterFuncpath also treated 64-bit values as a singleuintptr, only observedEAXfor integer results, and did not retrieve floating-point results from x87.This change adds the Windows/386 ABI handling needed for typed
RegisterFunc/RegisterLibFunccalls and typed callbacks:float32, andfloat64arguments on the 32-bit stack;EDX:EAX;ST(0)and restores callback floating-point results there;The Windows CI jobs now use an explicit MSYS2
MINGW32GNU toolchain, verify that it can build a 32-bit DLL, and run both Cgo and non-Cgo Windows/386 suites (including unoptimized builds) on Go 1.25, 1.26, and 1.27rc1.Validation:
go test ./...windows-latestjobs: https://github.com/SagerNet/purego/actions/runs/29236606685