diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-11-25 13:17:05 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-11-25 13:19:08 +0100 |
commit | 156209c6f4b00adc22b5a40e18bedd227ae65dc7 (patch) | |
tree | ad7f425ca781289b18d821d5544627f86d7a3ba8 /go-patches | |
parent | mod: remove x/sys fork (diff) | |
download | wireguard-windows-156209c6f4b00adc22b5a40e18bedd227ae65dc7.tar.xz wireguard-windows-156209c6f4b00adc22b5a40e18bedd227ae65dc7.zip |
go-patches: support non-cooperative preemption on arm and arm64
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'go-patches')
-rw-r--r-- | go-patches/0005-release-branch.go1.17-runtime-support-non-cooperativ.patch | 59 | ||||
-rw-r--r-- | go-patches/0006-runtime-support-non-cooperative-preemption-on-window.patch | 65 |
2 files changed, 124 insertions, 0 deletions
diff --git a/go-patches/0005-release-branch.go1.17-runtime-support-non-cooperativ.patch b/go-patches/0005-release-branch.go1.17-runtime-support-non-cooperativ.patch new file mode 100644 index 00000000..dbab4ba0 --- /dev/null +++ b/go-patches/0005-release-branch.go1.17-runtime-support-non-cooperativ.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" <Jason@zx2c4.com> +Date: Tue, 23 Nov 2021 20:04:24 +0100 +Subject: [PATCH] [release-branch.go1.17] runtime: support non-cooperative + preemption on windows/arm + +This adds support for injecting asynchronous preemption calls on +windows/arm. This code follows sigctxt.pushCall for POSIX OSes +on arm, except we subtract 1 from IP, just as in CL 273727. + +Updates #10958. +Updates #24543. +Updates #49759. + +Change-Id: Id0c2aed28662f50631b8c8cede3b4e6f088dafea +Reviewed-on: https://go-review.googlesource.com/c/go/+/366734 +Trust: Jason A. Donenfeld <Jason@zx2c4.com> +Reviewed-by: Austin Clements <austin@google.com> +Reviewed-by: Patrik Nyblom <pnyb@google.com> +Reviewed-by: Cherry Mui <cherryyz@google.com> +--- + src/runtime/os_windows.go | 16 ++++++++++++++-- + 1 file changed, 14 insertions(+), 2 deletions(-) + +diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go +index f0935264ac..faeb6ce552 100644 +--- a/src/runtime/os_windows.go ++++ b/src/runtime/os_windows.go +@@ -1303,7 +1303,7 @@ func setThreadCPUProfiler(hz int32) { + atomic.Store((*uint32)(unsafe.Pointer(&getg().m.profilehz)), uint32(hz)) + } + +-const preemptMSupported = GOARCH == "386" || GOARCH == "amd64" ++const preemptMSupported = GOARCH != "arm64" + + // suspendLock protects simultaneous SuspendThread operations from + // suspending each other. +@@ -1396,8 +1396,20 @@ func preemptM(mp *m) { + *(*uintptr)(unsafe.Pointer(sp)) = newpc + c.set_sp(sp) + c.set_ip(targetPC) +- } + ++ case "arm": ++ // Push LR. The injected call is responsible ++ // for restoring LR. gentraceback is aware of ++ // this extra slot. See sigctxt.pushCall in ++ // signal_arm.go, which is similar except we ++ // subtract 1 from IP here. ++ sp := c.sp() ++ sp -= sys.PtrSize ++ c.set_sp(sp) ++ *(*uint32)(unsafe.Pointer(sp)) = uint32(c.lr()) ++ c.set_lr(newpc - 1) ++ c.set_ip(targetPC) ++ } + stdcall2(_SetThreadContext, thread, uintptr(unsafe.Pointer(c))) + } + } diff --git a/go-patches/0006-runtime-support-non-cooperative-preemption-on-window.patch b/go-patches/0006-runtime-support-non-cooperative-preemption-on-window.patch new file mode 100644 index 00000000..c99ea390 --- /dev/null +++ b/go-patches/0006-runtime-support-non-cooperative-preemption-on-window.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: "Jason A. Donenfeld" <Jason@zx2c4.com> +Date: Tue, 23 Nov 2021 20:57:24 +0100 +Subject: [PATCH] runtime: support non-cooperative preemption on windows/arm64 + +This adds support for injecting asynchronous preemption calls on +windows/arm64. This code exactly follows sigctxt.pushCall for POSIX OSes +on arm64. + +Fixes #49759. + +Change-Id: Id35ff6bc105c1db9d7ed2918d3ecab0e4e9a9431 +Reviewed-on: https://go-review.googlesource.com/c/go/+/366735 +Trust: Jason A. Donenfeld <Jason@zx2c4.com> +Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> +TryBot-Result: Go Bot <gobot@golang.org> +Reviewed-by: Cherry Mui <cherryyz@google.com> +Reviewed-by: Austin Clements <austin@google.com> +Reviewed-by: Patrik Nyblom <pnyb@google.com> +--- + src/runtime/os_windows.go | 18 ++++++++++++------ + 1 file changed, 12 insertions(+), 6 deletions(-) + +diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go +index faeb6ce552..7bf9a426d1 100644 +--- a/src/runtime/os_windows.go ++++ b/src/runtime/os_windows.go +@@ -1303,18 +1303,13 @@ func setThreadCPUProfiler(hz int32) { + atomic.Store((*uint32)(unsafe.Pointer(&getg().m.profilehz)), uint32(hz)) + } + +-const preemptMSupported = GOARCH != "arm64" ++const preemptMSupported = true + + // suspendLock protects simultaneous SuspendThread operations from + // suspending each other. + var suspendLock mutex + + func preemptM(mp *m) { +- if !preemptMSupported { +- // TODO: Implement call injection +- return +- } +- + if mp == getg().m { + throw("self-preempt") + } +@@ -1409,6 +1404,17 @@ func preemptM(mp *m) { + *(*uint32)(unsafe.Pointer(sp)) = uint32(c.lr()) + c.set_lr(newpc - 1) + c.set_ip(targetPC) ++ ++ case "arm64": ++ // Push LR. The injected call is responsible ++ // for restoring LR. gentraceback is aware of ++ // this extra slot. See sigctxt.pushCall in ++ // signal_arm64.go. ++ sp := c.sp() - 16 // SP needs 16-byte alignment ++ c.set_sp(sp) ++ *(*uint64)(unsafe.Pointer(sp)) = uint64(c.lr()) ++ c.set_lr(newpc) ++ c.set_ip(targetPC) + } + stdcall2(_SetThreadContext, thread, uintptr(unsafe.Pointer(c))) + } |