1// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT 2 3package winio 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 modkernel32 = windows.NewLazySystemDLL("kernel32.dll") 41 modadvapi32 = windows.NewLazySystemDLL("advapi32.dll") 42 43 procCancelIoEx = modkernel32.NewProc("CancelIoEx") 44 procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort") 45 procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus") 46 procSetFileCompletionNotificationModes = modkernel32.NewProc("SetFileCompletionNotificationModes") 47 procConnectNamedPipe = modkernel32.NewProc("ConnectNamedPipe") 48 procCreateNamedPipeW = modkernel32.NewProc("CreateNamedPipeW") 49 procCreateFileW = modkernel32.NewProc("CreateFileW") 50 procWaitNamedPipeW = modkernel32.NewProc("WaitNamedPipeW") 51 procGetNamedPipeInfo = modkernel32.NewProc("GetNamedPipeInfo") 52 procGetNamedPipeHandleStateW = modkernel32.NewProc("GetNamedPipeHandleStateW") 53 procLocalAlloc = modkernel32.NewProc("LocalAlloc") 54 procLookupAccountNameW = modadvapi32.NewProc("LookupAccountNameW") 55 procConvertSidToStringSidW = modadvapi32.NewProc("ConvertSidToStringSidW") 56 procConvertStringSecurityDescriptorToSecurityDescriptorW = modadvapi32.NewProc("ConvertStringSecurityDescriptorToSecurityDescriptorW") 57 procConvertSecurityDescriptorToStringSecurityDescriptorW = modadvapi32.NewProc("ConvertSecurityDescriptorToStringSecurityDescriptorW") 58 procLocalFree = modkernel32.NewProc("LocalFree") 59 procGetSecurityDescriptorLength = modadvapi32.NewProc("GetSecurityDescriptorLength") 60 procGetFileInformationByHandleEx = modkernel32.NewProc("GetFileInformationByHandleEx") 61 procSetFileInformationByHandle = modkernel32.NewProc("SetFileInformationByHandle") 62 procAdjustTokenPrivileges = modadvapi32.NewProc("AdjustTokenPrivileges") 63 procImpersonateSelf = modadvapi32.NewProc("ImpersonateSelf") 64 procRevertToSelf = modadvapi32.NewProc("RevertToSelf") 65 procOpenThreadToken = modadvapi32.NewProc("OpenThreadToken") 66 procGetCurrentThread = modkernel32.NewProc("GetCurrentThread") 67 procLookupPrivilegeValueW = modadvapi32.NewProc("LookupPrivilegeValueW") 68 procLookupPrivilegeNameW = modadvapi32.NewProc("LookupPrivilegeNameW") 69 procLookupPrivilegeDisplayNameW = modadvapi32.NewProc("LookupPrivilegeDisplayNameW") 70 procBackupRead = modkernel32.NewProc("BackupRead") 71 procBackupWrite = modkernel32.NewProc("BackupWrite") 72) 73 74func cancelIoEx(file syscall.Handle, o *syscall.Overlapped) (err error) { 75 r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(file), uintptr(unsafe.Pointer(o)), 0) 76 if r1 == 0 { 77 if e1 != 0 { 78 err = errnoErr(e1) 79 } else { 80 err = syscall.EINVAL 81 } 82 } 83 return 84} 85 86func createIoCompletionPort(file syscall.Handle, port syscall.Handle, key uintptr, threadCount uint32) (newport syscall.Handle, err error) { 87 r0, _, e1 := syscall.Syscall6(procCreateIoCompletionPort.Addr(), 4, uintptr(file), uintptr(port), uintptr(key), uintptr(threadCount), 0, 0) 88 newport = syscall.Handle(r0) 89 if newport == 0 { 90 if e1 != 0 { 91 err = errnoErr(e1) 92 } else { 93 err = syscall.EINVAL 94 } 95 } 96 return 97} 98 99func getQueuedCompletionStatus(port syscall.Handle, bytes *uint32, key *uintptr, o **ioOperation, timeout uint32) (err error) { 100 r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(port), uintptr(unsafe.Pointer(bytes)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(o)), uintptr(timeout), 0) 101 if r1 == 0 { 102 if e1 != 0 { 103 err = errnoErr(e1) 104 } else { 105 err = syscall.EINVAL 106 } 107 } 108 return 109} 110 111func setFileCompletionNotificationModes(h syscall.Handle, flags uint8) (err error) { 112 r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(h), uintptr(flags), 0) 113 if r1 == 0 { 114 if e1 != 0 { 115 err = errnoErr(e1) 116 } else { 117 err = syscall.EINVAL 118 } 119 } 120 return 121} 122 123func connectNamedPipe(pipe syscall.Handle, o *syscall.Overlapped) (err error) { 124 r1, _, e1 := syscall.Syscall(procConnectNamedPipe.Addr(), 2, uintptr(pipe), uintptr(unsafe.Pointer(o)), 0) 125 if r1 == 0 { 126 if e1 != 0 { 127 err = errnoErr(e1) 128 } else { 129 err = syscall.EINVAL 130 } 131 } 132 return 133} 134 135func createNamedPipe(name string, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) { 136 var _p0 *uint16 137 _p0, err = syscall.UTF16PtrFromString(name) 138 if err != nil { 139 return 140 } 141 return _createNamedPipe(_p0, flags, pipeMode, maxInstances, outSize, inSize, defaultTimeout, sa) 142} 143 144func _createNamedPipe(name *uint16, flags uint32, pipeMode uint32, maxInstances uint32, outSize uint32, inSize uint32, defaultTimeout uint32, sa *syscall.SecurityAttributes) (handle syscall.Handle, err error) { 145 r0, _, e1 := syscall.Syscall9(procCreateNamedPipeW.Addr(), 8, uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(pipeMode), uintptr(maxInstances), uintptr(outSize), uintptr(inSize), uintptr(defaultTimeout), uintptr(unsafe.Pointer(sa)), 0) 146 handle = syscall.Handle(r0) 147 if handle == syscall.InvalidHandle { 148 if e1 != 0 { 149 err = errnoErr(e1) 150 } else { 151 err = syscall.EINVAL 152 } 153 } 154 return 155} 156 157func createFile(name string, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) { 158 var _p0 *uint16 159 _p0, err = syscall.UTF16PtrFromString(name) 160 if err != nil { 161 return 162 } 163 return _createFile(_p0, access, mode, sa, createmode, attrs, templatefile) 164} 165 166func _createFile(name *uint16, access uint32, mode uint32, sa *syscall.SecurityAttributes, createmode uint32, attrs uint32, templatefile syscall.Handle) (handle syscall.Handle, err error) { 167 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) 168 handle = syscall.Handle(r0) 169 if handle == syscall.InvalidHandle { 170 if e1 != 0 { 171 err = errnoErr(e1) 172 } else { 173 err = syscall.EINVAL 174 } 175 } 176 return 177} 178 179func waitNamedPipe(name string, timeout uint32) (err error) { 180 var _p0 *uint16 181 _p0, err = syscall.UTF16PtrFromString(name) 182 if err != nil { 183 return 184 } 185 return _waitNamedPipe(_p0, timeout) 186} 187 188func _waitNamedPipe(name *uint16, timeout uint32) (err error) { 189 r1, _, e1 := syscall.Syscall(procWaitNamedPipeW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(timeout), 0) 190 if r1 == 0 { 191 if e1 != 0 { 192 err = errnoErr(e1) 193 } else { 194 err = syscall.EINVAL 195 } 196 } 197 return 198} 199 200func getNamedPipeInfo(pipe syscall.Handle, flags *uint32, outSize *uint32, inSize *uint32, maxInstances *uint32) (err error) { 201 r1, _, e1 := syscall.Syscall6(procGetNamedPipeInfo.Addr(), 5, uintptr(pipe), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(outSize)), uintptr(unsafe.Pointer(inSize)), uintptr(unsafe.Pointer(maxInstances)), 0) 202 if r1 == 0 { 203 if e1 != 0 { 204 err = errnoErr(e1) 205 } else { 206 err = syscall.EINVAL 207 } 208 } 209 return 210} 211 212func getNamedPipeHandleState(pipe syscall.Handle, state *uint32, curInstances *uint32, maxCollectionCount *uint32, collectDataTimeout *uint32, userName *uint16, maxUserNameSize uint32) (err error) { 213 r1, _, e1 := syscall.Syscall9(procGetNamedPipeHandleStateW.Addr(), 7, uintptr(pipe), uintptr(unsafe.Pointer(state)), uintptr(unsafe.Pointer(curInstances)), uintptr(unsafe.Pointer(maxCollectionCount)), uintptr(unsafe.Pointer(collectDataTimeout)), uintptr(unsafe.Pointer(userName)), uintptr(maxUserNameSize), 0, 0) 214 if r1 == 0 { 215 if e1 != 0 { 216 err = errnoErr(e1) 217 } else { 218 err = syscall.EINVAL 219 } 220 } 221 return 222} 223 224func localAlloc(uFlags uint32, length uint32) (ptr uintptr) { 225 r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(uFlags), uintptr(length), 0) 226 ptr = uintptr(r0) 227 return 228} 229 230func lookupAccountName(systemName *uint16, accountName string, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) { 231 var _p0 *uint16 232 _p0, err = syscall.UTF16PtrFromString(accountName) 233 if err != nil { 234 return 235 } 236 return _lookupAccountName(systemName, _p0, sid, sidSize, refDomain, refDomainSize, sidNameUse) 237} 238 239func _lookupAccountName(systemName *uint16, accountName *uint16, sid *byte, sidSize *uint32, refDomain *uint16, refDomainSize *uint32, sidNameUse *uint32) (err error) { 240 r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidSize)), uintptr(unsafe.Pointer(refDomain)), uintptr(unsafe.Pointer(refDomainSize)), uintptr(unsafe.Pointer(sidNameUse)), 0, 0) 241 if r1 == 0 { 242 if e1 != 0 { 243 err = errnoErr(e1) 244 } else { 245 err = syscall.EINVAL 246 } 247 } 248 return 249} 250 251func convertSidToStringSid(sid *byte, str **uint16) (err error) { 252 r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(str)), 0) 253 if r1 == 0 { 254 if e1 != 0 { 255 err = errnoErr(e1) 256 } else { 257 err = syscall.EINVAL 258 } 259 } 260 return 261} 262 263func convertStringSecurityDescriptorToSecurityDescriptor(str string, revision uint32, sd *uintptr, size *uint32) (err error) { 264 var _p0 *uint16 265 _p0, err = syscall.UTF16PtrFromString(str) 266 if err != nil { 267 return 268 } 269 return _convertStringSecurityDescriptorToSecurityDescriptor(_p0, revision, sd, size) 270} 271 272func _convertStringSecurityDescriptorToSecurityDescriptor(str *uint16, revision uint32, sd *uintptr, size *uint32) (err error) { 273 r1, _, e1 := syscall.Syscall6(procConvertStringSecurityDescriptorToSecurityDescriptorW.Addr(), 4, uintptr(unsafe.Pointer(str)), uintptr(revision), uintptr(unsafe.Pointer(sd)), uintptr(unsafe.Pointer(size)), 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 284func convertSecurityDescriptorToStringSecurityDescriptor(sd *byte, revision uint32, secInfo uint32, sddl **uint16, sddlSize *uint32) (err error) { 285 r1, _, e1 := syscall.Syscall6(procConvertSecurityDescriptorToStringSecurityDescriptorW.Addr(), 5, uintptr(unsafe.Pointer(sd)), uintptr(revision), uintptr(secInfo), uintptr(unsafe.Pointer(sddl)), uintptr(unsafe.Pointer(sddlSize)), 0) 286 if r1 == 0 { 287 if e1 != 0 { 288 err = errnoErr(e1) 289 } else { 290 err = syscall.EINVAL 291 } 292 } 293 return 294} 295 296func localFree(mem uintptr) { 297 syscall.Syscall(procLocalFree.Addr(), 1, uintptr(mem), 0, 0) 298 return 299} 300 301func getSecurityDescriptorLength(sd uintptr) (len uint32) { 302 r0, _, _ := syscall.Syscall(procGetSecurityDescriptorLength.Addr(), 1, uintptr(sd), 0, 0) 303 len = uint32(r0) 304 return 305} 306 307func getFileInformationByHandleEx(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) { 308 r1, _, e1 := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 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 319func setFileInformationByHandle(h syscall.Handle, class uint32, buffer *byte, size uint32) (err error) { 320 r1, _, e1 := syscall.Syscall6(procSetFileInformationByHandle.Addr(), 4, uintptr(h), uintptr(class), uintptr(unsafe.Pointer(buffer)), uintptr(size), 0, 0) 321 if r1 == 0 { 322 if e1 != 0 { 323 err = errnoErr(e1) 324 } else { 325 err = syscall.EINVAL 326 } 327 } 328 return 329} 330 331func adjustTokenPrivileges(token windows.Token, releaseAll bool, input *byte, outputSize uint32, output *byte, requiredSize *uint32) (success bool, err error) { 332 var _p0 uint32 333 if releaseAll { 334 _p0 = 1 335 } else { 336 _p0 = 0 337 } 338 r0, _, e1 := syscall.Syscall6(procAdjustTokenPrivileges.Addr(), 6, uintptr(token), uintptr(_p0), uintptr(unsafe.Pointer(input)), uintptr(outputSize), uintptr(unsafe.Pointer(output)), uintptr(unsafe.Pointer(requiredSize))) 339 success = r0 != 0 340 if true { 341 if e1 != 0 { 342 err = errnoErr(e1) 343 } else { 344 err = syscall.EINVAL 345 } 346 } 347 return 348} 349 350func impersonateSelf(level uint32) (err error) { 351 r1, _, e1 := syscall.Syscall(procImpersonateSelf.Addr(), 1, uintptr(level), 0, 0) 352 if r1 == 0 { 353 if e1 != 0 { 354 err = errnoErr(e1) 355 } else { 356 err = syscall.EINVAL 357 } 358 } 359 return 360} 361 362func revertToSelf() (err error) { 363 r1, _, e1 := syscall.Syscall(procRevertToSelf.Addr(), 0, 0, 0, 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 374func openThreadToken(thread syscall.Handle, accessMask uint32, openAsSelf bool, token *windows.Token) (err error) { 375 var _p0 uint32 376 if openAsSelf { 377 _p0 = 1 378 } else { 379 _p0 = 0 380 } 381 r1, _, e1 := syscall.Syscall6(procOpenThreadToken.Addr(), 4, uintptr(thread), uintptr(accessMask), uintptr(_p0), uintptr(unsafe.Pointer(token)), 0, 0) 382 if r1 == 0 { 383 if e1 != 0 { 384 err = errnoErr(e1) 385 } else { 386 err = syscall.EINVAL 387 } 388 } 389 return 390} 391 392func getCurrentThread() (h syscall.Handle) { 393 r0, _, _ := syscall.Syscall(procGetCurrentThread.Addr(), 0, 0, 0, 0) 394 h = syscall.Handle(r0) 395 return 396} 397 398func lookupPrivilegeValue(systemName string, name string, luid *uint64) (err error) { 399 var _p0 *uint16 400 _p0, err = syscall.UTF16PtrFromString(systemName) 401 if err != nil { 402 return 403 } 404 var _p1 *uint16 405 _p1, err = syscall.UTF16PtrFromString(name) 406 if err != nil { 407 return 408 } 409 return _lookupPrivilegeValue(_p0, _p1, luid) 410} 411 412func _lookupPrivilegeValue(systemName *uint16, name *uint16, luid *uint64) (err error) { 413 r1, _, e1 := syscall.Syscall(procLookupPrivilegeValueW.Addr(), 3, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(luid))) 414 if r1 == 0 { 415 if e1 != 0 { 416 err = errnoErr(e1) 417 } else { 418 err = syscall.EINVAL 419 } 420 } 421 return 422} 423 424func lookupPrivilegeName(systemName string, luid *uint64, buffer *uint16, size *uint32) (err error) { 425 var _p0 *uint16 426 _p0, err = syscall.UTF16PtrFromString(systemName) 427 if err != nil { 428 return 429 } 430 return _lookupPrivilegeName(_p0, luid, buffer, size) 431} 432 433func _lookupPrivilegeName(systemName *uint16, luid *uint64, buffer *uint16, size *uint32) (err error) { 434 r1, _, e1 := syscall.Syscall6(procLookupPrivilegeNameW.Addr(), 4, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(luid)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), 0, 0) 435 if r1 == 0 { 436 if e1 != 0 { 437 err = errnoErr(e1) 438 } else { 439 err = syscall.EINVAL 440 } 441 } 442 return 443} 444 445func lookupPrivilegeDisplayName(systemName string, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) { 446 var _p0 *uint16 447 _p0, err = syscall.UTF16PtrFromString(systemName) 448 if err != nil { 449 return 450 } 451 return _lookupPrivilegeDisplayName(_p0, name, buffer, size, languageId) 452} 453 454func _lookupPrivilegeDisplayName(systemName *uint16, name *uint16, buffer *uint16, size *uint32, languageId *uint32) (err error) { 455 r1, _, e1 := syscall.Syscall6(procLookupPrivilegeDisplayNameW.Addr(), 5, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(buffer)), uintptr(unsafe.Pointer(size)), uintptr(unsafe.Pointer(languageId)), 0) 456 if r1 == 0 { 457 if e1 != 0 { 458 err = errnoErr(e1) 459 } else { 460 err = syscall.EINVAL 461 } 462 } 463 return 464} 465 466func backupRead(h syscall.Handle, b []byte, bytesRead *uint32, abort bool, processSecurity bool, context *uintptr) (err error) { 467 var _p0 *byte 468 if len(b) > 0 { 469 _p0 = &b[0] 470 } 471 var _p1 uint32 472 if abort { 473 _p1 = 1 474 } else { 475 _p1 = 0 476 } 477 var _p2 uint32 478 if processSecurity { 479 _p2 = 1 480 } else { 481 _p2 = 0 482 } 483 r1, _, e1 := syscall.Syscall9(procBackupRead.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesRead)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0) 484 if r1 == 0 { 485 if e1 != 0 { 486 err = errnoErr(e1) 487 } else { 488 err = syscall.EINVAL 489 } 490 } 491 return 492} 493 494func backupWrite(h syscall.Handle, b []byte, bytesWritten *uint32, abort bool, processSecurity bool, context *uintptr) (err error) { 495 var _p0 *byte 496 if len(b) > 0 { 497 _p0 = &b[0] 498 } 499 var _p1 uint32 500 if abort { 501 _p1 = 1 502 } else { 503 _p1 = 0 504 } 505 var _p2 uint32 506 if processSecurity { 507 _p2 = 1 508 } else { 509 _p2 = 0 510 } 511 r1, _, e1 := syscall.Syscall9(procBackupWrite.Addr(), 7, uintptr(h), uintptr(unsafe.Pointer(_p0)), uintptr(len(b)), uintptr(unsafe.Pointer(bytesWritten)), uintptr(_p1), uintptr(_p2), uintptr(unsafe.Pointer(context)), 0, 0) 512 if r1 == 0 { 513 if e1 != 0 { 514 err = errnoErr(e1) 515 } else { 516 err = syscall.EINVAL 517 } 518 } 519 return 520} 521