]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: call unlockOSThread directly in Windows syscall functions
authorCherry Mui <cherryyz@google.com>
Thu, 6 May 2021 16:24:20 +0000 (12:24 -0400)
committerCherry Mui <cherryyz@google.com>
Thu, 6 May 2021 20:30:00 +0000 (20:30 +0000)
Windows syscall functions (e.g. syscall.Syscall9) are defined as
cgo_unsafe_args (because it takes the address of one argument and
use that to access all arguments) which makes them ABI0. In some
case we may need ABI wrappers for them. Because those functions
have a large number of arguments, the wrapper can take a
non-trivial amount of stack frame, causing nosplit overflow when
inlining is disabled. The overflow call chain involves
deferreturn.

This CL changes a deferred call to unlockOSThread to a direct
call. If the syscall functions panics, it is likely a fatal error
anyway.

Fixes #45698.

Change-Id: I280be826644de1205f9c8f5efaa4ec5e1b4eebc1
Reviewed-on: https://go-review.googlesource.com/c/go/+/316650
Trust: Cherry Mui <cherryyz@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
src/runtime/syscall_windows.go

index 6521bb2c418aa77f3fe2d10df22d006d752f4011..6b9195bcd5253394fd988a9bc0ecce6d832f9528 100644 (file)
@@ -482,12 +482,12 @@ func syscall_Syscall6(fn, nargs, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err ui
 //go:cgo_unsafe_args
 func syscall_Syscall9(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1, r2, err uintptr) {
        lockOSThread()
-       defer unlockOSThread()
        c := &getg().m.syscall
        c.fn = fn
        c.n = nargs
        c.args = uintptr(noescape(unsafe.Pointer(&a1)))
        cgocall(asmstdcallAddr, unsafe.Pointer(c))
+       unlockOSThread()
        return c.r1, c.r2, c.err
 }
 
@@ -496,12 +496,12 @@ func syscall_Syscall9(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9 uintptr) (r1
 //go:cgo_unsafe_args
 func syscall_Syscall12(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12 uintptr) (r1, r2, err uintptr) {
        lockOSThread()
-       defer unlockOSThread()
        c := &getg().m.syscall
        c.fn = fn
        c.n = nargs
        c.args = uintptr(noescape(unsafe.Pointer(&a1)))
        cgocall(asmstdcallAddr, unsafe.Pointer(c))
+       unlockOSThread()
        return c.r1, c.r2, c.err
 }
 
@@ -510,12 +510,12 @@ func syscall_Syscall12(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
 //go:cgo_unsafe_args
 func syscall_Syscall15(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15 uintptr) (r1, r2, err uintptr) {
        lockOSThread()
-       defer unlockOSThread()
        c := &getg().m.syscall
        c.fn = fn
        c.n = nargs
        c.args = uintptr(noescape(unsafe.Pointer(&a1)))
        cgocall(asmstdcallAddr, unsafe.Pointer(c))
+       unlockOSThread()
        return c.r1, c.r2, c.err
 }
 
@@ -524,11 +524,11 @@ func syscall_Syscall15(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11,
 //go:cgo_unsafe_args
 func syscall_Syscall18(fn, nargs, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18 uintptr) (r1, r2, err uintptr) {
        lockOSThread()
-       defer unlockOSThread()
        c := &getg().m.syscall
        c.fn = fn
        c.n = nargs
        c.args = uintptr(noescape(unsafe.Pointer(&a1)))
        cgocall(asmstdcallAddr, unsafe.Pointer(c))
+       unlockOSThread()
        return c.r1, c.r2, c.err
 }