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	modnetapi32 = syscall.NewLazyDLL(sysdll.Add("netapi32.dll"))
42	modadvapi32 = syscall.NewLazyDLL(sysdll.Add("advapi32.dll"))
43
44	procGetAdaptersAddresses  = modiphlpapi.NewProc("GetAdaptersAddresses")
45	procGetComputerNameExW    = modkernel32.NewProc("GetComputerNameExW")
46	procMoveFileExW           = modkernel32.NewProc("MoveFileExW")
47	procGetModuleFileNameW    = modkernel32.NewProc("GetModuleFileNameW")
48	procGetACP                = modkernel32.NewProc("GetACP")
49	procGetConsoleCP          = modkernel32.NewProc("GetConsoleCP")
50	procMultiByteToWideChar   = modkernel32.NewProc("MultiByteToWideChar")
51	procGetCurrentThread      = modkernel32.NewProc("GetCurrentThread")
52	procNetShareAdd           = modnetapi32.NewProc("NetShareAdd")
53	procNetShareDel           = modnetapi32.NewProc("NetShareDel")
54	procImpersonateSelf       = modadvapi32.NewProc("ImpersonateSelf")
55	procRevertToSelf          = modadvapi32.NewProc("RevertToSelf")
56	procOpenThreadToken       = modadvapi32.NewProc("OpenThreadToken")
57	procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
58	procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
59)
60
61func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
62	r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
63	if r0 != 0 {
64		errcode = syscall.Errno(r0)
65	}
66	return
67}
68
69func GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) {
70	r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nameformat), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
71	if r1 == 0 {
72		if e1 != 0 {
73			err = errnoErr(e1)
74		} else {
75			err = syscall.EINVAL
76		}
77	}
78	return
79}
80
81func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
82	r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
83	if r1 == 0 {
84		if e1 != 0 {
85			err = errnoErr(e1)
86		} else {
87			err = syscall.EINVAL
88		}
89	}
90	return
91}
92
93func GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) {
94	r0, _, e1 := syscall.Syscall(procGetModuleFileNameW.Addr(), 3, uintptr(module), uintptr(unsafe.Pointer(fn)), uintptr(len))
95	n = uint32(r0)
96	if n == 0 {
97		if e1 != 0 {
98			err = errnoErr(e1)
99		} else {
100			err = syscall.EINVAL
101		}
102	}
103	return
104}
105
106func GetACP() (acp uint32) {
107	r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
108	acp = uint32(r0)
109	return
110}
111
112func GetConsoleCP() (ccp uint32) {
113	r0, _, _ := syscall.Syscall(procGetConsoleCP.Addr(), 0, 0, 0, 0)
114	ccp = uint32(r0)
115	return
116}
117
118func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
119	r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
120	nwrite = int32(r0)
121	if nwrite == 0 {
122		if e1 != 0 {
123			err = errnoErr(e1)
124		} else {
125			err = syscall.EINVAL
126		}
127	}
128	return
129}
130
131func GetCurrentThread() (pseudoHandle syscall.Handle, err error) {
132	r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
133	pseudoHandle = syscall.Handle(r0)
134	if pseudoHandle == 0 {
135		if e1 != 0 {
136			err = errnoErr(e1)
137		} else {
138			err = syscall.EINVAL
139		}
140	}
141	return
142}
143
144func NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) {
145	r0, _, _ := syscall.Syscall6(procNetShareAdd.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(level), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(parmErr)), 0, 0)
146	if r0 != 0 {
147		neterr = syscall.Errno(r0)
148	}
149	return
150}
151
152func NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) {
153	r0, _, _ := syscall.Syscall(procNetShareDel.Addr(), 3, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(netName)), uintptr(reserved))
154	if r0 != 0 {
155		neterr = syscall.Errno(r0)
156	}
157	return
158}
159
160func ImpersonateSelf(impersonationlevel uint32) (err error) {
161	r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
162	if r1 == 0 {
163		if e1 != 0 {
164			err = errnoErr(e1)
165		} else {
166			err = syscall.EINVAL
167		}
168	}
169	return
170}
171
172func RevertToSelf() (err error) {
173	r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
174	if r1 == 0 {
175		if e1 != 0 {
176			err = errnoErr(e1)
177		} else {
178			err = syscall.EINVAL
179		}
180	}
181	return
182}
183
184func OpenThreadToken(h syscall.Handle, access uint32, openasself bool, token *syscall.Token) (err error) {
185	var _p0 uint32
186	if openasself {
187		_p0 = 1
188	} else {
189		_p0 = 0
190	}
191	r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(h), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
192	if r1 == 0 {
193		if e1 != 0 {
194			err = errnoErr(e1)
195		} else {
196			err = syscall.EINVAL
197		}
198	}
199	return
200}
201
202func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
203	r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
204	if r1 == 0 {
205		if e1 != 0 {
206			err = errnoErr(e1)
207		} else {
208			err = syscall.EINVAL
209		}
210	}
211	return
212}
213
214func adjustTokenPrivileges(token syscall.Token, disableAllPrivileges bool, newstate *TOKEN_PRIVILEGES, buflen uint32, prevstate *TOKEN_PRIVILEGES, returnlen *uint32) (ret uint32, err error) {
215	var _p0 uint32
216	if disableAllPrivileges {
217		_p0 = 1
218	} else {
219		_p0 = 0
220	}
221	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)))
222	ret = uint32(r0)
223	if true {
224		if e1 != 0 {
225			err = errnoErr(e1)
226		} else {
227			err = syscall.EINVAL
228		}
229	}
230	return
231}
232