zsyscall_windows.go 79 KB

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