blob: 2ddf81b97c46bdde2ac84999fe55bed9080d80b7 [file] [log] [blame]
Alex Brainmanc07ca772014-03-11 16:36:14 +11001// go build mksyscall_windows.go && ./mksyscall_windows syscall_windows.go security_windows.go syscall_windows_amd64.go
Alex Brainmane71fc0c2011-07-07 10:40:45 +10002// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
3
4package syscall
5
6import "unsafe"
7
8var (
Alex Brainman9d7e3932011-07-31 20:07:04 +10009 modkernel32 = NewLazyDLL("kernel32.dll")
10 modadvapi32 = NewLazyDLL("advapi32.dll")
11 modshell32 = NewLazyDLL("shell32.dll")
Paul Lalondebb8bbb22011-09-08 16:32:40 +100012 modmswsock = NewLazyDLL("mswsock.dll")
Mikkel Krautz31533952011-10-13 22:58:19 -040013 modcrypt32 = NewLazyDLL("crypt32.dll")
Alex Brainman9d7e3932011-07-31 20:07:04 +100014 modws2_32 = NewLazyDLL("ws2_32.dll")
15 moddnsapi = NewLazyDLL("dnsapi.dll")
16 modiphlpapi = NewLazyDLL("iphlpapi.dll")
Alex Brainmandcbc77d2012-01-30 22:59:10 +110017 modsecur32 = NewLazyDLL("secur32.dll")
18 modnetapi32 = NewLazyDLL("netapi32.dll")
19 moduserenv = NewLazyDLL("userenv.dll")
Alex Brainmane71fc0c2011-07-07 10:40:45 +100020
Dmitriy Vyukoved8c5502013-08-08 17:36:43 +040021 procGetLastError = modkernel32.NewProc("GetLastError")
22 procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
23 procFreeLibrary = modkernel32.NewProc("FreeLibrary")
24 procGetProcAddress = modkernel32.NewProc("GetProcAddress")
25 procGetVersion = modkernel32.NewProc("GetVersion")
26 procFormatMessageW = modkernel32.NewProc("FormatMessageW")
27 procExitProcess = modkernel32.NewProc("ExitProcess")
28 procCreateFileW = modkernel32.NewProc("CreateFileW")
29 procReadFile = modkernel32.NewProc("ReadFile")
30 procWriteFile = modkernel32.NewProc("WriteFile")
31 procSetFilePointer = modkernel32.NewProc("SetFilePointer")
32 procCloseHandle = modkernel32.NewProc("CloseHandle")
33 procGetStdHandle = modkernel32.NewProc("GetStdHandle")
34 procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
35 procFindNextFileW = modkernel32.NewProc("FindNextFileW")
36 procFindClose = modkernel32.NewProc("FindClose")
37 procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
38 procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
39 procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
40 procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
41 procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
42 procDeleteFileW = modkernel32.NewProc("DeleteFileW")
43 procMoveFileW = modkernel32.NewProc("MoveFileW")
44 procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
45 procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
46 procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
47 procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
48 procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
49 procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
50 procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
51 procCancelIo = modkernel32.NewProc("CancelIo")
52 procCancelIoEx = modkernel32.NewProc("CancelIoEx")
53 procCreateProcessW = modkernel32.NewProc("CreateProcessW")
54 procOpenProcess = modkernel32.NewProc("OpenProcess")
55 procTerminateProcess = modkernel32.NewProc("TerminateProcess")
56 procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
57 procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
58 procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
59 procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
60 procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
61 procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
62 procGetTempPathW = modkernel32.NewProc("GetTempPathW")
63 procCreatePipe = modkernel32.NewProc("CreatePipe")
64 procGetFileType = modkernel32.NewProc("GetFileType")
65 procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
66 procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
67 procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
68 procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
69 procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
70 procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
71 procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
72 procSetFileTime = modkernel32.NewProc("SetFileTime")
73 procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
74 procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
75 procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
76 procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
77 procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
78 procLocalFree = modkernel32.NewProc("LocalFree")
79 procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
80 procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
81 procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
82 procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
83 procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
84 procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
85 procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
86 procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
87 procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
88 procVirtualLock = modkernel32.NewProc("VirtualLock")
89 procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
90 procTransmitFile = modmswsock.NewProc("TransmitFile")
91 procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
92 procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
93 procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
94 procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
95 procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
96 procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
97 procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
98 procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
99 procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
100 procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
101 procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
102 procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
103 procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
104 procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
105 procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
106 procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
107 procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
108 procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
109 procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
110 procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
Alan Shreve6f6f1bd2014-06-14 15:51:00 +1000111 procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
112 procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
113 procProcess32NextW = modkernel32.NewProc("Process32NextW")
Dmitriy Vyukoved8c5502013-08-08 17:36:43 +0400114 procWSAStartup = modws2_32.NewProc("WSAStartup")
115 procWSACleanup = modws2_32.NewProc("WSACleanup")
116 procWSAIoctl = modws2_32.NewProc("WSAIoctl")
117 procsocket = modws2_32.NewProc("socket")
118 procsetsockopt = modws2_32.NewProc("setsockopt")
119 procgetsockopt = modws2_32.NewProc("getsockopt")
120 procbind = modws2_32.NewProc("bind")
121 procconnect = modws2_32.NewProc("connect")
122 procgetsockname = modws2_32.NewProc("getsockname")
123 procgetpeername = modws2_32.NewProc("getpeername")
124 proclisten = modws2_32.NewProc("listen")
125 procshutdown = modws2_32.NewProc("shutdown")
126 procclosesocket = modws2_32.NewProc("closesocket")
127 procAcceptEx = modmswsock.NewProc("AcceptEx")
128 procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
129 procWSARecv = modws2_32.NewProc("WSARecv")
130 procWSASend = modws2_32.NewProc("WSASend")
131 procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
132 procWSASendTo = modws2_32.NewProc("WSASendTo")
133 procgethostbyname = modws2_32.NewProc("gethostbyname")
134 procgetservbyname = modws2_32.NewProc("getservbyname")
135 procntohs = modws2_32.NewProc("ntohs")
136 procgetprotobyname = modws2_32.NewProc("getprotobyname")
137 procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
138 procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
139 procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
140 procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
141 procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
142 procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
143 procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
144 procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
145 procTranslateNameW = modsecur32.NewProc("TranslateNameW")
146 procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
147 procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
148 procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
149 procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
150 procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
151 procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
152 procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
153 procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
154 procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
155 procCopySid = modadvapi32.NewProc("CopySid")
156 procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
157 procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
158 procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000159)
160
Alex Brainmanef65fed2011-12-08 12:07:21 +1100161func GetLastError() (lasterr error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000162 r0, _, _ := Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +1100163 if r0 != 0 {
164 lasterr = Errno(r0)
165 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000166 return
167}
168
Russ Coxc017a822011-11-13 22:44:52 -0500169func LoadLibrary(libname string) (handle Handle, err error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -0400170 var _p0 *uint16
171 _p0, err = UTF16PtrFromString(libname)
172 if err != nil {
173 return
174 }
175 r0, _, e1 := Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000176 handle = Handle(r0)
177 if handle == 0 {
178 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500179 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000180 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500181 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000182 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000183 }
184 return
185}
186
Russ Coxc017a822011-11-13 22:44:52 -0500187func FreeLibrary(handle Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000188 r1, _, e1 := Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000189 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000190 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500191 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000192 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500193 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000194 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000195 }
196 return
197}
198
Russ Coxc017a822011-11-13 22:44:52 -0500199func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -0400200 var _p0 *byte
201 _p0, err = BytePtrFromString(procname)
202 if err != nil {
203 return
204 }
205 r0, _, e1 := Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(_p0)), 0)
Alex Brainman37f390a2011-09-06 09:59:08 +1000206 proc = uintptr(r0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000207 if proc == 0 {
208 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500209 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000210 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500211 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000212 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000213 }
214 return
215}
216
Russ Coxc017a822011-11-13 22:44:52 -0500217func GetVersion() (ver uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000218 r0, _, e1 := Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000219 ver = uint32(r0)
220 if ver == 0 {
221 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500222 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000223 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500224 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000225 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000226 }
227 return
228}
229
Russ Coxc017a822011-11-13 22:44:52 -0500230func FormatMessage(flags uint32, msgsrc uint32, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000231 var _p0 *uint16
232 if len(buf) > 0 {
233 _p0 = &buf[0]
234 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000235 r0, _, e1 := Syscall9(procFormatMessageW.Addr(), 7, uintptr(flags), uintptr(msgsrc), uintptr(msgid), uintptr(langid), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(args)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000236 n = uint32(r0)
237 if n == 0 {
238 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500239 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000240 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500241 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000242 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000243 }
244 return
245}
246
247func ExitProcess(exitcode uint32) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000248 Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000249 return
250}
251
Russ Coxc017a822011-11-13 22:44:52 -0500252func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000253 r0, _, e1 := Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000254 handle = Handle(r0)
255 if handle == InvalidHandle {
256 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500257 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000258 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500259 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000260 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000261 }
262 return
263}
264
Russ Coxc017a822011-11-13 22:44:52 -0500265func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000266 var _p0 *byte
267 if len(buf) > 0 {
268 _p0 = &buf[0]
269 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000270 r1, _, e1 := Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000271 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000272 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500273 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000274 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500275 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000276 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000277 }
278 return
279}
280
Russ Coxc017a822011-11-13 22:44:52 -0500281func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000282 var _p0 *byte
283 if len(buf) > 0 {
284 _p0 = &buf[0]
285 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000286 r1, _, e1 := Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000287 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000288 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500289 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000290 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500291 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000292 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000293 }
294 return
295}
296
Russ Coxc017a822011-11-13 22:44:52 -0500297func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000298 r0, _, e1 := Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000299 newlowoffset = uint32(r0)
300 if newlowoffset == 0xffffffff {
301 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500302 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000303 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500304 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000305 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000306 }
307 return
308}
309
Russ Coxc017a822011-11-13 22:44:52 -0500310func CloseHandle(handle Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000311 r1, _, e1 := Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000312 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000313 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500314 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000315 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500316 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000317 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000318 }
319 return
320}
321
Russ Coxc017a822011-11-13 22:44:52 -0500322func GetStdHandle(stdhandle int) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000323 r0, _, e1 := Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000324 handle = Handle(r0)
325 if handle == InvalidHandle {
326 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500327 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000328 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500329 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000330 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000331 }
332 return
333}
334
Russ Cox7ad37672012-06-08 13:54:48 -0400335func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000336 r0, _, e1 := Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000337 handle = Handle(r0)
338 if handle == InvalidHandle {
339 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500340 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000341 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500342 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000343 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000344 }
345 return
346}
347
Russ Cox7ad37672012-06-08 13:54:48 -0400348func findNextFile1(handle Handle, data *win32finddata1) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000349 r1, _, e1 := Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000350 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000351 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500352 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000353 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500354 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000355 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000356 }
357 return
358}
359
Russ Coxc017a822011-11-13 22:44:52 -0500360func FindClose(handle Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000361 r1, _, e1 := Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000362 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000363 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500364 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000365 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500366 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000367 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000368 }
369 return
370}
371
Russ Coxc017a822011-11-13 22:44:52 -0500372func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000373 r1, _, e1 := Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000374 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000375 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500376 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000377 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500378 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000379 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000380 }
381 return
382}
383
Russ Coxc017a822011-11-13 22:44:52 -0500384func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000385 r0, _, e1 := Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000386 n = uint32(r0)
387 if n == 0 {
388 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500389 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000390 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500391 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000392 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000393 }
394 return
395}
396
Russ Coxc017a822011-11-13 22:44:52 -0500397func SetCurrentDirectory(path *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000398 r1, _, e1 := Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000399 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000400 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500401 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000402 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500403 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000404 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000405 }
406 return
407}
408
Russ Coxc017a822011-11-13 22:44:52 -0500409func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000410 r1, _, e1 := Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000411 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000412 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500413 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000414 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500415 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000416 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000417 }
418 return
419}
420
Russ Coxc017a822011-11-13 22:44:52 -0500421func RemoveDirectory(path *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000422 r1, _, e1 := Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000423 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000424 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500425 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000426 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500427 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000428 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000429 }
430 return
431}
432
Russ Coxc017a822011-11-13 22:44:52 -0500433func DeleteFile(path *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000434 r1, _, e1 := Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000435 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000436 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500437 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000438 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500439 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000440 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000441 }
442 return
443}
444
Russ Coxc017a822011-11-13 22:44:52 -0500445func MoveFile(from *uint16, to *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000446 r1, _, e1 := Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000447 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000448 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500449 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000450 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500451 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000452 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000453 }
454 return
455}
456
Russ Coxc017a822011-11-13 22:44:52 -0500457func GetComputerName(buf *uint16, n *uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000458 r1, _, e1 := Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000459 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000460 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500461 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000462 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500463 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000464 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000465 }
466 return
467}
468
Russ Coxc017a822011-11-13 22:44:52 -0500469func SetEndOfFile(handle Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000470 r1, _, e1 := Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000471 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000472 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500473 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000474 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500475 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000476 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000477 }
478 return
479}
480
481func GetSystemTimeAsFileTime(time *Filetime) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000482 Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000483 return
484}
485
Russ Coxc017a822011-11-13 22:44:52 -0500486func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000487 r0, _, e1 := Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000488 rc = uint32(r0)
489 if rc == 0xffffffff {
490 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500491 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000492 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500493 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000494 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000495 }
496 return
497}
498
Russ Coxc017a822011-11-13 22:44:52 -0500499func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000500 r0, _, e1 := Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000501 handle = Handle(r0)
502 if handle == 0 {
503 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500504 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000505 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500506 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000507 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000508 }
509 return
510}
511
Russ Coxc017a822011-11-13 22:44:52 -0500512func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000513 r1, _, e1 := Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000514 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000515 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500516 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000517 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500518 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000519 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000520 }
521 return
522}
523
Russ Coxc017a822011-11-13 22:44:52 -0500524func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
Hector Chu7ecf6c92011-10-18 21:09:58 +0100525 r1, _, e1 := Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000526 if r1 == 0 {
Hector Chu7ecf6c92011-10-18 21:09:58 +0100527 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500528 err = error(e1)
Hector Chu7ecf6c92011-10-18 21:09:58 +0100529 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500530 err = EINVAL
Hector Chu7ecf6c92011-10-18 21:09:58 +0100531 }
Hector Chu7ecf6c92011-10-18 21:09:58 +0100532 }
533 return
534}
535
Russ Coxc017a822011-11-13 22:44:52 -0500536func CancelIo(s Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000537 r1, _, e1 := Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000538 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000539 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500540 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000541 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500542 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000543 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000544 }
545 return
546}
547
Alex Brainmanfa3e4fc2012-10-31 10:24:37 +1100548func CancelIoEx(s Handle, o *Overlapped) (err error) {
549 r1, _, e1 := Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
550 if r1 == 0 {
551 if e1 != 0 {
552 err = error(e1)
553 } else {
554 err = EINVAL
555 }
556 }
557 return
558}
559
Russ Coxc017a822011-11-13 22:44:52 -0500560func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000561 var _p0 uint32
562 if inheritHandles {
563 _p0 = 1
564 } else {
565 _p0 = 0
566 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000567 r1, _, e1 := Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000568 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000569 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500570 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000571 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500572 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000573 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000574 }
575 return
576}
577
Russ Coxc017a822011-11-13 22:44:52 -0500578func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000579 var _p0 uint32
580 if inheritHandle {
581 _p0 = 1
582 } else {
583 _p0 = 0
584 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000585 r0, _, e1 := Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000586 handle = Handle(r0)
587 if handle == 0 {
588 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500589 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000590 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500591 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000592 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000593 }
594 return
595}
596
Russ Coxc017a822011-11-13 22:44:52 -0500597func TerminateProcess(handle Handle, exitcode uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000598 r1, _, e1 := Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000599 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000600 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500601 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000602 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500603 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000604 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000605 }
606 return
607}
608
Russ Coxc017a822011-11-13 22:44:52 -0500609func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000610 r1, _, e1 := Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000611 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000612 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500613 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000614 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500615 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000616 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000617 }
618 return
619}
620
Russ Coxc017a822011-11-13 22:44:52 -0500621func GetStartupInfo(startupInfo *StartupInfo) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000622 r1, _, e1 := Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000623 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000624 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500625 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000626 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500627 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000628 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000629 }
630 return
631}
632
Russ Coxc017a822011-11-13 22:44:52 -0500633func GetCurrentProcess() (pseudoHandle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000634 r0, _, e1 := Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000635 pseudoHandle = Handle(r0)
636 if pseudoHandle == 0 {
637 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500638 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000639 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500640 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000641 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000642 }
643 return
644}
645
Alex Brainmanc3fbc9a2012-03-02 14:47:40 +1100646func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
647 r1, _, e1 := Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000648 if r1 == 0 {
Alex Brainmanc3fbc9a2012-03-02 14:47:40 +1100649 if e1 != 0 {
650 err = error(e1)
651 } else {
652 err = EINVAL
653 }
654 }
655 return
656}
657
Russ Coxc017a822011-11-13 22:44:52 -0500658func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000659 var _p0 uint32
660 if bInheritHandle {
661 _p0 = 1
662 } else {
663 _p0 = 0
664 }
Alex Brainman9d7e3932011-07-31 20:07:04 +1000665 r1, _, e1 := Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000666 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000667 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500668 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000669 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500670 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000671 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000672 }
673 return
674}
675
Russ Coxc017a822011-11-13 22:44:52 -0500676func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000677 r0, _, e1 := Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000678 event = uint32(r0)
679 if event == 0xffffffff {
680 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500681 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000682 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500683 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000684 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000685 }
686 return
687}
688
Russ Coxc017a822011-11-13 22:44:52 -0500689func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000690 r0, _, e1 := Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000691 n = uint32(r0)
692 if n == 0 {
693 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500694 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000695 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500696 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000697 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000698 }
699 return
700}
701
Russ Coxc017a822011-11-13 22:44:52 -0500702func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000703 r1, _, e1 := Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000704 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000705 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500706 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000707 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500708 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000709 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000710 }
711 return
712}
713
Russ Coxc017a822011-11-13 22:44:52 -0500714func GetFileType(filehandle Handle) (n uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000715 r0, _, e1 := Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000716 n = uint32(r0)
717 if n == 0 {
718 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500719 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000720 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500721 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000722 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000723 }
724 return
725}
726
Russ Coxc017a822011-11-13 22:44:52 -0500727func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000728 r1, _, e1 := Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000729 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000730 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500731 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000732 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500733 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000734 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000735 }
736 return
737}
738
Russ Coxc017a822011-11-13 22:44:52 -0500739func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000740 r1, _, e1 := Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000741 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000742 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500743 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000744 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500745 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000746 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000747 }
748 return
749}
750
Russ Coxc017a822011-11-13 22:44:52 -0500751func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000752 r1, _, e1 := Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
Alex Brainman0e6f9272012-09-25 17:06:39 +1000753 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000754 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500755 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000756 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500757 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000758 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000759 }
760 return
761}
762
Russ Coxc017a822011-11-13 22:44:52 -0500763func GetEnvironmentStrings() (envs *uint16, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000764 r0, _, e1 := Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000765 envs = (*uint16)(unsafe.Pointer(r0))
766 if envs == nil {
767 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500768 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000769 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500770 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000771 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000772 }
773 return
774}
775
Russ Coxc017a822011-11-13 22:44:52 -0500776func FreeEnvironmentStrings(envs *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000777 r1, _, e1 := Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000778 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000779 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500780 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000781 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500782 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000783 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000784 }
785 return
786}
787
Russ Coxc017a822011-11-13 22:44:52 -0500788func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000789 r0, _, e1 := Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000790 n = uint32(r0)
791 if n == 0 {
792 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500793 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000794 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500795 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000796 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000797 }
798 return
799}
800
Russ Coxc017a822011-11-13 22:44:52 -0500801func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000802 r1, _, e1 := Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000803 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000804 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500805 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000806 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500807 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000808 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000809 }
810 return
811}
812
Russ Coxc017a822011-11-13 22:44:52 -0500813func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000814 r1, _, e1 := Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000815 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000816 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500817 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000818 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500819 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000820 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000821 }
822 return
823}
824
Russ Coxc017a822011-11-13 22:44:52 -0500825func GetFileAttributes(name *uint16) (attrs uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000826 r0, _, e1 := Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000827 attrs = uint32(r0)
828 if attrs == INVALID_FILE_ATTRIBUTES {
829 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500830 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000831 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500832 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000833 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000834 }
835 return
836}
837
Russ Coxc017a822011-11-13 22:44:52 -0500838func SetFileAttributes(name *uint16, attrs uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000839 r1, _, e1 := Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000840 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000841 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500842 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000843 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500844 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000845 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000846 }
847 return
848}
849
Russ Coxc017a822011-11-13 22:44:52 -0500850func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
Alex Brainman37f390a2011-09-06 09:59:08 +1000851 r1, _, e1 := Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
Alex Brainman0e6f9272012-09-25 17:06:39 +1000852 if r1 == 0 {
Alex Brainman37f390a2011-09-06 09:59:08 +1000853 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500854 err = error(e1)
Alex Brainman37f390a2011-09-06 09:59:08 +1000855 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500856 err = EINVAL
Alex Brainman37f390a2011-09-06 09:59:08 +1000857 }
Alex Brainman37f390a2011-09-06 09:59:08 +1000858 }
859 return
860}
861
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000862func GetCommandLine() (cmd *uint16) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000863 r0, _, _ := Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000864 cmd = (*uint16)(unsafe.Pointer(r0))
865 return
866}
867
Russ Coxc017a822011-11-13 22:44:52 -0500868func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000869 r0, _, e1 := Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000870 argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
871 if argv == nil {
872 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500873 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000874 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500875 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000876 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000877 }
878 return
879}
880
Russ Coxc017a822011-11-13 22:44:52 -0500881func LocalFree(hmem Handle) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000882 r0, _, e1 := Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000883 handle = Handle(r0)
884 if handle != 0 {
885 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500886 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000887 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500888 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000889 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000890 }
891 return
892}
893
Russ Coxc017a822011-11-13 22:44:52 -0500894func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000895 r1, _, e1 := Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
Alex Brainman0e6f9272012-09-25 17:06:39 +1000896 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000897 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500898 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000899 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500900 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000901 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000902 }
903 return
904}
905
Russ Coxc017a822011-11-13 22:44:52 -0500906func FlushFileBuffers(handle Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000907 r1, _, e1 := Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000908 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000909 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500910 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000911 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500912 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000913 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000914 }
915 return
916}
917
Russ Coxc017a822011-11-13 22:44:52 -0500918func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000919 r0, _, e1 := Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000920 n = uint32(r0)
921 if n == 0 {
922 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500923 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000924 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500925 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000926 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000927 }
928 return
929}
930
Alex Brainman0029b0d2012-03-08 10:00:25 +1100931func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
932 r0, _, e1 := Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
933 n = uint32(r0)
934 if n == 0 {
935 if e1 != 0 {
936 err = error(e1)
937 } else {
938 err = EINVAL
939 }
940 }
941 return
942}
943
Alex Brainman7a396542012-03-27 15:53:08 +1100944func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
945 r0, _, e1 := Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
946 n = uint32(r0)
947 if n == 0 {
948 if e1 != 0 {
949 err = error(e1)
950 } else {
951 err = EINVAL
952 }
953 }
954 return
955}
956
Russ Coxc017a822011-11-13 22:44:52 -0500957func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000958 r0, _, e1 := Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000959 handle = Handle(r0)
960 if handle == 0 {
961 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500962 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000963 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500964 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000965 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000966 }
967 return
968}
969
Russ Coxc017a822011-11-13 22:44:52 -0500970func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000971 r0, _, e1 := Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000972 addr = uintptr(r0)
973 if addr == 0 {
974 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500975 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000976 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500977 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000978 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000979 }
980 return
981}
982
Russ Coxc017a822011-11-13 22:44:52 -0500983func UnmapViewOfFile(addr uintptr) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000984 r1, _, e1 := Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000985 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000986 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500987 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000988 } else {
Russ Coxc017a822011-11-13 22:44:52 -0500989 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000990 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000991 }
992 return
993}
994
Russ Coxc017a822011-11-13 22:44:52 -0500995func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +1000996 r1, _, e1 := Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +1000997 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +1000998 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -0500999 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001000 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001001 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001002 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001003 }
1004 return
1005}
1006
Russ Coxc017a822011-11-13 22:44:52 -05001007func VirtualLock(addr uintptr, length uintptr) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001008 r1, _, e1 := Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001009 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001010 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001011 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001012 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001013 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001014 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001015 }
1016 return
1017}
1018
Russ Coxc017a822011-11-13 22:44:52 -05001019func VirtualUnlock(addr uintptr, length uintptr) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001020 r1, _, e1 := Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001021 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001022 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001023 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001024 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001025 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001026 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001027 }
1028 return
1029}
1030
Russ Coxc017a822011-11-13 22:44:52 -05001031func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001032 r1, _, e1 := Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001033 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001034 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001035 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001036 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001037 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001038 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001039 }
1040 return
1041}
1042
Russ Coxc017a822011-11-13 22:44:52 -05001043func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
Hector Chu7ecf6c92011-10-18 21:09:58 +01001044 var _p0 uint32
1045 if watchSubTree {
1046 _p0 = 1
1047 } else {
1048 _p0 = 0
1049 }
1050 r1, _, e1 := Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001051 if r1 == 0 {
Hector Chu7ecf6c92011-10-18 21:09:58 +01001052 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001053 err = error(e1)
Hector Chu7ecf6c92011-10-18 21:09:58 +01001054 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001055 err = EINVAL
Hector Chu7ecf6c92011-10-18 21:09:58 +01001056 }
Hector Chu7ecf6c92011-10-18 21:09:58 +01001057 }
1058 return
1059}
1060
Russ Coxc017a822011-11-13 22:44:52 -05001061func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
Mikkel Krautz31533952011-10-13 22:58:19 -04001062 r0, _, e1 := Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
1063 store = Handle(r0)
1064 if store == 0 {
1065 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001066 err = error(e1)
Mikkel Krautz31533952011-10-13 22:58:19 -04001067 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001068 err = EINVAL
Mikkel Krautz31533952011-10-13 22:58:19 -04001069 }
Mikkel Krautz31533952011-10-13 22:58:19 -04001070 }
1071 return
1072}
1073
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001074func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
1075 r0, _, e1 := Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
1076 handle = Handle(r0)
1077 if handle == InvalidHandle {
1078 if e1 != 0 {
1079 err = error(e1)
1080 } else {
1081 err = EINVAL
1082 }
1083 }
1084 return
1085}
1086
Alex Brainmand5f37122011-12-01 12:38:00 -05001087func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
1088 r0, _, e1 := Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
Mikkel Krautz31533952011-10-13 22:58:19 -04001089 context = (*CertContext)(unsafe.Pointer(r0))
Alex Brainmand5f37122011-12-01 12:38:00 -05001090 if context == nil {
1091 if e1 != 0 {
1092 err = error(e1)
1093 } else {
1094 err = EINVAL
1095 }
1096 }
Mikkel Krautz31533952011-10-13 22:58:19 -04001097 return
1098}
1099
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001100func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
1101 r1, _, e1 := Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001102 if r1 == 0 {
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001103 if e1 != 0 {
1104 err = error(e1)
1105 } else {
1106 err = EINVAL
1107 }
1108 }
1109 return
1110}
1111
Russ Coxc017a822011-11-13 22:44:52 -05001112func CertCloseStore(store Handle, flags uint32) (err error) {
Mikkel Krautz31533952011-10-13 22:58:19 -04001113 r1, _, e1 := Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001114 if r1 == 0 {
Mikkel Krautz31533952011-10-13 22:58:19 -04001115 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001116 err = error(e1)
Mikkel Krautz31533952011-10-13 22:58:19 -04001117 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001118 err = EINVAL
Mikkel Krautz31533952011-10-13 22:58:19 -04001119 }
Mikkel Krautz31533952011-10-13 22:58:19 -04001120 }
1121 return
1122}
1123
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001124func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
1125 r1, _, e1 := Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001126 if r1 == 0 {
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001127 if e1 != 0 {
1128 err = error(e1)
1129 } else {
1130 err = EINVAL
1131 }
1132 }
1133 return
1134}
1135
1136func CertFreeCertificateChain(ctx *CertChainContext) {
1137 Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
1138 return
1139}
1140
1141func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
1142 r0, _, e1 := Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
1143 context = (*CertContext)(unsafe.Pointer(r0))
1144 if context == nil {
1145 if e1 != 0 {
1146 err = error(e1)
1147 } else {
1148 err = EINVAL
1149 }
1150 }
1151 return
1152}
1153
1154func CertFreeCertificateContext(ctx *CertContext) (err error) {
1155 r1, _, e1 := Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001156 if r1 == 0 {
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001157 if e1 != 0 {
1158 err = error(e1)
1159 } else {
1160 err = EINVAL
1161 }
1162 }
1163 return
1164}
1165
1166func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
1167 r1, _, e1 := Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001168 if r1 == 0 {
Mikkel Krautza324a5a2012-03-07 13:12:35 -05001169 if e1 != 0 {
1170 err = error(e1)
1171 } else {
1172 err = EINVAL
1173 }
1174 }
1175 return
1176}
1177
Alex Brainmanef65fed2011-12-08 12:07:21 +11001178func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
Alex Brainmanac17fd42011-11-18 10:07:36 +11001179 r0, _, _ := Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001180 if r0 != 0 {
1181 regerrno = Errno(r0)
1182 }
Alex Brainmanac17fd42011-11-18 10:07:36 +11001183 return
1184}
1185
Alex Brainmanef65fed2011-12-08 12:07:21 +11001186func RegCloseKey(key Handle) (regerrno error) {
Alex Brainmanac17fd42011-11-18 10:07:36 +11001187 r0, _, _ := Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001188 if r0 != 0 {
1189 regerrno = Errno(r0)
1190 }
Alex Brainmanac17fd42011-11-18 10:07:36 +11001191 return
1192}
1193
Alex Brainmanef65fed2011-12-08 12:07:21 +11001194func RegQueryInfoKey(key Handle, class *uint16, classLen *uint32, reserved *uint32, subkeysLen *uint32, maxSubkeyLen *uint32, maxClassLen *uint32, valuesLen *uint32, maxValueNameLen *uint32, maxValueLen *uint32, saLen *uint32, lastWriteTime *Filetime) (regerrno error) {
Alex Brainmanac17fd42011-11-18 10:07:36 +11001195 r0, _, _ := Syscall12(procRegQueryInfoKeyW.Addr(), 12, uintptr(key), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(subkeysLen)), uintptr(unsafe.Pointer(maxSubkeyLen)), uintptr(unsafe.Pointer(maxClassLen)), uintptr(unsafe.Pointer(valuesLen)), uintptr(unsafe.Pointer(maxValueNameLen)), uintptr(unsafe.Pointer(maxValueLen)), uintptr(unsafe.Pointer(saLen)), uintptr(unsafe.Pointer(lastWriteTime)))
Alex Brainmanef65fed2011-12-08 12:07:21 +11001196 if r0 != 0 {
1197 regerrno = Errno(r0)
1198 }
Alex Brainmanac17fd42011-11-18 10:07:36 +11001199 return
1200}
1201
Alex Brainmanef65fed2011-12-08 12:07:21 +11001202func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
Alex Brainmanac17fd42011-11-18 10:07:36 +11001203 r0, _, _ := Syscall9(procRegEnumKeyExW.Addr(), 8, uintptr(key), uintptr(index), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(class)), uintptr(unsafe.Pointer(classLen)), uintptr(unsafe.Pointer(lastWriteTime)), 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001204 if r0 != 0 {
1205 regerrno = Errno(r0)
1206 }
Alex Brainmanac17fd42011-11-18 10:07:36 +11001207 return
1208}
1209
Alex Brainmanef65fed2011-12-08 12:07:21 +11001210func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
Alex Brainmanac17fd42011-11-18 10:07:36 +11001211 r0, _, _ := Syscall6(procRegQueryValueExW.Addr(), 6, uintptr(key), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(reserved)), uintptr(unsafe.Pointer(valtype)), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(buflen)))
Alex Brainmanef65fed2011-12-08 12:07:21 +11001212 if r0 != 0 {
1213 regerrno = Errno(r0)
1214 }
Alex Brainmanac17fd42011-11-18 10:07:36 +11001215 return
1216}
1217
Russ Cox7762a9d2012-06-08 14:28:29 -04001218func getCurrentProcessId() (pid uint32) {
Alex Brainman50e59512012-05-23 13:05:05 +10001219 r0, _, _ := Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
1220 pid = uint32(r0)
1221 return
1222}
1223
Alex Brainman18601f82012-09-12 12:04:45 +10001224func GetConsoleMode(console Handle, mode *uint32) (err error) {
1225 r1, _, e1 := Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001226 if r1 == 0 {
Alex Brainman18601f82012-09-12 12:04:45 +10001227 if e1 != 0 {
1228 err = error(e1)
1229 } else {
1230 err = EINVAL
1231 }
1232 }
1233 return
1234}
1235
1236func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
1237 r1, _, e1 := Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001238 if r1 == 0 {
Alex Brainman18601f82012-09-12 12:04:45 +10001239 if e1 != 0 {
1240 err = error(e1)
1241 } else {
1242 err = EINVAL
1243 }
1244 }
1245 return
1246}
1247
Alex Brainman26498682013-02-26 14:18:48 +11001248func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
1249 r1, _, e1 := Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
1250 if r1 == 0 {
1251 if e1 != 0 {
1252 err = error(e1)
1253 } else {
1254 err = EINVAL
1255 }
1256 }
1257 return
1258}
1259
Alan Shreve6f6f1bd2014-06-14 15:51:00 +10001260func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
1261 r0, _, e1 := Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
1262 handle = Handle(r0)
1263 if handle == InvalidHandle {
1264 if e1 != 0 {
1265 err = error(e1)
1266 } else {
1267 err = EINVAL
1268 }
1269 }
1270 return
1271}
1272
1273func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
1274 r1, _, e1 := Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
1275 if r1 == 0 {
1276 if e1 != 0 {
1277 err = error(e1)
1278 } else {
1279 err = EINVAL
1280 }
1281 }
1282 return
1283}
1284
1285func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
1286 r1, _, e1 := Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
1287 if r1 == 0 {
1288 if e1 != 0 {
1289 err = error(e1)
1290 } else {
1291 err = EINVAL
1292 }
1293 }
1294 return
1295}
1296
Alex Brainmanef65fed2011-12-08 12:07:21 +11001297func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001298 r0, _, _ := Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001299 if r0 != 0 {
1300 sockerr = Errno(r0)
1301 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001302 return
1303}
1304
Russ Coxc017a822011-11-13 22:44:52 -05001305func WSACleanup() (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001306 r1, _, e1 := Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001307 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001308 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001309 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001310 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001311 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001312 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001313 }
1314 return
1315}
1316
Russ Coxc017a822011-11-13 22:44:52 -05001317func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001318 r1, _, e1 := Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001319 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001320 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001321 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001322 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001323 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001324 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001325 }
1326 return
1327}
1328
Russ Coxc017a822011-11-13 22:44:52 -05001329func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001330 r0, _, e1 := Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001331 handle = Handle(r0)
1332 if handle == InvalidHandle {
1333 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001334 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001335 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001336 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001337 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001338 }
1339 return
1340}
1341
Russ Coxc017a822011-11-13 22:44:52 -05001342func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001343 r1, _, e1 := Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001344 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001345 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001346 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001347 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001348 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001349 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001350 }
1351 return
1352}
1353
Alex Brainman50e59512012-05-23 13:05:05 +10001354func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
1355 r1, _, e1 := Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001356 if r1 == socket_error {
Alex Brainman50e59512012-05-23 13:05:05 +10001357 if e1 != 0 {
1358 err = error(e1)
1359 } else {
1360 err = EINVAL
1361 }
1362 }
1363 return
1364}
1365
Alex Brainman258ee612014-04-06 12:18:01 +10001366func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001367 r1, _, e1 := Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001368 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001369 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001370 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001371 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001372 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001373 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001374 }
1375 return
1376}
1377
Alex Brainman258ee612014-04-06 12:18:01 +10001378func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001379 r1, _, e1 := Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001380 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001381 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001382 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001383 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001384 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001385 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001386 }
1387 return
1388}
1389
Russ Coxc017a822011-11-13 22:44:52 -05001390func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001391 r1, _, e1 := Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001392 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001393 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001394 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001395 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001396 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001397 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001398 }
1399 return
1400}
1401
Russ Coxc017a822011-11-13 22:44:52 -05001402func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001403 r1, _, e1 := Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001404 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001405 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001406 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001407 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001408 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001409 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001410 }
1411 return
1412}
1413
Russ Coxc017a822011-11-13 22:44:52 -05001414func listen(s Handle, backlog int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001415 r1, _, e1 := Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001416 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001417 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001418 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001419 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001420 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001421 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001422 }
1423 return
1424}
1425
Russ Coxc017a822011-11-13 22:44:52 -05001426func shutdown(s Handle, how int32) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001427 r1, _, e1 := Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001428 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001429 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001430 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001431 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001432 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001433 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001434 }
1435 return
1436}
1437
Russ Coxc017a822011-11-13 22:44:52 -05001438func Closesocket(s Handle) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001439 r1, _, e1 := Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001440 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001441 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001442 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001443 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001444 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001445 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001446 }
1447 return
1448}
1449
Russ Coxc017a822011-11-13 22:44:52 -05001450func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001451 r1, _, e1 := Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001452 if r1 == 0 {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001453 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001454 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001455 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001456 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001457 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001458 }
1459 return
1460}
1461
1462func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001463 Syscall9(procGetAcceptExSockaddrs.Addr(), 8, uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(lrsa)), uintptr(unsafe.Pointer(lrsalen)), uintptr(unsafe.Pointer(rrsa)), uintptr(unsafe.Pointer(rrsalen)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001464 return
1465}
1466
Russ Coxc017a822011-11-13 22:44:52 -05001467func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001468 r1, _, e1 := Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001469 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001470 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001471 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001472 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001473 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001474 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001475 }
1476 return
1477}
1478
Russ Coxc017a822011-11-13 22:44:52 -05001479func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001480 r1, _, e1 := Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001481 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001482 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001483 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001484 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001485 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001486 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001487 }
1488 return
1489}
1490
Russ Coxc017a822011-11-13 22:44:52 -05001491func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001492 r1, _, e1 := Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001493 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001494 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001495 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001496 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001497 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001498 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001499 }
1500 return
1501}
1502
Russ Coxc017a822011-11-13 22:44:52 -05001503func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001504 r1, _, e1 := Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001505 if r1 == socket_error {
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001506 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001507 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001508 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001509 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001510 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001511 }
1512 return
1513}
1514
Russ Coxc017a822011-11-13 22:44:52 -05001515func GetHostByName(name string) (h *Hostent, err error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -04001516 var _p0 *byte
1517 _p0, err = BytePtrFromString(name)
1518 if err != nil {
1519 return
1520 }
1521 r0, _, e1 := Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001522 h = (*Hostent)(unsafe.Pointer(r0))
1523 if h == nil {
1524 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001525 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001526 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001527 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001528 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001529 }
1530 return
1531}
1532
Russ Coxc017a822011-11-13 22:44:52 -05001533func GetServByName(name string, proto string) (s *Servent, err error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -04001534 var _p0 *byte
1535 _p0, err = BytePtrFromString(name)
1536 if err != nil {
1537 return
1538 }
1539 var _p1 *byte
1540 _p1, err = BytePtrFromString(proto)
1541 if err != nil {
1542 return
1543 }
1544 r0, _, e1 := Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001545 s = (*Servent)(unsafe.Pointer(r0))
1546 if s == nil {
1547 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001548 err = error(e1)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001549 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001550 err = EINVAL
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001551 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001552 }
1553 return
1554}
1555
1556func Ntohs(netshort uint16) (u uint16) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001557 r0, _, _ := Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001558 u = uint16(r0)
1559 return
1560}
1561
Russ Coxc017a822011-11-13 22:44:52 -05001562func GetProtoByName(name string) (p *Protoent, err error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -04001563 var _p0 *byte
1564 _p0, err = BytePtrFromString(name)
1565 if err != nil {
1566 return
1567 }
1568 r0, _, e1 := Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(_p0)), 0, 0)
Alex Brainman059c68b2011-10-12 10:29:22 +11001569 p = (*Protoent)(unsafe.Pointer(r0))
1570 if p == nil {
1571 if e1 != 0 {
Russ Coxc017a822011-11-13 22:44:52 -05001572 err = error(e1)
Alex Brainman059c68b2011-10-12 10:29:22 +11001573 } else {
Russ Coxc017a822011-11-13 22:44:52 -05001574 err = EINVAL
Alex Brainman059c68b2011-10-12 10:29:22 +11001575 }
Alex Brainman059c68b2011-10-12 10:29:22 +11001576 }
1577 return
1578}
1579
Alex Brainmanef65fed2011-12-08 12:07:21 +11001580func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
Alexey Borzenkova1083692012-08-05 17:24:32 -04001581 var _p0 *uint16
1582 _p0, status = UTF16PtrFromString(name)
1583 if status != nil {
1584 return
1585 }
1586 r0, _, _ := Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(_p0)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
Alex Brainmanef65fed2011-12-08 12:07:21 +11001587 if r0 != 0 {
1588 status = Errno(r0)
1589 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001590 return
1591}
1592
1593func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001594 Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001595 return
1596}
1597
Alex Brainmaneb2e6e52012-11-07 16:58:20 +11001598func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
1599 r0, _, _ := Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
1600 if r0 != 0 {
1601 sockerr = Errno(r0)
1602 }
1603 return
1604}
1605
1606func FreeAddrInfoW(addrinfo *AddrinfoW) {
1607 Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
1608 return
1609}
1610
Alex Brainmanef65fed2011-12-08 12:07:21 +11001611func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001612 r0, _, _ := Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001613 if r0 != 0 {
1614 errcode = Errno(r0)
1615 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001616 return
1617}
1618
Alex Brainmanef65fed2011-12-08 12:07:21 +11001619func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
Alex Brainman9d7e3932011-07-31 20:07:04 +10001620 r0, _, _ := Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
Alex Brainmanef65fed2011-12-08 12:07:21 +11001621 if r0 != 0 {
1622 errcode = Errno(r0)
1623 }
Alex Brainmane71fc0c2011-07-07 10:40:45 +10001624 return
1625}
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001626
Dmitriy Vyukoved8c5502013-08-08 17:36:43 +04001627func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
1628 r1, _, e1 := Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
1629 if r1 == 0 {
1630 if e1 != 0 {
1631 err = error(e1)
1632 } else {
1633 err = EINVAL
1634 }
1635 }
1636 return
1637}
1638
1639func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
1640 r0, _, e1 := Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
1641 n = int32(r0)
1642 if n == -1 {
1643 if e1 != 0 {
1644 err = error(e1)
1645 } else {
1646 err = EINVAL
1647 }
1648 }
1649 return
1650}
1651
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001652func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
1653 r1, _, e1 := Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001654 if r1&0xff == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001655 if e1 != 0 {
1656 err = error(e1)
1657 } else {
1658 err = EINVAL
1659 }
1660 }
1661 return
1662}
1663
1664func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
1665 r1, _, e1 := Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001666 if r1&0xff == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001667 if e1 != 0 {
1668 err = error(e1)
1669 } else {
1670 err = EINVAL
1671 }
1672 }
1673 return
1674}
1675
1676func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
1677 r0, _, _ := Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
1678 if r0 != 0 {
1679 neterr = Errno(r0)
1680 }
1681 return
1682}
1683
Alexey Borzenkovfae362e2013-05-15 13:24:54 +10001684func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
1685 r0, _, _ := Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
1686 if r0 != 0 {
1687 neterr = Errno(r0)
1688 }
1689 return
1690}
1691
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001692func NetApiBufferFree(buf *byte) (neterr error) {
1693 r0, _, _ := Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
1694 if r0 != 0 {
1695 neterr = Errno(r0)
1696 }
1697 return
1698}
1699
1700func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
1701 r1, _, e1 := Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001702 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001703 if e1 != 0 {
1704 err = error(e1)
1705 } else {
1706 err = EINVAL
1707 }
1708 }
1709 return
1710}
1711
1712func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
1713 r1, _, e1 := Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001714 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001715 if e1 != 0 {
1716 err = error(e1)
1717 } else {
1718 err = EINVAL
1719 }
1720 }
1721 return
1722}
1723
1724func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
1725 r1, _, e1 := Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001726 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001727 if e1 != 0 {
1728 err = error(e1)
1729 } else {
1730 err = EINVAL
1731 }
1732 }
1733 return
1734}
1735
1736func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
1737 r1, _, e1 := Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001738 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001739 if e1 != 0 {
1740 err = error(e1)
1741 } else {
1742 err = EINVAL
1743 }
1744 }
1745 return
1746}
1747
1748func GetLengthSid(sid *SID) (len uint32) {
1749 r0, _, _ := Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
1750 len = uint32(r0)
1751 return
1752}
1753
1754func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
1755 r1, _, e1 := Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001756 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001757 if e1 != 0 {
1758 err = error(e1)
1759 } else {
1760 err = EINVAL
1761 }
1762 }
1763 return
1764}
1765
1766func OpenProcessToken(h Handle, access uint32, token *Token) (err error) {
1767 r1, _, e1 := Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001768 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001769 if e1 != 0 {
1770 err = error(e1)
1771 } else {
1772 err = EINVAL
1773 }
1774 }
1775 return
1776}
1777
1778func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
1779 r1, _, e1 := Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
Alex Brainman0e6f9272012-09-25 17:06:39 +10001780 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001781 if e1 != 0 {
1782 err = error(e1)
1783 } else {
1784 err = EINVAL
1785 }
1786 }
1787 return
1788}
1789
1790func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
1791 r1, _, e1 := Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
Alex Brainman0e6f9272012-09-25 17:06:39 +10001792 if r1 == 0 {
Alex Brainmandcbc77d2012-01-30 22:59:10 +11001793 if e1 != 0 {
1794 err = error(e1)
1795 } else {
1796 err = EINVAL
1797 }
1798 }
1799 return
1800}