diff options
| author | qmuntal <quimmuntal@gmail.com> | 2026-03-06 12:22:14 +0100 |
|---|---|---|
| committer | Quim Muntal <quimmuntal@gmail.com> | 2026-03-18 23:34:43 -0700 |
| commit | 4216fa3d0471aa290e591abf0e209992edfc1f54 (patch) | |
| tree | cf74b45a5163a9f0fb1aa871d0c528fb80eab31f /src/internal/runtime/syscall | |
| parent | bf1c1b3bde50f33593cd0db8f19812ea957964f5 (diff) | |
| download | go-4216fa3d0471aa290e591abf0e209992edfc1f54.tar.xz | |
runtime: return the error code as a return value in asmstdcall
This shaves off 8 bytes from the syscall_syscalln stack frame, which is
significant as that call path is almost over the nosplit limit.
Also, it follows the cgocall convention of returning the error code as
a return value, making it easier to reason about.
Cq-Include-Trybots: luci.golang.try:gotip-windows-amd64-longtest,gotip-windows-arm64,gotip-windows-386
Change-Id: I62acdb7c0d4cf9cb928bf3974d3300dd752f6c29
Reviewed-on: https://go-review.googlesource.com/c/go/+/751861
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/internal/runtime/syscall')
4 files changed, 14 insertions, 8 deletions
diff --git a/src/internal/runtime/syscall/windows/asm_windows_386.s b/src/internal/runtime/syscall/windows/asm_windows_386.s index 29cce00309..b7aa6db2a8 100644 --- a/src/internal/runtime/syscall/windows/asm_windows_386.s +++ b/src/internal/runtime/syscall/windows/asm_windows_386.s @@ -5,10 +5,14 @@ #include "go_asm.h" #include "textflag.h" -TEXT ·StdCall<ABIInternal>(SB),NOSPLIT,$0 - JMP ·asmstdcall(SB) +TEXT ·StdCall<ABIInternal>(SB),NOSPLIT,$4-8 + MOVL fn+0(FP), AX + MOVL AX, 0(SP) + CALL ·asmstdcall(SB) + MOVL AX, ret+4(FP) + RET -TEXT ·asmstdcall(SB),NOSPLIT,$0 +TEXT ·asmstdcall(SB),NOSPLIT,$0-4 MOVL fn+0(FP), BX MOVL SP, BP // save stack pointer @@ -43,6 +47,5 @@ docall: // GetLastError(). MOVL 0x34(FS), AX - MOVL AX, StdCallInfo_Err(BX) RET diff --git a/src/internal/runtime/syscall/windows/asm_windows_amd64.s b/src/internal/runtime/syscall/windows/asm_windows_amd64.s index c31cbcdd14..7f0cb4a0f9 100644 --- a/src/internal/runtime/syscall/windows/asm_windows_amd64.s +++ b/src/internal/runtime/syscall/windows/asm_windows_amd64.s @@ -79,6 +79,5 @@ _0args: // GetLastError(). MOVQ 0x30(GS), DI MOVL 0x68(DI), AX - MOVQ AX, StdCallInfo_Err(CX) RET diff --git a/src/internal/runtime/syscall/windows/asm_windows_arm64.s b/src/internal/runtime/syscall/windows/asm_windows_arm64.s index fb4cda0f83..96a0727a7a 100644 --- a/src/internal/runtime/syscall/windows/asm_windows_arm64.s +++ b/src/internal/runtime/syscall/windows/asm_windows_arm64.s @@ -83,7 +83,6 @@ _0args: // GetLastError MOVD TEB_error(R18_PLATFORM), R0 - MOVD R0, StdCallInfo_Err(R19) // Restore callee-saved registers. LDP 16(RSP), (R19, R20) diff --git a/src/internal/runtime/syscall/windows/syscall_windows.go b/src/internal/runtime/syscall/windows/syscall_windows.go index 0d350f0d7f..f505e15795 100644 --- a/src/internal/runtime/syscall/windows/syscall_windows.go +++ b/src/internal/runtime/syscall/windows/syscall_windows.go @@ -24,15 +24,20 @@ type StdCallInfo struct { Args uintptr // parameters R1 uintptr // return values R2 uintptr - Err uintptr // error number } // StdCall calls a function using Windows' stdcall convention. +// The calling thread's last-error code value is cleared before calling the function, +// and stored in the return value. // //go:noescape -func StdCall(fn *StdCallInfo) +func StdCall(fn *StdCallInfo) uint32 // asmstdcall is the function pointer for [AsmStdCallAddr]. +// The calling thread's last-error code value is cleared before calling the function, +// and returned in the C ABI return register (not via Go stack convention). +// This function is not called directly from Go; it is either jumped to from +// [StdCall] or called from C via [AsmStdCallAddr]. func asmstdcall(fn *StdCallInfo) // AsmStdCallAddr is the address of a function that accepts a pointer |
