|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: "Jason A. Donenfeld" < [email protected]> |
| 3 | +Date: Tue, 23 Nov 2021 20:04:24 +0100 |
| 4 | +Subject: [PATCH] [release-branch.go1.17] runtime: support non-cooperative |
| 5 | + preemption on windows/arm |
| 6 | + |
| 7 | +This adds support for injecting asynchronous preemption calls on |
| 8 | +windows/arm. This code follows sigctxt.pushCall for POSIX OSes |
| 9 | +on arm, except we subtract 1 from IP, just as in CL 273727. |
| 10 | + |
| 11 | +Updates #10958. |
| 12 | +Updates #24543. |
| 13 | +Updates #49759. |
| 14 | + |
| 15 | +Change-Id: Id0c2aed28662f50631b8c8cede3b4e6f088dafea |
| 16 | +Reviewed-on: https://go-review.googlesource.com/c/go/+/366734 |
| 17 | +Trust: Jason A. Donenfeld < [email protected]> |
| 18 | +Reviewed-by: Austin Clements < [email protected]> |
| 19 | +Reviewed-by: Patrik Nyblom < [email protected]> |
| 20 | +Reviewed-by: Cherry Mui < [email protected]> |
| 21 | +--- |
| 22 | + src/runtime/os_windows.go | 16 ++++++++++++++-- |
| 23 | + 1 file changed, 14 insertions(+), 2 deletions(-) |
| 24 | + |
| 25 | +diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go |
| 26 | +index f0935264ac..faeb6ce552 100644 |
| 27 | +--- a/src/runtime/os_windows.go |
| 28 | ++++ b/src/runtime/os_windows.go |
| 29 | +@@ -1303,7 +1303,7 @@ func setThreadCPUProfiler(hz int32) { |
| 30 | + atomic.Store((*uint32)(unsafe.Pointer(&getg().m.profilehz)), uint32(hz)) |
| 31 | + } |
| 32 | + |
| 33 | +-const preemptMSupported = GOARCH == "386" || GOARCH == "amd64" |
| 34 | ++const preemptMSupported = GOARCH != "arm64" |
| 35 | + |
| 36 | + // suspendLock protects simultaneous SuspendThread operations from |
| 37 | + // suspending each other. |
| 38 | +@@ -1396,8 +1396,20 @@ func preemptM(mp *m) { |
| 39 | + *(*uintptr)(unsafe.Pointer(sp)) = newpc |
| 40 | + c.set_sp(sp) |
| 41 | + c.set_ip(targetPC) |
| 42 | +- } |
| 43 | + |
| 44 | ++ case "arm": |
| 45 | ++ // Push LR. The injected call is responsible |
| 46 | ++ // for restoring LR. gentraceback is aware of |
| 47 | ++ // this extra slot. See sigctxt.pushCall in |
| 48 | ++ // signal_arm.go, which is similar except we |
| 49 | ++ // subtract 1 from IP here. |
| 50 | ++ sp := c.sp() |
| 51 | ++ sp -= sys.PtrSize |
| 52 | ++ c.set_sp(sp) |
| 53 | ++ *(*uint32)(unsafe.Pointer(sp)) = uint32(c.lr()) |
| 54 | ++ c.set_lr(newpc - 1) |
| 55 | ++ c.set_ip(targetPC) |
| 56 | ++ } |
| 57 | + stdcall2(_SetThreadContext, thread, uintptr(unsafe.Pointer(c))) |
| 58 | + } |
| 59 | + } |
0 commit comments