]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: clean up windows a bit
authorRuss Cox <rsc@golang.org>
Thu, 28 Jan 2021 14:23:35 +0000 (09:23 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 19 Feb 2021 00:04:14 +0000 (00:04 +0000)
Document the various hard-coded architecture checks
or remove them in favor of more general checks.
This should be a no-op now but will make the arm64 port
have fewer diffs.

This CL is part of a stack adding windows/arm64
support (#36439), intended to land in the Go 1.17 cycle.
This CL is, however, not windows/arm64-specific.
It is cleanup meant to make the port (and future ports) easier.

Change-Id: Ifd6b19e44e8c9ca4a0d2590f314928ce235821b3
Reviewed-on: https://go-review.googlesource.com/c/go/+/288813
Trust: Russ Cox <rsc@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
src/runtime/os_windows.go
src/runtime/signal_windows.go
src/runtime/syscall_windows.go

index a8406460e2391682752b942485d02281036ec29a..375c34ed993919de27b64773a9f9c1753d867e6a 100644 (file)
@@ -236,6 +236,8 @@ func windowsLoadSystemLib(name []byte) uintptr {
        }
 }
 
+const haveCputicksAsm = GOARCH == "386" || GOARCH == "amd64"
+
 func loadOptionalSyscalls() {
        var kernel32dll = []byte("kernel32.dll\000")
        k32 := stdcall1(_LoadLibraryA, uintptr(unsafe.Pointer(&kernel32dll[0])))
@@ -262,7 +264,7 @@ func loadOptionalSyscalls() {
        }
        _NtWaitForSingleObject = windowsFindfunc(n32, []byte("NtWaitForSingleObject\000"))
 
-       if GOARCH == "arm" {
+       if !haveCputicksAsm {
                _QueryPerformanceCounter = windowsFindfunc(k32, []byte("QueryPerformanceCounter\000"))
                if _QueryPerformanceCounter == nil {
                        throw("could not find QPC syscalls")
@@ -452,8 +454,10 @@ func createHighResTimer() uintptr {
                _SYNCHRONIZE|_TIMER_QUERY_STATE|_TIMER_MODIFY_STATE)
 }
 
+const highResTimerSupported = GOARCH == "386" || GOARCH == "amd64"
+
 func initHighResTimer() {
-       if GOARCH == "arm" {
+       if !highResTimerSupported {
                // TODO: Not yet implemented.
                return
        }
@@ -1217,14 +1221,14 @@ func setThreadCPUProfiler(hz int32) {
        atomic.Store((*uint32)(unsafe.Pointer(&getg().m.profilehz)), uint32(hz))
 }
 
-const preemptMSupported = GOARCH != "arm"
+const preemptMSupported = GOARCH == "386" || GOARCH == "amd64"
 
 // suspendLock protects simultaneous SuspendThread operations from
 // suspending each other.
 var suspendLock mutex
 
 func preemptM(mp *m) {
-       if GOARCH == "arm" {
+       if !preemptMSupported {
                // TODO: Implement call injection
                return
        }
index 18834b0ec57ffc65308a9c4fa9550c4e482161f0..cb1fbe9f81451e9f35c95f40cebeaf177be58e65 100644 (file)
@@ -5,6 +5,7 @@
 package runtime
 
 import (
+       "runtime/internal/sys"
        "unsafe"
 )
 
@@ -132,16 +133,14 @@ func exceptionhandler(info *exceptionrecord, r *context, gp *g) int32 {
        // overwrite the PC. (See issue #35773)
        if r.ip() != 0 && r.ip() != funcPC(asyncPreempt) {
                sp := unsafe.Pointer(r.sp())
-               sp = add(sp, ^(unsafe.Sizeof(uintptr(0)) - 1)) // sp--
+               delta := uintptr(sys.StackAlign)
+               sp = add(sp, -delta)
                r.set_sp(uintptr(sp))
-               switch GOARCH {
-               default:
-                       panic("unsupported architecture")
-               case "386", "amd64":
-                       *((*uintptr)(sp)) = r.ip()
-               case "arm":
+               if usesLR {
                        *((*uintptr)(sp)) = r.lr()
                        r.set_lr(r.ip())
+               } else {
+                       *((*uintptr)(sp)) = r.ip()
                }
        }
        r.set_ip(funcPC(sigpanic))
index add40bb0b345ba0526913a704cec5562e043947d..6052cc333cce35dbd45434fc92257cfeae168fe9 100644 (file)
@@ -116,13 +116,14 @@ func compileCallback(fn eface, cdecl bool) (code uintptr) {
                        // registers and the stack.
                        panic("compileCallback: argument size is larger than uintptr")
                }
-               if k := t.kind & kindMask; (GOARCH == "amd64" || GOARCH == "arm") && (k == kindFloat32 || k == kindFloat64) {
+               if k := t.kind & kindMask; GOARCH != "386" && (k == kindFloat32 || k == kindFloat64) {
                        // In fastcall, floating-point arguments in
                        // the first four positions are passed in
                        // floating-point registers, which we don't
                        // currently spill. arm passes floating-point
                        // arguments in VFP registers, which we also
                        // don't support.
+                       // So basically we only support 386.
                        panic("compileCallback: float arguments not supported")
                }