diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-16 02:54:11 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-16 03:14:14 +0100 |
commit | ddb87f397d74a89f71877ecb02c18ffa79931ad7 (patch) | |
tree | dc58d0f7fed192365905c7bc797713de1f66feaa | |
parent | ringlogger: have caller cleanup inherited handle on failure (diff) | |
download | wireguard-windows-ddb87f397d74a89f71877ecb02c18ffa79931ad7.tar.xz wireguard-windows-ddb87f397d74a89f71877ecb02c18ffa79931ad7.zip |
global: use syscall.SyscallN
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | driver/configuration_windows.go | 8 | ||||
-rw-r--r-- | driver/driver_windows.go | 18 | ||||
-rw-r--r-- | driver/memmod/memmod_windows.go | 8 | ||||
-rw-r--r-- | elevate/shellexecute.go | 4 |
4 files changed, 19 insertions, 19 deletions
diff --git a/driver/configuration_windows.go b/driver/configuration_windows.go index 5a12be63..43a8af66 100644 --- a/driver/configuration_windows.go +++ b/driver/configuration_windows.go @@ -81,7 +81,7 @@ var ( // SetAdapterState sets the adapter either Up or Down. func (wireguard *Adapter) SetAdapterState(adapterState AdapterState) (err error) { - r0, _, e1 := syscall.Syscall(procWireGuardSetAdapterState.Addr(), 2, wireguard.handle, uintptr(adapterState), 0) + r0, _, e1 := syscall.SyscallN(procWireGuardSetAdapterState.Addr(), wireguard.handle, uintptr(adapterState)) if r0 == 0 { err = e1 } @@ -90,7 +90,7 @@ func (wireguard *Adapter) SetAdapterState(adapterState AdapterState) (err error) // AdapterState returns the current state of the adapter. func (wireguard *Adapter) AdapterState() (adapterState AdapterState, err error) { - r0, _, e1 := syscall.Syscall(procWireGuardGetAdapterState.Addr(), 2, wireguard.handle, uintptr(unsafe.Pointer(&adapterState)), 0) + r0, _, e1 := syscall.SyscallN(procWireGuardGetAdapterState.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&adapterState))) if r0 == 0 { err = e1 } @@ -99,7 +99,7 @@ func (wireguard *Adapter) AdapterState() (adapterState AdapterState, err error) // SetConfiguration sets the adapter configuration. func (wireguard *Adapter) SetConfiguration(interfaze *Interface, size uint32) (err error) { - r0, _, e1 := syscall.Syscall(procWireGuardSetConfiguration.Addr(), 3, wireguard.handle, uintptr(unsafe.Pointer(interfaze)), uintptr(size)) + r0, _, e1 := syscall.SyscallN(procWireGuardSetConfiguration.Addr(), wireguard.handle, uintptr(unsafe.Pointer(interfaze)), uintptr(size)) if r0 == 0 { err = e1 } @@ -114,7 +114,7 @@ func (wireguard *Adapter) Configuration() (interfaze *Interface, err error) { } for { buf := make([]byte, size) - r0, _, e1 := syscall.Syscall(procWireGuardGetConfiguration.Addr(), 3, wireguard.handle, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&size))) + r0, _, e1 := syscall.SyscallN(procWireGuardGetConfiguration.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&size))) if r0 != 0 { wireguard.lastGetGuessSize = size return (*Interface)(unsafe.Pointer(&buf[0])), nil diff --git a/driver/driver_windows.go b/driver/driver_windows.go index 74dd087c..60422207 100644 --- a/driver/driver_windows.go +++ b/driver/driver_windows.go @@ -67,11 +67,11 @@ func setupLogger(dll *lazyDLL) { } else if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" { callback = windows.NewCallback(logMessage) } - syscall.Syscall(dll.NewProc("WireGuardSetLogger").Addr(), 1, callback, 0, 0) + syscall.SyscallN(dll.NewProc("WireGuardSetLogger").Addr(), callback) } func closeAdapter(wireguard *Adapter) { - syscall.Syscall(procWireGuardCloseAdapter.Addr(), 1, wireguard.handle, 0, 0) + syscall.SyscallN(procWireGuardCloseAdapter.Addr(), wireguard.handle) } // CreateAdapter creates a WireGuard adapter. name is the cosmetic name of the adapter. @@ -90,7 +90,7 @@ func CreateAdapter(name, tunnelType string, requestedGUID *windows.GUID) (wiregu if err != nil { return } - r0, _, e1 := syscall.Syscall(procWireGuardCreateAdapter.Addr(), 3, uintptr(unsafe.Pointer(name16)), uintptr(unsafe.Pointer(tunnelType16)), uintptr(unsafe.Pointer(requestedGUID))) + r0, _, e1 := syscall.SyscallN(procWireGuardCreateAdapter.Addr(), uintptr(unsafe.Pointer(name16)), uintptr(unsafe.Pointer(tunnelType16)), uintptr(unsafe.Pointer(requestedGUID))) if r0 == 0 { err = e1 return @@ -107,7 +107,7 @@ func OpenAdapter(name string) (wireguard *Adapter, err error) { if err != nil { return } - r0, _, e1 := syscall.Syscall(procWireGuardOpenAdapter.Addr(), 1, uintptr(unsafe.Pointer(name16)), 0, 0) + r0, _, e1 := syscall.SyscallN(procWireGuardOpenAdapter.Addr(), uintptr(unsafe.Pointer(name16))) if r0 == 0 { err = e1 return @@ -120,7 +120,7 @@ func OpenAdapter(name string) (wireguard *Adapter, err error) { // Close closes a WireGuard adapter. func (wireguard *Adapter) Close() (err error) { runtime.SetFinalizer(wireguard, nil) - r1, _, e1 := syscall.Syscall(procWireGuardCloseAdapter.Addr(), 1, wireguard.handle, 0, 0) + r1, _, e1 := syscall.SyscallN(procWireGuardCloseAdapter.Addr(), wireguard.handle) if r1 == 0 { err = e1 } @@ -129,7 +129,7 @@ func (wireguard *Adapter) Close() (err error) { // Uninstall removes the driver from the system if no drivers are currently in use. func Uninstall() (err error) { - r1, _, e1 := syscall.Syscall(procWireGuardDeleteDriver.Addr(), 0, 0, 0, 0) + r1, _, e1 := syscall.SyscallN(procWireGuardDeleteDriver.Addr()) if r1 == 0 { err = e1 } @@ -146,7 +146,7 @@ const ( // SetLogging enables or disables logging on the WireGuard adapter. func (wireguard *Adapter) SetLogging(logState AdapterLogState) (err error) { - r1, _, e1 := syscall.Syscall(procWireGuardSetAdapterLogging.Addr(), 2, wireguard.handle, uintptr(logState), 0) + r1, _, e1 := syscall.SyscallN(procWireGuardSetAdapterLogging.Addr(), wireguard.handle, uintptr(logState)) if r1 == 0 { err = e1 } @@ -155,7 +155,7 @@ func (wireguard *Adapter) SetLogging(logState AdapterLogState) (err error) { // RunningVersion returns the version of the loaded driver. func RunningVersion() (version uint32, err error) { - r0, _, e1 := syscall.Syscall(procWireGuardGetRunningDriverVersion.Addr(), 0, 0, 0, 0) + r0, _, e1 := syscall.SyscallN(procWireGuardGetRunningDriverVersion.Addr()) version = uint32(r0) if version == 0 { err = e1 @@ -165,6 +165,6 @@ func RunningVersion() (version uint32, err error) { // LUID returns the LUID of the adapter. func (wireguard *Adapter) LUID() (luid winipcfg.LUID) { - syscall.Syscall(procWireGuardGetAdapterLUID.Addr(), 2, wireguard.handle, uintptr(unsafe.Pointer(&luid)), 0) + syscall.SyscallN(procWireGuardGetAdapterLUID.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&luid))) return } diff --git a/driver/memmod/memmod_windows.go b/driver/memmod/memmod_windows.go index 63f066fd..05d71f1e 100644 --- a/driver/memmod/memmod_windows.go +++ b/driver/memmod/memmod_windows.go @@ -233,7 +233,7 @@ func (module *Module) executeTLS() { if f == 0 { break } - syscall.Syscall(f, 3, module.codeBase, uintptr(DLL_PROCESS_ATTACH), uintptr(0)) + syscall.SyscallN(f, module.codeBase, DLL_PROCESS_ATTACH, 0) callback += unsafe.Sizeof(f) } } @@ -444,7 +444,7 @@ func hookRtlPcToFileHeader() error { } } loadedAddressRangesMu.RUnlock() - ret, _, _ := syscall.Syscall(originalRtlPcToFileHeader, 2, pcValue, uintptr(unsafe.Pointer(baseOfImage)), 0) + ret, _, _ := syscall.SyscallN(originalRtlPcToFileHeader, pcValue, uintptr(unsafe.Pointer(baseOfImage))) return ret }) err = windows.VirtualProtect(uintptr(unsafe.Pointer(thunk)), unsafe.Sizeof(*thunk), oldProtect, &oldProtect) @@ -605,7 +605,7 @@ func LoadLibrary(data []byte) (module *Module, err error) { module.entry = module.codeBase + uintptr(module.headers.OptionalHeader.AddressOfEntryPoint) if module.isDLL { // Notify library about attaching to process. - r0, _, _ := syscall.Syscall(module.entry, 3, module.codeBase, uintptr(DLL_PROCESS_ATTACH), 0) + r0, _, _ := syscall.SyscallN(module.entry, module.codeBase, DLL_PROCESS_ATTACH, 0) successful := r0 != 0 if !successful { err = windows.ERROR_DLL_INIT_FAILED @@ -623,7 +623,7 @@ func LoadLibrary(data []byte) (module *Module, err error) { func (module *Module) Free() { if module.initialized { // Notify library about detaching from process. - syscall.Syscall(module.entry, 3, module.codeBase, uintptr(DLL_PROCESS_DETACH), 0) + syscall.SyscallN(module.entry, module.codeBase, DLL_PROCESS_DETACH, 0) module.initialized = false } if module.modules != nil { diff --git a/elevate/shellexecute.go b/elevate/shellexecute.go index 0c411a66..b47fb64a 100644 --- a/elevate/shellexecute.go +++ b/elevate/shellexecute.go @@ -130,13 +130,13 @@ func ShellExecute(program, arguments, directory string, show int32) (err error) return } - defer syscall.Syscall((*interfacePointer)[releaseOffset], 1, uintptr(unsafe.Pointer(interfacePointer)), 0, 0) + defer syscall.SyscallN((*interfacePointer)[releaseOffset], uintptr(unsafe.Pointer(interfacePointer))) if program16 == nil { return } - if ret, _, _ := syscall.Syscall6((*interfacePointer)[shellExecuteOffset], 6, + if ret, _, _ := syscall.SyscallN((*interfacePointer)[shellExecuteOffset], uintptr(unsafe.Pointer(interfacePointer)), uintptr(unsafe.Pointer(program16)), uintptr(unsafe.Pointer(arguments16)), |