zsyscall_windows.go 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // Code generated by 'go generate'; DO NOT EDIT.
  2. package safefile
  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. modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
  34. procNtCreateFile = modntdll.NewProc("NtCreateFile")
  35. procNtSetInformationFile = modntdll.NewProc("NtSetInformationFile")
  36. procRtlNtStatusToDosErrorNoTeb = modntdll.NewProc("RtlNtStatusToDosErrorNoTeb")
  37. procLocalAlloc = modkernel32.NewProc("LocalAlloc")
  38. procLocalFree = modkernel32.NewProc("LocalFree")
  39. )
  40. 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) {
  41. 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)
  42. status = uint32(r0)
  43. return
  44. }
  45. func ntSetInformationFile(handle uintptr, iosb *ioStatusBlock, information uintptr, length uint32, class uint32) (status uint32) {
  46. r0, _, _ := syscall.Syscall6(procNtSetInformationFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(iosb)), uintptr(information), uintptr(length), uintptr(class), 0)
  47. status = uint32(r0)
  48. return
  49. }
  50. func rtlNtStatusToDosError(status uint32) (winerr error) {
  51. r0, _, _ := syscall.Syscall(procRtlNtStatusToDosErrorNoTeb.Addr(), 1, uintptr(status), 0, 0)
  52. if r0 != 0 {
  53. winerr = syscall.Errno(r0)
  54. }
  55. return
  56. }
  57. func localAlloc(flags uint32, size int) (ptr uintptr) {
  58. r0, _, _ := syscall.Syscall(procLocalAlloc.Addr(), 2, uintptr(flags), uintptr(size), 0)
  59. ptr = uintptr(r0)
  60. return
  61. }
  62. func localFree(ptr uintptr) {
  63. syscall.Syscall(procLocalFree.Addr(), 1, uintptr(ptr), 0, 0)
  64. return
  65. }