zsyscall_windows.go 76 KB

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