From 639cb1b629e575487af78bb3f60af24a7df7a3f7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 16 Apr 2021 00:00:32 -0400 Subject: [PATCH] runtime: mark stdcallN functions cgo_unsafe_args These functions take the address of an argument and expect to be able to reach later arguments from that pointer. This means they must be laid out sequentially in memory (using ABI0) and all arguments must be live even though they don't all appear to be referenced. This is exactly what go:cgo_unsafe_args does. Without this, GOEXPERIMENT=regabi,regabiargs on windows/amd64 crashes on runtime startup because the stdcall functions are called with their arguments in registers, so taking the address of one of them has no bearing on the memory locations of the following arguments. With this, GOEXPERIMENT=regabi,regabiargs on windows/amd64 passes all.bash. For #40724. Change-Id: I4a4d6a913f85799b43f61c234d21ebb113a9b527 Reviewed-on: https://go-review.googlesource.com/c/go/+/310733 Trust: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Go Bot Reviewed-by: Michael Knyszek Reviewed-by: Cherry Zhang --- src/runtime/os_windows.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index bc1240f8bb..36182f4e9a 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -1084,6 +1084,7 @@ func stdcall0(fn stdFunction) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall1(fn stdFunction, a0 uintptr) uintptr { mp := getg().m mp.libcall.n = 1 @@ -1092,6 +1093,7 @@ func stdcall1(fn stdFunction, a0 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall2(fn stdFunction, a0, a1 uintptr) uintptr { mp := getg().m mp.libcall.n = 2 @@ -1100,6 +1102,7 @@ func stdcall2(fn stdFunction, a0, a1 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall3(fn stdFunction, a0, a1, a2 uintptr) uintptr { mp := getg().m mp.libcall.n = 3 @@ -1108,6 +1111,7 @@ func stdcall3(fn stdFunction, a0, a1, a2 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall4(fn stdFunction, a0, a1, a2, a3 uintptr) uintptr { mp := getg().m mp.libcall.n = 4 @@ -1116,6 +1120,7 @@ func stdcall4(fn stdFunction, a0, a1, a2, a3 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall5(fn stdFunction, a0, a1, a2, a3, a4 uintptr) uintptr { mp := getg().m mp.libcall.n = 5 @@ -1124,6 +1129,7 @@ func stdcall5(fn stdFunction, a0, a1, a2, a3, a4 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall6(fn stdFunction, a0, a1, a2, a3, a4, a5 uintptr) uintptr { mp := getg().m mp.libcall.n = 6 @@ -1132,6 +1138,7 @@ func stdcall6(fn stdFunction, a0, a1, a2, a3, a4, a5 uintptr) uintptr { } //go:nosplit +//go:cgo_unsafe_args func stdcall7(fn stdFunction, a0, a1, a2, a3, a4, a5, a6 uintptr) uintptr { mp := getg().m mp.libcall.n = 7