blob: dcd10e06917eeb67b41176b8ca87a009fe98ce25 [file] [log] [blame]
Tobias Klauser8014b7b2018-06-14 09:37:16 +02001// Code generated by 'go generate'; DO NOT EDIT.
Rob Pike20acc5c2014-08-11 14:48:46 -07002
Rob Pike8442dd22014-08-11 15:58:26 -07003package windows
Rob Pike20acc5c2014-08-11 14:48:46 -07004
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +00005import (
6 "syscall"
7 "unsafe"
8)
Rob Pike20acc5c2014-08-11 14:48:46 -07009
Carlos Castillo5b683252015-02-27 04:46:26 -080010var _ unsafe.Pointer
11
Alex Brainmanca83bd22016-12-02 16:54:46 +110012// Do the interface allocations only once for common
13// Errno values.
14const (
15 errnoERROR_IO_PENDING = 997
16)
17
18var (
19 errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
20)
21
22// errnoErr returns common boxed Errno values, to prevent
23// allocations at runtime.
24func errnoErr(e syscall.Errno) error {
25 switch e {
26 case 0:
27 return nil
28 case errnoERROR_IO_PENDING:
29 return errERROR_IO_PENDING
30 }
31 // TODO: add more here, after collecting data on the common
32 // error values see on Windows. (perhaps when running
33 // all.bat?)
34 return e
35}
36
Rob Pike20acc5c2014-08-11 14:48:46 -070037var (
Alex Brainman042a8f52016-04-06 15:52:57 +100038 modadvapi32 = NewLazySystemDLL("advapi32.dll")
39 modkernel32 = NewLazySystemDLL("kernel32.dll")
40 modshell32 = NewLazySystemDLL("shell32.dll")
Jason A. Donenfeld56c252d2019-05-25 15:17:43 +020041 moduserenv = NewLazySystemDLL("userenv.dll")
Alex Brainman042a8f52016-04-06 15:52:57 +100042 modmswsock = NewLazySystemDLL("mswsock.dll")
43 modcrypt32 = NewLazySystemDLL("crypt32.dll")
Jason A. Donenfeldea4c4252019-05-25 15:27:23 +020044 moduser32 = NewLazySystemDLL("user32.dll")
Alex Brainman042a8f52016-04-06 15:52:57 +100045 modws2_32 = NewLazySystemDLL("ws2_32.dll")
46 moddnsapi = NewLazySystemDLL("dnsapi.dll")
47 modiphlpapi = NewLazySystemDLL("iphlpapi.dll")
48 modsecur32 = NewLazySystemDLL("secur32.dll")
49 modnetapi32 = NewLazySystemDLL("netapi32.dll")
Jason A. Donenfeldf91f9b32019-05-13 10:42:08 +020050 modwtsapi32 = NewLazySystemDLL("wtsapi32.dll")
Rob Pike20acc5c2014-08-11 14:48:46 -070051
Alex Brainman65705ef2015-04-17 16:35:40 +100052 procRegisterEventSourceW = modadvapi32.NewProc("RegisterEventSourceW")
53 procDeregisterEventSource = modadvapi32.NewProc("DeregisterEventSource")
54 procReportEventW = modadvapi32.NewProc("ReportEventW")
55 procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
56 procCloseServiceHandle = modadvapi32.NewProc("CloseServiceHandle")
57 procCreateServiceW = modadvapi32.NewProc("CreateServiceW")
58 procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
59 procDeleteService = modadvapi32.NewProc("DeleteService")
60 procStartServiceW = modadvapi32.NewProc("StartServiceW")
61 procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
62 procControlService = modadvapi32.NewProc("ControlService")
63 procStartServiceCtrlDispatcherW = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
64 procSetServiceStatus = modadvapi32.NewProc("SetServiceStatus")
65 procChangeServiceConfigW = modadvapi32.NewProc("ChangeServiceConfigW")
66 procQueryServiceConfigW = modadvapi32.NewProc("QueryServiceConfigW")
67 procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W")
68 procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W")
Alex Brainmanfb4cac32017-06-14 16:48:48 +100069 procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW")
pytimer56ad15c2018-05-23 10:12:58 +080070 procQueryServiceStatusEx = modadvapi32.NewProc("QueryServiceStatusEx")
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +020071 procNotifyServiceStatusChangeW = modadvapi32.NewProc("NotifyServiceStatusChangeW")
Rob Pike20acc5c2014-08-11 14:48:46 -070072 procGetLastError = modkernel32.NewProc("GetLastError")
73 procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +000074 procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
Rob Pike20acc5c2014-08-11 14:48:46 -070075 procFreeLibrary = modkernel32.NewProc("FreeLibrary")
76 procGetProcAddress = modkernel32.NewProc("GetProcAddress")
77 procGetVersion = modkernel32.NewProc("GetVersion")
78 procFormatMessageW = modkernel32.NewProc("FormatMessageW")
79 procExitProcess = modkernel32.NewProc("ExitProcess")
Jason A. Donenfeld791d8a02019-05-25 15:13:12 +020080 procIsWow64Process = modkernel32.NewProc("IsWow64Process")
Rob Pike20acc5c2014-08-11 14:48:46 -070081 procCreateFileW = modkernel32.NewProc("CreateFileW")
82 procReadFile = modkernel32.NewProc("ReadFile")
83 procWriteFile = modkernel32.NewProc("WriteFile")
Jason A. Donenfeldf49334f2019-03-20 23:14:46 -060084 procGetOverlappedResult = modkernel32.NewProc("GetOverlappedResult")
Rob Pike20acc5c2014-08-11 14:48:46 -070085 procSetFilePointer = modkernel32.NewProc("SetFilePointer")
86 procCloseHandle = modkernel32.NewProc("CloseHandle")
87 procGetStdHandle = modkernel32.NewProc("GetStdHandle")
Tamir Dubersteinf3918c32017-04-05 12:58:12 -040088 procSetStdHandle = modkernel32.NewProc("SetStdHandle")
Rob Pike20acc5c2014-08-11 14:48:46 -070089 procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
90 procFindNextFileW = modkernel32.NewProc("FindNextFileW")
91 procFindClose = modkernel32.NewProc("FindClose")
92 procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
James Nugent16da32b2019-04-14 19:23:05 +000093 procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx")
Rob Pike20acc5c2014-08-11 14:48:46 -070094 procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
95 procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
96 procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
97 procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
98 procDeleteFileW = modkernel32.NewProc("DeleteFileW")
99 procMoveFileW = modkernel32.NewProc("MoveFileW")
Alex Brainman442cd602016-01-13 11:01:27 +1100100 procMoveFileExW = modkernel32.NewProc("MoveFileExW")
Rob Pike20acc5c2014-08-11 14:48:46 -0700101 procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
Carlos Castillo5b683252015-02-27 04:46:26 -0800102 procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
Rob Pike20acc5c2014-08-11 14:48:46 -0700103 procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
104 procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
Tamir Duberstein39e3dc22017-04-05 13:01:15 -0400105 procGetSystemTimePreciseAsFileTime = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
Rob Pike20acc5c2014-08-11 14:48:46 -0700106 procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
107 procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
108 procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
109 procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
110 procCancelIo = modkernel32.NewProc("CancelIo")
111 procCancelIoEx = modkernel32.NewProc("CancelIoEx")
112 procCreateProcessW = modkernel32.NewProc("CreateProcessW")
113 procOpenProcess = modkernel32.NewProc("OpenProcess")
Jason A. Donenfeld56c252d2019-05-25 15:17:43 +0200114 procShellExecuteW = modshell32.NewProc("ShellExecuteW")
Rob Pike20acc5c2014-08-11 14:48:46 -0700115 procTerminateProcess = modkernel32.NewProc("TerminateProcess")
116 procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
117 procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
118 procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200119 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
Rob Pike20acc5c2014-08-11 14:48:46 -0700120 procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
121 procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
122 procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
Jason A. Donenfeld980327f2019-02-03 02:44:23 +0100123 procWaitForMultipleObjects = modkernel32.NewProc("WaitForMultipleObjects")
Rob Pike20acc5c2014-08-11 14:48:46 -0700124 procGetTempPathW = modkernel32.NewProc("GetTempPathW")
125 procCreatePipe = modkernel32.NewProc("CreatePipe")
126 procGetFileType = modkernel32.NewProc("GetFileType")
127 procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
128 procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
129 procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
130 procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
131 procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
132 procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
133 procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
Jason A. Donenfeld06a5c492019-05-12 16:41:16 +0200134 procCreateEnvironmentBlock = moduserenv.NewProc("CreateEnvironmentBlock")
135 procDestroyEnvironmentBlock = moduserenv.NewProc("DestroyEnvironmentBlock")
Rob Pike20acc5c2014-08-11 14:48:46 -0700136 procSetFileTime = modkernel32.NewProc("SetFileTime")
137 procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
138 procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
139 procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
140 procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
141 procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
142 procLocalFree = modkernel32.NewProc("LocalFree")
143 procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
144 procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
145 procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
146 procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
147 procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
148 procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
149 procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
150 procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
151 procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
152 procVirtualLock = modkernel32.NewProc("VirtualLock")
153 procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
Awnd18155c2017-07-01 07:14:08 +0100154 procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
155 procVirtualFree = modkernel32.NewProc("VirtualFree")
156 procVirtualProtect = modkernel32.NewProc("VirtualProtect")
Rob Pike20acc5c2014-08-11 14:48:46 -0700157 procTransmitFile = modmswsock.NewProc("TransmitFile")
158 procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
159 procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
160 procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
161 procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
162 procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
163 procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
164 procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
165 procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
166 procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
167 procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
168 procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
169 procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
170 procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
171 procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
172 procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
173 procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
174 procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
175 procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +0200176 procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
177 procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
Rob Pike20acc5c2014-08-11 14:48:46 -0700178 procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
179 procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
180 procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
181 procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
182 procProcess32NextW = modkernel32.NewProc("Process32NextW")
183 procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
184 procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
185 procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
Alex Brainman65705ef2015-04-17 16:35:40 +1000186 procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
187 procCreateEventW = modkernel32.NewProc("CreateEventW")
Tobias Klauser07c18292017-08-16 14:26:40 +0200188 procCreateEventExW = modkernel32.NewProc("CreateEventExW")
189 procOpenEventW = modkernel32.NewProc("OpenEventW")
Alex Brainman65705ef2015-04-17 16:35:40 +1000190 procSetEvent = modkernel32.NewProc("SetEvent")
Tobias Klauser07c18292017-08-16 14:26:40 +0200191 procResetEvent = modkernel32.NewProc("ResetEvent")
192 procPulseEvent = modkernel32.NewProc("PulseEvent")
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +0200193 procSleepEx = modkernel32.NewProc("SleepEx")
Takuto Ikutac3d486d2019-05-24 21:41:07 +0900194 procCreateJobObjectW = modkernel32.NewProc("CreateJobObjectW")
195 procAssignProcessToJobObject = modkernel32.NewProc("AssignProcessToJobObject")
196 procTerminateJobObject = modkernel32.NewProc("TerminateJobObject")
Takuto Ikutae44a3b52019-05-24 19:23:22 +0900197 procSetErrorMode = modkernel32.NewProc("SetErrorMode")
Takuto Ikuta9cd64302019-05-27 14:19:46 +0900198 procResumeThread = modkernel32.NewProc("ResumeThread")
Takuto Ikuta854af272019-05-28 17:17:54 +0900199 procSetPriorityClass = modkernel32.NewProc("SetPriorityClass")
200 procGetPriorityClass = modkernel32.NewProc("GetPriorityClass")
Takuto Ikutacc920272019-05-28 19:11:08 +0900201 procSetInformationJobObject = modkernel32.NewProc("SetInformationJobObject")
Takuto Ikuta95d888e2019-05-30 18:10:03 +0900202 procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
Scott Crunkleton0dd5e192017-11-15 23:26:13 -0800203 procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW")
204 procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW")
205 procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
206 procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW")
207 procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW")
208 procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW")
209 procFindVolumeClose = modkernel32.NewProc("FindVolumeClose")
210 procFindVolumeMountPointClose = modkernel32.NewProc("FindVolumeMountPointClose")
Brad Fitzpatrick0131e682017-12-13 20:31:17 +0000211 procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW")
Scott Crunkleton0dd5e192017-11-15 23:26:13 -0800212 procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives")
213 procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW")
214 procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
215 procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
216 procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
217 procGetVolumePathNameW = modkernel32.NewProc("GetVolumePathNameW")
218 procGetVolumePathNamesForVolumeNameW = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
219 procQueryDosDeviceW = modkernel32.NewProc("QueryDosDeviceW")
220 procSetVolumeLabelW = modkernel32.NewProc("SetVolumeLabelW")
221 procSetVolumeMountPointW = modkernel32.NewProc("SetVolumeMountPointW")
Jason A. Donenfeldea4c4252019-05-25 15:27:23 +0200222 procMessageBoxW = moduser32.NewProc("MessageBoxW")
Rob Pike20acc5c2014-08-11 14:48:46 -0700223 procWSAStartup = modws2_32.NewProc("WSAStartup")
224 procWSACleanup = modws2_32.NewProc("WSACleanup")
225 procWSAIoctl = modws2_32.NewProc("WSAIoctl")
226 procsocket = modws2_32.NewProc("socket")
227 procsetsockopt = modws2_32.NewProc("setsockopt")
228 procgetsockopt = modws2_32.NewProc("getsockopt")
229 procbind = modws2_32.NewProc("bind")
230 procconnect = modws2_32.NewProc("connect")
231 procgetsockname = modws2_32.NewProc("getsockname")
232 procgetpeername = modws2_32.NewProc("getpeername")
233 proclisten = modws2_32.NewProc("listen")
234 procshutdown = modws2_32.NewProc("shutdown")
235 procclosesocket = modws2_32.NewProc("closesocket")
236 procAcceptEx = modmswsock.NewProc("AcceptEx")
237 procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
238 procWSARecv = modws2_32.NewProc("WSARecv")
239 procWSASend = modws2_32.NewProc("WSASend")
240 procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
241 procWSASendTo = modws2_32.NewProc("WSASendTo")
242 procgethostbyname = modws2_32.NewProc("gethostbyname")
243 procgetservbyname = modws2_32.NewProc("getservbyname")
244 procntohs = modws2_32.NewProc("ntohs")
245 procgetprotobyname = modws2_32.NewProc("getprotobyname")
246 procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
247 procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
Alex Brainmand1ee94c2014-08-20 12:25:19 +1000248 procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
Rob Pike20acc5c2014-08-11 14:48:46 -0700249 procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
250 procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
251 procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
252 procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
253 procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
254 procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
Alex Brainman442cd602016-01-13 11:01:27 +1100255 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
256 procGetACP = modkernel32.NewProc("GetACP")
257 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
Rob Pike20acc5c2014-08-11 14:48:46 -0700258 procTranslateNameW = modsecur32.NewProc("TranslateNameW")
259 procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
260 procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
261 procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
262 procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
263 procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
264 procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
265 procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
266 procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
267 procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
268 procCopySid = modadvapi32.NewProc("CopySid")
Alex Brainman65705ef2015-04-17 16:35:40 +1000269 procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid")
Jason A. Donenfelda2f829d2019-03-13 03:55:42 -0600270 procCreateWellKnownSid = modadvapi32.NewProc("CreateWellKnownSid")
Jason A. Donenfeld2219a012019-05-21 17:33:12 +0200271 procIsWellKnownSid = modadvapi32.NewProc("IsWellKnownSid")
Alex Brainman65705ef2015-04-17 16:35:40 +1000272 procFreeSid = modadvapi32.NewProc("FreeSid")
273 procEqualSid = modadvapi32.NewProc("EqualSid")
Jason A. Donenfeld2219a012019-05-21 17:33:12 +0200274 procGetSidIdentifierAuthority = modadvapi32.NewProc("GetSidIdentifierAuthority")
275 procGetSidSubAuthorityCount = modadvapi32.NewProc("GetSidSubAuthorityCount")
276 procGetSidSubAuthority = modadvapi32.NewProc("GetSidSubAuthority")
277 procIsValidSid = modadvapi32.NewProc("IsValidSid")
Scott Crunkleton1006bb32017-11-27 18:10:40 -0800278 procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership")
Rob Pike20acc5c2014-08-11 14:48:46 -0700279 procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200280 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200281 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
282 procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
283 procSetThreadToken = modadvapi32.NewProc("SetThreadToken")
284 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
285 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
Jason A. Donenfeldcedb8e12019-05-15 13:59:33 +0200286 procAdjustTokenGroups = modadvapi32.NewProc("AdjustTokenGroups")
Rob Pike20acc5c2014-08-11 14:48:46 -0700287 procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200288 procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
289 procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx")
Rob Pike20acc5c2014-08-11 14:48:46 -0700290 procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
Jason A. Donenfeld10058d72019-03-06 18:49:41 +0100291 procGetSystemDirectoryW = modkernel32.NewProc("GetSystemDirectoryW")
Jason A. Donenfeldf91f9b32019-05-13 10:42:08 +0200292 procWTSQueryUserToken = modwtsapi32.NewProc("WTSQueryUserToken")
293 procWTSEnumerateSessionsW = modwtsapi32.NewProc("WTSEnumerateSessionsW")
294 procWTSFreeMemory = modwtsapi32.NewProc("WTSFreeMemory")
Rob Pike20acc5c2014-08-11 14:48:46 -0700295)
296
Alex Brainman65705ef2015-04-17 16:35:40 +1000297func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
298 r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0)
299 handle = Handle(r0)
300 if handle == 0 {
301 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100302 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000303 } else {
304 err = syscall.EINVAL
305 }
306 }
307 return
308}
309
310func DeregisterEventSource(handle Handle) (err error) {
311 r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0)
312 if r1 == 0 {
313 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100314 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000315 } else {
316 err = syscall.EINVAL
317 }
318 }
319 return
320}
321
322func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) {
323 r1, _, e1 := syscall.Syscall9(procReportEventW.Addr(), 9, uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData)))
324 if r1 == 0 {
325 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100326 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000327 } else {
328 err = syscall.EINVAL
329 }
330 }
331 return
332}
333
334func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) {
335 r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
336 handle = Handle(r0)
337 if handle == 0 {
338 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100339 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000340 } else {
341 err = syscall.EINVAL
342 }
343 }
344 return
345}
346
347func CloseServiceHandle(handle Handle) (err error) {
348 r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0)
349 if r1 == 0 {
350 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100351 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000352 } else {
353 err = syscall.EINVAL
354 }
355 }
356 return
357}
358
359func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) {
360 r0, _, e1 := syscall.Syscall15(procCreateServiceW.Addr(), 13, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(unsafe.Pointer(displayName)), uintptr(access), uintptr(srvType), uintptr(startType), uintptr(errCtl), uintptr(unsafe.Pointer(pathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), 0, 0)
361 handle = Handle(r0)
362 if handle == 0 {
363 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100364 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000365 } else {
366 err = syscall.EINVAL
367 }
368 }
369 return
370}
371
372func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) {
373 r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
374 handle = Handle(r0)
375 if handle == 0 {
376 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100377 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000378 } else {
379 err = syscall.EINVAL
380 }
381 }
382 return
383}
384
385func DeleteService(service Handle) (err error) {
386 r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0)
387 if r1 == 0 {
388 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100389 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000390 } else {
391 err = syscall.EINVAL
392 }
393 }
394 return
395}
396
397func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) {
398 r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors)))
399 if r1 == 0 {
400 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100401 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000402 } else {
403 err = syscall.EINVAL
404 }
405 }
406 return
407}
408
409func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) {
410 r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0)
411 if r1 == 0 {
412 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100413 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000414 } else {
415 err = syscall.EINVAL
416 }
417 }
418 return
419}
420
421func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) {
422 r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status)))
423 if r1 == 0 {
424 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100425 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000426 } else {
427 err = syscall.EINVAL
428 }
429 }
430 return
431}
432
433func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) {
434 r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0)
435 if r1 == 0 {
436 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100437 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000438 } else {
439 err = syscall.EINVAL
440 }
441 }
442 return
443}
444
445func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) {
446 r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0)
447 if r1 == 0 {
448 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100449 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000450 } else {
451 err = syscall.EINVAL
452 }
453 }
454 return
455}
456
457func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, errorControl uint32, binaryPathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16, displayName *uint16) (err error) {
458 r1, _, e1 := syscall.Syscall12(procChangeServiceConfigW.Addr(), 11, uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName)), 0)
459 if r1 == 0 {
460 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100461 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000462 } else {
463 err = syscall.EINVAL
464 }
465 }
466 return
467}
468
469func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) {
470 r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0)
471 if r1 == 0 {
472 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100473 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000474 } else {
475 err = syscall.EINVAL
476 }
477 }
478 return
479}
480
481func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) {
482 r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info)))
483 if r1 == 0 {
484 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100485 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000486 } else {
487 err = syscall.EINVAL
488 }
489 }
490 return
491}
492
493func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
494 r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
495 if r1 == 0 {
496 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100497 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000498 } else {
499 err = syscall.EINVAL
500 }
501 }
502 return
503}
504
Alex Brainmanfb4cac32017-06-14 16:48:48 +1000505func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) {
506 r1, _, e1 := syscall.Syscall12(procEnumServicesStatusExW.Addr(), 10, uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName)), 0, 0)
507 if r1 == 0 {
508 if e1 != 0 {
509 err = errnoErr(e1)
510 } else {
511 err = syscall.EINVAL
512 }
513 }
514 return
515}
516
pytimer56ad15c2018-05-23 10:12:58 +0800517func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
518 r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
519 if r1 == 0 {
520 if e1 != 0 {
521 err = errnoErr(e1)
522 } else {
523 err = syscall.EINVAL
524 }
525 }
526 return
527}
528
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +0200529func NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) {
530 r0, _, _ := syscall.Syscall(procNotifyServiceStatusChangeW.Addr(), 3, uintptr(service), uintptr(notifyMask), uintptr(unsafe.Pointer(notifier)))
531 if r0 != 0 {
532 ret = syscall.Errno(r0)
533 }
534 return
535}
536
Rob Pike20acc5c2014-08-11 14:48:46 -0700537func GetLastError() (lasterr error) {
Rob Pike71181952014-08-13 14:08:39 -0700538 r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700539 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -0700540 lasterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700541 }
542 return
543}
544
545func LoadLibrary(libname string) (handle Handle, err error) {
546 var _p0 *uint16
Alex Brainman7d091bf2014-08-19 15:20:17 +1000547 _p0, err = syscall.UTF16PtrFromString(libname)
Rob Pike20acc5c2014-08-11 14:48:46 -0700548 if err != nil {
549 return
550 }
Alex Brainmanc17938b2014-10-06 10:48:58 +1100551 return _LoadLibrary(_p0)
552}
553
554func _LoadLibrary(libname *uint16) (handle Handle, err error) {
555 r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700556 handle = Handle(r0)
557 if handle == 0 {
558 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100559 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700560 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000561 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700562 }
563 }
564 return
565}
566
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +0000567func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) {
568 var _p0 *uint16
569 _p0, err = syscall.UTF16PtrFromString(libname)
570 if err != nil {
571 return
572 }
573 return _LoadLibraryEx(_p0, zero, flags)
574}
575
576func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) {
577 r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags))
578 handle = Handle(r0)
579 if handle == 0 {
580 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100581 err = errnoErr(e1)
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +0000582 } else {
583 err = syscall.EINVAL
584 }
585 }
586 return
587}
588
Rob Pike20acc5c2014-08-11 14:48:46 -0700589func FreeLibrary(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700590 r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700591 if r1 == 0 {
592 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100593 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700594 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000595 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700596 }
597 }
598 return
599}
600
601func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
602 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +1000603 _p0, err = syscall.BytePtrFromString(procname)
Rob Pike20acc5c2014-08-11 14:48:46 -0700604 if err != nil {
605 return
606 }
Alex Brainmanc17938b2014-10-06 10:48:58 +1100607 return _GetProcAddress(module, _p0)
608}
609
610func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
611 r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700612 proc = uintptr(r0)
613 if proc == 0 {
614 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100615 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700616 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000617 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700618 }
619 }
620 return
621}
622
623func GetVersion() (ver uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700624 r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700625 ver = uint32(r0)
626 if ver == 0 {
627 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100628 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700629 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000630 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700631 }
632 }
633 return
634}
635
Alex Brainman2019c8d2015-06-17 15:36:00 +1000636func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
Rob Pike20acc5c2014-08-11 14:48:46 -0700637 var _p0 *uint16
638 if len(buf) > 0 {
639 _p0 = &buf[0]
640 }
Rob Pike71181952014-08-13 14:08:39 -0700641 r0, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -0700642 n = uint32(r0)
643 if n == 0 {
644 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100645 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700646 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000647 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700648 }
649 }
650 return
651}
652
653func ExitProcess(exitcode uint32) {
Rob Pike71181952014-08-13 14:08:39 -0700654 syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700655 return
656}
657
Jason A. Donenfeld791d8a02019-05-25 15:13:12 +0200658func IsWow64Process(handle Handle, isWow64 *bool) (err error) {
659 r1, _, e1 := syscall.Syscall(procIsWow64Process.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(isWow64)), 0)
660 if r1 == 0 {
661 if e1 != 0 {
662 err = errnoErr(e1)
663 } else {
664 err = syscall.EINVAL
665 }
666 }
667 return
668}
669
Jason A. Donenfeldca7f33d2019-05-06 11:56:55 +0200670func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile Handle) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700671 r0, _, e1 := syscall.Syscall9(procCreateFileW.Addr(), 7, uintptr(unsafe.Pointer(name)), uintptr(access), uintptr(mode), uintptr(unsafe.Pointer(sa)), uintptr(createmode), uintptr(attrs), uintptr(templatefile), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700672 handle = Handle(r0)
673 if handle == InvalidHandle {
674 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100675 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700676 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000677 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700678 }
679 }
680 return
681}
682
683func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
684 var _p0 *byte
685 if len(buf) > 0 {
686 _p0 = &buf[0]
687 }
Rob Pike71181952014-08-13 14:08:39 -0700688 r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700689 if r1 == 0 {
690 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100691 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700692 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000693 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700694 }
695 }
696 return
697}
698
699func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
700 var _p0 *byte
701 if len(buf) > 0 {
702 _p0 = &buf[0]
703 }
Rob Pike71181952014-08-13 14:08:39 -0700704 r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700705 if r1 == 0 {
706 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100707 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700708 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000709 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700710 }
711 }
712 return
713}
714
Jason A. Donenfeldf49334f2019-03-20 23:14:46 -0600715func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) {
716 var _p0 uint32
717 if wait {
718 _p0 = 1
719 } else {
720 _p0 = 0
721 }
722 r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0), 0, 0)
723 if r1 == 0 {
724 if e1 != 0 {
725 err = errnoErr(e1)
726 } else {
727 err = syscall.EINVAL
728 }
729 }
730 return
731}
732
Rob Pike20acc5c2014-08-11 14:48:46 -0700733func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700734 r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700735 newlowoffset = uint32(r0)
736 if newlowoffset == 0xffffffff {
737 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100738 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700739 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000740 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700741 }
742 }
743 return
744}
745
746func CloseHandle(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700747 r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700748 if r1 == 0 {
749 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100750 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700751 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000752 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700753 }
754 }
755 return
756}
757
Tamir Dubersteinff24cb32017-04-05 12:54:02 -0400758func GetStdHandle(stdhandle uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700759 r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700760 handle = Handle(r0)
761 if handle == InvalidHandle {
762 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100763 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700764 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000765 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700766 }
767 }
768 return
769}
770
Tamir Dubersteinf3918c32017-04-05 12:58:12 -0400771func SetStdHandle(stdhandle uint32, handle Handle) (err error) {
772 r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
773 if r1 == 0 {
774 if e1 != 0 {
775 err = errnoErr(e1)
776 } else {
777 err = syscall.EINVAL
778 }
779 }
780 return
781}
782
Rob Pike20acc5c2014-08-11 14:48:46 -0700783func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700784 r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700785 handle = Handle(r0)
786 if handle == InvalidHandle {
787 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100788 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700789 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000790 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700791 }
792 }
793 return
794}
795
796func findNextFile1(handle Handle, data *win32finddata1) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700797 r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700798 if r1 == 0 {
799 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100800 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700801 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000802 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700803 }
804 }
805 return
806}
807
808func FindClose(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700809 r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700810 if r1 == 0 {
811 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100812 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700813 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000814 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700815 }
816 }
817 return
818}
819
820func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700821 r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700822 if r1 == 0 {
823 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100824 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700825 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000826 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700827 }
828 }
829 return
830}
831
James Nugent16da32b2019-04-14 19:23:05 +0000832func GetFileInformationByHandleEx(handle Handle, class uint32, outBuffer *byte, outBufferLen uint32) (err error) {
833 r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferLen), 0, 0)
834 if r1 == 0 {
835 if e1 != 0 {
836 err = errnoErr(e1)
837 } else {
838 err = syscall.EINVAL
839 }
840 }
841 return
842}
843
Rob Pike20acc5c2014-08-11 14:48:46 -0700844func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700845 r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700846 n = uint32(r0)
847 if n == 0 {
848 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100849 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700850 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000851 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700852 }
853 }
854 return
855}
856
857func SetCurrentDirectory(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700858 r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700859 if r1 == 0 {
860 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100861 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700862 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000863 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700864 }
865 }
866 return
867}
868
869func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700870 r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700871 if r1 == 0 {
872 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100873 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700874 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000875 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700876 }
877 }
878 return
879}
880
881func RemoveDirectory(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700882 r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700883 if r1 == 0 {
884 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100885 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700886 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000887 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700888 }
889 }
890 return
891}
892
893func DeleteFile(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700894 r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700895 if r1 == 0 {
896 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100897 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700898 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000899 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700900 }
901 }
902 return
903}
904
905func MoveFile(from *uint16, to *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700906 r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700907 if r1 == 0 {
908 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100909 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700910 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000911 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700912 }
913 }
914 return
915}
916
Alex Brainman442cd602016-01-13 11:01:27 +1100917func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
918 r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
919 if r1 == 0 {
920 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100921 err = errnoErr(e1)
Alex Brainman442cd602016-01-13 11:01:27 +1100922 } else {
923 err = syscall.EINVAL
924 }
925 }
926 return
927}
928
Rob Pike20acc5c2014-08-11 14:48:46 -0700929func GetComputerName(buf *uint16, n *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700930 r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700931 if r1 == 0 {
932 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100933 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700934 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000935 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700936 }
937 }
938 return
939}
940
Carlos Castillo5b683252015-02-27 04:46:26 -0800941func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) {
942 r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
943 if r1 == 0 {
944 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100945 err = errnoErr(e1)
Carlos Castillo5b683252015-02-27 04:46:26 -0800946 } else {
947 err = syscall.EINVAL
948 }
949 }
950 return
951}
952
Rob Pike20acc5c2014-08-11 14:48:46 -0700953func SetEndOfFile(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700954 r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700955 if r1 == 0 {
956 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100957 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700958 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000959 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700960 }
961 }
962 return
963}
964
965func GetSystemTimeAsFileTime(time *Filetime) {
Rob Pike71181952014-08-13 14:08:39 -0700966 syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700967 return
968}
969
Tamir Duberstein39e3dc22017-04-05 13:01:15 -0400970func GetSystemTimePreciseAsFileTime(time *Filetime) {
971 syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
972 return
973}
974
Rob Pike20acc5c2014-08-11 14:48:46 -0700975func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700976 r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700977 rc = uint32(r0)
978 if rc == 0xffffffff {
979 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100980 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700981 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000982 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700983 }
984 }
985 return
986}
987
988func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700989 r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700990 handle = Handle(r0)
991 if handle == 0 {
992 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100993 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700994 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000995 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700996 }
997 }
998 return
999}
1000
1001func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001002 r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001003 if r1 == 0 {
1004 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001005 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001006 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001007 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001008 }
1009 }
1010 return
1011}
1012
1013func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001014 r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001015 if r1 == 0 {
1016 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001017 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001018 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001019 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001020 }
1021 }
1022 return
1023}
1024
1025func CancelIo(s Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001026 r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001027 if r1 == 0 {
1028 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001029 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001030 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001031 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001032 }
1033 }
1034 return
1035}
1036
1037func CancelIoEx(s Handle, o *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001038 r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001039 if r1 == 0 {
1040 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001041 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001042 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001043 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001044 }
1045 }
1046 return
1047}
1048
1049func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
1050 var _p0 uint32
1051 if inheritHandles {
1052 _p0 = 1
1053 } else {
1054 _p0 = 0
1055 }
Rob Pike71181952014-08-13 14:08:39 -07001056 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07001057 if r1 == 0 {
1058 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001059 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001060 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001061 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001062 }
1063 }
1064 return
1065}
1066
1067func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
1068 var _p0 uint32
1069 if inheritHandle {
1070 _p0 = 1
1071 } else {
1072 _p0 = 0
1073 }
Rob Pike71181952014-08-13 14:08:39 -07001074 r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
Rob Pike20acc5c2014-08-11 14:48:46 -07001075 handle = Handle(r0)
1076 if handle == 0 {
1077 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001078 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001079 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001080 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001081 }
1082 }
1083 return
1084}
1085
Jason A. Donenfeld56c252d2019-05-25 15:17:43 +02001086func ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) {
1087 r1, _, e1 := syscall.Syscall6(procShellExecuteW.Addr(), 6, uintptr(hwnd), uintptr(unsafe.Pointer(verb)), uintptr(unsafe.Pointer(file)), uintptr(unsafe.Pointer(args)), uintptr(unsafe.Pointer(cwd)), uintptr(showCmd))
1088 if r1 == 0 {
1089 if e1 != 0 {
1090 err = errnoErr(e1)
1091 } else {
1092 err = syscall.EINVAL
1093 }
1094 }
1095 return
1096}
1097
Rob Pike20acc5c2014-08-11 14:48:46 -07001098func TerminateProcess(handle Handle, exitcode uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001099 r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001100 if r1 == 0 {
1101 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001102 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001103 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001104 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001105 }
1106 }
1107 return
1108}
1109
1110func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001111 r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001112 if r1 == 0 {
1113 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001114 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001115 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001116 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001117 }
1118 }
1119 return
1120}
1121
1122func GetStartupInfo(startupInfo *StartupInfo) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001123 r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001124 if r1 == 0 {
1125 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001126 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001127 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001128 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001129 }
1130 }
1131 return
1132}
1133
1134func GetCurrentProcess() (pseudoHandle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001135 r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001136 pseudoHandle = Handle(r0)
1137 if pseudoHandle == 0 {
1138 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001139 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001140 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001141 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001142 }
1143 }
1144 return
1145}
1146
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02001147func GetCurrentThread() (pseudoHandle Handle, err error) {
1148 r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
1149 pseudoHandle = Handle(r0)
1150 if pseudoHandle == 0 {
1151 if e1 != 0 {
1152 err = errnoErr(e1)
1153 } else {
1154 err = syscall.EINVAL
1155 }
1156 }
1157 return
1158}
1159
Rob Pike20acc5c2014-08-11 14:48:46 -07001160func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001161 r1, _, e1 := syscall.Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001162 if r1 == 0 {
1163 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001164 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001165 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001166 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001167 }
1168 }
1169 return
1170}
1171
1172func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
1173 var _p0 uint32
1174 if bInheritHandle {
1175 _p0 = 1
1176 } else {
1177 _p0 = 0
1178 }
Rob Pike71181952014-08-13 14:08:39 -07001179 r1, _, e1 := syscall.Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001180 if r1 == 0 {
1181 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001182 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001183 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001184 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001185 }
1186 }
1187 return
1188}
1189
1190func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001191 r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001192 event = uint32(r0)
1193 if event == 0xffffffff {
1194 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001195 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001196 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001197 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001198 }
1199 }
1200 return
1201}
1202
Jason A. Donenfeld980327f2019-02-03 02:44:23 +01001203func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) {
1204 var _p0 uint32
1205 if waitAll {
1206 _p0 = 1
1207 } else {
1208 _p0 = 0
1209 }
1210 r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0)
1211 event = uint32(r0)
1212 if event == 0xffffffff {
1213 if e1 != 0 {
1214 err = errnoErr(e1)
1215 } else {
1216 err = syscall.EINVAL
1217 }
1218 }
1219 return
1220}
1221
Rob Pike20acc5c2014-08-11 14:48:46 -07001222func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001223 r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001224 n = uint32(r0)
1225 if n == 0 {
1226 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001227 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001228 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001229 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001230 }
1231 }
1232 return
1233}
1234
1235func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001236 r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001237 if r1 == 0 {
1238 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001239 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001240 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001241 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001242 }
1243 }
1244 return
1245}
1246
1247func GetFileType(filehandle Handle) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001248 r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001249 n = uint32(r0)
1250 if n == 0 {
1251 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001252 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001253 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001254 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001255 }
1256 }
1257 return
1258}
1259
1260func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001261 r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001262 if r1 == 0 {
1263 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001264 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001265 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001266 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001267 }
1268 }
1269 return
1270}
1271
1272func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001273 r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001274 if r1 == 0 {
1275 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001276 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001277 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001278 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001279 }
1280 }
1281 return
1282}
1283
1284func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001285 r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001286 if r1 == 0 {
1287 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001288 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001289 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001290 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001291 }
1292 }
1293 return
1294}
1295
1296func GetEnvironmentStrings() (envs *uint16, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001297 r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001298 envs = (*uint16)(unsafe.Pointer(r0))
1299 if envs == nil {
1300 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001301 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001302 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001303 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001304 }
1305 }
1306 return
1307}
1308
1309func FreeEnvironmentStrings(envs *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001310 r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001311 if r1 == 0 {
1312 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001313 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001314 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001315 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001316 }
1317 }
1318 return
1319}
1320
1321func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001322 r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
Rob Pike20acc5c2014-08-11 14:48:46 -07001323 n = uint32(r0)
1324 if n == 0 {
1325 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001326 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001327 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001328 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001329 }
1330 }
1331 return
1332}
1333
1334func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001335 r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001336 if r1 == 0 {
1337 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001338 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001339 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001340 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001341 }
1342 }
1343 return
1344}
1345
Jason A. Donenfeld06a5c492019-05-12 16:41:16 +02001346func CreateEnvironmentBlock(block **uint16, token Token, inheritExisting bool) (err error) {
1347 var _p0 uint32
1348 if inheritExisting {
1349 _p0 = 1
1350 } else {
1351 _p0 = 0
1352 }
1353 r1, _, e1 := syscall.Syscall(procCreateEnvironmentBlock.Addr(), 3, uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0))
1354 if r1 == 0 {
1355 if e1 != 0 {
1356 err = errnoErr(e1)
1357 } else {
1358 err = syscall.EINVAL
1359 }
1360 }
1361 return
1362}
1363
1364func DestroyEnvironmentBlock(block *uint16) (err error) {
1365 r1, _, e1 := syscall.Syscall(procDestroyEnvironmentBlock.Addr(), 1, uintptr(unsafe.Pointer(block)), 0, 0)
1366 if r1 == 0 {
1367 if e1 != 0 {
1368 err = errnoErr(e1)
1369 } else {
1370 err = syscall.EINVAL
1371 }
1372 }
1373 return
1374}
1375
Rob Pike20acc5c2014-08-11 14:48:46 -07001376func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001377 r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001378 if r1 == 0 {
1379 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001380 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001381 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001382 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001383 }
1384 }
1385 return
1386}
1387
1388func GetFileAttributes(name *uint16) (attrs uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001389 r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001390 attrs = uint32(r0)
1391 if attrs == INVALID_FILE_ATTRIBUTES {
1392 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001393 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001394 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001395 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001396 }
1397 }
1398 return
1399}
1400
1401func SetFileAttributes(name *uint16, attrs uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001402 r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001403 if r1 == 0 {
1404 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001405 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001406 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001407 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001408 }
1409 }
1410 return
1411}
1412
1413func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001414 r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001415 if r1 == 0 {
1416 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001417 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001418 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001419 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001420 }
1421 }
1422 return
1423}
1424
1425func GetCommandLine() (cmd *uint16) {
Rob Pike71181952014-08-13 14:08:39 -07001426 r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001427 cmd = (*uint16)(unsafe.Pointer(r0))
1428 return
1429}
1430
1431func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001432 r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001433 argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
1434 if argv == nil {
1435 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001436 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001437 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001438 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001439 }
1440 }
1441 return
1442}
1443
1444func LocalFree(hmem Handle) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001445 r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001446 handle = Handle(r0)
1447 if handle != 0 {
1448 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001449 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001450 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001451 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001452 }
1453 }
1454 return
1455}
1456
1457func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001458 r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
Rob Pike20acc5c2014-08-11 14:48:46 -07001459 if r1 == 0 {
1460 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001461 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001462 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001463 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001464 }
1465 }
1466 return
1467}
1468
1469func FlushFileBuffers(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001470 r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001471 if r1 == 0 {
1472 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001473 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001474 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001475 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001476 }
1477 }
1478 return
1479}
1480
1481func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001482 r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001483 n = uint32(r0)
1484 if n == 0 {
1485 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001486 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001487 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001488 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001489 }
1490 }
1491 return
1492}
1493
1494func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001495 r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001496 n = uint32(r0)
1497 if n == 0 {
1498 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001499 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001500 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001501 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001502 }
1503 }
1504 return
1505}
1506
1507func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001508 r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001509 n = uint32(r0)
1510 if n == 0 {
1511 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001512 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001513 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001514 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001515 }
1516 }
1517 return
1518}
1519
1520func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001521 r0, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001522 handle = Handle(r0)
1523 if handle == 0 {
1524 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001525 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001526 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001527 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001528 }
1529 }
1530 return
1531}
1532
1533func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001534 r0, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001535 addr = uintptr(r0)
1536 if addr == 0 {
1537 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001538 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001539 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001540 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001541 }
1542 }
1543 return
1544}
1545
1546func UnmapViewOfFile(addr uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001547 r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001548 if r1 == 0 {
1549 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001550 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001551 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001552 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001553 }
1554 }
1555 return
1556}
1557
1558func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001559 r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001560 if r1 == 0 {
1561 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001562 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001563 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001564 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001565 }
1566 }
1567 return
1568}
1569
1570func VirtualLock(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001571 r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001572 if r1 == 0 {
1573 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001574 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001575 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001576 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001577 }
1578 }
1579 return
1580}
1581
1582func VirtualUnlock(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001583 r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001584 if r1 == 0 {
1585 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001586 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001587 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001588 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001589 }
1590 }
1591 return
1592}
1593
Awnd18155c2017-07-01 07:14:08 +01001594func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) {
1595 r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0)
1596 value = uintptr(r0)
1597 if value == 0 {
1598 if e1 != 0 {
1599 err = errnoErr(e1)
1600 } else {
1601 err = syscall.EINVAL
1602 }
1603 }
1604 return
1605}
1606
1607func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) {
1608 r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype))
1609 if r1 == 0 {
1610 if e1 != 0 {
1611 err = errnoErr(e1)
1612 } else {
1613 err = syscall.EINVAL
1614 }
1615 }
1616 return
1617}
1618
1619func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) {
1620 r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0)
1621 if r1 == 0 {
1622 if e1 != 0 {
1623 err = errnoErr(e1)
1624 } else {
1625 err = syscall.EINVAL
1626 }
1627 }
1628 return
1629}
1630
Rob Pike20acc5c2014-08-11 14:48:46 -07001631func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001632 r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001633 if r1 == 0 {
1634 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001635 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001636 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001637 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001638 }
1639 }
1640 return
1641}
1642
1643func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
1644 var _p0 uint32
1645 if watchSubTree {
1646 _p0 = 1
1647 } else {
1648 _p0 = 0
1649 }
Rob Pike71181952014-08-13 14:08:39 -07001650 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07001651 if r1 == 0 {
1652 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001653 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001654 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001655 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001656 }
1657 }
1658 return
1659}
1660
1661func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001662 r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001663 store = Handle(r0)
1664 if store == 0 {
1665 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001666 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001667 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001668 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001669 }
1670 }
1671 return
1672}
1673
1674func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001675 r0, _, e1 := syscall.Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001676 handle = Handle(r0)
1677 if handle == InvalidHandle {
1678 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001679 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001680 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001681 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001682 }
1683 }
1684 return
1685}
1686
1687func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001688 r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001689 context = (*CertContext)(unsafe.Pointer(r0))
1690 if context == nil {
1691 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001692 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001693 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001694 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001695 }
1696 }
1697 return
1698}
1699
1700func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001701 r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001702 if r1 == 0 {
1703 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001704 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001705 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001706 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001707 }
1708 }
1709 return
1710}
1711
1712func CertCloseStore(store Handle, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001713 r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001714 if r1 == 0 {
1715 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001716 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001717 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001718 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001719 }
1720 }
1721 return
1722}
1723
1724func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001725 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07001726 if r1 == 0 {
1727 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001728 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001729 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001730 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001731 }
1732 }
1733 return
1734}
1735
1736func CertFreeCertificateChain(ctx *CertChainContext) {
Rob Pike71181952014-08-13 14:08:39 -07001737 syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001738 return
1739}
1740
1741func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001742 r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001743 context = (*CertContext)(unsafe.Pointer(r0))
1744 if context == nil {
1745 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001746 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001747 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001748 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001749 }
1750 }
1751 return
1752}
1753
1754func CertFreeCertificateContext(ctx *CertContext) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001755 r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001756 if r1 == 0 {
1757 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001758 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001759 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001760 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001761 }
1762 }
1763 return
1764}
1765
1766func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001767 r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001768 if r1 == 0 {
1769 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001770 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001771 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001772 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001773 }
1774 }
1775 return
1776}
1777
1778func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001779 r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001780 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001781 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001782 }
1783 return
1784}
1785
1786func RegCloseKey(key Handle) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001787 r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001788 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001789 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001790 }
1791 return
1792}
1793
1794func 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) {
Rob Pike71181952014-08-13 14:08:39 -07001795 r0, _, _ := syscall.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)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001796 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001797 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001798 }
1799 return
1800}
1801
1802func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001803 r0, _, _ := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07001804 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001805 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001806 }
1807 return
1808}
1809
1810func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001811 r0, _, _ := syscall.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)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001812 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001813 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001814 }
1815 return
1816}
1817
1818func getCurrentProcessId() (pid uint32) {
Rob Pike71181952014-08-13 14:08:39 -07001819 r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001820 pid = uint32(r0)
1821 return
1822}
1823
1824func GetConsoleMode(console Handle, mode *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001825 r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001826 if r1 == 0 {
1827 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001828 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001829 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001830 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001831 }
1832 }
1833 return
1834}
1835
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +02001836func SetConsoleMode(console Handle, mode uint32) (err error) {
1837 r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0)
1838 if r1 == 0 {
1839 if e1 != 0 {
1840 err = errnoErr(e1)
1841 } else {
1842 err = syscall.EINVAL
1843 }
1844 }
1845 return
1846}
1847
1848func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) {
Tobias Klauser07c18292017-08-16 14:26:40 +02001849 r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0)
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +02001850 if r1 == 0 {
1851 if e1 != 0 {
1852 err = errnoErr(e1)
1853 } else {
1854 err = syscall.EINVAL
1855 }
1856 }
1857 return
1858}
1859
Rob Pike20acc5c2014-08-11 14:48:46 -07001860func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001861 r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001862 if r1 == 0 {
1863 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001864 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001865 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001866 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001867 }
1868 }
1869 return
1870}
1871
1872func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001873 r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001874 if r1 == 0 {
1875 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001876 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001877 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001878 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001879 }
1880 }
1881 return
1882}
1883
1884func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001885 r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001886 handle = Handle(r0)
1887 if handle == InvalidHandle {
1888 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001889 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001890 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001891 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001892 }
1893 }
1894 return
1895}
1896
1897func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001898 r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001899 if r1 == 0 {
1900 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001901 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001902 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001903 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001904 }
1905 }
1906 return
1907}
1908
1909func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001910 r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001911 if r1 == 0 {
1912 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001913 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001914 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001915 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001916 }
1917 }
1918 return
1919}
1920
1921func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001922 r1, _, e1 := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001923 if r1 == 0 {
1924 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001925 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001926 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001927 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001928 }
1929 }
1930 return
1931}
1932
1933func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001934 r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
Rob Pike20acc5c2014-08-11 14:48:46 -07001935 if r1&0xff == 0 {
1936 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001937 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001938 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001939 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001940 }
1941 }
1942 return
1943}
1944
1945func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001946 r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
Rob Pike20acc5c2014-08-11 14:48:46 -07001947 if r1&0xff == 0 {
1948 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001949 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001950 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001951 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001952 }
1953 }
1954 return
1955}
1956
Alex Brainman65705ef2015-04-17 16:35:40 +10001957func GetCurrentThreadId() (id uint32) {
1958 r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
1959 id = uint32(r0)
1960 return
1961}
1962
Tobias Klauser07c18292017-08-16 14:26:40 +02001963func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) {
Alex Brainman65705ef2015-04-17 16:35:40 +10001964 r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
1965 handle = Handle(r0)
1966 if handle == 0 {
1967 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001968 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10001969 } else {
1970 err = syscall.EINVAL
1971 }
1972 }
1973 return
1974}
1975
Tobias Klauser07c18292017-08-16 14:26:40 +02001976func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) {
1977 r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0)
1978 handle = Handle(r0)
1979 if handle == 0 {
1980 if e1 != 0 {
1981 err = errnoErr(e1)
1982 } else {
1983 err = syscall.EINVAL
1984 }
1985 }
1986 return
1987}
1988
1989func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) {
1990 var _p0 uint32
1991 if inheritHandle {
1992 _p0 = 1
1993 } else {
1994 _p0 = 0
1995 }
1996 r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name)))
1997 handle = Handle(r0)
1998 if handle == 0 {
1999 if e1 != 0 {
2000 err = errnoErr(e1)
2001 } else {
2002 err = syscall.EINVAL
2003 }
2004 }
2005 return
2006}
2007
Alex Brainman65705ef2015-04-17 16:35:40 +10002008func SetEvent(event Handle) (err error) {
2009 r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0)
2010 if r1 == 0 {
2011 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002012 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002013 } else {
2014 err = syscall.EINVAL
2015 }
2016 }
2017 return
2018}
2019
Tobias Klauser07c18292017-08-16 14:26:40 +02002020func ResetEvent(event Handle) (err error) {
2021 r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0)
2022 if r1 == 0 {
2023 if e1 != 0 {
2024 err = errnoErr(e1)
2025 } else {
2026 err = syscall.EINVAL
2027 }
2028 }
2029 return
2030}
2031
2032func PulseEvent(event Handle) (err error) {
2033 r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0)
2034 if r1 == 0 {
2035 if e1 != 0 {
2036 err = errnoErr(e1)
2037 } else {
2038 err = syscall.EINVAL
2039 }
2040 }
2041 return
2042}
2043
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +02002044func SleepEx(milliseconds uint32, alertable bool) (ret uint32) {
2045 var _p0 uint32
2046 if alertable {
2047 _p0 = 1
2048 } else {
2049 _p0 = 0
2050 }
2051 r0, _, _ := syscall.Syscall(procSleepEx.Addr(), 2, uintptr(milliseconds), uintptr(_p0), 0)
2052 ret = uint32(r0)
2053 return
2054}
2055
Takuto Ikutac3d486d2019-05-24 21:41:07 +09002056func CreateJobObject(jobAttr *SecurityAttributes, name *uint16) (handle Handle, err error) {
2057 r0, _, e1 := syscall.Syscall(procCreateJobObjectW.Addr(), 2, uintptr(unsafe.Pointer(jobAttr)), uintptr(unsafe.Pointer(name)), 0)
2058 handle = Handle(r0)
2059 if handle == 0 {
2060 if e1 != 0 {
2061 err = errnoErr(e1)
2062 } else {
2063 err = syscall.EINVAL
2064 }
2065 }
2066 return
2067}
2068
2069func AssignProcessToJobObject(job Handle, process Handle) (err error) {
2070 r1, _, e1 := syscall.Syscall(procAssignProcessToJobObject.Addr(), 2, uintptr(job), uintptr(process), 0)
2071 if r1 == 0 {
2072 if e1 != 0 {
2073 err = errnoErr(e1)
2074 } else {
2075 err = syscall.EINVAL
2076 }
2077 }
2078 return
2079}
2080
2081func TerminateJobObject(job Handle, exitCode uint32) (err error) {
2082 r1, _, e1 := syscall.Syscall(procTerminateJobObject.Addr(), 2, uintptr(job), uintptr(exitCode), 0)
2083 if r1 == 0 {
2084 if e1 != 0 {
2085 err = errnoErr(e1)
2086 } else {
2087 err = syscall.EINVAL
2088 }
2089 }
2090 return
2091}
2092
Takuto Ikutae44a3b52019-05-24 19:23:22 +09002093func SetErrorMode(mode uint32) (ret uint32) {
2094 r0, _, _ := syscall.Syscall(procSetErrorMode.Addr(), 1, uintptr(mode), 0, 0)
2095 ret = uint32(r0)
2096 return
2097}
2098
Takuto Ikuta9cd64302019-05-27 14:19:46 +09002099func ResumeThread(thread Handle) (ret uint32, err error) {
2100 r0, _, e1 := syscall.Syscall(procResumeThread.Addr(), 1, uintptr(thread), 0, 0)
2101 ret = uint32(r0)
2102 if ret == 0xffffffff {
2103 if e1 != 0 {
2104 err = errnoErr(e1)
2105 } else {
2106 err = syscall.EINVAL
2107 }
2108 }
2109 return
2110}
2111
Takuto Ikuta854af272019-05-28 17:17:54 +09002112func SetPriorityClass(process Handle, priorityClass uint32) (err error) {
2113 r1, _, e1 := syscall.Syscall(procSetPriorityClass.Addr(), 2, uintptr(process), uintptr(priorityClass), 0)
2114 if r1 == 0 {
2115 if e1 != 0 {
2116 err = errnoErr(e1)
2117 } else {
2118 err = syscall.EINVAL
2119 }
2120 }
2121 return
2122}
2123
2124func GetPriorityClass(process Handle) (ret uint32, err error) {
2125 r0, _, e1 := syscall.Syscall(procGetPriorityClass.Addr(), 1, uintptr(process), 0, 0)
2126 ret = uint32(r0)
2127 if ret == 0 {
2128 if e1 != 0 {
2129 err = errnoErr(e1)
2130 } else {
2131 err = syscall.EINVAL
2132 }
2133 }
2134 return
2135}
2136
Takuto Ikutacc920272019-05-28 19:11:08 +09002137func SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error) {
2138 r0, _, e1 := syscall.Syscall6(procSetInformationJobObject.Addr(), 4, uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength), 0, 0)
2139 ret = int(r0)
2140 if ret == 0 {
2141 if e1 != 0 {
2142 err = errnoErr(e1)
2143 } else {
2144 err = syscall.EINVAL
2145 }
2146 }
2147 return
2148}
2149
Takuto Ikuta95d888e2019-05-30 18:10:03 +09002150func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error) {
2151 r1, _, e1 := syscall.Syscall(procGenerateConsoleCtrlEvent.Addr(), 2, uintptr(ctrlEvent), uintptr(processGroupID), 0)
2152 if r1 == 0 {
2153 if e1 != 0 {
2154 err = errnoErr(e1)
2155 } else {
2156 err = syscall.EINVAL
2157 }
2158 }
2159 return
2160}
2161
Scott Crunkleton0dd5e192017-11-15 23:26:13 -08002162func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) {
2163 r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)))
2164 if r1 == 0 {
2165 if e1 != 0 {
2166 err = errnoErr(e1)
2167 } else {
2168 err = syscall.EINVAL
2169 }
2170 }
2171 return
2172}
2173
2174func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) {
2175 r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0)
2176 if r1 == 0 {
2177 if e1 != 0 {
2178 err = errnoErr(e1)
2179 } else {
2180 err = syscall.EINVAL
2181 }
2182 }
2183 return
2184}
2185
2186func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) {
2187 r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0)
2188 handle = Handle(r0)
2189 if handle == InvalidHandle {
2190 if e1 != 0 {
2191 err = errnoErr(e1)
2192 } else {
2193 err = syscall.EINVAL
2194 }
2195 }
2196 return
2197}
2198
2199func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) {
2200 r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
2201 handle = Handle(r0)
2202 if handle == InvalidHandle {
2203 if e1 != 0 {
2204 err = errnoErr(e1)
2205 } else {
2206 err = syscall.EINVAL
2207 }
2208 }
2209 return
2210}
2211
2212func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) {
2213 r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength))
2214 if r1 == 0 {
2215 if e1 != 0 {
2216 err = errnoErr(e1)
2217 } else {
2218 err = syscall.EINVAL
2219 }
2220 }
2221 return
2222}
2223
2224func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) {
2225 r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
2226 if r1 == 0 {
2227 if e1 != 0 {
2228 err = errnoErr(e1)
2229 } else {
2230 err = syscall.EINVAL
2231 }
2232 }
2233 return
2234}
2235
2236func FindVolumeClose(findVolume Handle) (err error) {
2237 r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0)
2238 if r1 == 0 {
2239 if e1 != 0 {
2240 err = errnoErr(e1)
2241 } else {
2242 err = syscall.EINVAL
2243 }
2244 }
2245 return
2246}
2247
2248func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) {
2249 r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0)
2250 if r1 == 0 {
2251 if e1 != 0 {
2252 err = errnoErr(e1)
2253 } else {
2254 err = syscall.EINVAL
2255 }
2256 }
2257 return
2258}
2259
2260func GetDriveType(rootPathName *uint16) (driveType uint32) {
Brad Fitzpatrick0131e682017-12-13 20:31:17 +00002261 r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0)
Scott Crunkleton0dd5e192017-11-15 23:26:13 -08002262 driveType = uint32(r0)
2263 return
2264}
2265
2266func GetLogicalDrives() (drivesBitMask uint32, err error) {
2267 r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0)
2268 drivesBitMask = uint32(r0)
2269 if drivesBitMask == 0 {
2270 if e1 != 0 {
2271 err = errnoErr(e1)
2272 } else {
2273 err = syscall.EINVAL
2274 }
2275 }
2276 return
2277}
2278
2279func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) {
2280 r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0)
2281 n = uint32(r0)
2282 if n == 0 {
2283 if e1 != 0 {
2284 err = errnoErr(e1)
2285 } else {
2286 err = syscall.EINVAL
2287 }
2288 }
2289 return
2290}
2291
2292func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
2293 r1, _, e1 := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0)
2294 if r1 == 0 {
2295 if e1 != 0 {
2296 err = errnoErr(e1)
2297 } else {
2298 err = syscall.EINVAL
2299 }
2300 }
2301 return
2302}
2303
2304func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
2305 r1, _, e1 := syscall.Syscall9(procGetVolumeInformationByHandleW.Addr(), 8, uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0)
2306 if r1 == 0 {
2307 if e1 != 0 {
2308 err = errnoErr(e1)
2309 } else {
2310 err = syscall.EINVAL
2311 }
2312 }
2313 return
2314}
2315
2316func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
2317 r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
2318 if r1 == 0 {
2319 if e1 != 0 {
2320 err = errnoErr(e1)
2321 } else {
2322 err = syscall.EINVAL
2323 }
2324 }
2325 return
2326}
2327
2328func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) {
2329 r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength))
2330 if r1 == 0 {
2331 if e1 != 0 {
2332 err = errnoErr(e1)
2333 } else {
2334 err = syscall.EINVAL
2335 }
2336 }
2337 return
2338}
2339
2340func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) {
2341 r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0)
2342 if r1 == 0 {
2343 if e1 != 0 {
2344 err = errnoErr(e1)
2345 } else {
2346 err = syscall.EINVAL
2347 }
2348 }
2349 return
2350}
2351
2352func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) {
2353 r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max))
2354 n = uint32(r0)
2355 if n == 0 {
2356 if e1 != 0 {
2357 err = errnoErr(e1)
2358 } else {
2359 err = syscall.EINVAL
2360 }
2361 }
2362 return
2363}
2364
2365func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) {
2366 r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0)
2367 if r1 == 0 {
2368 if e1 != 0 {
2369 err = errnoErr(e1)
2370 } else {
2371 err = syscall.EINVAL
2372 }
2373 }
2374 return
2375}
2376
2377func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) {
2378 r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0)
2379 if r1 == 0 {
2380 if e1 != 0 {
2381 err = errnoErr(e1)
2382 } else {
2383 err = syscall.EINVAL
2384 }
2385 }
2386 return
2387}
2388
Jason A. Donenfeldea4c4252019-05-25 15:27:23 +02002389func MessageBox(hwnd Handle, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) {
2390 r0, _, e1 := syscall.Syscall6(procMessageBoxW.Addr(), 4, uintptr(hwnd), uintptr(unsafe.Pointer(text)), uintptr(unsafe.Pointer(caption)), uintptr(boxtype), 0, 0)
2391 ret = int32(r0)
2392 if ret == 0 {
2393 if e1 != 0 {
2394 err = errnoErr(e1)
2395 } else {
2396 err = syscall.EINVAL
2397 }
2398 }
2399 return
2400}
2401
Rob Pike20acc5c2014-08-11 14:48:46 -07002402func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
Rob Pike71181952014-08-13 14:08:39 -07002403 r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002404 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002405 sockerr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002406 }
2407 return
2408}
2409
2410func WSACleanup() (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002411 r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002412 if r1 == socket_error {
2413 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002414 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002415 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002416 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002417 }
2418 }
2419 return
2420}
2421
2422func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002423 r1, _, e1 := syscall.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))
Rob Pike20acc5c2014-08-11 14:48:46 -07002424 if r1 == socket_error {
2425 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002426 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002427 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002428 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002429 }
2430 }
2431 return
2432}
2433
2434func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07002435 r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
Rob Pike20acc5c2014-08-11 14:48:46 -07002436 handle = Handle(r0)
2437 if handle == InvalidHandle {
2438 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002439 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002440 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002441 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002442 }
2443 }
2444 return
2445}
2446
2447func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002448 r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002449 if r1 == socket_error {
2450 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002451 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002452 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002453 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002454 }
2455 }
2456 return
2457}
2458
2459func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002460 r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002461 if r1 == socket_error {
2462 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002463 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002464 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002465 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002466 }
2467 }
2468 return
2469}
2470
2471func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002472 r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Rob Pike20acc5c2014-08-11 14:48:46 -07002473 if r1 == socket_error {
2474 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002475 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002476 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002477 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002478 }
2479 }
2480 return
2481}
2482
2483func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002484 r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Rob Pike20acc5c2014-08-11 14:48:46 -07002485 if r1 == socket_error {
2486 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002487 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002488 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002489 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002490 }
2491 }
2492 return
2493}
2494
2495func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002496 r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002497 if r1 == socket_error {
2498 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002499 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002500 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002501 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002502 }
2503 }
2504 return
2505}
2506
2507func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002508 r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002509 if r1 == socket_error {
2510 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002511 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002512 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002513 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002514 }
2515 }
2516 return
2517}
2518
2519func listen(s Handle, backlog int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002520 r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002521 if r1 == socket_error {
2522 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002523 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002524 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002525 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002526 }
2527 }
2528 return
2529}
2530
2531func shutdown(s Handle, how int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002532 r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002533 if r1 == socket_error {
2534 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002535 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002536 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002537 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002538 }
2539 }
2540 return
2541}
2542
2543func Closesocket(s Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002544 r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002545 if r1 == socket_error {
2546 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002547 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002548 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002549 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002550 }
2551 }
2552 return
2553}
2554
2555func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002556 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002557 if r1 == 0 {
2558 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002559 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002560 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002561 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002562 }
2563 }
2564 return
2565}
2566
2567func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
Rob Pike71181952014-08-13 14:08:39 -07002568 syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002569 return
2570}
2571
2572func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002573 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002574 if r1 == socket_error {
2575 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002576 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002577 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002578 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002579 }
2580 }
2581 return
2582}
2583
2584func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002585 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002586 if r1 == socket_error {
2587 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002588 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002589 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002590 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002591 }
2592 }
2593 return
2594}
2595
2596func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002597 r1, _, e1 := syscall.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)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002598 if r1 == socket_error {
2599 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002600 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002601 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002602 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002603 }
2604 }
2605 return
2606}
2607
2608func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002609 r1, _, e1 := syscall.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)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002610 if r1 == socket_error {
2611 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002612 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002613 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002614 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002615 }
2616 }
2617 return
2618}
2619
2620func GetHostByName(name string) (h *Hostent, err error) {
2621 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002622 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002623 if err != nil {
2624 return
2625 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002626 return _GetHostByName(_p0)
2627}
2628
2629func _GetHostByName(name *byte) (h *Hostent, err error) {
2630 r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002631 h = (*Hostent)(unsafe.Pointer(r0))
2632 if h == nil {
2633 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002634 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002635 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002636 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002637 }
2638 }
2639 return
2640}
2641
2642func GetServByName(name string, proto string) (s *Servent, err error) {
2643 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002644 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002645 if err != nil {
2646 return
2647 }
2648 var _p1 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002649 _p1, err = syscall.BytePtrFromString(proto)
Rob Pike20acc5c2014-08-11 14:48:46 -07002650 if err != nil {
2651 return
2652 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002653 return _GetServByName(_p0, _p1)
2654}
2655
2656func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
2657 r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002658 s = (*Servent)(unsafe.Pointer(r0))
2659 if s == nil {
2660 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002661 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002662 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002663 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002664 }
2665 }
2666 return
2667}
2668
2669func Ntohs(netshort uint16) (u uint16) {
Rob Pike71181952014-08-13 14:08:39 -07002670 r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002671 u = uint16(r0)
2672 return
2673}
2674
2675func GetProtoByName(name string) (p *Protoent, err error) {
2676 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002677 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002678 if err != nil {
2679 return
2680 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002681 return _GetProtoByName(_p0)
2682}
2683
2684func _GetProtoByName(name *byte) (p *Protoent, err error) {
2685 r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002686 p = (*Protoent)(unsafe.Pointer(r0))
2687 if p == nil {
2688 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002689 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002690 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002691 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002692 }
2693 }
2694 return
2695}
2696
2697func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
2698 var _p0 *uint16
Alex Brainman7d091bf2014-08-19 15:20:17 +10002699 _p0, status = syscall.UTF16PtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002700 if status != nil {
2701 return
2702 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002703 return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
2704}
2705
2706func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
2707 r0, _, _ := syscall.Syscall6(procDnsQuery_W.Addr(), 6, uintptr(unsafe.Pointer(name)), uintptr(qtype), uintptr(options), uintptr(unsafe.Pointer(extra)), uintptr(unsafe.Pointer(qrs)), uintptr(unsafe.Pointer(pr)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002708 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002709 status = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002710 }
2711 return
2712}
2713
2714func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
Rob Pike71181952014-08-13 14:08:39 -07002715 syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002716 return
2717}
2718
Alex Brainmand1ee94c2014-08-20 12:25:19 +10002719func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
2720 r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
2721 same = r0 != 0
2722 return
2723}
2724
Rob Pike20acc5c2014-08-11 14:48:46 -07002725func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
Rob Pike71181952014-08-13 14:08:39 -07002726 r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002727 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002728 sockerr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002729 }
2730 return
2731}
2732
2733func FreeAddrInfoW(addrinfo *AddrinfoW) {
Rob Pike71181952014-08-13 14:08:39 -07002734 syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002735 return
2736}
2737
2738func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
Rob Pike71181952014-08-13 14:08:39 -07002739 r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002740 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002741 errcode = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002742 }
2743 return
2744}
2745
2746func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
Rob Pike71181952014-08-13 14:08:39 -07002747 r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002748 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002749 errcode = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002750 }
2751 return
2752}
2753
2754func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002755 r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002756 if r1 == 0 {
2757 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002758 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002759 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002760 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002761 }
2762 }
2763 return
2764}
2765
2766func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07002767 r0, _, e1 := syscall.Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002768 n = int32(r0)
2769 if n == -1 {
2770 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002771 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002772 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002773 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002774 }
2775 }
2776 return
2777}
2778
Alex Brainman442cd602016-01-13 11:01:27 +11002779func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
2780 r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
2781 if r0 != 0 {
2782 errcode = syscall.Errno(r0)
2783 }
2784 return
2785}
2786
2787func GetACP() (acp uint32) {
2788 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
2789 acp = uint32(r0)
2790 return
2791}
2792
2793func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
2794 r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
2795 nwrite = int32(r0)
2796 if nwrite == 0 {
2797 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002798 err = errnoErr(e1)
Alex Brainman442cd602016-01-13 11:01:27 +11002799 } else {
2800 err = syscall.EINVAL
2801 }
2802 }
2803 return
2804}
2805
Rob Pike20acc5c2014-08-11 14:48:46 -07002806func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002807 r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002808 if r1&0xff == 0 {
2809 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002810 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002811 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002812 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002813 }
2814 }
2815 return
2816}
2817
2818func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002819 r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002820 if r1&0xff == 0 {
2821 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002822 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002823 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002824 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002825 }
2826 }
2827 return
2828}
2829
2830func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002831 r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002832 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002833 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002834 }
2835 return
2836}
2837
2838func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002839 r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002840 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002841 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002842 }
2843 return
2844}
2845
2846func NetApiBufferFree(buf *byte) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002847 r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002848 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002849 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002850 }
2851 return
2852}
2853
2854func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002855 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002856 if r1 == 0 {
2857 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002858 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002859 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002860 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002861 }
2862 }
2863 return
2864}
2865
2866func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002867 r1, _, e1 := syscall.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)
Rob Pike20acc5c2014-08-11 14:48:46 -07002868 if r1 == 0 {
2869 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002870 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002871 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002872 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002873 }
2874 }
2875 return
2876}
2877
2878func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002879 r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002880 if r1 == 0 {
2881 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002882 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002883 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002884 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002885 }
2886 }
2887 return
2888}
2889
2890func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002891 r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002892 if r1 == 0 {
2893 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002894 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002895 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002896 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002897 }
2898 }
2899 return
2900}
2901
2902func GetLengthSid(sid *SID) (len uint32) {
Rob Pike71181952014-08-13 14:08:39 -07002903 r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002904 len = uint32(r0)
2905 return
2906}
2907
2908func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002909 r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002910 if r1 == 0 {
2911 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002912 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002913 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002914 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002915 }
2916 }
2917 return
2918}
2919
Alex Brainman65705ef2015-04-17 16:35:40 +10002920func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, subAuth0 uint32, subAuth1 uint32, subAuth2 uint32, subAuth3 uint32, subAuth4 uint32, subAuth5 uint32, subAuth6 uint32, subAuth7 uint32, sid **SID) (err error) {
2921 r1, _, e1 := syscall.Syscall12(procAllocateAndInitializeSid.Addr(), 11, uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid)), 0)
2922 if r1 == 0 {
2923 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002924 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002925 } else {
2926 err = syscall.EINVAL
2927 }
2928 }
2929 return
2930}
2931
Jason A. Donenfelda2f829d2019-03-13 03:55:42 -06002932func createWellKnownSid(sidType WELL_KNOWN_SID_TYPE, domainSid *SID, sid *SID, sizeSid *uint32) (err error) {
2933 r1, _, e1 := syscall.Syscall6(procCreateWellKnownSid.Addr(), 4, uintptr(sidType), uintptr(unsafe.Pointer(domainSid)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sizeSid)), 0, 0)
2934 if r1 == 0 {
2935 if e1 != 0 {
2936 err = errnoErr(e1)
2937 } else {
2938 err = syscall.EINVAL
2939 }
2940 }
2941 return
2942}
2943
Jason A. Donenfeld2219a012019-05-21 17:33:12 +02002944func isWellKnownSid(sid *SID, sidType WELL_KNOWN_SID_TYPE) (isWellKnown bool) {
2945 r0, _, _ := syscall.Syscall(procIsWellKnownSid.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(sidType), 0)
2946 isWellKnown = r0 != 0
2947 return
2948}
2949
Alex Brainman65705ef2015-04-17 16:35:40 +10002950func FreeSid(sid *SID) (err error) {
2951 r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2952 if r1 != 0 {
2953 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002954 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002955 } else {
2956 err = syscall.EINVAL
2957 }
2958 }
2959 return
2960}
2961
2962func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) {
2963 r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0)
2964 isEqual = r0 != 0
2965 return
2966}
2967
Jason A. Donenfeld2219a012019-05-21 17:33:12 +02002968func getSidIdentifierAuthority(sid *SID) (authority *SidIdentifierAuthority) {
2969 r0, _, _ := syscall.Syscall(procGetSidIdentifierAuthority.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2970 authority = (*SidIdentifierAuthority)(unsafe.Pointer(r0))
2971 return
2972}
2973
2974func getSidSubAuthorityCount(sid *SID) (count *uint8) {
2975 r0, _, _ := syscall.Syscall(procGetSidSubAuthorityCount.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2976 count = (*uint8)(unsafe.Pointer(r0))
2977 return
2978}
2979
2980func getSidSubAuthority(sid *SID, index uint32) (subAuthority *uint32) {
2981 r0, _, _ := syscall.Syscall(procGetSidSubAuthority.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(index), 0)
2982 subAuthority = (*uint32)(unsafe.Pointer(r0))
2983 return
2984}
2985
2986func isValidSid(sid *SID) (isValid bool) {
2987 r0, _, _ := syscall.Syscall(procIsValidSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2988 isValid = r0 != 0
2989 return
2990}
2991
Scott Crunkleton1006bb32017-11-27 18:10:40 -08002992func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) {
2993 r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember)))
2994 if r1 == 0 {
2995 if e1 != 0 {
2996 err = errnoErr(e1)
2997 } else {
2998 err = syscall.EINVAL
2999 }
3000 }
3001 return
3002}
3003
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003004func OpenProcessToken(process Handle, access uint32, token *Token) (err error) {
3005 r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(process), uintptr(access), uintptr(unsafe.Pointer(token)))
Rob Pike20acc5c2014-08-11 14:48:46 -07003006 if r1 == 0 {
3007 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003008 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003009 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003010 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003011 }
3012 }
3013 return
3014}
3015
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003016func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token) (err error) {
3017 var _p0 uint32
3018 if openAsSelf {
3019 _p0 = 1
3020 } else {
3021 _p0 = 0
3022 }
3023 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
3024 if r1 == 0 {
3025 if e1 != 0 {
3026 err = errnoErr(e1)
3027 } else {
3028 err = syscall.EINVAL
3029 }
3030 }
3031 return
3032}
3033
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003034func ImpersonateSelf(impersonationlevel uint32) (err error) {
3035 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
3036 if r1 == 0 {
3037 if e1 != 0 {
3038 err = errnoErr(e1)
3039 } else {
3040 err = syscall.EINVAL
3041 }
3042 }
3043 return
3044}
3045
3046func RevertToSelf() (err error) {
3047 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
3048 if r1 == 0 {
3049 if e1 != 0 {
3050 err = errnoErr(e1)
3051 } else {
3052 err = syscall.EINVAL
3053 }
3054 }
3055 return
3056}
3057
3058func SetThreadToken(thread *Handle, token Token) (err error) {
3059 r1, _, e1 := syscall.Syscall(procSetThreadToken.Addr(), 2, uintptr(unsafe.Pointer(thread)), uintptr(token), 0)
3060 if r1 == 0 {
3061 if e1 != 0 {
3062 err = errnoErr(e1)
3063 } else {
3064 err = syscall.EINVAL
3065 }
3066 }
3067 return
3068}
3069
3070func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
3071 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
3072 if r1 == 0 {
3073 if e1 != 0 {
3074 err = errnoErr(e1)
3075 } else {
3076 err = syscall.EINVAL
3077 }
3078 }
3079 return
3080}
3081
3082func AdjustTokenPrivileges(token Token, disableAllPrivileges bool, newstate *Tokenprivileges, buflen uint32, prevstate *Tokenprivileges, returnlen *uint32) (err error) {
3083 var _p0 uint32
3084 if disableAllPrivileges {
3085 _p0 = 1
3086 } else {
3087 _p0 = 0
3088 }
3089 r1, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
3090 if r1 == 0 {
3091 if e1 != 0 {
3092 err = errnoErr(e1)
3093 } else {
3094 err = syscall.EINVAL
3095 }
3096 }
3097 return
3098}
3099
Jason A. Donenfeldcedb8e12019-05-15 13:59:33 +02003100func AdjustTokenGroups(token Token, resetToDefault bool, newstate *Tokengroups, buflen uint32, prevstate *Tokengroups, returnlen *uint32) (err error) {
3101 var _p0 uint32
3102 if resetToDefault {
3103 _p0 = 1
3104 } else {
3105 _p0 = 0
3106 }
3107 r1, _, e1 := syscall.Syscall6(procAdjustTokenGroups.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(newstate)), uintptr(buflen), uintptr(unsafe.Pointer(prevstate)), uintptr(unsafe.Pointer(returnlen)))
3108 if r1 == 0 {
3109 if e1 != 0 {
3110 err = errnoErr(e1)
3111 } else {
3112 err = syscall.EINVAL
3113 }
3114 }
3115 return
3116}
3117
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003118func GetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
3119 r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
3120 if r1 == 0 {
3121 if e1 != 0 {
3122 err = errnoErr(e1)
3123 } else {
3124 err = syscall.EINVAL
3125 }
3126 }
3127 return
3128}
3129
3130func SetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32) (err error) {
3131 r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), 0, 0)
3132 if r1 == 0 {
3133 if e1 != 0 {
3134 err = errnoErr(e1)
3135 } else {
3136 err = syscall.EINVAL
3137 }
3138 }
3139 return
3140}
3141
3142func DuplicateTokenEx(existingToken Token, desiredAccess uint32, tokenAttributes *SecurityAttributes, impersonationLevel uint32, tokenType uint32, newToken *Token) (err error) {
3143 r1, _, e1 := syscall.Syscall6(procDuplicateTokenEx.Addr(), 6, uintptr(existingToken), uintptr(desiredAccess), uintptr(unsafe.Pointer(tokenAttributes)), uintptr(impersonationLevel), uintptr(tokenType), uintptr(unsafe.Pointer(newToken)))
Rob Pike20acc5c2014-08-11 14:48:46 -07003144 if r1 == 0 {
3145 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003146 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003147 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003148 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003149 }
3150 }
3151 return
3152}
3153
3154func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07003155 r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07003156 if r1 == 0 {
3157 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003158 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003159 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003160 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003161 }
3162 }
3163 return
3164}
Jason A. Donenfeld10058d72019-03-06 18:49:41 +01003165
3166func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) {
3167 r0, _, e1 := syscall.Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0)
3168 len = uint32(r0)
3169 if len == 0 {
3170 if e1 != 0 {
3171 err = errnoErr(e1)
3172 } else {
3173 err = syscall.EINVAL
3174 }
3175 }
3176 return
3177}
Jason A. Donenfeldf91f9b32019-05-13 10:42:08 +02003178
3179func WTSQueryUserToken(session uint32, token *Token) (err error) {
3180 r1, _, e1 := syscall.Syscall(procWTSQueryUserToken.Addr(), 2, uintptr(session), uintptr(unsafe.Pointer(token)), 0)
3181 if r1 == 0 {
3182 if e1 != 0 {
3183 err = errnoErr(e1)
3184 } else {
3185 err = syscall.EINVAL
3186 }
3187 }
3188 return
3189}
3190
3191func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) {
3192 r1, _, e1 := syscall.Syscall6(procWTSEnumerateSessionsW.Addr(), 5, uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count)), 0)
3193 if r1 == 0 {
3194 if e1 != 0 {
3195 err = errnoErr(e1)
3196 } else {
3197 err = syscall.EINVAL
3198 }
3199 }
3200 return
3201}
3202
3203func WTSFreeMemory(ptr uintptr) {
3204 syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0)
3205 return
3206}