From ab2e3ce77c3935b38a954c7fb720875e9173dddd Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 5 Oct 2023 12:35:35 +0200 Subject: [PATCH] runtime: use cgo_import_dynamic for QueryPerformanceCounter 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 Reviewed-by: Alex Brainman TryBot-Result: Gopher Robot Run-TryBot: Quim Muntal LUCI-TryBot-Result: Go LUCI Reviewed-by: Than McIntosh --- src/runtime/os_windows.go | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 734c94b794..8ca8d77909 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -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") -- 2.50.0