Skip to content

Commit c58243a

Browse files
committed
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 <[email protected]> Reviewed-by: Austin Clements <[email protected]> Reviewed-by: Patrik Nyblom <[email protected]> Reviewed-by: Cherry Mui <[email protected]>
1 parent b2a5a37 commit c58243a

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/runtime/os_windows.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ func setThreadCPUProfiler(hz int32) {
13061306
atomic.Store((*uint32)(unsafe.Pointer(&getg().m.profilehz)), uint32(hz))
13071307
}
13081308

1309-
const preemptMSupported = GOARCH == "386" || GOARCH == "amd64"
1309+
const preemptMSupported = GOARCH != "arm64"
13101310

13111311
// suspendLock protects simultaneous SuspendThread operations from
13121312
// suspending each other.
@@ -1399,8 +1399,20 @@ func preemptM(mp *m) {
13991399
*(*uintptr)(unsafe.Pointer(sp)) = newpc
14001400
c.set_sp(sp)
14011401
c.set_ip(targetPC)
1402-
}
14031402

1403+
case "arm":
1404+
// Push LR. The injected call is responsible
1405+
// for restoring LR. gentraceback is aware of
1406+
// this extra slot. See sigctxt.pushCall in
1407+
// signal_arm.go, which is similar except we
1408+
// subtract 1 from IP here.
1409+
sp := c.sp()
1410+
sp -= goarch.PtrSize
1411+
c.set_sp(sp)
1412+
*(*uint32)(unsafe.Pointer(sp)) = uint32(c.lr())
1413+
c.set_lr(newpc - 1)
1414+
c.set_ip(targetPC)
1415+
}
14041416
stdcall2(_SetThreadContext, thread, uintptr(unsafe.Pointer(c)))
14051417
}
14061418
}

0 commit comments

Comments
 (0)