]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: support nil libcall.args when calling stdcall on Windows
authorqmuntal <quimmuntal@gmail.com>
Thu, 7 Sep 2023 09:09:10 +0000 (11:09 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Thu, 7 Sep 2023 21:16:03 +0000 (21:16 +0000)
Having to pass a dummy pointer to the libcall.args field is a bit
annoying. This change allows nil to be passed instead.

windows/arm and windows/arm64 already support nil libcall.args.

Change-Id: I07a2bdb7d1f76b13d125397ff5177337c43536a3
Reviewed-on: https://go-review.googlesource.com/c/go/+/526016
Reviewed-by: Ian Lance Taylor <iant@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
src/runtime/os_windows.go
src/runtime/sys_windows_386.s
src/runtime/sys_windows_amd64.s

index 41875d2264046748b97aa5bd129b71ca5e44234f..e52f9e6bd53efb890fa66c8a54d4ec7f14bed0ba 100644 (file)
@@ -985,7 +985,7 @@ func stdcall(fn stdFunction) uintptr {
 func stdcall0(fn stdFunction) uintptr {
        mp := getg().m
        mp.libcall.n = 0
-       mp.libcall.args = uintptr(noescape(unsafe.Pointer(&fn))) // it's unused but must be non-nil, otherwise crashes
+       mp.libcall.args = 0
        return stdcall(fn)
 }
 
index cb854c52e018ad72e94d901bec648e81f376eba1..2efde4515bec5d6ea7ad02f88d15f02c3b4470cc 100644 (file)
 // void runtime·asmstdcall(void *c);
 TEXT runtime·asmstdcall(SB),NOSPLIT,$0
        MOVL    fn+0(FP), BX
+       MOVL    SP, BP  // save stack pointer
 
        // SetLastError(0).
        MOVL    $0, 0x34(FS)
 
+       MOVL    libcall_n(BX), CX
+
+       // Fast version, do not store args on the stack.
+       CMPL    CX, $0
+       JE      docall
+
        // Copy args to the stack.
-       MOVL    SP, BP
-       MOVL    libcall_n(BX), CX       // words
        MOVL    CX, AX
        SALL    $2, AX
        SUBL    AX, SP                  // room for args
@@ -29,6 +34,7 @@ TEXT runtime·asmstdcall(SB),NOSPLIT,$0
        CLD
        REP; MOVSL
 
+docall:
        // Call stdcall or cdecl function.
        // DI SI BP BX are preserved, SP is not
        CALL    libcall_fn(BX)
index 6d26bd34472a136c4f2f3256ced5312d7ec32cea..4a14b45c63159bd69d0b811010ec32223fc3442a 100644 (file)
@@ -29,6 +29,11 @@ TEXT runtime·asmstdcall(SB),NOSPLIT,$16
 
        SUBQ    $(const_maxArgs*8), SP  // room for args
 
+       // Fast version, do not store args on the stack nor
+       // load them into registers.
+       CMPL    CX, $0
+       JE      docall
+
        // Fast version, do not store args on the stack.
        CMPL    CX, $4
        JLE     loadregs
@@ -59,6 +64,7 @@ loadregs:
        MOVQ    R8, X2
        MOVQ    R9, X3
 
+docall:
        // Call stdcall function.
        CALL    AX