blob: a7663b5fc280280342f5bc5c46830f2868f17a4a [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")
Jason A. Donenfeld5da28582019-06-06 15:35:02 +0200136 procGetTickCount64 = modkernel32.NewProc("GetTickCount64")
Rob Pike20acc5c2014-08-11 14:48:46 -0700137 procSetFileTime = modkernel32.NewProc("SetFileTime")
138 procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
139 procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
140 procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
141 procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
142 procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
143 procLocalFree = modkernel32.NewProc("LocalFree")
144 procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
145 procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
146 procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
147 procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
148 procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
149 procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
150 procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
151 procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
152 procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
153 procVirtualLock = modkernel32.NewProc("VirtualLock")
154 procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
Awnd18155c2017-07-01 07:14:08 +0100155 procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
156 procVirtualFree = modkernel32.NewProc("VirtualFree")
157 procVirtualProtect = modkernel32.NewProc("VirtualProtect")
Rob Pike20acc5c2014-08-11 14:48:46 -0700158 procTransmitFile = modmswsock.NewProc("TransmitFile")
159 procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
160 procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
161 procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
162 procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
163 procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
164 procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
165 procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
166 procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
167 procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
168 procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
169 procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
170 procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
171 procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
172 procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
173 procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
174 procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
175 procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
176 procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +0200177 procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
178 procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
Rob Pike20acc5c2014-08-11 14:48:46 -0700179 procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
180 procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
181 procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
182 procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
183 procProcess32NextW = modkernel32.NewProc("Process32NextW")
184 procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
185 procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
186 procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
Alex Brainman65705ef2015-04-17 16:35:40 +1000187 procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
188 procCreateEventW = modkernel32.NewProc("CreateEventW")
Tobias Klauser07c18292017-08-16 14:26:40 +0200189 procCreateEventExW = modkernel32.NewProc("CreateEventExW")
190 procOpenEventW = modkernel32.NewProc("OpenEventW")
Alex Brainman65705ef2015-04-17 16:35:40 +1000191 procSetEvent = modkernel32.NewProc("SetEvent")
Tobias Klauser07c18292017-08-16 14:26:40 +0200192 procResetEvent = modkernel32.NewProc("ResetEvent")
193 procPulseEvent = modkernel32.NewProc("PulseEvent")
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +0200194 procSleepEx = modkernel32.NewProc("SleepEx")
Takuto Ikutac3d486d2019-05-24 21:41:07 +0900195 procCreateJobObjectW = modkernel32.NewProc("CreateJobObjectW")
196 procAssignProcessToJobObject = modkernel32.NewProc("AssignProcessToJobObject")
197 procTerminateJobObject = modkernel32.NewProc("TerminateJobObject")
Takuto Ikutae44a3b52019-05-24 19:23:22 +0900198 procSetErrorMode = modkernel32.NewProc("SetErrorMode")
Takuto Ikuta9cd64302019-05-27 14:19:46 +0900199 procResumeThread = modkernel32.NewProc("ResumeThread")
Takuto Ikuta854af272019-05-28 17:17:54 +0900200 procSetPriorityClass = modkernel32.NewProc("SetPriorityClass")
201 procGetPriorityClass = modkernel32.NewProc("GetPriorityClass")
Takuto Ikutacc920272019-05-28 19:11:08 +0900202 procSetInformationJobObject = modkernel32.NewProc("SetInformationJobObject")
Takuto Ikuta95d888e2019-05-30 18:10:03 +0900203 procGenerateConsoleCtrlEvent = modkernel32.NewProc("GenerateConsoleCtrlEvent")
Scott Crunkleton0dd5e192017-11-15 23:26:13 -0800204 procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW")
205 procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW")
206 procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW")
207 procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW")
208 procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW")
209 procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW")
210 procFindVolumeClose = modkernel32.NewProc("FindVolumeClose")
211 procFindVolumeMountPointClose = modkernel32.NewProc("FindVolumeMountPointClose")
Brad Fitzpatrick0131e682017-12-13 20:31:17 +0000212 procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW")
Scott Crunkleton0dd5e192017-11-15 23:26:13 -0800213 procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives")
214 procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW")
215 procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
216 procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW")
217 procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW")
218 procGetVolumePathNameW = modkernel32.NewProc("GetVolumePathNameW")
219 procGetVolumePathNamesForVolumeNameW = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW")
220 procQueryDosDeviceW = modkernel32.NewProc("QueryDosDeviceW")
221 procSetVolumeLabelW = modkernel32.NewProc("SetVolumeLabelW")
222 procSetVolumeMountPointW = modkernel32.NewProc("SetVolumeMountPointW")
Jason A. Donenfeldea4c4252019-05-25 15:27:23 +0200223 procMessageBoxW = moduser32.NewProc("MessageBoxW")
Rob Pike20acc5c2014-08-11 14:48:46 -0700224 procWSAStartup = modws2_32.NewProc("WSAStartup")
225 procWSACleanup = modws2_32.NewProc("WSACleanup")
226 procWSAIoctl = modws2_32.NewProc("WSAIoctl")
227 procsocket = modws2_32.NewProc("socket")
228 procsetsockopt = modws2_32.NewProc("setsockopt")
229 procgetsockopt = modws2_32.NewProc("getsockopt")
230 procbind = modws2_32.NewProc("bind")
231 procconnect = modws2_32.NewProc("connect")
232 procgetsockname = modws2_32.NewProc("getsockname")
233 procgetpeername = modws2_32.NewProc("getpeername")
234 proclisten = modws2_32.NewProc("listen")
235 procshutdown = modws2_32.NewProc("shutdown")
236 procclosesocket = modws2_32.NewProc("closesocket")
237 procAcceptEx = modmswsock.NewProc("AcceptEx")
238 procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
239 procWSARecv = modws2_32.NewProc("WSARecv")
240 procWSASend = modws2_32.NewProc("WSASend")
241 procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
242 procWSASendTo = modws2_32.NewProc("WSASendTo")
243 procgethostbyname = modws2_32.NewProc("gethostbyname")
244 procgetservbyname = modws2_32.NewProc("getservbyname")
245 procntohs = modws2_32.NewProc("ntohs")
246 procgetprotobyname = modws2_32.NewProc("getprotobyname")
247 procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
248 procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
Alex Brainmand1ee94c2014-08-20 12:25:19 +1000249 procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
Rob Pike20acc5c2014-08-11 14:48:46 -0700250 procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
251 procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
252 procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
253 procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
254 procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
255 procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
Alex Brainman442cd602016-01-13 11:01:27 +1100256 procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
257 procGetACP = modkernel32.NewProc("GetACP")
258 procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
Rob Pike20acc5c2014-08-11 14:48:46 -0700259 procTranslateNameW = modsecur32.NewProc("TranslateNameW")
260 procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
261 procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
262 procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
263 procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
264 procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
265 procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
266 procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
267 procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
268 procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
269 procCopySid = modadvapi32.NewProc("CopySid")
Alex Brainman65705ef2015-04-17 16:35:40 +1000270 procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid")
Jason A. Donenfelda2f829d2019-03-13 03:55:42 -0600271 procCreateWellKnownSid = modadvapi32.NewProc("CreateWellKnownSid")
Jason A. Donenfeld2219a012019-05-21 17:33:12 +0200272 procIsWellKnownSid = modadvapi32.NewProc("IsWellKnownSid")
Alex Brainman65705ef2015-04-17 16:35:40 +1000273 procFreeSid = modadvapi32.NewProc("FreeSid")
274 procEqualSid = modadvapi32.NewProc("EqualSid")
Jason A. Donenfeld2219a012019-05-21 17:33:12 +0200275 procGetSidIdentifierAuthority = modadvapi32.NewProc("GetSidIdentifierAuthority")
276 procGetSidSubAuthorityCount = modadvapi32.NewProc("GetSidSubAuthorityCount")
277 procGetSidSubAuthority = modadvapi32.NewProc("GetSidSubAuthority")
278 procIsValidSid = modadvapi32.NewProc("IsValidSid")
Scott Crunkleton1006bb32017-11-27 18:10:40 -0800279 procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership")
Rob Pike20acc5c2014-08-11 14:48:46 -0700280 procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200281 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200282 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf")
283 procRevertToSelf = modadvapi32.NewProc("RevertToSelf")
284 procSetThreadToken = modadvapi32.NewProc("SetThreadToken")
285 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW")
286 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges")
Jason A. Donenfeldcedb8e12019-05-15 13:59:33 +0200287 procAdjustTokenGroups = modadvapi32.NewProc("AdjustTokenGroups")
Rob Pike20acc5c2014-08-11 14:48:46 -0700288 procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +0200289 procSetTokenInformation = modadvapi32.NewProc("SetTokenInformation")
290 procDuplicateTokenEx = modadvapi32.NewProc("DuplicateTokenEx")
Rob Pike20acc5c2014-08-11 14:48:46 -0700291 procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
Jason A. Donenfeld10058d72019-03-06 18:49:41 +0100292 procGetSystemDirectoryW = modkernel32.NewProc("GetSystemDirectoryW")
Jason A. Donenfeldf91f9b32019-05-13 10:42:08 +0200293 procWTSQueryUserToken = modwtsapi32.NewProc("WTSQueryUserToken")
294 procWTSEnumerateSessionsW = modwtsapi32.NewProc("WTSEnumerateSessionsW")
295 procWTSFreeMemory = modwtsapi32.NewProc("WTSFreeMemory")
Rob Pike20acc5c2014-08-11 14:48:46 -0700296)
297
Alex Brainman65705ef2015-04-17 16:35:40 +1000298func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
299 r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0)
300 handle = Handle(r0)
301 if handle == 0 {
302 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100303 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000304 } else {
305 err = syscall.EINVAL
306 }
307 }
308 return
309}
310
311func DeregisterEventSource(handle Handle) (err error) {
312 r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0)
313 if r1 == 0 {
314 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100315 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000316 } else {
317 err = syscall.EINVAL
318 }
319 }
320 return
321}
322
323func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) {
324 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)))
325 if r1 == 0 {
326 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100327 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000328 } else {
329 err = syscall.EINVAL
330 }
331 }
332 return
333}
334
335func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) {
336 r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
337 handle = Handle(r0)
338 if handle == 0 {
339 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100340 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000341 } else {
342 err = syscall.EINVAL
343 }
344 }
345 return
346}
347
348func CloseServiceHandle(handle Handle) (err error) {
349 r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0)
350 if r1 == 0 {
351 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100352 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000353 } else {
354 err = syscall.EINVAL
355 }
356 }
357 return
358}
359
360func 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) {
361 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)
362 handle = Handle(r0)
363 if handle == 0 {
364 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100365 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000366 } else {
367 err = syscall.EINVAL
368 }
369 }
370 return
371}
372
373func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) {
374 r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
375 handle = Handle(r0)
376 if handle == 0 {
377 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100378 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000379 } else {
380 err = syscall.EINVAL
381 }
382 }
383 return
384}
385
386func DeleteService(service Handle) (err error) {
387 r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0)
388 if r1 == 0 {
389 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100390 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000391 } else {
392 err = syscall.EINVAL
393 }
394 }
395 return
396}
397
398func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) {
399 r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors)))
400 if r1 == 0 {
401 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100402 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000403 } else {
404 err = syscall.EINVAL
405 }
406 }
407 return
408}
409
410func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) {
411 r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0)
412 if r1 == 0 {
413 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100414 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000415 } else {
416 err = syscall.EINVAL
417 }
418 }
419 return
420}
421
422func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) {
423 r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status)))
424 if r1 == 0 {
425 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100426 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000427 } else {
428 err = syscall.EINVAL
429 }
430 }
431 return
432}
433
434func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) {
435 r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0)
436 if r1 == 0 {
437 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100438 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000439 } else {
440 err = syscall.EINVAL
441 }
442 }
443 return
444}
445
446func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) {
447 r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0)
448 if r1 == 0 {
449 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100450 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000451 } else {
452 err = syscall.EINVAL
453 }
454 }
455 return
456}
457
458func 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) {
459 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)
460 if r1 == 0 {
461 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100462 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000463 } else {
464 err = syscall.EINVAL
465 }
466 }
467 return
468}
469
470func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) {
471 r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0)
472 if r1 == 0 {
473 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100474 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000475 } else {
476 err = syscall.EINVAL
477 }
478 }
479 return
480}
481
482func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) {
483 r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info)))
484 if r1 == 0 {
485 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100486 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000487 } else {
488 err = syscall.EINVAL
489 }
490 }
491 return
492}
493
494func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
495 r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
496 if r1 == 0 {
497 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100498 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +1000499 } else {
500 err = syscall.EINVAL
501 }
502 }
503 return
504}
505
Alex Brainmanfb4cac32017-06-14 16:48:48 +1000506func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) {
507 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)
508 if r1 == 0 {
509 if e1 != 0 {
510 err = errnoErr(e1)
511 } else {
512 err = syscall.EINVAL
513 }
514 }
515 return
516}
517
pytimer56ad15c2018-05-23 10:12:58 +0800518func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
519 r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
520 if r1 == 0 {
521 if e1 != 0 {
522 err = errnoErr(e1)
523 } else {
524 err = syscall.EINVAL
525 }
526 }
527 return
528}
529
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +0200530func NotifyServiceStatusChange(service Handle, notifyMask uint32, notifier *SERVICE_NOTIFY) (ret error) {
531 r0, _, _ := syscall.Syscall(procNotifyServiceStatusChangeW.Addr(), 3, uintptr(service), uintptr(notifyMask), uintptr(unsafe.Pointer(notifier)))
532 if r0 != 0 {
533 ret = syscall.Errno(r0)
534 }
535 return
536}
537
Rob Pike20acc5c2014-08-11 14:48:46 -0700538func GetLastError() (lasterr error) {
Rob Pike71181952014-08-13 14:08:39 -0700539 r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700540 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -0700541 lasterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700542 }
543 return
544}
545
546func LoadLibrary(libname string) (handle Handle, err error) {
547 var _p0 *uint16
Alex Brainman7d091bf2014-08-19 15:20:17 +1000548 _p0, err = syscall.UTF16PtrFromString(libname)
Rob Pike20acc5c2014-08-11 14:48:46 -0700549 if err != nil {
550 return
551 }
Alex Brainmanc17938b2014-10-06 10:48:58 +1100552 return _LoadLibrary(_p0)
553}
554
555func _LoadLibrary(libname *uint16) (handle Handle, err error) {
556 r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700557 handle = Handle(r0)
558 if handle == 0 {
559 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100560 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700561 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000562 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700563 }
564 }
565 return
566}
567
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +0000568func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) {
569 var _p0 *uint16
570 _p0, err = syscall.UTF16PtrFromString(libname)
571 if err != nil {
572 return
573 }
574 return _LoadLibraryEx(_p0, zero, flags)
575}
576
577func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) {
578 r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags))
579 handle = Handle(r0)
580 if handle == 0 {
581 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100582 err = errnoErr(e1)
Brad Fitzpatrick3dff6e12016-04-01 04:10:49 +0000583 } else {
584 err = syscall.EINVAL
585 }
586 }
587 return
588}
589
Rob Pike20acc5c2014-08-11 14:48:46 -0700590func FreeLibrary(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700591 r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700592 if r1 == 0 {
593 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100594 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700595 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000596 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700597 }
598 }
599 return
600}
601
602func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
603 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +1000604 _p0, err = syscall.BytePtrFromString(procname)
Rob Pike20acc5c2014-08-11 14:48:46 -0700605 if err != nil {
606 return
607 }
Alex Brainmanc17938b2014-10-06 10:48:58 +1100608 return _GetProcAddress(module, _p0)
609}
610
611func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
612 r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700613 proc = uintptr(r0)
614 if proc == 0 {
615 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100616 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700617 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000618 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700619 }
620 }
621 return
622}
623
624func GetVersion() (ver uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700625 r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700626 ver = uint32(r0)
627 if ver == 0 {
628 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100629 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700630 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000631 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700632 }
633 }
634 return
635}
636
Alex Brainman2019c8d2015-06-17 15:36:00 +1000637func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
Rob Pike20acc5c2014-08-11 14:48:46 -0700638 var _p0 *uint16
639 if len(buf) > 0 {
640 _p0 = &buf[0]
641 }
Rob Pike71181952014-08-13 14:08:39 -0700642 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 -0700643 n = uint32(r0)
644 if n == 0 {
645 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100646 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700647 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000648 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700649 }
650 }
651 return
652}
653
654func ExitProcess(exitcode uint32) {
Rob Pike71181952014-08-13 14:08:39 -0700655 syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700656 return
657}
658
Jason A. Donenfeld791d8a02019-05-25 15:13:12 +0200659func IsWow64Process(handle Handle, isWow64 *bool) (err error) {
660 r1, _, e1 := syscall.Syscall(procIsWow64Process.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(isWow64)), 0)
661 if r1 == 0 {
662 if e1 != 0 {
663 err = errnoErr(e1)
664 } else {
665 err = syscall.EINVAL
666 }
667 }
668 return
669}
670
Jason A. Donenfeldca7f33d2019-05-06 11:56:55 +0200671func 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 -0700672 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 -0700673 handle = Handle(r0)
674 if handle == InvalidHandle {
675 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100676 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700677 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000678 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700679 }
680 }
681 return
682}
683
684func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
685 var _p0 *byte
686 if len(buf) > 0 {
687 _p0 = &buf[0]
688 }
Rob Pike71181952014-08-13 14:08:39 -0700689 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 -0700690 if r1 == 0 {
691 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100692 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700693 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000694 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700695 }
696 }
697 return
698}
699
700func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
701 var _p0 *byte
702 if len(buf) > 0 {
703 _p0 = &buf[0]
704 }
Rob Pike71181952014-08-13 14:08:39 -0700705 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 -0700706 if r1 == 0 {
707 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100708 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700709 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000710 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700711 }
712 }
713 return
714}
715
Jason A. Donenfeldf49334f2019-03-20 23:14:46 -0600716func GetOverlappedResult(handle Handle, overlapped *Overlapped, done *uint32, wait bool) (err error) {
717 var _p0 uint32
718 if wait {
719 _p0 = 1
720 } else {
721 _p0 = 0
722 }
723 r1, _, e1 := syscall.Syscall6(procGetOverlappedResult.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(done)), uintptr(_p0), 0, 0)
724 if r1 == 0 {
725 if e1 != 0 {
726 err = errnoErr(e1)
727 } else {
728 err = syscall.EINVAL
729 }
730 }
731 return
732}
733
Rob Pike20acc5c2014-08-11 14:48:46 -0700734func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700735 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 -0700736 newlowoffset = uint32(r0)
737 if newlowoffset == 0xffffffff {
738 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100739 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700740 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000741 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700742 }
743 }
744 return
745}
746
747func CloseHandle(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700748 r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700749 if r1 == 0 {
750 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100751 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700752 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000753 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700754 }
755 }
756 return
757}
758
Tamir Dubersteinff24cb32017-04-05 12:54:02 -0400759func GetStdHandle(stdhandle uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700760 r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700761 handle = Handle(r0)
762 if handle == InvalidHandle {
763 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100764 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700765 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000766 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700767 }
768 }
769 return
770}
771
Tamir Dubersteinf3918c32017-04-05 12:58:12 -0400772func SetStdHandle(stdhandle uint32, handle Handle) (err error) {
773 r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0)
774 if r1 == 0 {
775 if e1 != 0 {
776 err = errnoErr(e1)
777 } else {
778 err = syscall.EINVAL
779 }
780 }
781 return
782}
783
Rob Pike20acc5c2014-08-11 14:48:46 -0700784func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700785 r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700786 handle = Handle(r0)
787 if handle == InvalidHandle {
788 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100789 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700790 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000791 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700792 }
793 }
794 return
795}
796
797func findNextFile1(handle Handle, data *win32finddata1) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700798 r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700799 if r1 == 0 {
800 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100801 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700802 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000803 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700804 }
805 }
806 return
807}
808
809func FindClose(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700810 r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700811 if r1 == 0 {
812 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100813 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700814 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000815 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700816 }
817 }
818 return
819}
820
821func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700822 r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700823 if r1 == 0 {
824 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100825 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700826 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000827 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700828 }
829 }
830 return
831}
832
James Nugent16da32b2019-04-14 19:23:05 +0000833func GetFileInformationByHandleEx(handle Handle, class uint32, outBuffer *byte, outBufferLen uint32) (err error) {
834 r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(handle), uintptr(class), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferLen), 0, 0)
835 if r1 == 0 {
836 if e1 != 0 {
837 err = errnoErr(e1)
838 } else {
839 err = syscall.EINVAL
840 }
841 }
842 return
843}
844
Rob Pike20acc5c2014-08-11 14:48:46 -0700845func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700846 r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700847 n = uint32(r0)
848 if n == 0 {
849 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100850 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700851 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000852 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700853 }
854 }
855 return
856}
857
858func SetCurrentDirectory(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700859 r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700860 if r1 == 0 {
861 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100862 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700863 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000864 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700865 }
866 }
867 return
868}
869
870func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700871 r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700872 if r1 == 0 {
873 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100874 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700875 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000876 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700877 }
878 }
879 return
880}
881
882func RemoveDirectory(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700883 r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700884 if r1 == 0 {
885 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100886 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700887 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000888 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700889 }
890 }
891 return
892}
893
894func DeleteFile(path *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700895 r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700896 if r1 == 0 {
897 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100898 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700899 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000900 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700901 }
902 }
903 return
904}
905
906func MoveFile(from *uint16, to *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700907 r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700908 if r1 == 0 {
909 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100910 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700911 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000912 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700913 }
914 }
915 return
916}
917
Alex Brainman442cd602016-01-13 11:01:27 +1100918func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
919 r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
920 if r1 == 0 {
921 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100922 err = errnoErr(e1)
Alex Brainman442cd602016-01-13 11:01:27 +1100923 } else {
924 err = syscall.EINVAL
925 }
926 }
927 return
928}
929
Rob Pike20acc5c2014-08-11 14:48:46 -0700930func GetComputerName(buf *uint16, n *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700931 r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700932 if r1 == 0 {
933 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100934 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700935 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000936 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700937 }
938 }
939 return
940}
941
Carlos Castillo5b683252015-02-27 04:46:26 -0800942func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) {
943 r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
944 if r1 == 0 {
945 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100946 err = errnoErr(e1)
Carlos Castillo5b683252015-02-27 04:46:26 -0800947 } else {
948 err = syscall.EINVAL
949 }
950 }
951 return
952}
953
Rob Pike20acc5c2014-08-11 14:48:46 -0700954func SetEndOfFile(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -0700955 r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700956 if r1 == 0 {
957 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100958 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700959 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000960 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700961 }
962 }
963 return
964}
965
966func GetSystemTimeAsFileTime(time *Filetime) {
Rob Pike71181952014-08-13 14:08:39 -0700967 syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700968 return
969}
970
Tamir Duberstein39e3dc22017-04-05 13:01:15 -0400971func GetSystemTimePreciseAsFileTime(time *Filetime) {
972 syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
973 return
974}
975
Rob Pike20acc5c2014-08-11 14:48:46 -0700976func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700977 r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700978 rc = uint32(r0)
979 if rc == 0xffffffff {
980 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100981 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700982 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000983 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700984 }
985 }
986 return
987}
988
989func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -0700990 r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -0700991 handle = Handle(r0)
992 if handle == 0 {
993 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +1100994 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -0700995 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +1000996 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -0700997 }
998 }
999 return
1000}
1001
1002func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001003 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 -07001004 if r1 == 0 {
1005 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001006 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001007 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001008 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001009 }
1010 }
1011 return
1012}
1013
1014func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001015 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 -07001016 if r1 == 0 {
1017 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001018 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001019 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001020 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001021 }
1022 }
1023 return
1024}
1025
1026func CancelIo(s Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001027 r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001028 if r1 == 0 {
1029 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001030 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001031 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001032 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001033 }
1034 }
1035 return
1036}
1037
1038func CancelIoEx(s Handle, o *Overlapped) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001039 r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001040 if r1 == 0 {
1041 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001042 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001043 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001044 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001045 }
1046 }
1047 return
1048}
1049
1050func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
1051 var _p0 uint32
1052 if inheritHandles {
1053 _p0 = 1
1054 } else {
1055 _p0 = 0
1056 }
Rob Pike71181952014-08-13 14:08:39 -07001057 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 -07001058 if r1 == 0 {
1059 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001060 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001061 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001062 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001063 }
1064 }
1065 return
1066}
1067
1068func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
1069 var _p0 uint32
1070 if inheritHandle {
1071 _p0 = 1
1072 } else {
1073 _p0 = 0
1074 }
Rob Pike71181952014-08-13 14:08:39 -07001075 r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
Rob Pike20acc5c2014-08-11 14:48:46 -07001076 handle = Handle(r0)
1077 if handle == 0 {
1078 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001079 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001080 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001081 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001082 }
1083 }
1084 return
1085}
1086
Jason A. Donenfeld56c252d2019-05-25 15:17:43 +02001087func ShellExecute(hwnd Handle, verb *uint16, file *uint16, args *uint16, cwd *uint16, showCmd int32) (err error) {
1088 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))
1089 if r1 == 0 {
1090 if e1 != 0 {
1091 err = errnoErr(e1)
1092 } else {
1093 err = syscall.EINVAL
1094 }
1095 }
1096 return
1097}
1098
Rob Pike20acc5c2014-08-11 14:48:46 -07001099func TerminateProcess(handle Handle, exitcode uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001100 r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001101 if r1 == 0 {
1102 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001103 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001104 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001105 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001106 }
1107 }
1108 return
1109}
1110
1111func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001112 r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001113 if r1 == 0 {
1114 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001115 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001116 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001117 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001118 }
1119 }
1120 return
1121}
1122
1123func GetStartupInfo(startupInfo *StartupInfo) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001124 r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001125 if r1 == 0 {
1126 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001127 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001128 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001129 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001130 }
1131 }
1132 return
1133}
1134
1135func GetCurrentProcess() (pseudoHandle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001136 r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001137 pseudoHandle = Handle(r0)
1138 if pseudoHandle == 0 {
1139 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001140 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001141 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001142 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001143 }
1144 }
1145 return
1146}
1147
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02001148func GetCurrentThread() (pseudoHandle Handle, err error) {
1149 r0, _, e1 := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0)
1150 pseudoHandle = Handle(r0)
1151 if pseudoHandle == 0 {
1152 if e1 != 0 {
1153 err = errnoErr(e1)
1154 } else {
1155 err = syscall.EINVAL
1156 }
1157 }
1158 return
1159}
1160
Rob Pike20acc5c2014-08-11 14:48:46 -07001161func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001162 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 -07001163 if r1 == 0 {
1164 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001165 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001166 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001167 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001168 }
1169 }
1170 return
1171}
1172
1173func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
1174 var _p0 uint32
1175 if bInheritHandle {
1176 _p0 = 1
1177 } else {
1178 _p0 = 0
1179 }
Rob Pike71181952014-08-13 14:08:39 -07001180 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 -07001181 if r1 == 0 {
1182 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001183 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001184 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001185 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001186 }
1187 }
1188 return
1189}
1190
1191func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001192 r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001193 event = uint32(r0)
1194 if event == 0xffffffff {
1195 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001196 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001197 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001198 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001199 }
1200 }
1201 return
1202}
1203
Jason A. Donenfeld980327f2019-02-03 02:44:23 +01001204func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) {
1205 var _p0 uint32
1206 if waitAll {
1207 _p0 = 1
1208 } else {
1209 _p0 = 0
1210 }
1211 r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0)
1212 event = uint32(r0)
1213 if event == 0xffffffff {
1214 if e1 != 0 {
1215 err = errnoErr(e1)
1216 } else {
1217 err = syscall.EINVAL
1218 }
1219 }
1220 return
1221}
1222
Rob Pike20acc5c2014-08-11 14:48:46 -07001223func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001224 r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001225 n = uint32(r0)
1226 if n == 0 {
1227 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001228 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001229 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001230 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001231 }
1232 }
1233 return
1234}
1235
1236func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001237 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 -07001238 if r1 == 0 {
1239 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001240 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001241 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001242 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001243 }
1244 }
1245 return
1246}
1247
1248func GetFileType(filehandle Handle) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001249 r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001250 n = uint32(r0)
1251 if n == 0 {
1252 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001253 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001254 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001255 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001256 }
1257 }
1258 return
1259}
1260
1261func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001262 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 -07001263 if r1 == 0 {
1264 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001265 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001266 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001267 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001268 }
1269 }
1270 return
1271}
1272
1273func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001274 r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001275 if r1 == 0 {
1276 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001277 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001278 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001279 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001280 }
1281 }
1282 return
1283}
1284
1285func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001286 r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001287 if r1 == 0 {
1288 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001289 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001290 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001291 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001292 }
1293 }
1294 return
1295}
1296
1297func GetEnvironmentStrings() (envs *uint16, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001298 r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001299 envs = (*uint16)(unsafe.Pointer(r0))
1300 if envs == nil {
1301 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001302 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001303 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001304 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001305 }
1306 }
1307 return
1308}
1309
1310func FreeEnvironmentStrings(envs *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001311 r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001312 if r1 == 0 {
1313 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001314 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001315 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001316 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001317 }
1318 }
1319 return
1320}
1321
1322func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001323 r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
Rob Pike20acc5c2014-08-11 14:48:46 -07001324 n = uint32(r0)
1325 if n == 0 {
1326 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001327 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001328 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001329 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001330 }
1331 }
1332 return
1333}
1334
1335func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001336 r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001337 if r1 == 0 {
1338 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001339 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001340 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001341 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001342 }
1343 }
1344 return
1345}
1346
Jason A. Donenfeld06a5c492019-05-12 16:41:16 +02001347func CreateEnvironmentBlock(block **uint16, token Token, inheritExisting bool) (err error) {
1348 var _p0 uint32
1349 if inheritExisting {
1350 _p0 = 1
1351 } else {
1352 _p0 = 0
1353 }
1354 r1, _, e1 := syscall.Syscall(procCreateEnvironmentBlock.Addr(), 3, uintptr(unsafe.Pointer(block)), uintptr(token), uintptr(_p0))
1355 if r1 == 0 {
1356 if e1 != 0 {
1357 err = errnoErr(e1)
1358 } else {
1359 err = syscall.EINVAL
1360 }
1361 }
1362 return
1363}
1364
1365func DestroyEnvironmentBlock(block *uint16) (err error) {
1366 r1, _, e1 := syscall.Syscall(procDestroyEnvironmentBlock.Addr(), 1, uintptr(unsafe.Pointer(block)), 0, 0)
1367 if r1 == 0 {
1368 if e1 != 0 {
1369 err = errnoErr(e1)
1370 } else {
1371 err = syscall.EINVAL
1372 }
1373 }
1374 return
1375}
1376
Jason A. Donenfeld5da28582019-06-06 15:35:02 +02001377func getTickCount64() (ms uint64) {
1378 r0, _, _ := syscall.Syscall(procGetTickCount64.Addr(), 0, 0, 0, 0)
1379 ms = uint64(r0)
1380 return
1381}
1382
Rob Pike20acc5c2014-08-11 14:48:46 -07001383func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001384 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 -07001385 if r1 == 0 {
1386 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001387 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001388 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001389 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001390 }
1391 }
1392 return
1393}
1394
1395func GetFileAttributes(name *uint16) (attrs uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001396 r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001397 attrs = uint32(r0)
1398 if attrs == INVALID_FILE_ATTRIBUTES {
1399 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001400 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001401 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001402 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001403 }
1404 }
1405 return
1406}
1407
1408func SetFileAttributes(name *uint16, attrs uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001409 r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001410 if r1 == 0 {
1411 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001412 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001413 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001414 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001415 }
1416 }
1417 return
1418}
1419
1420func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001421 r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
Rob Pike20acc5c2014-08-11 14:48:46 -07001422 if r1 == 0 {
1423 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001424 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001425 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001426 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001427 }
1428 }
1429 return
1430}
1431
1432func GetCommandLine() (cmd *uint16) {
Rob Pike71181952014-08-13 14:08:39 -07001433 r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001434 cmd = (*uint16)(unsafe.Pointer(r0))
1435 return
1436}
1437
1438func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001439 r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001440 argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
1441 if argv == nil {
1442 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001443 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001444 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001445 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001446 }
1447 }
1448 return
1449}
1450
1451func LocalFree(hmem Handle) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001452 r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001453 handle = Handle(r0)
1454 if handle != 0 {
1455 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001456 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001457 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001458 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001459 }
1460 }
1461 return
1462}
1463
1464func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001465 r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
Rob Pike20acc5c2014-08-11 14:48:46 -07001466 if r1 == 0 {
1467 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001468 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001469 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001470 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001471 }
1472 }
1473 return
1474}
1475
1476func FlushFileBuffers(handle Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001477 r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001478 if r1 == 0 {
1479 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001480 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001481 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001482 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001483 }
1484 }
1485 return
1486}
1487
1488func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001489 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 -07001490 n = uint32(r0)
1491 if n == 0 {
1492 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001493 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001494 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001495 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001496 }
1497 }
1498 return
1499}
1500
1501func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001502 r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001503 n = uint32(r0)
1504 if n == 0 {
1505 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001506 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001507 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001508 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001509 }
1510 }
1511 return
1512}
1513
1514func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001515 r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001516 n = uint32(r0)
1517 if n == 0 {
1518 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001519 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001520 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001521 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001522 }
1523 }
1524 return
1525}
1526
1527func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001528 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 -07001529 handle = Handle(r0)
1530 if handle == 0 {
1531 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001532 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001533 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001534 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001535 }
1536 }
1537 return
1538}
1539
1540func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001541 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 -07001542 addr = uintptr(r0)
1543 if addr == 0 {
1544 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001545 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001546 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001547 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001548 }
1549 }
1550 return
1551}
1552
1553func UnmapViewOfFile(addr uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001554 r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001555 if r1 == 0 {
1556 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001557 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001558 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001559 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001560 }
1561 }
1562 return
1563}
1564
1565func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001566 r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001567 if r1 == 0 {
1568 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001569 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001570 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001571 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001572 }
1573 }
1574 return
1575}
1576
1577func VirtualLock(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001578 r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001579 if r1 == 0 {
1580 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001581 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001582 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001583 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001584 }
1585 }
1586 return
1587}
1588
1589func VirtualUnlock(addr uintptr, length uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001590 r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001591 if r1 == 0 {
1592 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001593 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001594 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001595 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001596 }
1597 }
1598 return
1599}
1600
Awnd18155c2017-07-01 07:14:08 +01001601func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) {
1602 r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0)
1603 value = uintptr(r0)
1604 if value == 0 {
1605 if e1 != 0 {
1606 err = errnoErr(e1)
1607 } else {
1608 err = syscall.EINVAL
1609 }
1610 }
1611 return
1612}
1613
1614func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) {
1615 r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype))
1616 if r1 == 0 {
1617 if e1 != 0 {
1618 err = errnoErr(e1)
1619 } else {
1620 err = syscall.EINVAL
1621 }
1622 }
1623 return
1624}
1625
1626func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) {
1627 r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0)
1628 if r1 == 0 {
1629 if e1 != 0 {
1630 err = errnoErr(e1)
1631 } else {
1632 err = syscall.EINVAL
1633 }
1634 }
1635 return
1636}
1637
Rob Pike20acc5c2014-08-11 14:48:46 -07001638func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001639 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 -07001640 if r1 == 0 {
1641 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001642 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001643 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001644 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001645 }
1646 }
1647 return
1648}
1649
1650func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
1651 var _p0 uint32
1652 if watchSubTree {
1653 _p0 = 1
1654 } else {
1655 _p0 = 0
1656 }
Rob Pike71181952014-08-13 14:08:39 -07001657 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 -07001658 if r1 == 0 {
1659 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001660 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001661 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001662 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001663 }
1664 }
1665 return
1666}
1667
1668func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001669 r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001670 store = Handle(r0)
1671 if store == 0 {
1672 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001673 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001674 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001675 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001676 }
1677 }
1678 return
1679}
1680
1681func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001682 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 -07001683 handle = Handle(r0)
1684 if handle == InvalidHandle {
1685 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001686 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001687 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001688 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001689 }
1690 }
1691 return
1692}
1693
1694func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001695 r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001696 context = (*CertContext)(unsafe.Pointer(r0))
1697 if context == nil {
1698 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001699 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001700 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001701 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001702 }
1703 }
1704 return
1705}
1706
1707func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001708 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 -07001709 if r1 == 0 {
1710 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001711 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001712 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001713 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001714 }
1715 }
1716 return
1717}
1718
1719func CertCloseStore(store Handle, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001720 r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001721 if r1 == 0 {
1722 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001723 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001724 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001725 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001726 }
1727 }
1728 return
1729}
1730
1731func 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 -07001732 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 -07001733 if r1 == 0 {
1734 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001735 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001736 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001737 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001738 }
1739 }
1740 return
1741}
1742
1743func CertFreeCertificateChain(ctx *CertChainContext) {
Rob Pike71181952014-08-13 14:08:39 -07001744 syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001745 return
1746}
1747
1748func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001749 r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
Rob Pike20acc5c2014-08-11 14:48:46 -07001750 context = (*CertContext)(unsafe.Pointer(r0))
1751 if context == nil {
1752 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001753 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001754 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001755 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001756 }
1757 }
1758 return
1759}
1760
1761func CertFreeCertificateContext(ctx *CertContext) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001762 r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001763 if r1 == 0 {
1764 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001765 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001766 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001767 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001768 }
1769 }
1770 return
1771}
1772
1773func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001774 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 -07001775 if r1 == 0 {
1776 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001777 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001778 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001779 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001780 }
1781 }
1782 return
1783}
1784
1785func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001786 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 -07001787 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001788 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001789 }
1790 return
1791}
1792
1793func RegCloseKey(key Handle) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001794 r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001795 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001796 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001797 }
1798 return
1799}
1800
1801func 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 -07001802 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 -07001803 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001804 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001805 }
1806 return
1807}
1808
1809func 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 -07001810 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 -07001811 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001812 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001813 }
1814 return
1815}
1816
1817func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
Rob Pike71181952014-08-13 14:08:39 -07001818 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 -07001819 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07001820 regerrno = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001821 }
1822 return
1823}
1824
1825func getCurrentProcessId() (pid uint32) {
Rob Pike71181952014-08-13 14:08:39 -07001826 r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001827 pid = uint32(r0)
1828 return
1829}
1830
1831func GetConsoleMode(console Handle, mode *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001832 r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001833 if r1 == 0 {
1834 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001835 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001836 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001837 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001838 }
1839 }
1840 return
1841}
1842
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +02001843func SetConsoleMode(console Handle, mode uint32) (err error) {
1844 r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0)
1845 if r1 == 0 {
1846 if e1 != 0 {
1847 err = errnoErr(e1)
1848 } else {
1849 err = syscall.EINVAL
1850 }
1851 }
1852 return
1853}
1854
1855func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) {
Tobias Klauser07c18292017-08-16 14:26:40 +02001856 r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0)
Tobias Klauserd6c3f2b2017-08-02 09:46:05 +02001857 if r1 == 0 {
1858 if e1 != 0 {
1859 err = errnoErr(e1)
1860 } else {
1861 err = syscall.EINVAL
1862 }
1863 }
1864 return
1865}
1866
Rob Pike20acc5c2014-08-11 14:48:46 -07001867func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001868 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 -07001869 if r1 == 0 {
1870 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001871 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001872 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001873 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001874 }
1875 }
1876 return
1877}
1878
1879func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001880 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 -07001881 if r1 == 0 {
1882 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001883 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001884 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001885 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001886 }
1887 }
1888 return
1889}
1890
1891func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07001892 r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001893 handle = Handle(r0)
1894 if handle == InvalidHandle {
1895 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001896 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001897 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001898 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001899 }
1900 }
1901 return
1902}
1903
1904func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001905 r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001906 if r1 == 0 {
1907 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001908 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001909 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001910 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001911 }
1912 }
1913 return
1914}
1915
1916func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001917 r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07001918 if r1 == 0 {
1919 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001920 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001921 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001922 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001923 }
1924 }
1925 return
1926}
1927
1928func 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 -07001929 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 -07001930 if r1 == 0 {
1931 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001932 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001933 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001934 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001935 }
1936 }
1937 return
1938}
1939
1940func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001941 r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
Rob Pike20acc5c2014-08-11 14:48:46 -07001942 if r1&0xff == 0 {
1943 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001944 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001945 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001946 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001947 }
1948 }
1949 return
1950}
1951
1952func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07001953 r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
Rob Pike20acc5c2014-08-11 14:48:46 -07001954 if r1&0xff == 0 {
1955 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001956 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07001957 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10001958 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07001959 }
1960 }
1961 return
1962}
1963
Alex Brainman65705ef2015-04-17 16:35:40 +10001964func GetCurrentThreadId() (id uint32) {
1965 r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
1966 id = uint32(r0)
1967 return
1968}
1969
Tobias Klauser07c18292017-08-16 14:26:40 +02001970func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) {
Alex Brainman65705ef2015-04-17 16:35:40 +10001971 r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
1972 handle = Handle(r0)
1973 if handle == 0 {
1974 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11001975 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10001976 } else {
1977 err = syscall.EINVAL
1978 }
1979 }
1980 return
1981}
1982
Tobias Klauser07c18292017-08-16 14:26:40 +02001983func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) {
1984 r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0)
1985 handle = Handle(r0)
1986 if handle == 0 {
1987 if e1 != 0 {
1988 err = errnoErr(e1)
1989 } else {
1990 err = syscall.EINVAL
1991 }
1992 }
1993 return
1994}
1995
1996func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) {
1997 var _p0 uint32
1998 if inheritHandle {
1999 _p0 = 1
2000 } else {
2001 _p0 = 0
2002 }
2003 r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name)))
2004 handle = Handle(r0)
2005 if handle == 0 {
2006 if e1 != 0 {
2007 err = errnoErr(e1)
2008 } else {
2009 err = syscall.EINVAL
2010 }
2011 }
2012 return
2013}
2014
Alex Brainman65705ef2015-04-17 16:35:40 +10002015func SetEvent(event Handle) (err error) {
2016 r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0)
2017 if r1 == 0 {
2018 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002019 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002020 } else {
2021 err = syscall.EINVAL
2022 }
2023 }
2024 return
2025}
2026
Tobias Klauser07c18292017-08-16 14:26:40 +02002027func ResetEvent(event Handle) (err error) {
2028 r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0)
2029 if r1 == 0 {
2030 if e1 != 0 {
2031 err = errnoErr(e1)
2032 } else {
2033 err = syscall.EINVAL
2034 }
2035 }
2036 return
2037}
2038
2039func PulseEvent(event Handle) (err error) {
2040 r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0)
2041 if r1 == 0 {
2042 if e1 != 0 {
2043 err = errnoErr(e1)
2044 } else {
2045 err = syscall.EINVAL
2046 }
2047 }
2048 return
2049}
2050
Jason A. Donenfeld24a5b222019-05-13 11:27:51 +02002051func SleepEx(milliseconds uint32, alertable bool) (ret uint32) {
2052 var _p0 uint32
2053 if alertable {
2054 _p0 = 1
2055 } else {
2056 _p0 = 0
2057 }
2058 r0, _, _ := syscall.Syscall(procSleepEx.Addr(), 2, uintptr(milliseconds), uintptr(_p0), 0)
2059 ret = uint32(r0)
2060 return
2061}
2062
Takuto Ikutac3d486d2019-05-24 21:41:07 +09002063func CreateJobObject(jobAttr *SecurityAttributes, name *uint16) (handle Handle, err error) {
2064 r0, _, e1 := syscall.Syscall(procCreateJobObjectW.Addr(), 2, uintptr(unsafe.Pointer(jobAttr)), uintptr(unsafe.Pointer(name)), 0)
2065 handle = Handle(r0)
2066 if handle == 0 {
2067 if e1 != 0 {
2068 err = errnoErr(e1)
2069 } else {
2070 err = syscall.EINVAL
2071 }
2072 }
2073 return
2074}
2075
2076func AssignProcessToJobObject(job Handle, process Handle) (err error) {
2077 r1, _, e1 := syscall.Syscall(procAssignProcessToJobObject.Addr(), 2, uintptr(job), uintptr(process), 0)
2078 if r1 == 0 {
2079 if e1 != 0 {
2080 err = errnoErr(e1)
2081 } else {
2082 err = syscall.EINVAL
2083 }
2084 }
2085 return
2086}
2087
2088func TerminateJobObject(job Handle, exitCode uint32) (err error) {
2089 r1, _, e1 := syscall.Syscall(procTerminateJobObject.Addr(), 2, uintptr(job), uintptr(exitCode), 0)
2090 if r1 == 0 {
2091 if e1 != 0 {
2092 err = errnoErr(e1)
2093 } else {
2094 err = syscall.EINVAL
2095 }
2096 }
2097 return
2098}
2099
Takuto Ikutae44a3b52019-05-24 19:23:22 +09002100func SetErrorMode(mode uint32) (ret uint32) {
2101 r0, _, _ := syscall.Syscall(procSetErrorMode.Addr(), 1, uintptr(mode), 0, 0)
2102 ret = uint32(r0)
2103 return
2104}
2105
Takuto Ikuta9cd64302019-05-27 14:19:46 +09002106func ResumeThread(thread Handle) (ret uint32, err error) {
2107 r0, _, e1 := syscall.Syscall(procResumeThread.Addr(), 1, uintptr(thread), 0, 0)
2108 ret = uint32(r0)
2109 if ret == 0xffffffff {
2110 if e1 != 0 {
2111 err = errnoErr(e1)
2112 } else {
2113 err = syscall.EINVAL
2114 }
2115 }
2116 return
2117}
2118
Takuto Ikuta854af272019-05-28 17:17:54 +09002119func SetPriorityClass(process Handle, priorityClass uint32) (err error) {
2120 r1, _, e1 := syscall.Syscall(procSetPriorityClass.Addr(), 2, uintptr(process), uintptr(priorityClass), 0)
2121 if r1 == 0 {
2122 if e1 != 0 {
2123 err = errnoErr(e1)
2124 } else {
2125 err = syscall.EINVAL
2126 }
2127 }
2128 return
2129}
2130
2131func GetPriorityClass(process Handle) (ret uint32, err error) {
2132 r0, _, e1 := syscall.Syscall(procGetPriorityClass.Addr(), 1, uintptr(process), 0, 0)
2133 ret = uint32(r0)
2134 if ret == 0 {
2135 if e1 != 0 {
2136 err = errnoErr(e1)
2137 } else {
2138 err = syscall.EINVAL
2139 }
2140 }
2141 return
2142}
2143
Takuto Ikutacc920272019-05-28 19:11:08 +09002144func SetInformationJobObject(job Handle, JobObjectInformationClass uint32, JobObjectInformation uintptr, JobObjectInformationLength uint32) (ret int, err error) {
2145 r0, _, e1 := syscall.Syscall6(procSetInformationJobObject.Addr(), 4, uintptr(job), uintptr(JobObjectInformationClass), uintptr(JobObjectInformation), uintptr(JobObjectInformationLength), 0, 0)
2146 ret = int(r0)
2147 if ret == 0 {
2148 if e1 != 0 {
2149 err = errnoErr(e1)
2150 } else {
2151 err = syscall.EINVAL
2152 }
2153 }
2154 return
2155}
2156
Takuto Ikuta95d888e2019-05-30 18:10:03 +09002157func GenerateConsoleCtrlEvent(ctrlEvent uint32, processGroupID uint32) (err error) {
2158 r1, _, e1 := syscall.Syscall(procGenerateConsoleCtrlEvent.Addr(), 2, uintptr(ctrlEvent), uintptr(processGroupID), 0)
2159 if r1 == 0 {
2160 if e1 != 0 {
2161 err = errnoErr(e1)
2162 } else {
2163 err = syscall.EINVAL
2164 }
2165 }
2166 return
2167}
2168
Scott Crunkleton0dd5e192017-11-15 23:26:13 -08002169func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) {
2170 r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)))
2171 if r1 == 0 {
2172 if e1 != 0 {
2173 err = errnoErr(e1)
2174 } else {
2175 err = syscall.EINVAL
2176 }
2177 }
2178 return
2179}
2180
2181func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) {
2182 r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0)
2183 if r1 == 0 {
2184 if e1 != 0 {
2185 err = errnoErr(e1)
2186 } else {
2187 err = syscall.EINVAL
2188 }
2189 }
2190 return
2191}
2192
2193func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) {
2194 r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0)
2195 handle = Handle(r0)
2196 if handle == InvalidHandle {
2197 if e1 != 0 {
2198 err = errnoErr(e1)
2199 } else {
2200 err = syscall.EINVAL
2201 }
2202 }
2203 return
2204}
2205
2206func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) {
2207 r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
2208 handle = Handle(r0)
2209 if handle == InvalidHandle {
2210 if e1 != 0 {
2211 err = errnoErr(e1)
2212 } else {
2213 err = syscall.EINVAL
2214 }
2215 }
2216 return
2217}
2218
2219func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) {
2220 r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength))
2221 if r1 == 0 {
2222 if e1 != 0 {
2223 err = errnoErr(e1)
2224 } else {
2225 err = syscall.EINVAL
2226 }
2227 }
2228 return
2229}
2230
2231func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) {
2232 r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength))
2233 if r1 == 0 {
2234 if e1 != 0 {
2235 err = errnoErr(e1)
2236 } else {
2237 err = syscall.EINVAL
2238 }
2239 }
2240 return
2241}
2242
2243func FindVolumeClose(findVolume Handle) (err error) {
2244 r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0)
2245 if r1 == 0 {
2246 if e1 != 0 {
2247 err = errnoErr(e1)
2248 } else {
2249 err = syscall.EINVAL
2250 }
2251 }
2252 return
2253}
2254
2255func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) {
2256 r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0)
2257 if r1 == 0 {
2258 if e1 != 0 {
2259 err = errnoErr(e1)
2260 } else {
2261 err = syscall.EINVAL
2262 }
2263 }
2264 return
2265}
2266
2267func GetDriveType(rootPathName *uint16) (driveType uint32) {
Brad Fitzpatrick0131e682017-12-13 20:31:17 +00002268 r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0)
Scott Crunkleton0dd5e192017-11-15 23:26:13 -08002269 driveType = uint32(r0)
2270 return
2271}
2272
2273func GetLogicalDrives() (drivesBitMask uint32, err error) {
2274 r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0)
2275 drivesBitMask = uint32(r0)
2276 if drivesBitMask == 0 {
2277 if e1 != 0 {
2278 err = errnoErr(e1)
2279 } else {
2280 err = syscall.EINVAL
2281 }
2282 }
2283 return
2284}
2285
2286func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) {
2287 r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0)
2288 n = uint32(r0)
2289 if n == 0 {
2290 if e1 != 0 {
2291 err = errnoErr(e1)
2292 } else {
2293 err = syscall.EINVAL
2294 }
2295 }
2296 return
2297}
2298
2299func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
2300 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)
2301 if r1 == 0 {
2302 if e1 != 0 {
2303 err = errnoErr(e1)
2304 } else {
2305 err = syscall.EINVAL
2306 }
2307 }
2308 return
2309}
2310
2311func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) {
2312 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)
2313 if r1 == 0 {
2314 if e1 != 0 {
2315 err = errnoErr(e1)
2316 } else {
2317 err = syscall.EINVAL
2318 }
2319 }
2320 return
2321}
2322
2323func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) {
2324 r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength))
2325 if r1 == 0 {
2326 if e1 != 0 {
2327 err = errnoErr(e1)
2328 } else {
2329 err = syscall.EINVAL
2330 }
2331 }
2332 return
2333}
2334
2335func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) {
2336 r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength))
2337 if r1 == 0 {
2338 if e1 != 0 {
2339 err = errnoErr(e1)
2340 } else {
2341 err = syscall.EINVAL
2342 }
2343 }
2344 return
2345}
2346
2347func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) {
2348 r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0)
2349 if r1 == 0 {
2350 if e1 != 0 {
2351 err = errnoErr(e1)
2352 } else {
2353 err = syscall.EINVAL
2354 }
2355 }
2356 return
2357}
2358
2359func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) {
2360 r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max))
2361 n = uint32(r0)
2362 if n == 0 {
2363 if e1 != 0 {
2364 err = errnoErr(e1)
2365 } else {
2366 err = syscall.EINVAL
2367 }
2368 }
2369 return
2370}
2371
2372func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) {
2373 r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0)
2374 if r1 == 0 {
2375 if e1 != 0 {
2376 err = errnoErr(e1)
2377 } else {
2378 err = syscall.EINVAL
2379 }
2380 }
2381 return
2382}
2383
2384func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) {
2385 r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0)
2386 if r1 == 0 {
2387 if e1 != 0 {
2388 err = errnoErr(e1)
2389 } else {
2390 err = syscall.EINVAL
2391 }
2392 }
2393 return
2394}
2395
Jason A. Donenfeldea4c4252019-05-25 15:27:23 +02002396func MessageBox(hwnd Handle, text *uint16, caption *uint16, boxtype uint32) (ret int32, err error) {
2397 r0, _, e1 := syscall.Syscall6(procMessageBoxW.Addr(), 4, uintptr(hwnd), uintptr(unsafe.Pointer(text)), uintptr(unsafe.Pointer(caption)), uintptr(boxtype), 0, 0)
2398 ret = int32(r0)
2399 if ret == 0 {
2400 if e1 != 0 {
2401 err = errnoErr(e1)
2402 } else {
2403 err = syscall.EINVAL
2404 }
2405 }
2406 return
2407}
2408
Rob Pike20acc5c2014-08-11 14:48:46 -07002409func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
Rob Pike71181952014-08-13 14:08:39 -07002410 r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002411 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002412 sockerr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002413 }
2414 return
2415}
2416
2417func WSACleanup() (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002418 r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002419 if r1 == socket_error {
2420 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002421 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002422 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002423 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002424 }
2425 }
2426 return
2427}
2428
2429func 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 -07002430 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 -07002431 if r1 == socket_error {
2432 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002433 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002434 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002435 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002436 }
2437 }
2438 return
2439}
2440
2441func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
Rob Pike71181952014-08-13 14:08:39 -07002442 r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
Rob Pike20acc5c2014-08-11 14:48:46 -07002443 handle = Handle(r0)
2444 if handle == InvalidHandle {
2445 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002446 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002447 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002448 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002449 }
2450 }
2451 return
2452}
2453
2454func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002455 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 -07002456 if r1 == socket_error {
2457 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002458 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002459 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002460 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002461 }
2462 }
2463 return
2464}
2465
2466func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002467 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 -07002468 if r1 == socket_error {
2469 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002470 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002471 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002472 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002473 }
2474 }
2475 return
2476}
2477
2478func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002479 r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Rob Pike20acc5c2014-08-11 14:48:46 -07002480 if r1 == socket_error {
2481 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002482 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002483 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002484 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002485 }
2486 }
2487 return
2488}
2489
2490func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002491 r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
Rob Pike20acc5c2014-08-11 14:48:46 -07002492 if r1 == socket_error {
2493 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002494 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002495 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002496 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002497 }
2498 }
2499 return
2500}
2501
2502func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002503 r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002504 if r1 == socket_error {
2505 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002506 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002507 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002508 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002509 }
2510 }
2511 return
2512}
2513
2514func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002515 r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002516 if r1 == socket_error {
2517 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002518 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002519 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002520 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002521 }
2522 }
2523 return
2524}
2525
2526func listen(s Handle, backlog int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002527 r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002528 if r1 == socket_error {
2529 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002530 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002531 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002532 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002533 }
2534 }
2535 return
2536}
2537
2538func shutdown(s Handle, how int32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002539 r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002540 if r1 == socket_error {
2541 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002542 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002543 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002544 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002545 }
2546 }
2547 return
2548}
2549
2550func Closesocket(s Handle) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002551 r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002552 if r1 == socket_error {
2553 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002554 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002555 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002556 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002557 }
2558 }
2559 return
2560}
2561
2562func 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 -07002563 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 -07002564 if r1 == 0 {
2565 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002566 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002567 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002568 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002569 }
2570 }
2571 return
2572}
2573
2574func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
Rob Pike71181952014-08-13 14:08:39 -07002575 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 -07002576 return
2577}
2578
2579func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002580 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 -07002581 if r1 == socket_error {
2582 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002583 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002584 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002585 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002586 }
2587 }
2588 return
2589}
2590
2591func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002592 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 -07002593 if r1 == socket_error {
2594 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002595 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002596 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002597 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002598 }
2599 }
2600 return
2601}
2602
2603func 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 -07002604 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 -07002605 if r1 == socket_error {
2606 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002607 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002608 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002609 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002610 }
2611 }
2612 return
2613}
2614
2615func 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 -07002616 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 -07002617 if r1 == socket_error {
2618 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002619 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002620 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002621 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002622 }
2623 }
2624 return
2625}
2626
2627func GetHostByName(name string) (h *Hostent, err error) {
2628 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002629 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002630 if err != nil {
2631 return
2632 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002633 return _GetHostByName(_p0)
2634}
2635
2636func _GetHostByName(name *byte) (h *Hostent, err error) {
2637 r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002638 h = (*Hostent)(unsafe.Pointer(r0))
2639 if h == nil {
2640 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002641 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002642 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002643 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002644 }
2645 }
2646 return
2647}
2648
2649func GetServByName(name string, proto string) (s *Servent, err error) {
2650 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002651 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002652 if err != nil {
2653 return
2654 }
2655 var _p1 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002656 _p1, err = syscall.BytePtrFromString(proto)
Rob Pike20acc5c2014-08-11 14:48:46 -07002657 if err != nil {
2658 return
2659 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002660 return _GetServByName(_p0, _p1)
2661}
2662
2663func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
2664 r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002665 s = (*Servent)(unsafe.Pointer(r0))
2666 if s == nil {
2667 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002668 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002669 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002670 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002671 }
2672 }
2673 return
2674}
2675
2676func Ntohs(netshort uint16) (u uint16) {
Rob Pike71181952014-08-13 14:08:39 -07002677 r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002678 u = uint16(r0)
2679 return
2680}
2681
2682func GetProtoByName(name string) (p *Protoent, err error) {
2683 var _p0 *byte
Alex Brainman7d091bf2014-08-19 15:20:17 +10002684 _p0, err = syscall.BytePtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002685 if err != nil {
2686 return
2687 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002688 return _GetProtoByName(_p0)
2689}
2690
2691func _GetProtoByName(name *byte) (p *Protoent, err error) {
2692 r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002693 p = (*Protoent)(unsafe.Pointer(r0))
2694 if p == nil {
2695 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002696 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002697 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002698 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002699 }
2700 }
2701 return
2702}
2703
2704func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
2705 var _p0 *uint16
Alex Brainman7d091bf2014-08-19 15:20:17 +10002706 _p0, status = syscall.UTF16PtrFromString(name)
Rob Pike20acc5c2014-08-11 14:48:46 -07002707 if status != nil {
2708 return
2709 }
Alex Brainmanc17938b2014-10-06 10:48:58 +11002710 return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
2711}
2712
2713func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
2714 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 -07002715 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002716 status = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002717 }
2718 return
2719}
2720
2721func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
Rob Pike71181952014-08-13 14:08:39 -07002722 syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002723 return
2724}
2725
Alex Brainmand1ee94c2014-08-20 12:25:19 +10002726func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
2727 r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
2728 same = r0 != 0
2729 return
2730}
2731
Rob Pike20acc5c2014-08-11 14:48:46 -07002732func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
Rob Pike71181952014-08-13 14:08:39 -07002733 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 -07002734 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002735 sockerr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002736 }
2737 return
2738}
2739
2740func FreeAddrInfoW(addrinfo *AddrinfoW) {
Rob Pike71181952014-08-13 14:08:39 -07002741 syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002742 return
2743}
2744
2745func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
Rob Pike71181952014-08-13 14:08:39 -07002746 r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002747 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002748 errcode = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002749 }
2750 return
2751}
2752
2753func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
Rob Pike71181952014-08-13 14:08:39 -07002754 r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002755 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002756 errcode = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002757 }
2758 return
2759}
2760
2761func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002762 r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002763 if r1 == 0 {
2764 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002765 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002766 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002767 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002768 }
2769 }
2770 return
2771}
2772
2773func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
Rob Pike71181952014-08-13 14:08:39 -07002774 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 -07002775 n = int32(r0)
2776 if n == -1 {
2777 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002778 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002779 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002780 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002781 }
2782 }
2783 return
2784}
2785
Alex Brainman442cd602016-01-13 11:01:27 +11002786func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
2787 r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
2788 if r0 != 0 {
2789 errcode = syscall.Errno(r0)
2790 }
2791 return
2792}
2793
2794func GetACP() (acp uint32) {
2795 r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
2796 acp = uint32(r0)
2797 return
2798}
2799
2800func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
2801 r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
2802 nwrite = int32(r0)
2803 if nwrite == 0 {
2804 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002805 err = errnoErr(e1)
Alex Brainman442cd602016-01-13 11:01:27 +11002806 } else {
2807 err = syscall.EINVAL
2808 }
2809 }
2810 return
2811}
2812
Rob Pike20acc5c2014-08-11 14:48:46 -07002813func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002814 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 -07002815 if r1&0xff == 0 {
2816 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002817 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002818 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002819 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002820 }
2821 }
2822 return
2823}
2824
2825func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002826 r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002827 if r1&0xff == 0 {
2828 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002829 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002830 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002831 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002832 }
2833 }
2834 return
2835}
2836
2837func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002838 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 -07002839 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002840 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002841 }
2842 return
2843}
2844
2845func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002846 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 -07002847 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002848 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002849 }
2850 return
2851}
2852
2853func NetApiBufferFree(buf *byte) (neterr error) {
Rob Pike71181952014-08-13 14:08:39 -07002854 r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002855 if r0 != 0 {
Rob Pike4faa3362014-08-14 10:28:19 -07002856 neterr = syscall.Errno(r0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002857 }
2858 return
2859}
2860
2861func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002862 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 -07002863 if r1 == 0 {
2864 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002865 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002866 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002867 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002868 }
2869 }
2870 return
2871}
2872
2873func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002874 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 -07002875 if r1 == 0 {
2876 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002877 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002878 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002879 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002880 }
2881 }
2882 return
2883}
2884
2885func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002886 r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002887 if r1 == 0 {
2888 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002889 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002890 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002891 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002892 }
2893 }
2894 return
2895}
2896
2897func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002898 r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002899 if r1 == 0 {
2900 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002901 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002902 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002903 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002904 }
2905 }
2906 return
2907}
2908
2909func GetLengthSid(sid *SID) (len uint32) {
Rob Pike71181952014-08-13 14:08:39 -07002910 r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
Rob Pike20acc5c2014-08-11 14:48:46 -07002911 len = uint32(r0)
2912 return
2913}
2914
2915func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07002916 r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
Rob Pike20acc5c2014-08-11 14:48:46 -07002917 if r1 == 0 {
2918 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002919 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07002920 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10002921 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07002922 }
2923 }
2924 return
2925}
2926
Alex Brainman65705ef2015-04-17 16:35:40 +10002927func 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) {
2928 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)
2929 if r1 == 0 {
2930 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002931 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002932 } else {
2933 err = syscall.EINVAL
2934 }
2935 }
2936 return
2937}
2938
Jason A. Donenfelda2f829d2019-03-13 03:55:42 -06002939func createWellKnownSid(sidType WELL_KNOWN_SID_TYPE, domainSid *SID, sid *SID, sizeSid *uint32) (err error) {
2940 r1, _, e1 := syscall.Syscall6(procCreateWellKnownSid.Addr(), 4, uintptr(sidType), uintptr(unsafe.Pointer(domainSid)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sizeSid)), 0, 0)
2941 if r1 == 0 {
2942 if e1 != 0 {
2943 err = errnoErr(e1)
2944 } else {
2945 err = syscall.EINVAL
2946 }
2947 }
2948 return
2949}
2950
Jason A. Donenfeld2219a012019-05-21 17:33:12 +02002951func isWellKnownSid(sid *SID, sidType WELL_KNOWN_SID_TYPE) (isWellKnown bool) {
2952 r0, _, _ := syscall.Syscall(procIsWellKnownSid.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(sidType), 0)
2953 isWellKnown = r0 != 0
2954 return
2955}
2956
Alex Brainman65705ef2015-04-17 16:35:40 +10002957func FreeSid(sid *SID) (err error) {
2958 r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2959 if r1 != 0 {
2960 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11002961 err = errnoErr(e1)
Alex Brainman65705ef2015-04-17 16:35:40 +10002962 } else {
2963 err = syscall.EINVAL
2964 }
2965 }
2966 return
2967}
2968
2969func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) {
2970 r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0)
2971 isEqual = r0 != 0
2972 return
2973}
2974
Jason A. Donenfeld2219a012019-05-21 17:33:12 +02002975func getSidIdentifierAuthority(sid *SID) (authority *SidIdentifierAuthority) {
2976 r0, _, _ := syscall.Syscall(procGetSidIdentifierAuthority.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2977 authority = (*SidIdentifierAuthority)(unsafe.Pointer(r0))
2978 return
2979}
2980
2981func getSidSubAuthorityCount(sid *SID) (count *uint8) {
2982 r0, _, _ := syscall.Syscall(procGetSidSubAuthorityCount.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2983 count = (*uint8)(unsafe.Pointer(r0))
2984 return
2985}
2986
2987func getSidSubAuthority(sid *SID, index uint32) (subAuthority *uint32) {
2988 r0, _, _ := syscall.Syscall(procGetSidSubAuthority.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(index), 0)
2989 subAuthority = (*uint32)(unsafe.Pointer(r0))
2990 return
2991}
2992
2993func isValidSid(sid *SID) (isValid bool) {
2994 r0, _, _ := syscall.Syscall(procIsValidSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
2995 isValid = r0 != 0
2996 return
2997}
2998
Scott Crunkleton1006bb32017-11-27 18:10:40 -08002999func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) {
3000 r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember)))
3001 if r1 == 0 {
3002 if e1 != 0 {
3003 err = errnoErr(e1)
3004 } else {
3005 err = syscall.EINVAL
3006 }
3007 }
3008 return
3009}
3010
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003011func OpenProcessToken(process Handle, access uint32, token *Token) (err error) {
3012 r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(process), uintptr(access), uintptr(unsafe.Pointer(token)))
Rob Pike20acc5c2014-08-11 14:48:46 -07003013 if r1 == 0 {
3014 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003015 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003016 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003017 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003018 }
3019 }
3020 return
3021}
3022
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003023func OpenThreadToken(thread Handle, access uint32, openAsSelf bool, token *Token) (err error) {
3024 var _p0 uint32
3025 if openAsSelf {
3026 _p0 = 1
3027 } else {
3028 _p0 = 0
3029 }
3030 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(access), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0)
3031 if r1 == 0 {
3032 if e1 != 0 {
3033 err = errnoErr(e1)
3034 } else {
3035 err = syscall.EINVAL
3036 }
3037 }
3038 return
3039}
3040
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003041func ImpersonateSelf(impersonationlevel uint32) (err error) {
3042 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(impersonationlevel), 0, 0)
3043 if r1 == 0 {
3044 if e1 != 0 {
3045 err = errnoErr(e1)
3046 } else {
3047 err = syscall.EINVAL
3048 }
3049 }
3050 return
3051}
3052
3053func RevertToSelf() (err error) {
3054 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 0)
3055 if r1 == 0 {
3056 if e1 != 0 {
3057 err = errnoErr(e1)
3058 } else {
3059 err = syscall.EINVAL
3060 }
3061 }
3062 return
3063}
3064
3065func SetThreadToken(thread *Handle, token Token) (err error) {
3066 r1, _, e1 := syscall.Syscall(procSetThreadToken.Addr(), 2, uintptr(unsafe.Pointer(thread)), uintptr(token), 0)
3067 if r1 == 0 {
3068 if e1 != 0 {
3069 err = errnoErr(e1)
3070 } else {
3071 err = syscall.EINVAL
3072 }
3073 }
3074 return
3075}
3076
3077func LookupPrivilegeValue(systemname *uint16, name *uint16, luid *LUID) (err error) {
3078 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemname)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid)))
3079 if r1 == 0 {
3080 if e1 != 0 {
3081 err = errnoErr(e1)
3082 } else {
3083 err = syscall.EINVAL
3084 }
3085 }
3086 return
3087}
3088
3089func AdjustTokenPrivileges(token Token, disableAllPrivileges bool, newstate *Tokenprivileges, buflen uint32, prevstate *Tokenprivileges, returnlen *uint32) (err error) {
3090 var _p0 uint32
3091 if disableAllPrivileges {
3092 _p0 = 1
3093 } else {
3094 _p0 = 0
3095 }
3096 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)))
3097 if r1 == 0 {
3098 if e1 != 0 {
3099 err = errnoErr(e1)
3100 } else {
3101 err = syscall.EINVAL
3102 }
3103 }
3104 return
3105}
3106
Jason A. Donenfeldcedb8e12019-05-15 13:59:33 +02003107func AdjustTokenGroups(token Token, resetToDefault bool, newstate *Tokengroups, buflen uint32, prevstate *Tokengroups, returnlen *uint32) (err error) {
3108 var _p0 uint32
3109 if resetToDefault {
3110 _p0 = 1
3111 } else {
3112 _p0 = 0
3113 }
3114 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)))
3115 if r1 == 0 {
3116 if e1 != 0 {
3117 err = errnoErr(e1)
3118 } else {
3119 err = syscall.EINVAL
3120 }
3121 }
3122 return
3123}
3124
Jason A. Donenfeld3a4b5fb2019-05-13 11:46:50 +02003125func GetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
3126 r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
3127 if r1 == 0 {
3128 if e1 != 0 {
3129 err = errnoErr(e1)
3130 } else {
3131 err = syscall.EINVAL
3132 }
3133 }
3134 return
3135}
3136
3137func SetTokenInformation(token Token, infoClass uint32, info *byte, infoLen uint32) (err error) {
3138 r1, _, e1 := syscall.Syscall6(procSetTokenInformation.Addr(), 4, uintptr(token), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), 0, 0)
3139 if r1 == 0 {
3140 if e1 != 0 {
3141 err = errnoErr(e1)
3142 } else {
3143 err = syscall.EINVAL
3144 }
3145 }
3146 return
3147}
3148
3149func DuplicateTokenEx(existingToken Token, desiredAccess uint32, tokenAttributes *SecurityAttributes, impersonationLevel uint32, tokenType uint32, newToken *Token) (err error) {
3150 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 -07003151 if r1 == 0 {
3152 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003153 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003154 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003155 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003156 }
3157 }
3158 return
3159}
3160
3161func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
Rob Pike71181952014-08-13 14:08:39 -07003162 r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
Rob Pike20acc5c2014-08-11 14:48:46 -07003163 if r1 == 0 {
3164 if e1 != 0 {
Alex Brainmanca83bd22016-12-02 16:54:46 +11003165 err = errnoErr(e1)
Rob Pike20acc5c2014-08-11 14:48:46 -07003166 } else {
Alex Brainman70c4b522014-08-15 13:37:15 +10003167 err = syscall.EINVAL
Rob Pike20acc5c2014-08-11 14:48:46 -07003168 }
3169 }
3170 return
3171}
Jason A. Donenfeld10058d72019-03-06 18:49:41 +01003172
3173func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) {
3174 r0, _, e1 := syscall.Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0)
3175 len = uint32(r0)
3176 if len == 0 {
3177 if e1 != 0 {
3178 err = errnoErr(e1)
3179 } else {
3180 err = syscall.EINVAL
3181 }
3182 }
3183 return
3184}
Jason A. Donenfeldf91f9b32019-05-13 10:42:08 +02003185
3186func WTSQueryUserToken(session uint32, token *Token) (err error) {
3187 r1, _, e1 := syscall.Syscall(procWTSQueryUserToken.Addr(), 2, uintptr(session), uintptr(unsafe.Pointer(token)), 0)
3188 if r1 == 0 {
3189 if e1 != 0 {
3190 err = errnoErr(e1)
3191 } else {
3192 err = syscall.EINVAL
3193 }
3194 }
3195 return
3196}
3197
3198func WTSEnumerateSessions(handle Handle, reserved uint32, version uint32, sessions **WTS_SESSION_INFO, count *uint32) (err error) {
3199 r1, _, e1 := syscall.Syscall6(procWTSEnumerateSessionsW.Addr(), 5, uintptr(handle), uintptr(reserved), uintptr(version), uintptr(unsafe.Pointer(sessions)), uintptr(unsafe.Pointer(count)), 0)
3200 if r1 == 0 {
3201 if e1 != 0 {
3202 err = errnoErr(e1)
3203 } else {
3204 err = syscall.EINVAL
3205 }
3206 }
3207 return
3208}
3209
3210func WTSFreeMemory(ptr uintptr) {
3211 syscall.Syscall(procWTSFreeMemory.Addr(), 1, uintptr(ptr), 0, 0)
3212 return
3213}