zsyscall_windows.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. // Code generated mksyscall_windows.exe DO NOT EDIT
  2. package winapi
  3. import (
  4. "syscall"
  5. "unsafe"
  6. "golang.org/x/sys/windows"
  7. )
  8. var _ unsafe.Pointer
  9. // Do the interface allocations only once for common
  10. // Errno values.
  11. const (
  12. errnoERROR_IO_PENDING = 997
  13. )
  14. var (
  15. errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING)
  16. )
  17. // errnoErr returns common boxed Errno values, to prevent
  18. // allocations at runtime.
  19. func errnoErr(e syscall.Errno) error {
  20. switch e {
  21. case 0:
  22. return nil
  23. case errnoERROR_IO_PENDING:
  24. return errERROR_IO_PENDING
  25. }
  26. // TODO: add more here, after collecting data on the common
  27. // error values see on Windows. (perhaps when running
  28. // all.bat?)
  29. return e
  30. }
  31. var (
  32. modntdll = windows.NewLazySystemDLL("ntdll.dll")
  33. modiphlpapi = windows.NewLazySystemDLL("iphlpapi.dll")
  34. modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
  35. modadvapi32 = windows.NewLazySystemDLL("advapi32.dll")
  36. modpsapi = windows.NewLazySystemDLL("psapi.dll")
  37. modcfgmgr32 = windows.NewLazySystemDLL("cfgmgr32.dll")
  38. procNtQuerySystemInformation = modntdll.NewProc("NtQuerySystemInformation")
  39. procSetJobCompartmentId = modiphlpapi.NewProc("SetJobCompartmentId")
  40. procSearchPathW = modkernel32.NewProc("SearchPathW")
  41. procCreateRemoteThread = modkernel32.NewProc("CreateRemoteThread")
  42. procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus")
  43. procIsProcessInJob = modkernel32.NewProc("IsProcessInJob")
  44. procQueryInformationJobObject = modkernel32.NewProc("QueryInformationJobObject")
  45. procOpenJobObjectW = modkernel32.NewProc("OpenJobObjectW")
  46. procSetIoRateControlInformationJobObject = modkernel32.NewProc("SetIoRateControlInformationJobObject")
  47. procQueryIoRateControlInformationJobObject = modkernel32.NewProc("QueryIoRateControlInformationJobObject")
  48. procNtOpenJobObject = modntdll.NewProc("NtOpenJobObject")
  49. procNtCreateJobObject = modntdll.NewProc("NtCreateJobObject")
  50. procLogonUserW = modadvapi32.NewProc("LogonUserW")
  51. procRtlMoveMemory = modkernel32.NewProc("RtlMoveMemory")
  52. procLocalAlloc = modkernel32.NewProc("LocalAlloc")
  53. procLocalFree = modkernel32.NewProc("LocalFree")
  54. procQueryWorkingSet = modpsapi.NewProc("QueryWorkingSet")
  55. procGetProcessImageFileNameW = modkernel32.NewProc("GetProcessImageFileNameW")
  56. procGetActiveProcessorCount = modkernel32.NewProc("GetActiveProcessorCount")
  57. procCM_Get_Device_ID_List_SizeA = modcfgmgr32.NewProc("CM_Get_Device_ID_List_SizeA")
  58. procCM_Get_Device_ID_ListA = modcfgmgr32.NewProc("CM_Get_Device_ID_ListA")
  59. procCM_Locate_DevNodeW = modcfgmgr32.NewProc("CM_Locate_DevNodeW")
  60. procCM_Get_DevNode_PropertyW = modcfgmgr32.NewProc("CM_Get_DevNode_PropertyW")
  61. procNtCreateFile = modntdll.NewProc("NtCreateFile")
  62. procNtSetInformationFile = modntdll.NewProc("NtSetInformationFile")
  63. procNtOpenDirectoryObject = modntdll.NewProc("NtOpenDirectoryObject")
  64. procNtQueryDirectoryObject = modntdll.NewProc("NtQueryDirectoryObject")
  65. procRtlNtStatusToDosError = modntdll.NewProc("RtlNtStatusToDosError")
  66. )
  67. func NtQuerySystemInformation(systemInfoClass int, systemInformation uintptr, systemInfoLength uint32, returnLength *uint32) (status uint32) {
  68. r0, _, _ := syscall.Syscall6(procNtQuerySystemInformation.Addr(), 4, uintptr(systemInfoClass), uintptr(systemInformation), uintptr(systemInfoLength), uintptr(unsafe.Pointer(returnLength)), 0, 0)
  69. status = uint32(r0)
  70. return
  71. }
  72. func SetJobCompartmentId(handle windows.Handle, compartmentId uint32) (win32Err error) {
  73. r0, _, _ := syscall.Syscall(procSetJobCompartmentId.Addr(), 2, uintptr(handle), uintptr(compartmentId), 0)
  74. if r0 != 0 {
  75. win32Err = syscall.Errno(r0)
  76. }
  77. return
  78. }
  79. func SearchPath(lpPath *uint16, lpFileName *uint16, lpExtension *uint16, nBufferLength uint32, lpBuffer *uint16, lpFilePath *uint16) (size uint32, err error) {
  80. r0, _, e1 := syscall.Syscall6(procSearchPathW.Addr(), 6, uintptr(unsafe.Pointer(lpPath)), uintptr(unsafe.Pointer(lpFileName)), uintptr(unsafe.Pointer(lpExtension)), uintptr(nBufferLength), uintptr(unsafe.Pointer(lpBuffer)), uintptr(unsafe.Pointer(lpFilePath)))
  81. size = uint32(r0)
  82. if size == 0 {
  83. if e1 != 0 {
  84. err = errnoErr(e1)
  85. } else {
  86. err = syscall.EINVAL
  87. }
  88. }
  89. return
  90. }
  91. func CreateRemoteThread(process windows.Handle, sa *windows.SecurityAttributes, stackSize uint32, startAddr uintptr, parameter uintptr, creationFlags uint32, threadID *uint32) (handle windows.Handle, err error) {
  92. r0, _, e1 := syscall.Syscall9(procCreateRemoteThread.Addr(), 7, uintptr(process), uintptr(unsafe.Pointer(sa)), uintptr(stackSize), uintptr(startAddr), uintptr(parameter), uintptr(creationFlags), uintptr(unsafe.Pointer(threadID)), 0, 0)
  93. handle = windows.Handle(r0)
  94. if handle == 0 {
  95. if e1 != 0 {
  96. err = errnoErr(e1)
  97. } else {
  98. err = syscall.EINVAL
  99. }
  100. }
  101. return
  102. }
  103. func GetQueuedCompletionStatus(cphandle windows.Handle, qty *uint32, key *uintptr, overlapped **windows.Overlapped, timeout uint32) (err error) {
  104. r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0)
  105. if r1 == 0 {
  106. if e1 != 0 {
  107. err = errnoErr(e1)
  108. } else {
  109. err = syscall.EINVAL
  110. }
  111. }
  112. return
  113. }
  114. func IsProcessInJob(procHandle windows.Handle, jobHandle windows.Handle, result *bool) (err error) {
  115. r1, _, e1 := syscall.Syscall(procIsProcessInJob.Addr(), 3, uintptr(procHandle), uintptr(jobHandle), uintptr(unsafe.Pointer(result)))
  116. if r1 == 0 {
  117. if e1 != 0 {
  118. err = errnoErr(e1)
  119. } else {
  120. err = syscall.EINVAL
  121. }
  122. }
  123. return
  124. }
  125. func QueryInformationJobObject(jobHandle windows.Handle, infoClass uint32, jobObjectInfo uintptr, jobObjectInformationLength uint32, lpReturnLength *uint32) (err error) {
  126. r1, _, e1 := syscall.Syscall6(procQueryInformationJobObject.Addr(), 5, uintptr(jobHandle), uintptr(infoClass), uintptr(jobObjectInfo), uintptr(jobObjectInformationLength), uintptr(unsafe.Pointer(lpReturnLength)), 0)
  127. if r1 == 0 {
  128. if e1 != 0 {
  129. err = errnoErr(e1)
  130. } else {
  131. err = syscall.EINVAL
  132. }
  133. }
  134. return
  135. }
  136. func OpenJobObject(desiredAccess uint32, inheritHandle bool, lpName *uint16) (handle windows.Handle, err error) {
  137. var _p0 uint32
  138. if inheritHandle {
  139. _p0 = 1
  140. } else {
  141. _p0 = 0
  142. }
  143. r0, _, e1 := syscall.Syscall(procOpenJobObjectW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(lpName)))
  144. handle = windows.Handle(r0)
  145. if handle == 0 {
  146. if e1 != 0 {
  147. err = errnoErr(e1)
  148. } else {
  149. err = syscall.EINVAL
  150. }
  151. }
  152. return
  153. }
  154. func SetIoRateControlInformationJobObject(jobHandle windows.Handle, ioRateControlInfo *JOBOBJECT_IO_RATE_CONTROL_INFORMATION) (ret uint32, err error) {
  155. r0, _, e1 := syscall.Syscall(procSetIoRateControlInformationJobObject.Addr(), 2, uintptr(jobHandle), uintptr(unsafe.Pointer(ioRateControlInfo)), 0)
  156. ret = uint32(r0)
  157. if ret == 0 {
  158. if e1 != 0 {
  159. err = errnoErr(e1)
  160. } else {
  161. err = syscall.EINVAL
  162. }
  163. }
  164. return
  165. }
  166. func QueryIoRateControlInformationJobObject(jobHandle windows.Handle, volumeName *uint16, ioRateControlInfo **JOBOBJECT_IO_RATE_CONTROL_INFORMATION, infoBlockCount *uint32) (ret uint32, err error) {
  167. r0, _, e1 := syscall.Syscall6(procQueryIoRateControlInformationJobObject.Addr(), 4, uintptr(jobHandle), uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(ioRateControlInfo)), uintptr(unsafe.Pointer(infoBlockCount)), 0, 0)
  168. ret = uint32(r0)
  169. if ret == 0 {
  170. if e1 != 0 {
  171. err = errnoErr(e1)
  172. } else {
  173. err = syscall.EINVAL
  174. }
  175. }
  176. return
  177. }
  178. func NtOpenJobObject(jobHandle *windows.Handle, desiredAccess uint32, objAttributes *ObjectAttributes) (status uint32) {
  179. r0, _, _ := syscall.Syscall(procNtOpenJobObject.Addr(), 3, uintptr(unsafe.Pointer(jobHandle)), uintptr(desiredAccess), uintptr(unsafe.Pointer(objAttributes)))
  180. status = uint32(r0)
  181. return
  182. }
  183. func NtCreateJobObject(jobHandle *windows.Handle, desiredAccess uint32, objAttributes *ObjectAttributes) (status uint32) {
  184. r0, _, _ := syscall.Syscall(procNtCreateJobObject.Addr(), 3, uintptr(unsafe.Pointer(jobHandle)), uintptr(desiredAccess), uintptr(unsafe.Pointer(objAttributes)))
  185. status = uint32(r0)
  186. return
  187. }
  188. func LogonUser(username *uint16, domain *uint16, password *uint16, logonType uint32, logonProvider uint32, token *windows.Token) (err error) {
  189. r1, _, e1 := syscall.Syscall6(procLogonUserW.Addr(), 6, uintptr(unsafe.Pointer(username)), uintptr(unsafe.Pointer(domain)), uintptr(unsafe.Pointer(password)), uintptr(logonType), uintptr(logonProvider), uintptr(unsafe.Pointer(token)))
  190. if r1 == 0 {
  191. if e1 != 0 {
  192. err = errnoErr(e1)
  193. } else {
  194. err = syscall.EINVAL
  195. }
  196. }
  197. return
  198. }
  199. func RtlMoveMemory(destination *byte, source *byte, length uintptr) (err error) {
  200. r1, _, e1 := syscall.Syscall(procRtlMoveMemory.Addr(), 3, uintptr(unsafe.Pointer(destination)), uintptr(unsafe.Pointer(source)), uintptr(length))
  201. if r1 == 0 {
  202. if e1 != 0 {
  203. err = errnoErr(e1)
  204. } else {
  205. err = syscall.EINVAL
  206. }
  207. }
  208. return
  209. }
  210. func LocalAlloc(flags uint32, size int) (ptr uintptr) {
  211. r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(flags), uintptr(size), 0)
  212. ptr = uintptr(r0)
  213. return
  214. }
  215. func LocalFree(ptr uintptr) {
  216. syscall.Syscall(procLocalFree.Addr(), 1, uintptr(ptr), 0, 0)
  217. return
  218. }
  219. func QueryWorkingSet(handle windows.Handle, pv uintptr, cb uint32) (err error) {
  220. r1, _, e1 := syscall.Syscall(procQueryWorkingSet.Addr(), 3, uintptr(handle), uintptr(pv), uintptr(cb))
  221. if r1 == 0 {
  222. if e1 != 0 {
  223. err = errnoErr(e1)
  224. } else {
  225. err = syscall.EINVAL
  226. }
  227. }
  228. return
  229. }
  230. func GetProcessImageFileName(hProcess windows.Handle, imageFileName *uint16, nSize uint32) (size uint32, err error) {
  231. r0, _, e1 := syscall.Syscall(procGetProcessImageFileNameW.Addr(), 3, uintptr(hProcess), uintptr(unsafe.Pointer(imageFileName)), uintptr(nSize))
  232. size = uint32(r0)
  233. if size == 0 {
  234. if e1 != 0 {
  235. err = errnoErr(e1)
  236. } else {
  237. err = syscall.EINVAL
  238. }
  239. }
  240. return
  241. }
  242. func GetActiveProcessorCount(groupNumber uint16) (amount uint32) {
  243. r0, _, _ := syscall.Syscall(procGetActiveProcessorCount.Addr(), 1, uintptr(groupNumber), 0, 0)
  244. amount = uint32(r0)
  245. return
  246. }
  247. func CMGetDeviceIDListSize(pulLen *uint32, pszFilter *byte, uFlags uint32) (hr error) {
  248. r0, _, _ := syscall.Syscall(procCM_Get_Device_ID_List_SizeA.Addr(), 3, uintptr(unsafe.Pointer(pulLen)), uintptr(unsafe.Pointer(pszFilter)), uintptr(uFlags))
  249. if int32(r0) < 0 {
  250. if r0&0x1fff0000 == 0x00070000 {
  251. r0 &= 0xffff
  252. }
  253. hr = syscall.Errno(r0)
  254. }
  255. return
  256. }
  257. func CMGetDeviceIDList(pszFilter *byte, buffer *byte, bufferLen uint32, uFlags uint32) (hr error) {
  258. r0, _, _ := syscall.Syscall6(procCM_Get_Device_ID_ListA.Addr(), 4, uintptr(unsafe.Pointer(pszFilter)), uintptr(unsafe.Pointer(buffer)), uintptr(bufferLen), uintptr(uFlags), 0, 0)
  259. if int32(r0) < 0 {
  260. if r0&0x1fff0000 == 0x00070000 {
  261. r0 &= 0xffff
  262. }
  263. hr = syscall.Errno(r0)
  264. }
  265. return
  266. }
  267. func CMLocateDevNode(pdnDevInst *uint32, pDeviceID string, uFlags uint32) (hr error) {
  268. var _p0 *uint16
  269. _p0, hr = syscall.UTF16PtrFromString(pDeviceID)
  270. if hr != nil {
  271. return
  272. }
  273. return _CMLocateDevNode(pdnDevInst, _p0, uFlags)
  274. }
  275. func _CMLocateDevNode(pdnDevInst *uint32, pDeviceID *uint16, uFlags uint32) (hr error) {
  276. r0, _, _ := syscall.Syscall(procCM_Locate_DevNodeW.Addr(), 3, uintptr(unsafe.Pointer(pdnDevInst)), uintptr(unsafe.Pointer(pDeviceID)), uintptr(uFlags))
  277. if int32(r0) < 0 {
  278. if r0&0x1fff0000 == 0x00070000 {
  279. r0 &= 0xffff
  280. }
  281. hr = syscall.Errno(r0)
  282. }
  283. return
  284. }
  285. func CMGetDevNodeProperty(dnDevInst uint32, propertyKey *DevPropKey, propertyType *uint32, propertyBuffer *uint16, propertyBufferSize *uint32, uFlags uint32) (hr error) {
  286. r0, _, _ := syscall.Syscall6(procCM_Get_DevNode_PropertyW.Addr(), 6, uintptr(dnDevInst), uintptr(unsafe.Pointer(propertyKey)), uintptr(unsafe.Pointer(propertyType)), uintptr(unsafe.Pointer(propertyBuffer)), uintptr(unsafe.Pointer(propertyBufferSize)), uintptr(uFlags))
  287. if int32(r0) < 0 {
  288. if r0&0x1fff0000 == 0x00070000 {
  289. r0 &= 0xffff
  290. }
  291. hr = syscall.Errno(r0)
  292. }
  293. return
  294. }
  295. func NtCreateFile(handle *uintptr, accessMask uint32, oa *ObjectAttributes, iosb *IOStatusBlock, allocationSize *uint64, fileAttributes uint32, shareAccess uint32, createDisposition uint32, createOptions uint32, eaBuffer *byte, eaLength uint32) (status uint32) {
  296. r0, _, _ := syscall.Syscall12(procNtCreateFile.Addr(), 11, uintptr(unsafe.Pointer(handle)), uintptr(accessMask), uintptr(unsafe.Pointer(oa)), uintptr(unsafe.Pointer(iosb)), uintptr(unsafe.Pointer(allocationSize)), uintptr(fileAttributes), uintptr(shareAccess), uintptr(createDisposition), uintptr(createOptions), uintptr(unsafe.Pointer(eaBuffer)), uintptr(eaLength), 0)
  297. status = uint32(r0)
  298. return
  299. }
  300. func NtSetInformationFile(handle uintptr, iosb *IOStatusBlock, information uintptr, length uint32, class uint32) (status uint32) {
  301. r0, _, _ := syscall.Syscall6(procNtSetInformationFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(information), uintptr(length), uintptr(class), 0)
  302. status = uint32(r0)
  303. return
  304. }
  305. func NtOpenDirectoryObject(handle *uintptr, accessMask uint32, oa *ObjectAttributes) (status uint32) {
  306. r0, _, _ := syscall.Syscall(procNtOpenDirectoryObject.Addr(), 3, uintptr(unsafe.Pointer(handle)), uintptr(accessMask), uintptr(unsafe.Pointer(oa)))
  307. status = uint32(r0)
  308. return
  309. }
  310. func NtQueryDirectoryObject(handle uintptr, buffer *byte, length uint32, singleEntry bool, restartScan bool, context *uint32, returnLength *uint32) (status uint32) {
  311. var _p0 uint32
  312. if singleEntry {
  313. _p0 = 1
  314. } else {
  315. _p0 = 0
  316. }
  317. var _p1 uint32
  318. if restartScan {
  319. _p1 = 1
  320. } else {
  321. _p1 = 0
  322. }
  323. r0, _, _ := syscall.Syscall9(procNtQueryDirectoryObject.Addr(), 7, uintptr(handle), uintptr(unsafe.Pointer(buffer)), uintptr(length), uintptr(_p0), uintptr(_p1), uintptr(unsafe.Pointer(context)), uintptr(unsafe.Pointer(returnLength)), 0, 0)
  324. status = uint32(r0)
  325. return
  326. }
  327. func RtlNtStatusToDosError(status uint32) (winerr error) {
  328. r0, _, _ := syscall.Syscall(procRtlNtStatusToDosError.Addr(), 1, uintptr(status), 0, 0)
  329. if r0 != 0 {
  330. winerr = syscall.Errno(r0)
  331. }
  332. return
  333. }