Skip to content

Commit ddb87f3

Browse files
committed
global: use syscall.SyscallN
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
1 parent 1c2ca6c commit ddb87f3

File tree

4 files changed

+19
-19
lines changed

4 files changed

+19
-19
lines changed

driver/configuration_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var (
8181

8282
// SetAdapterState sets the adapter either Up or Down.
8383
func (wireguard *Adapter) SetAdapterState(adapterState AdapterState) (err error) {
84-
r0, _, e1 := syscall.Syscall(procWireGuardSetAdapterState.Addr(), 2, wireguard.handle, uintptr(adapterState), 0)
84+
r0, _, e1 := syscall.SyscallN(procWireGuardSetAdapterState.Addr(), wireguard.handle, uintptr(adapterState))
8585
if r0 == 0 {
8686
err = e1
8787
}
@@ -90,7 +90,7 @@ func (wireguard *Adapter) SetAdapterState(adapterState AdapterState) (err error)
9090

9191
// AdapterState returns the current state of the adapter.
9292
func (wireguard *Adapter) AdapterState() (adapterState AdapterState, err error) {
93-
r0, _, e1 := syscall.Syscall(procWireGuardGetAdapterState.Addr(), 2, wireguard.handle, uintptr(unsafe.Pointer(&adapterState)), 0)
93+
r0, _, e1 := syscall.SyscallN(procWireGuardGetAdapterState.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&adapterState)))
9494
if r0 == 0 {
9595
err = e1
9696
}
@@ -99,7 +99,7 @@ func (wireguard *Adapter) AdapterState() (adapterState AdapterState, err error)
9999

100100
// SetConfiguration sets the adapter configuration.
101101
func (wireguard *Adapter) SetConfiguration(interfaze *Interface, size uint32) (err error) {
102-
r0, _, e1 := syscall.Syscall(procWireGuardSetConfiguration.Addr(), 3, wireguard.handle, uintptr(unsafe.Pointer(interfaze)), uintptr(size))
102+
r0, _, e1 := syscall.SyscallN(procWireGuardSetConfiguration.Addr(), wireguard.handle, uintptr(unsafe.Pointer(interfaze)), uintptr(size))
103103
if r0 == 0 {
104104
err = e1
105105
}
@@ -114,7 +114,7 @@ func (wireguard *Adapter) Configuration() (interfaze *Interface, err error) {
114114
}
115115
for {
116116
buf := make([]byte, size)
117-
r0, _, e1 := syscall.Syscall(procWireGuardGetConfiguration.Addr(), 3, wireguard.handle, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&size)))
117+
r0, _, e1 := syscall.SyscallN(procWireGuardGetConfiguration.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&buf[0])), uintptr(unsafe.Pointer(&size)))
118118
if r0 != 0 {
119119
wireguard.lastGetGuessSize = size
120120
return (*Interface)(unsafe.Pointer(&buf[0])), nil

driver/driver_windows.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ func setupLogger(dll *lazyDLL) {
6767
} else if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" {
6868
callback = windows.NewCallback(logMessage)
6969
}
70-
syscall.Syscall(dll.NewProc("WireGuardSetLogger").Addr(), 1, callback, 0, 0)
70+
syscall.SyscallN(dll.NewProc("WireGuardSetLogger").Addr(), callback)
7171
}
7272

7373
func closeAdapter(wireguard *Adapter) {
74-
syscall.Syscall(procWireGuardCloseAdapter.Addr(), 1, wireguard.handle, 0, 0)
74+
syscall.SyscallN(procWireGuardCloseAdapter.Addr(), wireguard.handle)
7575
}
7676

7777
// 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
9090
if err != nil {
9191
return
9292
}
93-
r0, _, e1 := syscall.Syscall(procWireGuardCreateAdapter.Addr(), 3, uintptr(unsafe.Pointer(name16)), uintptr(unsafe.Pointer(tunnelType16)), uintptr(unsafe.Pointer(requestedGUID)))
93+
r0, _, e1 := syscall.SyscallN(procWireGuardCreateAdapter.Addr(), uintptr(unsafe.Pointer(name16)), uintptr(unsafe.Pointer(tunnelType16)), uintptr(unsafe.Pointer(requestedGUID)))
9494
if r0 == 0 {
9595
err = e1
9696
return
@@ -107,7 +107,7 @@ func OpenAdapter(name string) (wireguard *Adapter, err error) {
107107
if err != nil {
108108
return
109109
}
110-
r0, _, e1 := syscall.Syscall(procWireGuardOpenAdapter.Addr(), 1, uintptr(unsafe.Pointer(name16)), 0, 0)
110+
r0, _, e1 := syscall.SyscallN(procWireGuardOpenAdapter.Addr(), uintptr(unsafe.Pointer(name16)))
111111
if r0 == 0 {
112112
err = e1
113113
return
@@ -120,7 +120,7 @@ func OpenAdapter(name string) (wireguard *Adapter, err error) {
120120
// Close closes a WireGuard adapter.
121121
func (wireguard *Adapter) Close() (err error) {
122122
runtime.SetFinalizer(wireguard, nil)
123-
r1, _, e1 := syscall.Syscall(procWireGuardCloseAdapter.Addr(), 1, wireguard.handle, 0, 0)
123+
r1, _, e1 := syscall.SyscallN(procWireGuardCloseAdapter.Addr(), wireguard.handle)
124124
if r1 == 0 {
125125
err = e1
126126
}
@@ -129,7 +129,7 @@ func (wireguard *Adapter) Close() (err error) {
129129

130130
// Uninstall removes the driver from the system if no drivers are currently in use.
131131
func Uninstall() (err error) {
132-
r1, _, e1 := syscall.Syscall(procWireGuardDeleteDriver.Addr(), 0, 0, 0, 0)
132+
r1, _, e1 := syscall.SyscallN(procWireGuardDeleteDriver.Addr())
133133
if r1 == 0 {
134134
err = e1
135135
}
@@ -146,7 +146,7 @@ const (
146146

147147
// SetLogging enables or disables logging on the WireGuard adapter.
148148
func (wireguard *Adapter) SetLogging(logState AdapterLogState) (err error) {
149-
r1, _, e1 := syscall.Syscall(procWireGuardSetAdapterLogging.Addr(), 2, wireguard.handle, uintptr(logState), 0)
149+
r1, _, e1 := syscall.SyscallN(procWireGuardSetAdapterLogging.Addr(), wireguard.handle, uintptr(logState))
150150
if r1 == 0 {
151151
err = e1
152152
}
@@ -155,7 +155,7 @@ func (wireguard *Adapter) SetLogging(logState AdapterLogState) (err error) {
155155

156156
// RunningVersion returns the version of the loaded driver.
157157
func RunningVersion() (version uint32, err error) {
158-
r0, _, e1 := syscall.Syscall(procWireGuardGetRunningDriverVersion.Addr(), 0, 0, 0, 0)
158+
r0, _, e1 := syscall.SyscallN(procWireGuardGetRunningDriverVersion.Addr())
159159
version = uint32(r0)
160160
if version == 0 {
161161
err = e1
@@ -165,6 +165,6 @@ func RunningVersion() (version uint32, err error) {
165165

166166
// LUID returns the LUID of the adapter.
167167
func (wireguard *Adapter) LUID() (luid winipcfg.LUID) {
168-
syscall.Syscall(procWireGuardGetAdapterLUID.Addr(), 2, wireguard.handle, uintptr(unsafe.Pointer(&luid)), 0)
168+
syscall.SyscallN(procWireGuardGetAdapterLUID.Addr(), wireguard.handle, uintptr(unsafe.Pointer(&luid)))
169169
return
170170
}

driver/memmod/memmod_windows.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func (module *Module) executeTLS() {
233233
if f == 0 {
234234
break
235235
}
236-
syscall.Syscall(f, 3, module.codeBase, uintptr(DLL_PROCESS_ATTACH), uintptr(0))
236+
syscall.SyscallN(f, module.codeBase, DLL_PROCESS_ATTACH, 0)
237237
callback += unsafe.Sizeof(f)
238238
}
239239
}
@@ -444,7 +444,7 @@ func hookRtlPcToFileHeader() error {
444444
}
445445
}
446446
loadedAddressRangesMu.RUnlock()
447-
ret, _, _ := syscall.Syscall(originalRtlPcToFileHeader, 2, pcValue, uintptr(unsafe.Pointer(baseOfImage)), 0)
447+
ret, _, _ := syscall.SyscallN(originalRtlPcToFileHeader, pcValue, uintptr(unsafe.Pointer(baseOfImage)))
448448
return ret
449449
})
450450
err = windows.VirtualProtect(uintptr(unsafe.Pointer(thunk)), unsafe.Sizeof(*thunk), oldProtect, &oldProtect)
@@ -605,7 +605,7 @@ func LoadLibrary(data []byte) (module *Module, err error) {
605605
module.entry = module.codeBase + uintptr(module.headers.OptionalHeader.AddressOfEntryPoint)
606606
if module.isDLL {
607607
// Notify library about attaching to process.
608-
r0, _, _ := syscall.Syscall(module.entry, 3, module.codeBase, uintptr(DLL_PROCESS_ATTACH), 0)
608+
r0, _, _ := syscall.SyscallN(module.entry, module.codeBase, DLL_PROCESS_ATTACH, 0)
609609
successful := r0 != 0
610610
if !successful {
611611
err = windows.ERROR_DLL_INIT_FAILED
@@ -623,7 +623,7 @@ func LoadLibrary(data []byte) (module *Module, err error) {
623623
func (module *Module) Free() {
624624
if module.initialized {
625625
// Notify library about detaching from process.
626-
syscall.Syscall(module.entry, 3, module.codeBase, uintptr(DLL_PROCESS_DETACH), 0)
626+
syscall.SyscallN(module.entry, module.codeBase, DLL_PROCESS_DETACH, 0)
627627
module.initialized = false
628628
}
629629
if module.modules != nil {

elevate/shellexecute.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,13 @@ func ShellExecute(program, arguments, directory string, show int32) (err error)
130130
return
131131
}
132132

133-
defer syscall.Syscall((*interfacePointer)[releaseOffset], 1, uintptr(unsafe.Pointer(interfacePointer)), 0, 0)
133+
defer syscall.SyscallN((*interfacePointer)[releaseOffset], uintptr(unsafe.Pointer(interfacePointer)))
134134

135135
if program16 == nil {
136136
return
137137
}
138138

139-
if ret, _, _ := syscall.Syscall6((*interfacePointer)[shellExecuteOffset], 6,
139+
if ret, _, _ := syscall.SyscallN((*interfacePointer)[shellExecuteOffset],
140140
uintptr(unsafe.Pointer(interfacePointer)),
141141
uintptr(unsafe.Pointer(program16)),
142142
uintptr(unsafe.Pointer(arguments16)),

0 commit comments

Comments
 (0)