zsyscall_windows.go 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276
  1. // MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT
  2. package windows
  3. import (
  4. "syscall"
  5. "unsafe"
  6. )
  7. var _ unsafe.Pointer
  8. // Do the interface allocations only once for common
  9. // Errno values.
  10. const (
  11. errnoERROR_IO_PENDING = 997
  12. )
  13. var (
  14. errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
  15. )
  16. // errnoErr returns common boxed Errno values, to prevent
  17. // allocations at runtime.
  18. func errnoErr(e syscall.Errno) error {
  19. switch e {
  20. case 0:
  21. return nil
  22. case errnoERROR_IO_PENDING:
  23. return errERROR_IO_PENDING
  24. }
  25. // TODO: add more here, after collecting data on the common
  26. // error values see on Windows. (perhaps when running
  27. // all.bat?)
  28. return e
  29. }
  30. var (
  31. modadvapi32 = NewLazySystemDLL("advapi32.dll")
  32. modkernel32 = NewLazySystemDLL("kernel32.dll")
  33. modshell32 = NewLazySystemDLL("shell32.dll")
  34. modmswsock = NewLazySystemDLL("mswsock.dll")
  35. modcrypt32 = NewLazySystemDLL("crypt32.dll")
  36. modws2_32 = NewLazySystemDLL("ws2_32.dll")
  37. moddnsapi = NewLazySystemDLL("dnsapi.dll")
  38. modiphlpapi = NewLazySystemDLL("iphlpapi.dll")
  39. modsecur32 = NewLazySystemDLL("secur32.dll")
  40. modnetapi32 = NewLazySystemDLL("netapi32.dll")
  41. moduserenv = NewLazySystemDLL("userenv.dll")
  42. procRegisterEventSourceW = modadvapi32.NewProc("RegisterEventSourceW")
  43. procDeregisterEventSource = modadvapi32.NewProc("DeregisterEventSource")
  44. procReportEventW = modadvapi32.NewProc("ReportEventW")
  45. procOpenSCManagerW = modadvapi32.NewProc("OpenSCManagerW")
  46. procCloseServiceHandle = modadvapi32.NewProc("CloseServiceHandle")
  47. procCreateServiceW = modadvapi32.NewProc("CreateServiceW")
  48. procOpenServiceW = modadvapi32.NewProc("OpenServiceW")
  49. procDeleteService = modadvapi32.NewProc("DeleteService")
  50. procStartServiceW = modadvapi32.NewProc("StartServiceW")
  51. procQueryServiceStatus = modadvapi32.NewProc("QueryServiceStatus")
  52. procControlService = modadvapi32.NewProc("ControlService")
  53. procStartServiceCtrlDispatcherW = modadvapi32.NewProc("StartServiceCtrlDispatcherW")
  54. procSetServiceStatus = modadvapi32.NewProc("SetServiceStatus")
  55. procChangeServiceConfigW = modadvapi32.NewProc("ChangeServiceConfigW")
  56. procQueryServiceConfigW = modadvapi32.NewProc("QueryServiceConfigW")
  57. procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W")
  58. procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W")
  59. procGetLastError = modkernel32.NewProc("GetLastError")
  60. procLoadLibraryW = modkernel32.NewProc("LoadLibraryW")
  61. procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW")
  62. procFreeLibrary = modkernel32.NewProc("FreeLibrary")
  63. procGetProcAddress = modkernel32.NewProc("GetProcAddress")
  64. procGetVersion = modkernel32.NewProc("GetVersion")
  65. procFormatMessageW = modkernel32.NewProc("FormatMessageW")
  66. procExitProcess = modkernel32.NewProc("ExitProcess")
  67. procCreateFileW = modkernel32.NewProc("CreateFileW")
  68. procReadFile = modkernel32.NewProc("ReadFile")
  69. procWriteFile = modkernel32.NewProc("WriteFile")
  70. procSetFilePointer = modkernel32.NewProc("SetFilePointer")
  71. procCloseHandle = modkernel32.NewProc("CloseHandle")
  72. procGetStdHandle = modkernel32.NewProc("GetStdHandle")
  73. procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
  74. procFindNextFileW = modkernel32.NewProc("FindNextFileW")
  75. procFindClose = modkernel32.NewProc("FindClose")
  76. procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
  77. procGetCurrentDirectoryW = modkernel32.NewProc("GetCurrentDirectoryW")
  78. procSetCurrentDirectoryW = modkernel32.NewProc("SetCurrentDirectoryW")
  79. procCreateDirectoryW = modkernel32.NewProc("CreateDirectoryW")
  80. procRemoveDirectoryW = modkernel32.NewProc("RemoveDirectoryW")
  81. procDeleteFileW = modkernel32.NewProc("DeleteFileW")
  82. procMoveFileW = modkernel32.NewProc("MoveFileW")
  83. procMoveFileExW = modkernel32.NewProc("MoveFileExW")
  84. procGetComputerNameW = modkernel32.NewProc("GetComputerNameW")
  85. procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
  86. procSetEndOfFile = modkernel32.NewProc("SetEndOfFile")
  87. procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
  88. procGetSystemTimePreciseAsFileTime = modkernel32.NewProc("GetSystemTimePreciseAsFileTime")
  89. procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation")
  90. procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort")
  91. procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
  92. procPostQueuedCompletionStatus = modkernel32.NewProc("PostQueuedCompletionStatus")
  93. procCancelIo = modkernel32.NewProc("CancelIo")
  94. procCancelIoEx = modkernel32.NewProc("CancelIoEx")
  95. procCreateProcessW = modkernel32.NewProc("CreateProcessW")
  96. procOpenProcess = modkernel32.NewProc("OpenProcess")
  97. procTerminateProcess = modkernel32.NewProc("TerminateProcess")
  98. procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
  99. procGetStartupInfoW = modkernel32.NewProc("GetStartupInfoW")
  100. procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
  101. procGetProcessTimes = modkernel32.NewProc("GetProcessTimes")
  102. procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
  103. procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject")
  104. procGetTempPathW = modkernel32.NewProc("GetTempPathW")
  105. procCreatePipe = modkernel32.NewProc("CreatePipe")
  106. procGetFileType = modkernel32.NewProc("GetFileType")
  107. procCryptAcquireContextW = modadvapi32.NewProc("CryptAcquireContextW")
  108. procCryptReleaseContext = modadvapi32.NewProc("CryptReleaseContext")
  109. procCryptGenRandom = modadvapi32.NewProc("CryptGenRandom")
  110. procGetEnvironmentStringsW = modkernel32.NewProc("GetEnvironmentStringsW")
  111. procFreeEnvironmentStringsW = modkernel32.NewProc("FreeEnvironmentStringsW")
  112. procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
  113. procSetEnvironmentVariableW = modkernel32.NewProc("SetEnvironmentVariableW")
  114. procSetFileTime = modkernel32.NewProc("SetFileTime")
  115. procGetFileAttributesW = modkernel32.NewProc("GetFileAttributesW")
  116. procSetFileAttributesW = modkernel32.NewProc("SetFileAttributesW")
  117. procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
  118. procGetCommandLineW = modkernel32.NewProc("GetCommandLineW")
  119. procCommandLineToArgvW = modshell32.NewProc("CommandLineToArgvW")
  120. procLocalFree = modkernel32.NewProc("LocalFree")
  121. procSetHandleInformation = modkernel32.NewProc("SetHandleInformation")
  122. procFlushFileBuffers = modkernel32.NewProc("FlushFileBuffers")
  123. procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
  124. procGetLongPathNameW = modkernel32.NewProc("GetLongPathNameW")
  125. procGetShortPathNameW = modkernel32.NewProc("GetShortPathNameW")
  126. procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
  127. procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
  128. procUnmapViewOfFile = modkernel32.NewProc("UnmapViewOfFile")
  129. procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile")
  130. procVirtualLock = modkernel32.NewProc("VirtualLock")
  131. procVirtualUnlock = modkernel32.NewProc("VirtualUnlock")
  132. procTransmitFile = modmswsock.NewProc("TransmitFile")
  133. procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW")
  134. procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW")
  135. procCertOpenStore = modcrypt32.NewProc("CertOpenStore")
  136. procCertEnumCertificatesInStore = modcrypt32.NewProc("CertEnumCertificatesInStore")
  137. procCertAddCertificateContextToStore = modcrypt32.NewProc("CertAddCertificateContextToStore")
  138. procCertCloseStore = modcrypt32.NewProc("CertCloseStore")
  139. procCertGetCertificateChain = modcrypt32.NewProc("CertGetCertificateChain")
  140. procCertFreeCertificateChain = modcrypt32.NewProc("CertFreeCertificateChain")
  141. procCertCreateCertificateContext = modcrypt32.NewProc("CertCreateCertificateContext")
  142. procCertFreeCertificateContext = modcrypt32.NewProc("CertFreeCertificateContext")
  143. procCertVerifyCertificateChainPolicy = modcrypt32.NewProc("CertVerifyCertificateChainPolicy")
  144. procRegOpenKeyExW = modadvapi32.NewProc("RegOpenKeyExW")
  145. procRegCloseKey = modadvapi32.NewProc("RegCloseKey")
  146. procRegQueryInfoKeyW = modadvapi32.NewProc("RegQueryInfoKeyW")
  147. procRegEnumKeyExW = modadvapi32.NewProc("RegEnumKeyExW")
  148. procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW")
  149. procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
  150. procGetConsoleMode = modkernel32.NewProc("GetConsoleMode")
  151. procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
  152. procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
  153. procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot")
  154. procProcess32FirstW = modkernel32.NewProc("Process32FirstW")
  155. procProcess32NextW = modkernel32.NewProc("Process32NextW")
  156. procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
  157. procCreateSymbolicLinkW = modkernel32.NewProc("CreateSymbolicLinkW")
  158. procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
  159. procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
  160. procCreateEventW = modkernel32.NewProc("CreateEventW")
  161. procSetEvent = modkernel32.NewProc("SetEvent")
  162. procWSAStartup = modws2_32.NewProc("WSAStartup")
  163. procWSACleanup = modws2_32.NewProc("WSACleanup")
  164. procWSAIoctl = modws2_32.NewProc("WSAIoctl")
  165. procsocket = modws2_32.NewProc("socket")
  166. procsetsockopt = modws2_32.NewProc("setsockopt")
  167. procgetsockopt = modws2_32.NewProc("getsockopt")
  168. procbind = modws2_32.NewProc("bind")
  169. procconnect = modws2_32.NewProc("connect")
  170. procgetsockname = modws2_32.NewProc("getsockname")
  171. procgetpeername = modws2_32.NewProc("getpeername")
  172. proclisten = modws2_32.NewProc("listen")
  173. procshutdown = modws2_32.NewProc("shutdown")
  174. procclosesocket = modws2_32.NewProc("closesocket")
  175. procAcceptEx = modmswsock.NewProc("AcceptEx")
  176. procGetAcceptExSockaddrs = modmswsock.NewProc("GetAcceptExSockaddrs")
  177. procWSARecv = modws2_32.NewProc("WSARecv")
  178. procWSASend = modws2_32.NewProc("WSASend")
  179. procWSARecvFrom = modws2_32.NewProc("WSARecvFrom")
  180. procWSASendTo = modws2_32.NewProc("WSASendTo")
  181. procgethostbyname = modws2_32.NewProc("gethostbyname")
  182. procgetservbyname = modws2_32.NewProc("getservbyname")
  183. procntohs = modws2_32.NewProc("ntohs")
  184. procgetprotobyname = modws2_32.NewProc("getprotobyname")
  185. procDnsQuery_W = moddnsapi.NewProc("DnsQuery_W")
  186. procDnsRecordListFree = moddnsapi.NewProc("DnsRecordListFree")
  187. procDnsNameCompare_W = moddnsapi.NewProc("DnsNameCompare_W")
  188. procGetAddrInfoW = modws2_32.NewProc("GetAddrInfoW")
  189. procFreeAddrInfoW = modws2_32.NewProc("FreeAddrInfoW")
  190. procGetIfEntry = modiphlpapi.NewProc("GetIfEntry")
  191. procGetAdaptersInfo = modiphlpapi.NewProc("GetAdaptersInfo")
  192. procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes")
  193. procWSAEnumProtocolsW = modws2_32.NewProc("WSAEnumProtocolsW")
  194. procGetAdaptersAddresses = modiphlpapi.NewProc("GetAdaptersAddresses")
  195. procGetACP = modkernel32.NewProc("GetACP")
  196. procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
  197. procTranslateNameW = modsecur32.NewProc("TranslateNameW")
  198. procGetUserNameExW = modsecur32.NewProc("GetUserNameExW")
  199. procNetUserGetInfo = modnetapi32.NewProc("NetUserGetInfo")
  200. procNetGetJoinInformation = modnetapi32.NewProc("NetGetJoinInformation")
  201. procNetApiBufferFree = modnetapi32.NewProc("NetApiBufferFree")
  202. procLookupAccountSidW = modadvapi32.NewProc("LookupAccountSidW")
  203. procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW")
  204. procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW")
  205. procConvertStringSidToSidW = modadvapi32.NewProc("ConvertStringSidToSidW")
  206. procGetLengthSid = modadvapi32.NewProc("GetLengthSid")
  207. procCopySid = modadvapi32.NewProc("CopySid")
  208. procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid")
  209. procFreeSid = modadvapi32.NewProc("FreeSid")
  210. procEqualSid = modadvapi32.NewProc("EqualSid")
  211. procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken")
  212. procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation")
  213. procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW")
  214. )
  215. func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) {
  216. r0, _, e1 := syscall.Syscall(procRegisterEventSourceW.Addr(), 2, uintptr(unsafe.Pointer(uncServerName)), uintptr(unsafe.Pointer(sourceName)), 0)
  217. handle = Handle(r0)
  218. if handle == 0 {
  219. if e1 != 0 {
  220. err = errnoErr(e1)
  221. } else {
  222. err = syscall.EINVAL
  223. }
  224. }
  225. return
  226. }
  227. func DeregisterEventSource(handle Handle) (err error) {
  228. r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0)
  229. if r1 == 0 {
  230. if e1 != 0 {
  231. err = errnoErr(e1)
  232. } else {
  233. err = syscall.EINVAL
  234. }
  235. }
  236. return
  237. }
  238. func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) {
  239. 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)))
  240. if r1 == 0 {
  241. if e1 != 0 {
  242. err = errnoErr(e1)
  243. } else {
  244. err = syscall.EINVAL
  245. }
  246. }
  247. return
  248. }
  249. func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle Handle, err error) {
  250. r0, _, e1 := syscall.Syscall(procOpenSCManagerW.Addr(), 3, uintptr(unsafe.Pointer(machineName)), uintptr(unsafe.Pointer(databaseName)), uintptr(access))
  251. handle = Handle(r0)
  252. if handle == 0 {
  253. if e1 != 0 {
  254. err = errnoErr(e1)
  255. } else {
  256. err = syscall.EINVAL
  257. }
  258. }
  259. return
  260. }
  261. func CloseServiceHandle(handle Handle) (err error) {
  262. r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0)
  263. if r1 == 0 {
  264. if e1 != 0 {
  265. err = errnoErr(e1)
  266. } else {
  267. err = syscall.EINVAL
  268. }
  269. }
  270. return
  271. }
  272. func 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) {
  273. 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)
  274. handle = Handle(r0)
  275. if handle == 0 {
  276. if e1 != 0 {
  277. err = errnoErr(e1)
  278. } else {
  279. err = syscall.EINVAL
  280. }
  281. }
  282. return
  283. }
  284. func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) {
  285. r0, _, e1 := syscall.Syscall(procOpenServiceW.Addr(), 3, uintptr(mgr), uintptr(unsafe.Pointer(serviceName)), uintptr(access))
  286. handle = Handle(r0)
  287. if handle == 0 {
  288. if e1 != 0 {
  289. err = errnoErr(e1)
  290. } else {
  291. err = syscall.EINVAL
  292. }
  293. }
  294. return
  295. }
  296. func DeleteService(service Handle) (err error) {
  297. r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0)
  298. if r1 == 0 {
  299. if e1 != 0 {
  300. err = errnoErr(e1)
  301. } else {
  302. err = syscall.EINVAL
  303. }
  304. }
  305. return
  306. }
  307. func StartService(service Handle, numArgs uint32, argVectors **uint16) (err error) {
  308. r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors)))
  309. if r1 == 0 {
  310. if e1 != 0 {
  311. err = errnoErr(e1)
  312. } else {
  313. err = syscall.EINVAL
  314. }
  315. }
  316. return
  317. }
  318. func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) {
  319. r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0)
  320. if r1 == 0 {
  321. if e1 != 0 {
  322. err = errnoErr(e1)
  323. } else {
  324. err = syscall.EINVAL
  325. }
  326. }
  327. return
  328. }
  329. func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err error) {
  330. r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status)))
  331. if r1 == 0 {
  332. if e1 != 0 {
  333. err = errnoErr(e1)
  334. } else {
  335. err = syscall.EINVAL
  336. }
  337. }
  338. return
  339. }
  340. func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) {
  341. r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0)
  342. if r1 == 0 {
  343. if e1 != 0 {
  344. err = errnoErr(e1)
  345. } else {
  346. err = syscall.EINVAL
  347. }
  348. }
  349. return
  350. }
  351. func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) {
  352. r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0)
  353. if r1 == 0 {
  354. if e1 != 0 {
  355. err = errnoErr(e1)
  356. } else {
  357. err = syscall.EINVAL
  358. }
  359. }
  360. return
  361. }
  362. func 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) {
  363. 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)
  364. if r1 == 0 {
  365. if e1 != 0 {
  366. err = errnoErr(e1)
  367. } else {
  368. err = syscall.EINVAL
  369. }
  370. }
  371. return
  372. }
  373. func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) {
  374. r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0)
  375. if r1 == 0 {
  376. if e1 != 0 {
  377. err = errnoErr(e1)
  378. } else {
  379. err = syscall.EINVAL
  380. }
  381. }
  382. return
  383. }
  384. func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) {
  385. r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info)))
  386. if r1 == 0 {
  387. if e1 != 0 {
  388. err = errnoErr(e1)
  389. } else {
  390. err = syscall.EINVAL
  391. }
  392. }
  393. return
  394. }
  395. func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) {
  396. r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0)
  397. if r1 == 0 {
  398. if e1 != 0 {
  399. err = errnoErr(e1)
  400. } else {
  401. err = syscall.EINVAL
  402. }
  403. }
  404. return
  405. }
  406. func GetLastError() (lasterr error) {
  407. r0, _, _ := syscall.Syscall(procGetLastError.Addr(), 0, 0, 0, 0)
  408. if r0 != 0 {
  409. lasterr = syscall.Errno(r0)
  410. }
  411. return
  412. }
  413. func LoadLibrary(libname string) (handle Handle, err error) {
  414. var _p0 *uint16
  415. _p0, err = syscall.UTF16PtrFromString(libname)
  416. if err != nil {
  417. return
  418. }
  419. return _LoadLibrary(_p0)
  420. }
  421. func _LoadLibrary(libname *uint16) (handle Handle, err error) {
  422. r0, _, e1 := syscall.Syscall(procLoadLibraryW.Addr(), 1, uintptr(unsafe.Pointer(libname)), 0, 0)
  423. handle = Handle(r0)
  424. if handle == 0 {
  425. if e1 != 0 {
  426. err = errnoErr(e1)
  427. } else {
  428. err = syscall.EINVAL
  429. }
  430. }
  431. return
  432. }
  433. func LoadLibraryEx(libname string, zero Handle, flags uintptr) (handle Handle, err error) {
  434. var _p0 *uint16
  435. _p0, err = syscall.UTF16PtrFromString(libname)
  436. if err != nil {
  437. return
  438. }
  439. return _LoadLibraryEx(_p0, zero, flags)
  440. }
  441. func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, err error) {
  442. r0, _, e1 := syscall.Syscall(procLoadLibraryExW.Addr(), 3, uintptr(unsafe.Pointer(libname)), uintptr(zero), uintptr(flags))
  443. handle = Handle(r0)
  444. if handle == 0 {
  445. if e1 != 0 {
  446. err = errnoErr(e1)
  447. } else {
  448. err = syscall.EINVAL
  449. }
  450. }
  451. return
  452. }
  453. func FreeLibrary(handle Handle) (err error) {
  454. r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0)
  455. if r1 == 0 {
  456. if e1 != 0 {
  457. err = errnoErr(e1)
  458. } else {
  459. err = syscall.EINVAL
  460. }
  461. }
  462. return
  463. }
  464. func GetProcAddress(module Handle, procname string) (proc uintptr, err error) {
  465. var _p0 *byte
  466. _p0, err = syscall.BytePtrFromString(procname)
  467. if err != nil {
  468. return
  469. }
  470. return _GetProcAddress(module, _p0)
  471. }
  472. func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) {
  473. r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), uintptr(unsafe.Pointer(procname)), 0)
  474. proc = uintptr(r0)
  475. if proc == 0 {
  476. if e1 != 0 {
  477. err = errnoErr(e1)
  478. } else {
  479. err = syscall.EINVAL
  480. }
  481. }
  482. return
  483. }
  484. func GetVersion() (ver uint32, err error) {
  485. r0, _, e1 := syscall.Syscall(procGetVersion.Addr(), 0, 0, 0, 0)
  486. ver = uint32(r0)
  487. if ver == 0 {
  488. if e1 != 0 {
  489. err = errnoErr(e1)
  490. } else {
  491. err = syscall.EINVAL
  492. }
  493. }
  494. return
  495. }
  496. func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, buf []uint16, args *byte) (n uint32, err error) {
  497. var _p0 *uint16
  498. if len(buf) > 0 {
  499. _p0 = &buf[0]
  500. }
  501. 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)
  502. n = uint32(r0)
  503. if n == 0 {
  504. if e1 != 0 {
  505. err = errnoErr(e1)
  506. } else {
  507. err = syscall.EINVAL
  508. }
  509. }
  510. return
  511. }
  512. func ExitProcess(exitcode uint32) {
  513. syscall.Syscall(procExitProcess.Addr(), 1, uintptr(exitcode), 0, 0)
  514. return
  515. }
  516. func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes, createmode uint32, attrs uint32, templatefile int32) (handle Handle, err error) {
  517. 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)
  518. handle = Handle(r0)
  519. if handle == InvalidHandle {
  520. if e1 != 0 {
  521. err = errnoErr(e1)
  522. } else {
  523. err = syscall.EINVAL
  524. }
  525. }
  526. return
  527. }
  528. func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
  529. var _p0 *byte
  530. if len(buf) > 0 {
  531. _p0 = &buf[0]
  532. }
  533. 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)
  534. if r1 == 0 {
  535. if e1 != 0 {
  536. err = errnoErr(e1)
  537. } else {
  538. err = syscall.EINVAL
  539. }
  540. }
  541. return
  542. }
  543. func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) {
  544. var _p0 *byte
  545. if len(buf) > 0 {
  546. _p0 = &buf[0]
  547. }
  548. 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)
  549. if r1 == 0 {
  550. if e1 != 0 {
  551. err = errnoErr(e1)
  552. } else {
  553. err = syscall.EINVAL
  554. }
  555. }
  556. return
  557. }
  558. func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) {
  559. r0, _, e1 := syscall.Syscall6(procSetFilePointer.Addr(), 4, uintptr(handle), uintptr(lowoffset), uintptr(unsafe.Pointer(highoffsetptr)), uintptr(whence), 0, 0)
  560. newlowoffset = uint32(r0)
  561. if newlowoffset == 0xffffffff {
  562. if e1 != 0 {
  563. err = errnoErr(e1)
  564. } else {
  565. err = syscall.EINVAL
  566. }
  567. }
  568. return
  569. }
  570. func CloseHandle(handle Handle) (err error) {
  571. r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0)
  572. if r1 == 0 {
  573. if e1 != 0 {
  574. err = errnoErr(e1)
  575. } else {
  576. err = syscall.EINVAL
  577. }
  578. }
  579. return
  580. }
  581. func GetStdHandle(stdhandle int) (handle Handle, err error) {
  582. r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0)
  583. handle = Handle(r0)
  584. if handle == InvalidHandle {
  585. if e1 != 0 {
  586. err = errnoErr(e1)
  587. } else {
  588. err = syscall.EINVAL
  589. }
  590. }
  591. return
  592. }
  593. func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) {
  594. r0, _, e1 := syscall.Syscall(procFindFirstFileW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(data)), 0)
  595. handle = Handle(r0)
  596. if handle == InvalidHandle {
  597. if e1 != 0 {
  598. err = errnoErr(e1)
  599. } else {
  600. err = syscall.EINVAL
  601. }
  602. }
  603. return
  604. }
  605. func findNextFile1(handle Handle, data *win32finddata1) (err error) {
  606. r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
  607. if r1 == 0 {
  608. if e1 != 0 {
  609. err = errnoErr(e1)
  610. } else {
  611. err = syscall.EINVAL
  612. }
  613. }
  614. return
  615. }
  616. func FindClose(handle Handle) (err error) {
  617. r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0)
  618. if r1 == 0 {
  619. if e1 != 0 {
  620. err = errnoErr(e1)
  621. } else {
  622. err = syscall.EINVAL
  623. }
  624. }
  625. return
  626. }
  627. func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (err error) {
  628. r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0)
  629. if r1 == 0 {
  630. if e1 != 0 {
  631. err = errnoErr(e1)
  632. } else {
  633. err = syscall.EINVAL
  634. }
  635. }
  636. return
  637. }
  638. func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) {
  639. r0, _, e1 := syscall.Syscall(procGetCurrentDirectoryW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
  640. n = uint32(r0)
  641. if n == 0 {
  642. if e1 != 0 {
  643. err = errnoErr(e1)
  644. } else {
  645. err = syscall.EINVAL
  646. }
  647. }
  648. return
  649. }
  650. func SetCurrentDirectory(path *uint16) (err error) {
  651. r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  652. if r1 == 0 {
  653. if e1 != 0 {
  654. err = errnoErr(e1)
  655. } else {
  656. err = syscall.EINVAL
  657. }
  658. }
  659. return
  660. }
  661. func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) {
  662. r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0)
  663. if r1 == 0 {
  664. if e1 != 0 {
  665. err = errnoErr(e1)
  666. } else {
  667. err = syscall.EINVAL
  668. }
  669. }
  670. return
  671. }
  672. func RemoveDirectory(path *uint16) (err error) {
  673. r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  674. if r1 == 0 {
  675. if e1 != 0 {
  676. err = errnoErr(e1)
  677. } else {
  678. err = syscall.EINVAL
  679. }
  680. }
  681. return
  682. }
  683. func DeleteFile(path *uint16) (err error) {
  684. r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0)
  685. if r1 == 0 {
  686. if e1 != 0 {
  687. err = errnoErr(e1)
  688. } else {
  689. err = syscall.EINVAL
  690. }
  691. }
  692. return
  693. }
  694. func MoveFile(from *uint16, to *uint16) (err error) {
  695. r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0)
  696. if r1 == 0 {
  697. if e1 != 0 {
  698. err = errnoErr(e1)
  699. } else {
  700. err = syscall.EINVAL
  701. }
  702. }
  703. return
  704. }
  705. func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) {
  706. r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags))
  707. if r1 == 0 {
  708. if e1 != 0 {
  709. err = errnoErr(e1)
  710. } else {
  711. err = syscall.EINVAL
  712. }
  713. }
  714. return
  715. }
  716. func GetComputerName(buf *uint16, n *uint32) (err error) {
  717. r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0)
  718. if r1 == 0 {
  719. if e1 != 0 {
  720. err = errnoErr(e1)
  721. } else {
  722. err = syscall.EINVAL
  723. }
  724. }
  725. return
  726. }
  727. func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) {
  728. r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)))
  729. if r1 == 0 {
  730. if e1 != 0 {
  731. err = errnoErr(e1)
  732. } else {
  733. err = syscall.EINVAL
  734. }
  735. }
  736. return
  737. }
  738. func SetEndOfFile(handle Handle) (err error) {
  739. r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0)
  740. if r1 == 0 {
  741. if e1 != 0 {
  742. err = errnoErr(e1)
  743. } else {
  744. err = syscall.EINVAL
  745. }
  746. }
  747. return
  748. }
  749. func GetSystemTimeAsFileTime(time *Filetime) {
  750. syscall.Syscall(procGetSystemTimeAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
  751. return
  752. }
  753. func GetSystemTimePreciseAsFileTime(time *Filetime) {
  754. syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0)
  755. return
  756. }
  757. func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) {
  758. r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0)
  759. rc = uint32(r0)
  760. if rc == 0xffffffff {
  761. if e1 != 0 {
  762. err = errnoErr(e1)
  763. } else {
  764. err = syscall.EINVAL
  765. }
  766. }
  767. return
  768. }
  769. func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) {
  770. r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(filehandle), uintptr(cphandle), uintptr(key), uintptr(threadcnt), 0, 0)
  771. handle = Handle(r0)
  772. if handle == 0 {
  773. if e1 != 0 {
  774. err = errnoErr(e1)
  775. } else {
  776. err = syscall.EINVAL
  777. }
  778. }
  779. return
  780. }
  781. func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) {
  782. r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
  783. if r1 == 0 {
  784. if e1 != 0 {
  785. err = errnoErr(e1)
  786. } else {
  787. err = syscall.EINVAL
  788. }
  789. }
  790. return
  791. }
  792. func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlapped *Overlapped) (err error) {
  793. r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0)
  794. if r1 == 0 {
  795. if e1 != 0 {
  796. err = errnoErr(e1)
  797. } else {
  798. err = syscall.EINVAL
  799. }
  800. }
  801. return
  802. }
  803. func CancelIo(s Handle) (err error) {
  804. r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0)
  805. if r1 == 0 {
  806. if e1 != 0 {
  807. err = errnoErr(e1)
  808. } else {
  809. err = syscall.EINVAL
  810. }
  811. }
  812. return
  813. }
  814. func CancelIoEx(s Handle, o *Overlapped) (err error) {
  815. r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0)
  816. if r1 == 0 {
  817. if e1 != 0 {
  818. err = errnoErr(e1)
  819. } else {
  820. err = syscall.EINVAL
  821. }
  822. }
  823. return
  824. }
  825. func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityAttributes, threadSecurity *SecurityAttributes, inheritHandles bool, creationFlags uint32, env *uint16, currentDir *uint16, startupInfo *StartupInfo, outProcInfo *ProcessInformation) (err error) {
  826. var _p0 uint32
  827. if inheritHandles {
  828. _p0 = 1
  829. } else {
  830. _p0 = 0
  831. }
  832. 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)
  833. if r1 == 0 {
  834. if e1 != 0 {
  835. err = errnoErr(e1)
  836. } else {
  837. err = syscall.EINVAL
  838. }
  839. }
  840. return
  841. }
  842. func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err error) {
  843. var _p0 uint32
  844. if inheritHandle {
  845. _p0 = 1
  846. } else {
  847. _p0 = 0
  848. }
  849. r0, _, e1 := syscall.Syscall(procOpenProcess.Addr(), 3, uintptr(da), uintptr(_p0), uintptr(pid))
  850. handle = Handle(r0)
  851. if handle == 0 {
  852. if e1 != 0 {
  853. err = errnoErr(e1)
  854. } else {
  855. err = syscall.EINVAL
  856. }
  857. }
  858. return
  859. }
  860. func TerminateProcess(handle Handle, exitcode uint32) (err error) {
  861. r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0)
  862. if r1 == 0 {
  863. if e1 != 0 {
  864. err = errnoErr(e1)
  865. } else {
  866. err = syscall.EINVAL
  867. }
  868. }
  869. return
  870. }
  871. func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) {
  872. r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0)
  873. if r1 == 0 {
  874. if e1 != 0 {
  875. err = errnoErr(e1)
  876. } else {
  877. err = syscall.EINVAL
  878. }
  879. }
  880. return
  881. }
  882. func GetStartupInfo(startupInfo *StartupInfo) (err error) {
  883. r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0)
  884. if r1 == 0 {
  885. if e1 != 0 {
  886. err = errnoErr(e1)
  887. } else {
  888. err = syscall.EINVAL
  889. }
  890. }
  891. return
  892. }
  893. func GetCurrentProcess() (pseudoHandle Handle, err error) {
  894. r0, _, e1 := syscall.Syscall(procGetCurrentProcess.Addr(), 0, 0, 0, 0)
  895. pseudoHandle = Handle(r0)
  896. if pseudoHandle == 0 {
  897. if e1 != 0 {
  898. err = errnoErr(e1)
  899. } else {
  900. err = syscall.EINVAL
  901. }
  902. }
  903. return
  904. }
  905. func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) {
  906. 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)
  907. if r1 == 0 {
  908. if e1 != 0 {
  909. err = errnoErr(e1)
  910. } else {
  911. err = syscall.EINVAL
  912. }
  913. }
  914. return
  915. }
  916. func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) {
  917. var _p0 uint32
  918. if bInheritHandle {
  919. _p0 = 1
  920. } else {
  921. _p0 = 0
  922. }
  923. 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)
  924. if r1 == 0 {
  925. if e1 != 0 {
  926. err = errnoErr(e1)
  927. } else {
  928. err = syscall.EINVAL
  929. }
  930. }
  931. return
  932. }
  933. func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) {
  934. r0, _, e1 := syscall.Syscall(procWaitForSingleObject.Addr(), 2, uintptr(handle), uintptr(waitMilliseconds), 0)
  935. event = uint32(r0)
  936. if event == 0xffffffff {
  937. if e1 != 0 {
  938. err = errnoErr(e1)
  939. } else {
  940. err = syscall.EINVAL
  941. }
  942. }
  943. return
  944. }
  945. func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) {
  946. r0, _, e1 := syscall.Syscall(procGetTempPathW.Addr(), 2, uintptr(buflen), uintptr(unsafe.Pointer(buf)), 0)
  947. n = uint32(r0)
  948. if n == 0 {
  949. if e1 != 0 {
  950. err = errnoErr(e1)
  951. } else {
  952. err = syscall.EINVAL
  953. }
  954. }
  955. return
  956. }
  957. func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) {
  958. r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0)
  959. if r1 == 0 {
  960. if e1 != 0 {
  961. err = errnoErr(e1)
  962. } else {
  963. err = syscall.EINVAL
  964. }
  965. }
  966. return
  967. }
  968. func GetFileType(filehandle Handle) (n uint32, err error) {
  969. r0, _, e1 := syscall.Syscall(procGetFileType.Addr(), 1, uintptr(filehandle), 0, 0)
  970. n = uint32(r0)
  971. if n == 0 {
  972. if e1 != 0 {
  973. err = errnoErr(e1)
  974. } else {
  975. err = syscall.EINVAL
  976. }
  977. }
  978. return
  979. }
  980. func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16, provtype uint32, flags uint32) (err error) {
  981. r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0)
  982. if r1 == 0 {
  983. if e1 != 0 {
  984. err = errnoErr(e1)
  985. } else {
  986. err = syscall.EINVAL
  987. }
  988. }
  989. return
  990. }
  991. func CryptReleaseContext(provhandle Handle, flags uint32) (err error) {
  992. r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0)
  993. if r1 == 0 {
  994. if e1 != 0 {
  995. err = errnoErr(e1)
  996. } else {
  997. err = syscall.EINVAL
  998. }
  999. }
  1000. return
  1001. }
  1002. func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) {
  1003. r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf)))
  1004. if r1 == 0 {
  1005. if e1 != 0 {
  1006. err = errnoErr(e1)
  1007. } else {
  1008. err = syscall.EINVAL
  1009. }
  1010. }
  1011. return
  1012. }
  1013. func GetEnvironmentStrings() (envs *uint16, err error) {
  1014. r0, _, e1 := syscall.Syscall(procGetEnvironmentStringsW.Addr(), 0, 0, 0, 0)
  1015. envs = (*uint16)(unsafe.Pointer(r0))
  1016. if envs == nil {
  1017. if e1 != 0 {
  1018. err = errnoErr(e1)
  1019. } else {
  1020. err = syscall.EINVAL
  1021. }
  1022. }
  1023. return
  1024. }
  1025. func FreeEnvironmentStrings(envs *uint16) (err error) {
  1026. r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0)
  1027. if r1 == 0 {
  1028. if e1 != 0 {
  1029. err = errnoErr(e1)
  1030. } else {
  1031. err = syscall.EINVAL
  1032. }
  1033. }
  1034. return
  1035. }
  1036. func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32, err error) {
  1037. r0, _, e1 := syscall.Syscall(procGetEnvironmentVariableW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(size))
  1038. n = uint32(r0)
  1039. if n == 0 {
  1040. if e1 != 0 {
  1041. err = errnoErr(e1)
  1042. } else {
  1043. err = syscall.EINVAL
  1044. }
  1045. }
  1046. return
  1047. }
  1048. func SetEnvironmentVariable(name *uint16, value *uint16) (err error) {
  1049. r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0)
  1050. if r1 == 0 {
  1051. if e1 != 0 {
  1052. err = errnoErr(e1)
  1053. } else {
  1054. err = syscall.EINVAL
  1055. }
  1056. }
  1057. return
  1058. }
  1059. func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetime) (err error) {
  1060. r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0)
  1061. if r1 == 0 {
  1062. if e1 != 0 {
  1063. err = errnoErr(e1)
  1064. } else {
  1065. err = syscall.EINVAL
  1066. }
  1067. }
  1068. return
  1069. }
  1070. func GetFileAttributes(name *uint16) (attrs uint32, err error) {
  1071. r0, _, e1 := syscall.Syscall(procGetFileAttributesW.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1072. attrs = uint32(r0)
  1073. if attrs == INVALID_FILE_ATTRIBUTES {
  1074. if e1 != 0 {
  1075. err = errnoErr(e1)
  1076. } else {
  1077. err = syscall.EINVAL
  1078. }
  1079. }
  1080. return
  1081. }
  1082. func SetFileAttributes(name *uint16, attrs uint32) (err error) {
  1083. r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0)
  1084. if r1 == 0 {
  1085. if e1 != 0 {
  1086. err = errnoErr(e1)
  1087. } else {
  1088. err = syscall.EINVAL
  1089. }
  1090. }
  1091. return
  1092. }
  1093. func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) {
  1094. r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info)))
  1095. if r1 == 0 {
  1096. if e1 != 0 {
  1097. err = errnoErr(e1)
  1098. } else {
  1099. err = syscall.EINVAL
  1100. }
  1101. }
  1102. return
  1103. }
  1104. func GetCommandLine() (cmd *uint16) {
  1105. r0, _, _ := syscall.Syscall(procGetCommandLineW.Addr(), 0, 0, 0, 0)
  1106. cmd = (*uint16)(unsafe.Pointer(r0))
  1107. return
  1108. }
  1109. func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err error) {
  1110. r0, _, e1 := syscall.Syscall(procCommandLineToArgvW.Addr(), 2, uintptr(unsafe.Pointer(cmd)), uintptr(unsafe.Pointer(argc)), 0)
  1111. argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0))
  1112. if argv == nil {
  1113. if e1 != 0 {
  1114. err = errnoErr(e1)
  1115. } else {
  1116. err = syscall.EINVAL
  1117. }
  1118. }
  1119. return
  1120. }
  1121. func LocalFree(hmem Handle) (handle Handle, err error) {
  1122. r0, _, e1 := syscall.Syscall(procLocalFree.Addr(), 1, uintptr(hmem), 0, 0)
  1123. handle = Handle(r0)
  1124. if handle != 0 {
  1125. if e1 != 0 {
  1126. err = errnoErr(e1)
  1127. } else {
  1128. err = syscall.EINVAL
  1129. }
  1130. }
  1131. return
  1132. }
  1133. func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) {
  1134. r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags))
  1135. if r1 == 0 {
  1136. if e1 != 0 {
  1137. err = errnoErr(e1)
  1138. } else {
  1139. err = syscall.EINVAL
  1140. }
  1141. }
  1142. return
  1143. }
  1144. func FlushFileBuffers(handle Handle) (err error) {
  1145. r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0)
  1146. if r1 == 0 {
  1147. if e1 != 0 {
  1148. err = errnoErr(e1)
  1149. } else {
  1150. err = syscall.EINVAL
  1151. }
  1152. }
  1153. return
  1154. }
  1155. func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) (n uint32, err error) {
  1156. r0, _, e1 := syscall.Syscall6(procGetFullPathNameW.Addr(), 4, uintptr(unsafe.Pointer(path)), uintptr(buflen), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(fname)), 0, 0)
  1157. n = uint32(r0)
  1158. if n == 0 {
  1159. if e1 != 0 {
  1160. err = errnoErr(e1)
  1161. } else {
  1162. err = syscall.EINVAL
  1163. }
  1164. }
  1165. return
  1166. }
  1167. func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err error) {
  1168. r0, _, e1 := syscall.Syscall(procGetLongPathNameW.Addr(), 3, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(buf)), uintptr(buflen))
  1169. n = uint32(r0)
  1170. if n == 0 {
  1171. if e1 != 0 {
  1172. err = errnoErr(e1)
  1173. } else {
  1174. err = syscall.EINVAL
  1175. }
  1176. }
  1177. return
  1178. }
  1179. func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uint32, err error) {
  1180. r0, _, e1 := syscall.Syscall(procGetShortPathNameW.Addr(), 3, uintptr(unsafe.Pointer(longpath)), uintptr(unsafe.Pointer(shortpath)), uintptr(buflen))
  1181. n = uint32(r0)
  1182. if n == 0 {
  1183. if e1 != 0 {
  1184. err = errnoErr(e1)
  1185. } else {
  1186. err = syscall.EINVAL
  1187. }
  1188. }
  1189. return
  1190. }
  1191. func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxSizeHigh uint32, maxSizeLow uint32, name *uint16) (handle Handle, err error) {
  1192. r0, _, e1 := syscall.Syscall6(procCreateFileMappingW.Addr(), 6, uintptr(fhandle), uintptr(unsafe.Pointer(sa)), uintptr(prot), uintptr(maxSizeHigh), uintptr(maxSizeLow), uintptr(unsafe.Pointer(name)))
  1193. handle = Handle(r0)
  1194. if handle == 0 {
  1195. if e1 != 0 {
  1196. err = errnoErr(e1)
  1197. } else {
  1198. err = syscall.EINVAL
  1199. }
  1200. }
  1201. return
  1202. }
  1203. func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow uint32, length uintptr) (addr uintptr, err error) {
  1204. r0, _, e1 := syscall.Syscall6(procMapViewOfFile.Addr(), 5, uintptr(handle), uintptr(access), uintptr(offsetHigh), uintptr(offsetLow), uintptr(length), 0)
  1205. addr = uintptr(r0)
  1206. if addr == 0 {
  1207. if e1 != 0 {
  1208. err = errnoErr(e1)
  1209. } else {
  1210. err = syscall.EINVAL
  1211. }
  1212. }
  1213. return
  1214. }
  1215. func UnmapViewOfFile(addr uintptr) (err error) {
  1216. r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0)
  1217. if r1 == 0 {
  1218. if e1 != 0 {
  1219. err = errnoErr(e1)
  1220. } else {
  1221. err = syscall.EINVAL
  1222. }
  1223. }
  1224. return
  1225. }
  1226. func FlushViewOfFile(addr uintptr, length uintptr) (err error) {
  1227. r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1228. if r1 == 0 {
  1229. if e1 != 0 {
  1230. err = errnoErr(e1)
  1231. } else {
  1232. err = syscall.EINVAL
  1233. }
  1234. }
  1235. return
  1236. }
  1237. func VirtualLock(addr uintptr, length uintptr) (err error) {
  1238. r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1239. if r1 == 0 {
  1240. if e1 != 0 {
  1241. err = errnoErr(e1)
  1242. } else {
  1243. err = syscall.EINVAL
  1244. }
  1245. }
  1246. return
  1247. }
  1248. func VirtualUnlock(addr uintptr, length uintptr) (err error) {
  1249. r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0)
  1250. if r1 == 0 {
  1251. if e1 != 0 {
  1252. err = errnoErr(e1)
  1253. } else {
  1254. err = syscall.EINVAL
  1255. }
  1256. }
  1257. return
  1258. }
  1259. func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) {
  1260. 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)
  1261. if r1 == 0 {
  1262. if e1 != 0 {
  1263. err = errnoErr(e1)
  1264. } else {
  1265. err = syscall.EINVAL
  1266. }
  1267. }
  1268. return
  1269. }
  1270. func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  1271. var _p0 uint32
  1272. if watchSubTree {
  1273. _p0 = 1
  1274. } else {
  1275. _p0 = 0
  1276. }
  1277. 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)
  1278. if r1 == 0 {
  1279. if e1 != 0 {
  1280. err = errnoErr(e1)
  1281. } else {
  1282. err = syscall.EINVAL
  1283. }
  1284. }
  1285. return
  1286. }
  1287. func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) {
  1288. r0, _, e1 := syscall.Syscall(procCertOpenSystemStoreW.Addr(), 2, uintptr(hprov), uintptr(unsafe.Pointer(name)), 0)
  1289. store = Handle(r0)
  1290. if store == 0 {
  1291. if e1 != 0 {
  1292. err = errnoErr(e1)
  1293. } else {
  1294. err = syscall.EINVAL
  1295. }
  1296. }
  1297. return
  1298. }
  1299. func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptProv uintptr, flags uint32, para uintptr) (handle Handle, err error) {
  1300. r0, _, e1 := syscall.Syscall6(procCertOpenStore.Addr(), 5, uintptr(storeProvider), uintptr(msgAndCertEncodingType), uintptr(cryptProv), uintptr(flags), uintptr(para), 0)
  1301. handle = Handle(r0)
  1302. if handle == InvalidHandle {
  1303. if e1 != 0 {
  1304. err = errnoErr(e1)
  1305. } else {
  1306. err = syscall.EINVAL
  1307. }
  1308. }
  1309. return
  1310. }
  1311. func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (context *CertContext, err error) {
  1312. r0, _, e1 := syscall.Syscall(procCertEnumCertificatesInStore.Addr(), 2, uintptr(store), uintptr(unsafe.Pointer(prevContext)), 0)
  1313. context = (*CertContext)(unsafe.Pointer(r0))
  1314. if context == nil {
  1315. if e1 != 0 {
  1316. err = errnoErr(e1)
  1317. } else {
  1318. err = syscall.EINVAL
  1319. }
  1320. }
  1321. return
  1322. }
  1323. func CertAddCertificateContextToStore(store Handle, certContext *CertContext, addDisposition uint32, storeContext **CertContext) (err error) {
  1324. r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0)
  1325. if r1 == 0 {
  1326. if e1 != 0 {
  1327. err = errnoErr(e1)
  1328. } else {
  1329. err = syscall.EINVAL
  1330. }
  1331. }
  1332. return
  1333. }
  1334. func CertCloseStore(store Handle, flags uint32) (err error) {
  1335. r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0)
  1336. if r1 == 0 {
  1337. if e1 != 0 {
  1338. err = errnoErr(e1)
  1339. } else {
  1340. err = syscall.EINVAL
  1341. }
  1342. }
  1343. return
  1344. }
  1345. func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, additionalStore Handle, para *CertChainPara, flags uint32, reserved uintptr, chainCtx **CertChainContext) (err error) {
  1346. 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)
  1347. if r1 == 0 {
  1348. if e1 != 0 {
  1349. err = errnoErr(e1)
  1350. } else {
  1351. err = syscall.EINVAL
  1352. }
  1353. }
  1354. return
  1355. }
  1356. func CertFreeCertificateChain(ctx *CertChainContext) {
  1357. syscall.Syscall(procCertFreeCertificateChain.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1358. return
  1359. }
  1360. func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, encodedLen uint32) (context *CertContext, err error) {
  1361. r0, _, e1 := syscall.Syscall(procCertCreateCertificateContext.Addr(), 3, uintptr(certEncodingType), uintptr(unsafe.Pointer(certEncoded)), uintptr(encodedLen))
  1362. context = (*CertContext)(unsafe.Pointer(r0))
  1363. if context == nil {
  1364. if e1 != 0 {
  1365. err = errnoErr(e1)
  1366. } else {
  1367. err = syscall.EINVAL
  1368. }
  1369. }
  1370. return
  1371. }
  1372. func CertFreeCertificateContext(ctx *CertContext) (err error) {
  1373. r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0)
  1374. if r1 == 0 {
  1375. if e1 != 0 {
  1376. err = errnoErr(e1)
  1377. } else {
  1378. err = syscall.EINVAL
  1379. }
  1380. }
  1381. return
  1382. }
  1383. func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext, para *CertChainPolicyPara, status *CertChainPolicyStatus) (err error) {
  1384. r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0)
  1385. if r1 == 0 {
  1386. if e1 != 0 {
  1387. err = errnoErr(e1)
  1388. } else {
  1389. err = syscall.EINVAL
  1390. }
  1391. }
  1392. return
  1393. }
  1394. func RegOpenKeyEx(key Handle, subkey *uint16, options uint32, desiredAccess uint32, result *Handle) (regerrno error) {
  1395. r0, _, _ := syscall.Syscall6(procRegOpenKeyExW.Addr(), 5, uintptr(key), uintptr(unsafe.Pointer(subkey)), uintptr(options), uintptr(desiredAccess), uintptr(unsafe.Pointer(result)), 0)
  1396. if r0 != 0 {
  1397. regerrno = syscall.Errno(r0)
  1398. }
  1399. return
  1400. }
  1401. func RegCloseKey(key Handle) (regerrno error) {
  1402. r0, _, _ := syscall.Syscall(procRegCloseKey.Addr(), 1, uintptr(key), 0, 0)
  1403. if r0 != 0 {
  1404. regerrno = syscall.Errno(r0)
  1405. }
  1406. return
  1407. }
  1408. func 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) {
  1409. 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)))
  1410. if r0 != 0 {
  1411. regerrno = syscall.Errno(r0)
  1412. }
  1413. return
  1414. }
  1415. func RegEnumKeyEx(key Handle, index uint32, name *uint16, nameLen *uint32, reserved *uint32, class *uint16, classLen *uint32, lastWriteTime *Filetime) (regerrno error) {
  1416. 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)
  1417. if r0 != 0 {
  1418. regerrno = syscall.Errno(r0)
  1419. }
  1420. return
  1421. }
  1422. func RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) {
  1423. 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)))
  1424. if r0 != 0 {
  1425. regerrno = syscall.Errno(r0)
  1426. }
  1427. return
  1428. }
  1429. func getCurrentProcessId() (pid uint32) {
  1430. r0, _, _ := syscall.Syscall(procGetCurrentProcessId.Addr(), 0, 0, 0, 0)
  1431. pid = uint32(r0)
  1432. return
  1433. }
  1434. func GetConsoleMode(console Handle, mode *uint32) (err error) {
  1435. r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0)
  1436. if r1 == 0 {
  1437. if e1 != 0 {
  1438. err = errnoErr(e1)
  1439. } else {
  1440. err = syscall.EINVAL
  1441. }
  1442. }
  1443. return
  1444. }
  1445. func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) {
  1446. r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0)
  1447. if r1 == 0 {
  1448. if e1 != 0 {
  1449. err = errnoErr(e1)
  1450. } else {
  1451. err = syscall.EINVAL
  1452. }
  1453. }
  1454. return
  1455. }
  1456. func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) {
  1457. r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0)
  1458. if r1 == 0 {
  1459. if e1 != 0 {
  1460. err = errnoErr(e1)
  1461. } else {
  1462. err = syscall.EINVAL
  1463. }
  1464. }
  1465. return
  1466. }
  1467. func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) {
  1468. r0, _, e1 := syscall.Syscall(procCreateToolhelp32Snapshot.Addr(), 2, uintptr(flags), uintptr(processId), 0)
  1469. handle = Handle(r0)
  1470. if handle == InvalidHandle {
  1471. if e1 != 0 {
  1472. err = errnoErr(e1)
  1473. } else {
  1474. err = syscall.EINVAL
  1475. }
  1476. }
  1477. return
  1478. }
  1479. func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1480. r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1481. if r1 == 0 {
  1482. if e1 != 0 {
  1483. err = errnoErr(e1)
  1484. } else {
  1485. err = syscall.EINVAL
  1486. }
  1487. }
  1488. return
  1489. }
  1490. func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) {
  1491. r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0)
  1492. if r1 == 0 {
  1493. if e1 != 0 {
  1494. err = errnoErr(e1)
  1495. } else {
  1496. err = syscall.EINVAL
  1497. }
  1498. }
  1499. return
  1500. }
  1501. func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBufferSize uint32, outBuffer *byte, outBufferSize uint32, bytesReturned *uint32, overlapped *Overlapped) (err error) {
  1502. 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)
  1503. if r1 == 0 {
  1504. if e1 != 0 {
  1505. err = errnoErr(e1)
  1506. } else {
  1507. err = syscall.EINVAL
  1508. }
  1509. }
  1510. return
  1511. }
  1512. func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) {
  1513. r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags))
  1514. if r1&0xff == 0 {
  1515. if e1 != 0 {
  1516. err = errnoErr(e1)
  1517. } else {
  1518. err = syscall.EINVAL
  1519. }
  1520. }
  1521. return
  1522. }
  1523. func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) {
  1524. r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved))
  1525. if r1&0xff == 0 {
  1526. if e1 != 0 {
  1527. err = errnoErr(e1)
  1528. } else {
  1529. err = syscall.EINVAL
  1530. }
  1531. }
  1532. return
  1533. }
  1534. func GetCurrentThreadId() (id uint32) {
  1535. r0, _, _ := syscall.Syscall(procGetCurrentThreadId.Addr(), 0, 0, 0, 0)
  1536. id = uint32(r0)
  1537. return
  1538. }
  1539. func CreateEvent(eventAttrs *syscall.SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) {
  1540. r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0)
  1541. handle = Handle(r0)
  1542. if handle == 0 {
  1543. if e1 != 0 {
  1544. err = errnoErr(e1)
  1545. } else {
  1546. err = syscall.EINVAL
  1547. }
  1548. }
  1549. return
  1550. }
  1551. func SetEvent(event Handle) (err error) {
  1552. r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0)
  1553. if r1 == 0 {
  1554. if e1 != 0 {
  1555. err = errnoErr(e1)
  1556. } else {
  1557. err = syscall.EINVAL
  1558. }
  1559. }
  1560. return
  1561. }
  1562. func WSAStartup(verreq uint32, data *WSAData) (sockerr error) {
  1563. r0, _, _ := syscall.Syscall(procWSAStartup.Addr(), 2, uintptr(verreq), uintptr(unsafe.Pointer(data)), 0)
  1564. if r0 != 0 {
  1565. sockerr = syscall.Errno(r0)
  1566. }
  1567. return
  1568. }
  1569. func WSACleanup() (err error) {
  1570. r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0)
  1571. if r1 == socket_error {
  1572. if e1 != 0 {
  1573. err = errnoErr(e1)
  1574. } else {
  1575. err = syscall.EINVAL
  1576. }
  1577. }
  1578. return
  1579. }
  1580. func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbob uint32, cbbr *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) {
  1581. 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))
  1582. if r1 == socket_error {
  1583. if e1 != 0 {
  1584. err = errnoErr(e1)
  1585. } else {
  1586. err = syscall.EINVAL
  1587. }
  1588. }
  1589. return
  1590. }
  1591. func socket(af int32, typ int32, protocol int32) (handle Handle, err error) {
  1592. r0, _, e1 := syscall.Syscall(procsocket.Addr(), 3, uintptr(af), uintptr(typ), uintptr(protocol))
  1593. handle = Handle(r0)
  1594. if handle == InvalidHandle {
  1595. if e1 != 0 {
  1596. err = errnoErr(e1)
  1597. } else {
  1598. err = syscall.EINVAL
  1599. }
  1600. }
  1601. return
  1602. }
  1603. func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32) (err error) {
  1604. r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0)
  1605. if r1 == socket_error {
  1606. if e1 != 0 {
  1607. err = errnoErr(e1)
  1608. } else {
  1609. err = syscall.EINVAL
  1610. }
  1611. }
  1612. return
  1613. }
  1614. func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int32) (err error) {
  1615. r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0)
  1616. if r1 == socket_error {
  1617. if e1 != 0 {
  1618. err = errnoErr(e1)
  1619. } else {
  1620. err = syscall.EINVAL
  1621. }
  1622. }
  1623. return
  1624. }
  1625. func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  1626. r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  1627. if r1 == socket_error {
  1628. if e1 != 0 {
  1629. err = errnoErr(e1)
  1630. } else {
  1631. err = syscall.EINVAL
  1632. }
  1633. }
  1634. return
  1635. }
  1636. func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) {
  1637. r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen))
  1638. if r1 == socket_error {
  1639. if e1 != 0 {
  1640. err = errnoErr(e1)
  1641. } else {
  1642. err = syscall.EINVAL
  1643. }
  1644. }
  1645. return
  1646. }
  1647. func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  1648. r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  1649. if r1 == socket_error {
  1650. if e1 != 0 {
  1651. err = errnoErr(e1)
  1652. } else {
  1653. err = syscall.EINVAL
  1654. }
  1655. }
  1656. return
  1657. }
  1658. func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) {
  1659. r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)))
  1660. if r1 == socket_error {
  1661. if e1 != 0 {
  1662. err = errnoErr(e1)
  1663. } else {
  1664. err = syscall.EINVAL
  1665. }
  1666. }
  1667. return
  1668. }
  1669. func listen(s Handle, backlog int32) (err error) {
  1670. r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0)
  1671. if r1 == socket_error {
  1672. if e1 != 0 {
  1673. err = errnoErr(e1)
  1674. } else {
  1675. err = syscall.EINVAL
  1676. }
  1677. }
  1678. return
  1679. }
  1680. func shutdown(s Handle, how int32) (err error) {
  1681. r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0)
  1682. if r1 == socket_error {
  1683. if e1 != 0 {
  1684. err = errnoErr(e1)
  1685. } else {
  1686. err = syscall.EINVAL
  1687. }
  1688. }
  1689. return
  1690. }
  1691. func Closesocket(s Handle) (err error) {
  1692. r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0)
  1693. if r1 == socket_error {
  1694. if e1 != 0 {
  1695. err = errnoErr(e1)
  1696. } else {
  1697. err = syscall.EINVAL
  1698. }
  1699. }
  1700. return
  1701. }
  1702. func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, recvd *uint32, overlapped *Overlapped) (err error) {
  1703. 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)
  1704. if r1 == 0 {
  1705. if e1 != 0 {
  1706. err = errnoErr(e1)
  1707. } else {
  1708. err = syscall.EINVAL
  1709. }
  1710. }
  1711. return
  1712. }
  1713. func GetAcceptExSockaddrs(buf *byte, rxdatalen uint32, laddrlen uint32, raddrlen uint32, lrsa **RawSockaddrAny, lrsalen *int32, rrsa **RawSockaddrAny, rrsalen *int32) {
  1714. 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)
  1715. return
  1716. }
  1717. func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, overlapped *Overlapped, croutine *byte) (err error) {
  1718. 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)
  1719. if r1 == socket_error {
  1720. if e1 != 0 {
  1721. err = errnoErr(e1)
  1722. } else {
  1723. err = syscall.EINVAL
  1724. }
  1725. }
  1726. return
  1727. }
  1728. func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, overlapped *Overlapped, croutine *byte) (err error) {
  1729. 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)
  1730. if r1 == socket_error {
  1731. if e1 != 0 {
  1732. err = errnoErr(e1)
  1733. } else {
  1734. err = syscall.EINVAL
  1735. }
  1736. }
  1737. return
  1738. }
  1739. func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32, from *RawSockaddrAny, fromlen *int32, overlapped *Overlapped, croutine *byte) (err error) {
  1740. 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)))
  1741. if r1 == socket_error {
  1742. if e1 != 0 {
  1743. err = errnoErr(e1)
  1744. } else {
  1745. err = syscall.EINVAL
  1746. }
  1747. }
  1748. return
  1749. }
  1750. func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, to *RawSockaddrAny, tolen int32, overlapped *Overlapped, croutine *byte) (err error) {
  1751. 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)))
  1752. if r1 == socket_error {
  1753. if e1 != 0 {
  1754. err = errnoErr(e1)
  1755. } else {
  1756. err = syscall.EINVAL
  1757. }
  1758. }
  1759. return
  1760. }
  1761. func GetHostByName(name string) (h *Hostent, err error) {
  1762. var _p0 *byte
  1763. _p0, err = syscall.BytePtrFromString(name)
  1764. if err != nil {
  1765. return
  1766. }
  1767. return _GetHostByName(_p0)
  1768. }
  1769. func _GetHostByName(name *byte) (h *Hostent, err error) {
  1770. r0, _, e1 := syscall.Syscall(procgethostbyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1771. h = (*Hostent)(unsafe.Pointer(r0))
  1772. if h == nil {
  1773. if e1 != 0 {
  1774. err = errnoErr(e1)
  1775. } else {
  1776. err = syscall.EINVAL
  1777. }
  1778. }
  1779. return
  1780. }
  1781. func GetServByName(name string, proto string) (s *Servent, err error) {
  1782. var _p0 *byte
  1783. _p0, err = syscall.BytePtrFromString(name)
  1784. if err != nil {
  1785. return
  1786. }
  1787. var _p1 *byte
  1788. _p1, err = syscall.BytePtrFromString(proto)
  1789. if err != nil {
  1790. return
  1791. }
  1792. return _GetServByName(_p0, _p1)
  1793. }
  1794. func _GetServByName(name *byte, proto *byte) (s *Servent, err error) {
  1795. r0, _, e1 := syscall.Syscall(procgetservbyname.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(proto)), 0)
  1796. s = (*Servent)(unsafe.Pointer(r0))
  1797. if s == nil {
  1798. if e1 != 0 {
  1799. err = errnoErr(e1)
  1800. } else {
  1801. err = syscall.EINVAL
  1802. }
  1803. }
  1804. return
  1805. }
  1806. func Ntohs(netshort uint16) (u uint16) {
  1807. r0, _, _ := syscall.Syscall(procntohs.Addr(), 1, uintptr(netshort), 0, 0)
  1808. u = uint16(r0)
  1809. return
  1810. }
  1811. func GetProtoByName(name string) (p *Protoent, err error) {
  1812. var _p0 *byte
  1813. _p0, err = syscall.BytePtrFromString(name)
  1814. if err != nil {
  1815. return
  1816. }
  1817. return _GetProtoByName(_p0)
  1818. }
  1819. func _GetProtoByName(name *byte) (p *Protoent, err error) {
  1820. r0, _, e1 := syscall.Syscall(procgetprotobyname.Addr(), 1, uintptr(unsafe.Pointer(name)), 0, 0)
  1821. p = (*Protoent)(unsafe.Pointer(r0))
  1822. if p == nil {
  1823. if e1 != 0 {
  1824. err = errnoErr(e1)
  1825. } else {
  1826. err = syscall.EINVAL
  1827. }
  1828. }
  1829. return
  1830. }
  1831. func DnsQuery(name string, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  1832. var _p0 *uint16
  1833. _p0, status = syscall.UTF16PtrFromString(name)
  1834. if status != nil {
  1835. return
  1836. }
  1837. return _DnsQuery(_p0, qtype, options, extra, qrs, pr)
  1838. }
  1839. func _DnsQuery(name *uint16, qtype uint16, options uint32, extra *byte, qrs **DNSRecord, pr *byte) (status error) {
  1840. 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)))
  1841. if r0 != 0 {
  1842. status = syscall.Errno(r0)
  1843. }
  1844. return
  1845. }
  1846. func DnsRecordListFree(rl *DNSRecord, freetype uint32) {
  1847. syscall.Syscall(procDnsRecordListFree.Addr(), 2, uintptr(unsafe.Pointer(rl)), uintptr(freetype), 0)
  1848. return
  1849. }
  1850. func DnsNameCompare(name1 *uint16, name2 *uint16) (same bool) {
  1851. r0, _, _ := syscall.Syscall(procDnsNameCompare_W.Addr(), 2, uintptr(unsafe.Pointer(name1)), uintptr(unsafe.Pointer(name2)), 0)
  1852. same = r0 != 0
  1853. return
  1854. }
  1855. func GetAddrInfoW(nodename *uint16, servicename *uint16, hints *AddrinfoW, result **AddrinfoW) (sockerr error) {
  1856. r0, _, _ := syscall.Syscall6(procGetAddrInfoW.Addr(), 4, uintptr(unsafe.Pointer(nodename)), uintptr(unsafe.Pointer(servicename)), uintptr(unsafe.Pointer(hints)), uintptr(unsafe.Pointer(result)), 0, 0)
  1857. if r0 != 0 {
  1858. sockerr = syscall.Errno(r0)
  1859. }
  1860. return
  1861. }
  1862. func FreeAddrInfoW(addrinfo *AddrinfoW) {
  1863. syscall.Syscall(procFreeAddrInfoW.Addr(), 1, uintptr(unsafe.Pointer(addrinfo)), 0, 0)
  1864. return
  1865. }
  1866. func GetIfEntry(pIfRow *MibIfRow) (errcode error) {
  1867. r0, _, _ := syscall.Syscall(procGetIfEntry.Addr(), 1, uintptr(unsafe.Pointer(pIfRow)), 0, 0)
  1868. if r0 != 0 {
  1869. errcode = syscall.Errno(r0)
  1870. }
  1871. return
  1872. }
  1873. func GetAdaptersInfo(ai *IpAdapterInfo, ol *uint32) (errcode error) {
  1874. r0, _, _ := syscall.Syscall(procGetAdaptersInfo.Addr(), 2, uintptr(unsafe.Pointer(ai)), uintptr(unsafe.Pointer(ol)), 0)
  1875. if r0 != 0 {
  1876. errcode = syscall.Errno(r0)
  1877. }
  1878. return
  1879. }
  1880. func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) {
  1881. r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0)
  1882. if r1 == 0 {
  1883. if e1 != 0 {
  1884. err = errnoErr(e1)
  1885. } else {
  1886. err = syscall.EINVAL
  1887. }
  1888. }
  1889. return
  1890. }
  1891. func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferLength *uint32) (n int32, err error) {
  1892. r0, _, e1 := syscall.Syscall(procWSAEnumProtocolsW.Addr(), 3, uintptr(unsafe.Pointer(protocols)), uintptr(unsafe.Pointer(protocolBuffer)), uintptr(unsafe.Pointer(bufferLength)))
  1893. n = int32(r0)
  1894. if n == -1 {
  1895. if e1 != 0 {
  1896. err = errnoErr(e1)
  1897. } else {
  1898. err = syscall.EINVAL
  1899. }
  1900. }
  1901. return
  1902. }
  1903. func GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) {
  1904. r0, _, _ := syscall.Syscall6(procGetAdaptersAddresses.Addr(), 5, uintptr(family), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(adapterAddresses)), uintptr(unsafe.Pointer(sizePointer)), 0)
  1905. if r0 != 0 {
  1906. errcode = syscall.Errno(r0)
  1907. }
  1908. return
  1909. }
  1910. func GetACP() (acp uint32) {
  1911. r0, _, _ := syscall.Syscall(procGetACP.Addr(), 0, 0, 0, 0)
  1912. acp = uint32(r0)
  1913. return
  1914. }
  1915. func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) {
  1916. r0, _, e1 := syscall.Syscall6(procMultiByteToWideChar.Addr(), 6, uintptr(codePage), uintptr(dwFlags), uintptr(unsafe.Pointer(str)), uintptr(nstr), uintptr(unsafe.Pointer(wchar)), uintptr(nwchar))
  1917. nwrite = int32(r0)
  1918. if nwrite == 0 {
  1919. if e1 != 0 {
  1920. err = errnoErr(e1)
  1921. } else {
  1922. err = syscall.EINVAL
  1923. }
  1924. }
  1925. return
  1926. }
  1927. func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint32, translatedName *uint16, nSize *uint32) (err error) {
  1928. r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0)
  1929. if r1&0xff == 0 {
  1930. if e1 != 0 {
  1931. err = errnoErr(e1)
  1932. } else {
  1933. err = syscall.EINVAL
  1934. }
  1935. }
  1936. return
  1937. }
  1938. func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err error) {
  1939. r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize)))
  1940. if r1&0xff == 0 {
  1941. if e1 != 0 {
  1942. err = errnoErr(e1)
  1943. } else {
  1944. err = syscall.EINVAL
  1945. }
  1946. }
  1947. return
  1948. }
  1949. func NetUserGetInfo(serverName *uint16, userName *uint16, level uint32, buf **byte) (neterr error) {
  1950. r0, _, _ := syscall.Syscall6(procNetUserGetInfo.Addr(), 4, uintptr(unsafe.Pointer(serverName)), uintptr(unsafe.Pointer(userName)), uintptr(level), uintptr(unsafe.Pointer(buf)), 0, 0)
  1951. if r0 != 0 {
  1952. neterr = syscall.Errno(r0)
  1953. }
  1954. return
  1955. }
  1956. func NetGetJoinInformation(server *uint16, name **uint16, bufType *uint32) (neterr error) {
  1957. r0, _, _ := syscall.Syscall(procNetGetJoinInformation.Addr(), 3, uintptr(unsafe.Pointer(server)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(bufType)))
  1958. if r0 != 0 {
  1959. neterr = syscall.Errno(r0)
  1960. }
  1961. return
  1962. }
  1963. func NetApiBufferFree(buf *byte) (neterr error) {
  1964. r0, _, _ := syscall.Syscall(procNetApiBufferFree.Addr(), 1, uintptr(unsafe.Pointer(buf)), 0, 0)
  1965. if r0 != 0 {
  1966. neterr = syscall.Errno(r0)
  1967. }
  1968. return
  1969. }
  1970. func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  1971. 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)
  1972. if r1 == 0 {
  1973. if e1 != 0 {
  1974. err = errnoErr(e1)
  1975. } else {
  1976. err = syscall.EINVAL
  1977. }
  1978. }
  1979. return
  1980. }
  1981. func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) {
  1982. 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)
  1983. if r1 == 0 {
  1984. if e1 != 0 {
  1985. err = errnoErr(e1)
  1986. } else {
  1987. err = syscall.EINVAL
  1988. }
  1989. }
  1990. return
  1991. }
  1992. func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) {
  1993. r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0)
  1994. if r1 == 0 {
  1995. if e1 != 0 {
  1996. err = errnoErr(e1)
  1997. } else {
  1998. err = syscall.EINVAL
  1999. }
  2000. }
  2001. return
  2002. }
  2003. func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) {
  2004. r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0)
  2005. if r1 == 0 {
  2006. if e1 != 0 {
  2007. err = errnoErr(e1)
  2008. } else {
  2009. err = syscall.EINVAL
  2010. }
  2011. }
  2012. return
  2013. }
  2014. func GetLengthSid(sid *SID) (len uint32) {
  2015. r0, _, _ := syscall.Syscall(procGetLengthSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
  2016. len = uint32(r0)
  2017. return
  2018. }
  2019. func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) {
  2020. r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid)))
  2021. if r1 == 0 {
  2022. if e1 != 0 {
  2023. err = errnoErr(e1)
  2024. } else {
  2025. err = syscall.EINVAL
  2026. }
  2027. }
  2028. return
  2029. }
  2030. func 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) {
  2031. 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)
  2032. if r1 == 0 {
  2033. if e1 != 0 {
  2034. err = errnoErr(e1)
  2035. } else {
  2036. err = syscall.EINVAL
  2037. }
  2038. }
  2039. return
  2040. }
  2041. func FreeSid(sid *SID) (err error) {
  2042. r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0)
  2043. if r1 != 0 {
  2044. if e1 != 0 {
  2045. err = errnoErr(e1)
  2046. } else {
  2047. err = syscall.EINVAL
  2048. }
  2049. }
  2050. return
  2051. }
  2052. func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) {
  2053. r0, _, _ := syscall.Syscall(procEqualSid.Addr(), 2, uintptr(unsafe.Pointer(sid1)), uintptr(unsafe.Pointer(sid2)), 0)
  2054. isEqual = r0 != 0
  2055. return
  2056. }
  2057. func OpenProcessToken(h Handle, access uint32, token *Token) (err error) {
  2058. r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token)))
  2059. if r1 == 0 {
  2060. if e1 != 0 {
  2061. err = errnoErr(e1)
  2062. } else {
  2063. err = syscall.EINVAL
  2064. }
  2065. }
  2066. return
  2067. }
  2068. func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) {
  2069. r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0)
  2070. if r1 == 0 {
  2071. if e1 != 0 {
  2072. err = errnoErr(e1)
  2073. } else {
  2074. err = syscall.EINVAL
  2075. }
  2076. }
  2077. return
  2078. }
  2079. func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) {
  2080. r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen)))
  2081. if r1 == 0 {
  2082. if e1 != 0 {
  2083. err = errnoErr(e1)
  2084. } else {
  2085. err = syscall.EINVAL
  2086. }
  2087. }
  2088. return
  2089. }