]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: use cgo_import_dynamic for QueryPerformanceCounter
authorqmuntal <quimmuntal@gmail.com>
Thu, 5 Oct 2023 10:35:35 +0000 (12:35 +0200)
committerQuim Muntal <quimmuntal@gmail.com>
Tue, 17 Oct 2023 20:36:52 +0000 (20:36 +0000)
QueryPerformanceCounter is available since Windows 2000 [1], so there
is no need to conditionally load it.

Even if the Go runtime doesn't eventually use it, it is still simpler
and faster to just tell the Windows loader to load it, instead of doing
it ourselves.

[1]: https://learn.microsoft.com/en-us/windows/win32/api/profileapi/nf-profileapi-queryperformancecounter

Change-Id: Ied3b54a6a8fe3b8d51aefab0fe483b3a193b5522
Reviewed-on: https://go-review.googlesource.com/c/go/+/532915
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Quim Muntal <quimmuntal@gmail.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Than McIntosh <thanm@google.com>
src/runtime/os_windows.go

index 734c94b79406e911c0c396bdadd3a7df3e10278a..8ca8d7790909e17fd29e51202f6c11c931fae61b 100644 (file)
@@ -43,6 +43,7 @@ const (
 //go:cgo_import_dynamic runtime._LoadLibraryExW LoadLibraryExW%3 "kernel32.dll"
 //go:cgo_import_dynamic runtime._LoadLibraryW LoadLibraryW%1 "kernel32.dll"
 //go:cgo_import_dynamic runtime._PostQueuedCompletionStatus PostQueuedCompletionStatus%4 "kernel32.dll"
+//go:cgo_import_dynamic runtime._QueryPerformanceCounter QueryPerformanceCounter%1 "kernel32.dll"
 //go:cgo_import_dynamic runtime._RaiseFailFastException RaiseFailFastException%3 "kernel32.dll"
 //go:cgo_import_dynamic runtime._ResumeThread ResumeThread%1 "kernel32.dll"
 //go:cgo_import_dynamic runtime._RtlLookupFunctionEntry RtlLookupFunctionEntry%3 "kernel32.dll"
@@ -151,7 +152,6 @@ var (
 
 var (
        advapi32dll = [...]uint16{'a', 'd', 'v', 'a', 'p', 'i', '3', '2', '.', 'd', 'l', 'l', 0}
-       kernel32dll = [...]uint16{'k', 'e', 'r', 'n', 'e', 'l', '3', '2', '.', 'd', 'l', 'l', 0}
        ntdlldll    = [...]uint16{'n', 't', 'd', 'l', 'l', '.', 'd', 'l', 'l', 0}
        powrprofdll = [...]uint16{'p', 'o', 'w', 'r', 'p', 'r', 'o', 'f', '.', 'd', 'l', 'l', 0}
        winmmdll    = [...]uint16{'w', 'i', 'n', 'm', 'm', '.', 'd', 'l', 'l', 0}
@@ -250,14 +250,7 @@ func windowsLoadSystemLib(name []uint16) uintptr {
        return stdcall3(_LoadLibraryExW, uintptr(unsafe.Pointer(&name[0])), 0, _LOAD_LIBRARY_SEARCH_SYSTEM32)
 }
 
-const haveCputicksAsm = GOARCH == "386" || GOARCH == "amd64"
-
 func loadOptionalSyscalls() {
-       k32 := windowsLoadSystemLib(kernel32dll[:])
-       if k32 == 0 {
-               throw("kernel32.dll not found")
-       }
-
        a32 := windowsLoadSystemLib(advapi32dll[:])
        if a32 == 0 {
                throw("advapi32.dll not found")
@@ -271,13 +264,6 @@ func loadOptionalSyscalls() {
        _RtlGetCurrentPeb = windowsFindfunc(n32, []byte("RtlGetCurrentPeb\000"))
        _RtlGetNtVersionNumbers = windowsFindfunc(n32, []byte("RtlGetNtVersionNumbers\000"))
 
-       if !haveCputicksAsm {
-               _QueryPerformanceCounter = windowsFindfunc(k32, []byte("QueryPerformanceCounter\000"))
-               if _QueryPerformanceCounter == nil {
-                       throw("could not find QPC syscalls")
-               }
-       }
-
        m32 := windowsLoadSystemLib(winmmdll[:])
        if m32 == 0 {
                throw("winmm.dll not found")