Source file src/internal/syscall/windows/syscall_windows.go

     1  // Copyright 2014 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package windows
     6  
     7  import (
     8  	"sync"
     9  	"syscall"
    10  	"unsafe"
    11  )
    12  
    13  // CanUseLongPaths is true when the OS supports opting into
    14  // proper long path handling without the need for fixups.
    15  //
    16  //go:linkname CanUseLongPaths
    17  var CanUseLongPaths bool
    18  
    19  // UTF16PtrToString is like UTF16ToString, but takes *uint16
    20  // as a parameter instead of []uint16.
    21  func UTF16PtrToString(p *uint16) string {
    22  	if p == nil {
    23  		return ""
    24  	}
    25  	end := unsafe.Pointer(p)
    26  	n := 0
    27  	for *(*uint16)(end) != 0 {
    28  		end = unsafe.Pointer(uintptr(end) + unsafe.Sizeof(*p))
    29  		n++
    30  	}
    31  	return syscall.UTF16ToString(unsafe.Slice(p, n))
    32  }
    33  
    34  const (
    35  	ERROR_BAD_LENGTH             syscall.Errno = 24
    36  	ERROR_SHARING_VIOLATION      syscall.Errno = 32
    37  	ERROR_LOCK_VIOLATION         syscall.Errno = 33
    38  	ERROR_NOT_SUPPORTED          syscall.Errno = 50
    39  	ERROR_CALL_NOT_IMPLEMENTED   syscall.Errno = 120
    40  	ERROR_INVALID_NAME           syscall.Errno = 123
    41  	ERROR_LOCK_FAILED            syscall.Errno = 167
    42  	ERROR_NO_TOKEN               syscall.Errno = 1008
    43  	ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113
    44  )
    45  
    46  const (
    47  	GAA_FLAG_INCLUDE_PREFIX   = 0x00000010
    48  	GAA_FLAG_INCLUDE_GATEWAYS = 0x0080
    49  )
    50  
    51  const (
    52  	IF_TYPE_OTHER              = 1
    53  	IF_TYPE_ETHERNET_CSMACD    = 6
    54  	IF_TYPE_ISO88025_TOKENRING = 9
    55  	IF_TYPE_PPP                = 23
    56  	IF_TYPE_SOFTWARE_LOOPBACK  = 24
    57  	IF_TYPE_ATM                = 37
    58  	IF_TYPE_IEEE80211          = 71
    59  	IF_TYPE_TUNNEL             = 131
    60  	IF_TYPE_IEEE1394           = 144
    61  )
    62  
    63  type SocketAddress struct {
    64  	Sockaddr       *syscall.RawSockaddrAny
    65  	SockaddrLength int32
    66  }
    67  
    68  type IpAdapterUnicastAddress struct {
    69  	Length             uint32
    70  	Flags              uint32
    71  	Next               *IpAdapterUnicastAddress
    72  	Address            SocketAddress
    73  	PrefixOrigin       int32
    74  	SuffixOrigin       int32
    75  	DadState           int32
    76  	ValidLifetime      uint32
    77  	PreferredLifetime  uint32
    78  	LeaseLifetime      uint32
    79  	OnLinkPrefixLength uint8
    80  }
    81  
    82  type IpAdapterAnycastAddress struct {
    83  	Length  uint32
    84  	Flags   uint32
    85  	Next    *IpAdapterAnycastAddress
    86  	Address SocketAddress
    87  }
    88  
    89  type IpAdapterMulticastAddress struct {
    90  	Length  uint32
    91  	Flags   uint32
    92  	Next    *IpAdapterMulticastAddress
    93  	Address SocketAddress
    94  }
    95  
    96  type IpAdapterDnsServerAdapter struct {
    97  	Length   uint32
    98  	Reserved uint32
    99  	Next     *IpAdapterDnsServerAdapter
   100  	Address  SocketAddress
   101  }
   102  
   103  type IpAdapterPrefix struct {
   104  	Length       uint32
   105  	Flags        uint32
   106  	Next         *IpAdapterPrefix
   107  	Address      SocketAddress
   108  	PrefixLength uint32
   109  }
   110  
   111  type IpAdapterWinsServerAddress struct {
   112  	Length   uint32
   113  	Reserved uint32
   114  	Next     *IpAdapterWinsServerAddress
   115  	Address  SocketAddress
   116  }
   117  
   118  type IpAdapterGatewayAddress struct {
   119  	Length   uint32
   120  	Reserved uint32
   121  	Next     *IpAdapterGatewayAddress
   122  	Address  SocketAddress
   123  }
   124  
   125  type IpAdapterAddresses struct {
   126  	Length                 uint32
   127  	IfIndex                uint32
   128  	Next                   *IpAdapterAddresses
   129  	AdapterName            *byte
   130  	FirstUnicastAddress    *IpAdapterUnicastAddress
   131  	FirstAnycastAddress    *IpAdapterAnycastAddress
   132  	FirstMulticastAddress  *IpAdapterMulticastAddress
   133  	FirstDnsServerAddress  *IpAdapterDnsServerAdapter
   134  	DnsSuffix              *uint16
   135  	Description            *uint16
   136  	FriendlyName           *uint16
   137  	PhysicalAddress        [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
   138  	PhysicalAddressLength  uint32
   139  	Flags                  uint32
   140  	Mtu                    uint32
   141  	IfType                 uint32
   142  	OperStatus             uint32
   143  	Ipv6IfIndex            uint32
   144  	ZoneIndices            [16]uint32
   145  	FirstPrefix            *IpAdapterPrefix
   146  	TransmitLinkSpeed      uint64
   147  	ReceiveLinkSpeed       uint64
   148  	FirstWinsServerAddress *IpAdapterWinsServerAddress
   149  	FirstGatewayAddress    *IpAdapterGatewayAddress
   150  	/* more fields might be present here. */
   151  }
   152  
   153  type SecurityAttributes struct {
   154  	Length             uint16
   155  	SecurityDescriptor uintptr
   156  	InheritHandle      bool
   157  }
   158  
   159  type FILE_BASIC_INFO struct {
   160  	CreationTime   int64
   161  	LastAccessTime int64
   162  	LastWriteTime  int64
   163  	ChangedTime    int64
   164  	FileAttributes uint32
   165  
   166  	// Pad out to 8-byte alignment.
   167  	//
   168  	// Without this padding, TestChmod fails due to an argument validation error
   169  	// in SetFileInformationByHandle on windows/386.
   170  	//
   171  	// https://learn.microsoft.com/en-us/cpp/build/reference/zp-struct-member-alignment?view=msvc-170
   172  	// says that “The C/C++ headers in the Windows SDK assume the platform's
   173  	// default alignment is used.” What we see here is padding rather than
   174  	// alignment, but maybe it is related.
   175  	_ uint32
   176  }
   177  
   178  const (
   179  	IfOperStatusUp             = 1
   180  	IfOperStatusDown           = 2
   181  	IfOperStatusTesting        = 3
   182  	IfOperStatusUnknown        = 4
   183  	IfOperStatusDormant        = 5
   184  	IfOperStatusNotPresent     = 6
   185  	IfOperStatusLowerLayerDown = 7
   186  )
   187  
   188  //sys	GetAdaptersAddresses(family uint32, flags uint32, reserved uintptr, adapterAddresses *IpAdapterAddresses, sizePointer *uint32) (errcode error) = iphlpapi.GetAdaptersAddresses
   189  //sys	GetComputerNameEx(nameformat uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW
   190  //sys	MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) = MoveFileExW
   191  //sys	GetModuleFileName(module syscall.Handle, fn *uint16, len uint32) (n uint32, err error) = kernel32.GetModuleFileNameW
   192  //sys	SetFileInformationByHandle(handle syscall.Handle, fileInformationClass uint32, buf unsafe.Pointer, bufsize uint32) (err error) = kernel32.SetFileInformationByHandle
   193  //sys	VirtualQuery(address uintptr, buffer *MemoryBasicInformation, length uintptr) (err error) = kernel32.VirtualQuery
   194  //sys	GetTempPath2(buflen uint32, buf *uint16) (n uint32, err error) = GetTempPath2W
   195  
   196  const (
   197  	// flags for CreateToolhelp32Snapshot
   198  	TH32CS_SNAPMODULE   = 0x08
   199  	TH32CS_SNAPMODULE32 = 0x10
   200  )
   201  
   202  const MAX_MODULE_NAME32 = 255
   203  
   204  type ModuleEntry32 struct {
   205  	Size         uint32
   206  	ModuleID     uint32
   207  	ProcessID    uint32
   208  	GlblcntUsage uint32
   209  	ProccntUsage uint32
   210  	ModBaseAddr  uintptr
   211  	ModBaseSize  uint32
   212  	ModuleHandle syscall.Handle
   213  	Module       [MAX_MODULE_NAME32 + 1]uint16
   214  	ExePath      [syscall.MAX_PATH]uint16
   215  }
   216  
   217  const SizeofModuleEntry32 = unsafe.Sizeof(ModuleEntry32{})
   218  
   219  //sys	Module32First(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32FirstW
   220  //sys	Module32Next(snapshot syscall.Handle, moduleEntry *ModuleEntry32) (err error) = kernel32.Module32NextW
   221  
   222  const (
   223  	WSA_FLAG_OVERLAPPED        = 0x01
   224  	WSA_FLAG_NO_HANDLE_INHERIT = 0x80
   225  
   226  	WSAEINVAL       syscall.Errno = 10022
   227  	WSAEMSGSIZE     syscall.Errno = 10040
   228  	WSAEAFNOSUPPORT syscall.Errno = 10047
   229  
   230  	MSG_PEEK   = 0x2
   231  	MSG_TRUNC  = 0x0100
   232  	MSG_CTRUNC = 0x0200
   233  
   234  	socket_error = uintptr(^uint32(0))
   235  )
   236  
   237  var WSAID_WSASENDMSG = syscall.GUID{
   238  	Data1: 0xa441e712,
   239  	Data2: 0x754f,
   240  	Data3: 0x43ca,
   241  	Data4: [8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d},
   242  }
   243  
   244  var WSAID_WSARECVMSG = syscall.GUID{
   245  	Data1: 0xf689d7c8,
   246  	Data2: 0x6f1f,
   247  	Data3: 0x436b,
   248  	Data4: [8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22},
   249  }
   250  
   251  var sendRecvMsgFunc struct {
   252  	once     sync.Once
   253  	sendAddr uintptr
   254  	recvAddr uintptr
   255  	err      error
   256  }
   257  
   258  type WSAMsg struct {
   259  	Name        syscall.Pointer
   260  	Namelen     int32
   261  	Buffers     *syscall.WSABuf
   262  	BufferCount uint32
   263  	Control     syscall.WSABuf
   264  	Flags       uint32
   265  }
   266  
   267  //sys	WSASocket(af int32, typ int32, protocol int32, protinfo *syscall.WSAProtocolInfo, group uint32, flags uint32) (handle syscall.Handle, err error) [failretval==syscall.InvalidHandle] = ws2_32.WSASocketW
   268  //sys	WSAGetOverlappedResult(h syscall.Handle, o *syscall.Overlapped, bytes *uint32, wait bool, flags *uint32) (err error) = ws2_32.WSAGetOverlappedResult
   269  
   270  func loadWSASendRecvMsg() error {
   271  	sendRecvMsgFunc.once.Do(func() {
   272  		var s syscall.Handle
   273  		s, sendRecvMsgFunc.err = syscall.Socket(syscall.AF_INET, syscall.SOCK_DGRAM, syscall.IPPROTO_UDP)
   274  		if sendRecvMsgFunc.err != nil {
   275  			return
   276  		}
   277  		defer syscall.CloseHandle(s)
   278  		var n uint32
   279  		sendRecvMsgFunc.err = syscall.WSAIoctl(s,
   280  			syscall.SIO_GET_EXTENSION_FUNCTION_POINTER,
   281  			(*byte)(unsafe.Pointer(&WSAID_WSARECVMSG)),
   282  			uint32(unsafe.Sizeof(WSAID_WSARECVMSG)),
   283  			(*byte)(unsafe.Pointer(&sendRecvMsgFunc.recvAddr)),
   284  			uint32(unsafe.Sizeof(sendRecvMsgFunc.recvAddr)),
   285  			&n, nil, 0)
   286  		if sendRecvMsgFunc.err != nil {
   287  			return
   288  		}
   289  		sendRecvMsgFunc.err = syscall.WSAIoctl(s,
   290  			syscall.SIO_GET_EXTENSION_FUNCTION_POINTER,
   291  			(*byte)(unsafe.Pointer(&WSAID_WSASENDMSG)),
   292  			uint32(unsafe.Sizeof(WSAID_WSASENDMSG)),
   293  			(*byte)(unsafe.Pointer(&sendRecvMsgFunc.sendAddr)),
   294  			uint32(unsafe.Sizeof(sendRecvMsgFunc.sendAddr)),
   295  			&n, nil, 0)
   296  	})
   297  	return sendRecvMsgFunc.err
   298  }
   299  
   300  func WSASendMsg(fd syscall.Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlapped *syscall.Overlapped, croutine *byte) error {
   301  	err := loadWSASendRecvMsg()
   302  	if err != nil {
   303  		return err
   304  	}
   305  	r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.sendAddr, 6, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(flags), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)))
   306  	if r1 == socket_error {
   307  		if e1 != 0 {
   308  			err = errnoErr(e1)
   309  		} else {
   310  			err = syscall.EINVAL
   311  		}
   312  	}
   313  	return err
   314  }
   315  
   316  func WSARecvMsg(fd syscall.Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *syscall.Overlapped, croutine *byte) error {
   317  	err := loadWSASendRecvMsg()
   318  	if err != nil {
   319  		return err
   320  	}
   321  	r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.recvAddr, 5, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(bytesReceived)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0)
   322  	if r1 == socket_error {
   323  		if e1 != 0 {
   324  			err = errnoErr(e1)
   325  		} else {
   326  			err = syscall.EINVAL
   327  		}
   328  	}
   329  	return err
   330  }
   331  
   332  const (
   333  	ComputerNameNetBIOS                   = 0
   334  	ComputerNameDnsHostname               = 1
   335  	ComputerNameDnsDomain                 = 2
   336  	ComputerNameDnsFullyQualified         = 3
   337  	ComputerNamePhysicalNetBIOS           = 4
   338  	ComputerNamePhysicalDnsHostname       = 5
   339  	ComputerNamePhysicalDnsDomain         = 6
   340  	ComputerNamePhysicalDnsFullyQualified = 7
   341  	ComputerNameMax                       = 8
   342  
   343  	MOVEFILE_REPLACE_EXISTING      = 0x1
   344  	MOVEFILE_COPY_ALLOWED          = 0x2
   345  	MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
   346  	MOVEFILE_WRITE_THROUGH         = 0x8
   347  	MOVEFILE_CREATE_HARDLINK       = 0x10
   348  	MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
   349  )
   350  
   351  func Rename(oldpath, newpath string) error {
   352  	from, err := syscall.UTF16PtrFromString(oldpath)
   353  	if err != nil {
   354  		return err
   355  	}
   356  	to, err := syscall.UTF16PtrFromString(newpath)
   357  	if err != nil {
   358  		return err
   359  	}
   360  	return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)
   361  }
   362  
   363  //sys LockFileEx(file syscall.Handle, flags uint32, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) = kernel32.LockFileEx
   364  //sys UnlockFileEx(file syscall.Handle, reserved uint32, bytesLow uint32, bytesHigh uint32, overlapped *syscall.Overlapped) (err error) = kernel32.UnlockFileEx
   365  
   366  const (
   367  	LOCKFILE_FAIL_IMMEDIATELY = 0x00000001
   368  	LOCKFILE_EXCLUSIVE_LOCK   = 0x00000002
   369  )
   370  
   371  const MB_ERR_INVALID_CHARS = 8
   372  
   373  //sys	GetACP() (acp uint32) = kernel32.GetACP
   374  //sys	GetConsoleCP() (ccp uint32) = kernel32.GetConsoleCP
   375  //sys	MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
   376  //sys	GetCurrentThread() (pseudoHandle syscall.Handle, err error) = kernel32.GetCurrentThread
   377  
   378  // Constants from lmshare.h
   379  const (
   380  	STYPE_DISKTREE  = 0x00
   381  	STYPE_TEMPORARY = 0x40000000
   382  )
   383  
   384  type SHARE_INFO_2 struct {
   385  	Netname     *uint16
   386  	Type        uint32
   387  	Remark      *uint16
   388  	Permissions uint32
   389  	MaxUses     uint32
   390  	CurrentUses uint32
   391  	Path        *uint16
   392  	Passwd      *uint16
   393  }
   394  
   395  //sys  NetShareAdd(serverName *uint16, level uint32, buf *byte, parmErr *uint16) (neterr error) = netapi32.NetShareAdd
   396  //sys  NetShareDel(serverName *uint16, netName *uint16, reserved uint32) (neterr error) = netapi32.NetShareDel
   397  
   398  const (
   399  	FILE_NAME_NORMALIZED = 0x0
   400  	FILE_NAME_OPENED     = 0x8
   401  
   402  	VOLUME_NAME_DOS  = 0x0
   403  	VOLUME_NAME_GUID = 0x1
   404  	VOLUME_NAME_NONE = 0x4
   405  	VOLUME_NAME_NT   = 0x2
   406  )
   407  
   408  //sys	GetFinalPathNameByHandle(file syscall.Handle, filePath *uint16, filePathSize uint32, flags uint32) (n uint32, err error) = kernel32.GetFinalPathNameByHandleW
   409  
   410  func ErrorLoadingGetTempPath2() error {
   411  	return procGetTempPath2W.Find()
   412  }
   413  
   414  //sys	CreateEnvironmentBlock(block **uint16, token syscall.Token, inheritExisting bool) (err error) = userenv.CreateEnvironmentBlock
   415  //sys	DestroyEnvironmentBlock(block *uint16) (err error) = userenv.DestroyEnvironmentBlock
   416  //sys	CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle syscall.Handle, err error) = kernel32.CreateEventW
   417  
   418  //sys	ProcessPrng(buf []byte) (err error) = bcryptprimitives.ProcessPrng
   419  
   420  type FILE_ID_BOTH_DIR_INFO struct {
   421  	NextEntryOffset uint32
   422  	FileIndex       uint32
   423  	CreationTime    syscall.Filetime
   424  	LastAccessTime  syscall.Filetime
   425  	LastWriteTime   syscall.Filetime
   426  	ChangeTime      syscall.Filetime
   427  	EndOfFile       uint64
   428  	AllocationSize  uint64
   429  	FileAttributes  uint32
   430  	FileNameLength  uint32
   431  	EaSize          uint32
   432  	ShortNameLength uint32
   433  	ShortName       [12]uint16
   434  	FileID          uint64
   435  	FileName        [1]uint16
   436  }
   437  
   438  type FILE_FULL_DIR_INFO struct {
   439  	NextEntryOffset uint32
   440  	FileIndex       uint32
   441  	CreationTime    syscall.Filetime
   442  	LastAccessTime  syscall.Filetime
   443  	LastWriteTime   syscall.Filetime
   444  	ChangeTime      syscall.Filetime
   445  	EndOfFile       uint64
   446  	AllocationSize  uint64
   447  	FileAttributes  uint32
   448  	FileNameLength  uint32
   449  	EaSize          uint32
   450  	FileName        [1]uint16
   451  }
   452  
   453  //sys	GetVolumeInformationByHandle(file syscall.Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) = GetVolumeInformationByHandleW
   454  //sys	GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) = GetVolumeNameForVolumeMountPointW
   455  
   456  //sys	RtlLookupFunctionEntry(pc uintptr, baseAddress *uintptr, table *byte) (ret uintptr) = kernel32.RtlLookupFunctionEntry
   457  //sys	RtlVirtualUnwind(handlerType uint32, baseAddress uintptr, pc uintptr, entry uintptr, ctxt uintptr, data *uintptr, frame *uintptr, ctxptrs *byte) (ret uintptr) = kernel32.RtlVirtualUnwind
   458  
   459  type SERVICE_STATUS struct {
   460  	ServiceType             uint32
   461  	CurrentState            uint32
   462  	ControlsAccepted        uint32
   463  	Win32ExitCode           uint32
   464  	ServiceSpecificExitCode uint32
   465  	CheckPoint              uint32
   466  	WaitHint                uint32
   467  }
   468  
   469  const (
   470  	SERVICE_RUNNING      = 4
   471  	SERVICE_QUERY_STATUS = 4
   472  )
   473  
   474  //sys    OpenService(mgr syscall.Handle, serviceName *uint16, access uint32) (handle syscall.Handle, err error) = advapi32.OpenServiceW
   475  //sys	QueryServiceStatus(hService syscall.Handle, lpServiceStatus *SERVICE_STATUS) (err error)  = advapi32.QueryServiceStatus
   476  //sys    OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (handle syscall.Handle, err error)  [failretval==0] = advapi32.OpenSCManagerW
   477  
   478  func FinalPath(h syscall.Handle, flags uint32) (string, error) {
   479  	buf := make([]uint16, 100)
   480  	for {
   481  		n, err := GetFinalPathNameByHandle(h, &buf[0], uint32(len(buf)), flags)
   482  		if err != nil {
   483  			return "", err
   484  		}
   485  		if n < uint32(len(buf)) {
   486  			break
   487  		}
   488  		buf = make([]uint16, n)
   489  	}
   490  	return syscall.UTF16ToString(buf), nil
   491  }
   492  
   493  // QueryPerformanceCounter retrieves the current value of performance counter.
   494  //
   495  //go:linkname QueryPerformanceCounter
   496  func QueryPerformanceCounter() int64 // Implemented in runtime package.
   497  
   498  // QueryPerformanceFrequency retrieves the frequency of the performance counter.
   499  // The returned value is represented as counts per second.
   500  //
   501  //go:linkname QueryPerformanceFrequency
   502  func QueryPerformanceFrequency() int64 // Implemented in runtime package.
   503  
   504  //sys   GetModuleHandle(modulename *uint16) (handle syscall.Handle, err error) = kernel32.GetModuleHandleW
   505  
   506  // NTStatus corresponds with NTSTATUS, error values returned by ntdll.dll and
   507  // other native functions.
   508  type NTStatus uint32
   509  
   510  func (s NTStatus) Errno() syscall.Errno {
   511  	return rtlNtStatusToDosErrorNoTeb(s)
   512  }
   513  
   514  func langID(pri, sub uint16) uint32 { return uint32(sub)<<10 | uint32(pri) }
   515  
   516  func (s NTStatus) Error() string {
   517  	return s.Errno().Error()
   518  }
   519  
   520  // x/sys/windows/mkerrors.bash can generate a complete list of NTStatus codes.
   521  //
   522  // At the moment, we only need a couple, so just put them here manually.
   523  // If this list starts getting long, we should consider generating the full set.
   524  const (
   525  	STATUS_FILE_IS_A_DIRECTORY       NTStatus = 0xC00000BA
   526  	STATUS_NOT_A_DIRECTORY           NTStatus = 0xC0000103
   527  	STATUS_REPARSE_POINT_ENCOUNTERED NTStatus = 0xC000050B
   528  )
   529  
   530  // NT Native APIs
   531  //sys   NtCreateFile(handle *syscall.Handle, access uint32, oa *OBJECT_ATTRIBUTES, iosb *IO_STATUS_BLOCK, allocationSize *int64, attributes uint32, share uint32, disposition uint32, options uint32, eabuffer uintptr, ealength uint32) (ntstatus error) = ntdll.NtCreateFile
   532  //sys   rtlNtStatusToDosErrorNoTeb(ntstatus NTStatus) (ret syscall.Errno) = ntdll.RtlNtStatusToDosErrorNoTeb
   533  

View as plain text