1// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
2
3package windows
4
5import (
6	"internal/syscall/windows/sysdll"
7	"syscall"
8	"unsafe"
9)
10
11var _ unsafe.Pointer
12
13// Do the interface allocations only once for common
14// Errno values.
15const (
16	errnoERROR_IO_PENDING = 997
17)
18
19var (
20	errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
21)
22
23// errnoErr returns common boxed Errno values, to prevent
24// allocations at runtime.
25func errnoErr(e syscall.Errno) error {
26	switch e {
27	case 0:
28		return nil
29	case errnoERROR_IO_PENDING:
30		return errERROR_IO_PENDING
31	}
32	// TODO: add more here, after collecting data on the common
33	// error values see on Windows. (perhaps when running
34	// all.bat?)
35	return e
36}
37
38var (
39	modiphlpapi = syscall.NewLazyDLL(sysdll.Add("iphlpapi.dll"))
40	modkernel32 = syscall.NewLazyDLL(sysdll.Add("kernel32.dll"))
41	modws2_32   = syscall.NewLazyDLL(sysdll.Add("ws2_32.dll"))
42	modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll"))
43	modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
44	modpsapi    = syscall.NewLazyDLL(sysdll.Add("psapi.dll"))
45
46	procGetAdaptersAddresses      = modiphlpapi.NewProc("GetAdaptersAddresses")
47	procGetComputerNameExW        = modkernel32.NewProc("GetComputerNameExW")
48	procMoveFileExW               = modkernel32.NewProc("MoveFileExW")
49	procGetModuleFileNameW        = modkernel32.NewProc("GetModuleFileNameW")
50	procWSASocketW                = modws2_32.NewProc("WSASocketW")
51	procGetACP                    = modkernel32.NewProc("GetACP")
52	procGetConsoleCP              = modkernel32.NewProc("GetConsoleCP")
53	procMultiByteToWideChar       = modkernel32.NewProc("MultiByteToWideChar")
54	procGetCurrentThread          = modkernel32.NewProc("GetCurrentThread")
55	procNetShareAdd               = modnetapi32.NewProc("NetShareAdd")
56	procNetShareDel               = modnetapi32.NewProc("NetShareDel")
57	procGetFinalPathNameByHandleW = modkernel32.NewProc("GetFinalPathNameByHandleW")
58	procImpersonateSelf           = modadvapi32.NewProc("ImpersonateSelf")
59	procRevertToSelf              = modadvapi32.NewProc("RevertToSelf")
60	procOpenThreadToken           = modadvapi32.NewProc("OpenThreadToken")
61	procLookupPrivilegeValueW     = modadvapi32.NewProc("LookupPrivilegeValueW")
62	procAdjustTokenPrivileges     = modadvapi32.NewProc("AdjustTokenPrivileges")
63	procDuplicateTokenEx          = modadvapi32.NewProc("DuplicateTokenEx")
64	procSetTokenInformation       = modadvapi32.NewProc("SetTokenInformation")
65	procGetProcessMemoryInfo      = modpsapi.NewProc("GetProcessMemoryInfo")
66)
67
68func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
69	r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
70	if r0 != 0 {
71		errcode = syscall.Errno(r0)
72	}
73	return
74}
75
76func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
77	r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
78	if r1 == 0 {
79		if e1 != 0 {
80			err = errnoErr(e1)
81		} else {
82			err = syscall.EINVAL
83		}
84	}
85	return
86}
87
88func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
89	r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
90	if r1 == 0 {
91		if e1 != 0 {
92			err = errnoErr(e1)
93		} else {
94			err = syscall.EINVAL
95		}
96	}
97	return
98}
99
100func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) {
101	r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len))
102	n = uint32(r0)
103	if n == 0 {
104		if e1 != 0 {
105			err = errnoErr(e1)
106		} else {
107			err = syscall.EINVAL
108		}
109	}
110	return
111}
112
113func WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) {
114	r0, _, e1 := syscall.Syscall6(procWSASocketW.Addr(), 6, uintptr(af), uintptr(typ), uintptr(protocol), uintptr(unsafe.Pointer(protinfo)), uintptr(group), uintptr(flags))
115	handle = syscall.Handle(r0)
116	if handle == syscall.InvalidHandle {
117		if e1 != 0 {
118			err = errnoErr(e1)
119		} else {
120			err = syscall.EINVAL
121		}
122	}
123	return
124}
125
126func GetACP() (acp uint32) {
127	r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
128	acp = uint32(r0)
129	return
130}
131
132func GetConsoleCP() (ccp uint32) {
133	r0, _, _ := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0)
134	ccp = uint32(r0)
135	return
136}
137
138func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
139	r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
140	nwrite = int32(r0)
141	if nwrite == 0 {
142		if e1 != 0 {
143			err = errnoErr(e1)
144		} else {
145			err = syscall.EINVAL
146		}
147	}
148	return
149}
150
151func GetCurrentThread() (pseudoHandle syscall.Handle, err error) {
152	r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
153	pseudoHandle = syscall.Handle(r0)
154	if pseudoHandle == 0 {
155		if e1 != 0 {
156			err = errnoErr(e1)
157		} else {
158			err = syscall.EINVAL
159		}
160	}
161	return
162}
163
164func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) {
165	r0, _, _ := syscall.Syscall6(procNetShareAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0)
166	if r0 != 0 {
167		neterr = syscall.Errno(r0)
168	}
169	return
170}
171
172func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) {
173	r0, _, _ := syscall.Syscall(procNetShareDel.Addr(), 3, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved))
174	if r0 != 0 {
175		neterr = syscall.Errno(r0)
176	}
177	return
178}
179
180func GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) {
181	r0, _, e1 := syscall.Syscall6(procGetFinalPathNameByHandleW.Addr(), 4, uintptr(file), uintptr(unsafe.Pointer(filePath)), uintptr(filePathSize), uintptr(flags), 0, 0)
182	n = uint32(r0)
183	if n == 0 {
184		if e1 != 0 {
185			err = errnoErr(e1)
186		} else {
187			err = syscall.EINVAL
188		}
189	}
190	return
191}
192
193func ImpersonateSelf(impersonationlevel uint32) (err error) {
194	r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
195	if r1 == 0 {
196		if e1 != 0 {
197			err = errnoErr(e1)
198		} else {
199			err = syscall.EINVAL
200		}
201	}
202	return
203}
204
205func RevertToSelf() (err error) {
206	r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
207	if r1 == 0 {
208		if e1 != 0 {
209			err = errnoErr(e1)
210		} else {
211			err = syscall.EINVAL
212		}
213	}
214	return
215}
216
217func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) {
218	var _p0 uint32
219	if openasself {
220		_p0 = 1
221	} else {
222		_p0 = 0
223	}
224	r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
225	if r1 == 0 {
226		if e1 != 0 {
227			err = errnoErr(e1)
228		} else {
229			err = syscall.EINVAL
230		}
231	}
232	return
233}
234
235func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
236	r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
237	if r1 == 0 {
238		if e1 != 0 {
239			err = errnoErr(e1)
240		} else {
241			err = syscall.EINVAL
242		}
243	}
244	return
245}
246
247func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) {
248	var _p0 uint32
249	if disableAllPrivileges {
250		_p0 = 1
251	} else {
252		_p0 = 0
253	}
254	r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
255	ret = uint32(r0)
256	if true {
257		if e1 != 0 {
258			err = errnoErr(e1)
259		} else {
260			err = syscall.EINVAL
261		}
262	}
263	return
264}
265
266func DuplicateTokenEx(hExistingToken syscall.Token, dwDesiredAccess uint32, lpTokenAttributes *syscall.SecurityAttributes, impersonationLevel uint32, tokenType TokenType, phNewToken *syscall.Token) (err error) {
267	r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(hExistingToken), uintptr(dwDesiredAccess), uintptr(unsafe.Pointer(lpTokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(phNewToken)))
268	if r1 == 0 {
269		if e1 != 0 {
270			err = errnoErr(e1)
271		} else {
272			err = syscall.EINVAL
273		}
274	}
275	return
276}
277
278func SetTokenInformation(tokenHandle syscall.Token, tokenInformationClass uint32, tokenInformation uintptr, tokenInformationLength uint32) (err error) {
279	r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(tokenHandle), uintptr(tokenInformationClass), uintptr(tokenInformation), uintptr(tokenInformationLength), 0, 0)
280	if r1 == 0 {
281		if e1 != 0 {
282			err = errnoErr(e1)
283		} else {
284			err = syscall.EINVAL
285		}
286	}
287	return
288}
289
290func GetProcessMemoryInfo(handle syscall.Handle, memCounters *PROCESS_MEMORY_COUNTERS, cb uint32) (err error) {
291	r1, _, e1 := syscall.Syscall(procGetProcessMemoryInfo.Addr(), 3, uintptr(handle), uintptr(unsafe.Pointer(memCounters)), uintptr(cb))
292	if r1 == 0 {
293		if e1 != 0 {
294			err = errnoErr(e1)
295		} else {
296			err = syscall.EINVAL
297		}
298	}
299	return
300}
301