//go:cgo_import_dynamic runtime._GetThreadContext GetThreadContext%2 "kernel32.dll"
//go:cgo_import_dynamic runtime._SetThreadContext SetThreadContext%2 "kernel32.dll"
//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._QueryPerformanceFrequency QueryPerformanceFrequency%1 "kernel32.dll"
_GetThreadContext,
_SetThreadContext,
_LoadLibraryExW,
- _LoadLibraryW,
_PostQueuedCompletionStatus,
_QueryPerformanceCounter,
_QueryPerformanceFrequency,
}
func windowsLoadSystemLib(name []uint16) uintptr {
+ const _LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
return stdcall3(_LoadLibraryExW, uintptr(unsafe.Pointer(&name[0])), 0, _LOAD_LIBRARY_SEARCH_SYSTEM32)
}
}
}
-const _LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
-
-//go:linkname syscall_loadsystemlibrary syscall.loadsystemlibrary
-func syscall_loadsystemlibrary(filename *uint16) (handle, err uintptr) {
- handle, _, err = syscall_syscalln(uintptr(unsafe.Pointer(_LoadLibraryExW)), 3, uintptr(unsafe.Pointer(filename)), 0, _LOAD_LIBRARY_SEARCH_SYSTEM32)
- KeepAlive(filename)
- if handle != 0 {
- err = 0
- }
- return
-}
-
-// golang.org/x/sys linknames syscall.loadlibrary
-// (in addition to standard package syscall).
-// Do not remove or change the type signature.
-//
-//go:linkname syscall_loadlibrary syscall.loadlibrary
-func syscall_loadlibrary(filename *uint16) (handle, err uintptr) {
- handle, _, err = syscall_syscalln(uintptr(unsafe.Pointer(_LoadLibraryW)), 1, uintptr(unsafe.Pointer(filename)))
- KeepAlive(filename)
- if handle != 0 {
- err = 0
- }
- return
-}
-
-// golang.org/x/sys linknames syscall.getprocaddress
-// (in addition to standard package syscall).
-// Do not remove or change the type signature.
-//
-//go:linkname syscall_getprocaddress syscall.getprocaddress
-func syscall_getprocaddress(handle uintptr, procname *byte) (outhandle, err uintptr) {
- outhandle, _, err = syscall_syscalln(uintptr(unsafe.Pointer(_GetProcAddress)), 2, handle, uintptr(unsafe.Pointer(procname)))
- KeepAlive(procname)
- if outhandle != 0 {
- err = 0
- }
- return
-}
-
//go:linkname syscall_syscalln syscall.syscalln
//go:nosplit
+//go:uintptrkeepalive
func syscall_syscalln(fn, n uintptr, args ...uintptr) (r1, r2, err uintptr) {
if n > uintptr(len(args)) {
panic("syscall: n > len(args)") // should not be reachable from user code
"unsafe"
)
+// Use double underscore to avoid name collision autogenerated functions.
+//go:cgo_import_dynamic syscall.__LoadLibraryExW LoadLibraryExW%3 "kernel32.dll"
+//go:cgo_import_dynamic syscall.__GetProcAddress GetProcAddress%2 "kernel32.dll"
+
+var (
+ __LoadLibraryExW unsafe.Pointer
+ __GetProcAddress unsafe.Pointer
+)
+
// DLLError describes reasons for DLL load failures.
type DLLError struct {
Err error
//
//go:noescape
func syscalln(fn, n uintptr, args ...uintptr) (r1, r2 uintptr, err Errno)
-func loadlibrary(filename *uint16) (handle uintptr, err Errno)
-func loadsystemlibrary(filename *uint16) (handle uintptr, err Errno)
-func getprocaddress(handle uintptr, procname *uint8) (proc uintptr, err Errno)
+
+// N.B. For the loadlibrary, loadlibrary, and getprocaddress functions below:
+//
+// //go:linkname to act as an allowlist for linker's -checklinkname, as
+// golang.org/x/sys/windows linknames these functions.
+
+//go:linkname loadlibrary
+func loadlibrary(filename *uint16) (uintptr, Errno) {
+ handle, _, err := SyscallN(uintptr(__LoadLibraryExW), uintptr(unsafe.Pointer(filename)), 0, 0)
+ if handle != 0 {
+ err = 0
+ }
+ return handle, err
+}
+
+//go:linkname loadsystemlibrary
+func loadsystemlibrary(filename *uint16) (uintptr, Errno) {
+ const _LOAD_LIBRARY_SEARCH_SYSTEM32 = 0x00000800
+ handle, _, err := SyscallN(uintptr(__LoadLibraryExW), uintptr(unsafe.Pointer(filename)), 0, _LOAD_LIBRARY_SEARCH_SYSTEM32)
+ if handle != 0 {
+ err = 0
+ }
+ return handle, err
+}
+
+//go:linkname getprocaddress
+func getprocaddress(handle uintptr, procname *uint8) (uintptr, Errno) {
+ proc, _, err := SyscallN(uintptr(__GetProcAddress), handle, uintptr(unsafe.Pointer(procname)))
+ if proc != 0 {
+ err = 0
+ }
+ return proc, err
+}
// A DLL implements access to a single DLL.
type DLL struct {