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