github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/syscall/windows/syscall_windows.go (about) 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 "github.com/shogo82148/std/syscall" 9 "github.com/shogo82148/std/unsafe" 10 ) 11 12 // CanUseLongPaths is true when the OS supports opting into 13 // proper long path handling without the need for fixups. 14 // 15 //go:linkname CanUseLongPaths 16 var CanUseLongPaths bool 17 18 // UTF16PtrToString is like UTF16ToString, but takes *uint16 19 // as a parameter instead of []uint16. 20 func UTF16PtrToString(p *uint16) string 21 22 const ( 23 ERROR_BAD_LENGTH syscall.Errno = 24 24 ERROR_SHARING_VIOLATION syscall.Errno = 32 25 ERROR_LOCK_VIOLATION syscall.Errno = 33 26 ERROR_NOT_SUPPORTED syscall.Errno = 50 27 ERROR_CALL_NOT_IMPLEMENTED syscall.Errno = 120 28 ERROR_INVALID_NAME syscall.Errno = 123 29 ERROR_LOCK_FAILED syscall.Errno = 167 30 ERROR_NO_UNICODE_TRANSLATION syscall.Errno = 1113 31 ) 32 33 const ( 34 GAA_FLAG_INCLUDE_PREFIX = 0x00000010 35 GAA_FLAG_INCLUDE_GATEWAYS = 0x0080 36 ) 37 38 const ( 39 IF_TYPE_OTHER = 1 40 IF_TYPE_ETHERNET_CSMACD = 6 41 IF_TYPE_ISO88025_TOKENRING = 9 42 IF_TYPE_PPP = 23 43 IF_TYPE_SOFTWARE_LOOPBACK = 24 44 IF_TYPE_ATM = 37 45 IF_TYPE_IEEE80211 = 71 46 IF_TYPE_TUNNEL = 131 47 IF_TYPE_IEEE1394 = 144 48 ) 49 50 type SocketAddress struct { 51 Sockaddr *syscall.RawSockaddrAny 52 SockaddrLength int32 53 } 54 55 type IpAdapterUnicastAddress struct { 56 Length uint32 57 Flags uint32 58 Next *IpAdapterUnicastAddress 59 Address SocketAddress 60 PrefixOrigin int32 61 SuffixOrigin int32 62 DadState int32 63 ValidLifetime uint32 64 PreferredLifetime uint32 65 LeaseLifetime uint32 66 OnLinkPrefixLength uint8 67 } 68 69 type IpAdapterAnycastAddress struct { 70 Length uint32 71 Flags uint32 72 Next *IpAdapterAnycastAddress 73 Address SocketAddress 74 } 75 76 type IpAdapterMulticastAddress struct { 77 Length uint32 78 Flags uint32 79 Next *IpAdapterMulticastAddress 80 Address SocketAddress 81 } 82 83 type IpAdapterDnsServerAdapter struct { 84 Length uint32 85 Reserved uint32 86 Next *IpAdapterDnsServerAdapter 87 Address SocketAddress 88 } 89 90 type IpAdapterPrefix struct { 91 Length uint32 92 Flags uint32 93 Next *IpAdapterPrefix 94 Address SocketAddress 95 PrefixLength uint32 96 } 97 98 type IpAdapterWinsServerAddress struct { 99 Length uint32 100 Reserved uint32 101 Next *IpAdapterWinsServerAddress 102 Address SocketAddress 103 } 104 105 type IpAdapterGatewayAddress struct { 106 Length uint32 107 Reserved uint32 108 Next *IpAdapterGatewayAddress 109 Address SocketAddress 110 } 111 112 type IpAdapterAddresses struct { 113 Length uint32 114 IfIndex uint32 115 Next *IpAdapterAddresses 116 AdapterName *byte 117 FirstUnicastAddress *IpAdapterUnicastAddress 118 FirstAnycastAddress *IpAdapterAnycastAddress 119 FirstMulticastAddress *IpAdapterMulticastAddress 120 FirstDnsServerAddress *IpAdapterDnsServerAdapter 121 DnsSuffix *uint16 122 Description *uint16 123 FriendlyName *uint16 124 PhysicalAddress [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte 125 PhysicalAddressLength uint32 126 Flags uint32 127 Mtu uint32 128 IfType uint32 129 OperStatus uint32 130 Ipv6IfIndex uint32 131 ZoneIndices [16]uint32 132 FirstPrefix *IpAdapterPrefix 133 TransmitLinkSpeed uint64 134 ReceiveLinkSpeed uint64 135 FirstWinsServerAddress *IpAdapterWinsServerAddress 136 FirstGatewayAddress *IpAdapterGatewayAddress 137 } 138 139 type SecurityAttributes struct { 140 Length uint16 141 SecurityDescriptor uintptr 142 InheritHandle bool 143 } 144 145 type FILE_BASIC_INFO struct { 146 CreationTime int64 147 LastAccessTime int64 148 LastWriteTime int64 149 ChangedTime int64 150 FileAttributes uint32 151 152 // Pad out to 8-byte alignment. 153 // 154 // Without this padding, TestChmod fails due to an argument validation error 155 // in SetFileInformationByHandle on windows/386. 156 // 157 // https://learn.microsoft.com/en-us/cpp/build/reference/zp-struct-member-alignment?view=msvc-170 158 // says that “The C/C++ headers in the Windows SDK assume the platform's 159 // default alignment is used.” What we see here is padding rather than 160 // alignment, but maybe it is related. 161 _ uint32 162 } 163 164 const ( 165 IfOperStatusUp = 1 166 IfOperStatusDown = 2 167 IfOperStatusTesting = 3 168 IfOperStatusUnknown = 4 169 IfOperStatusDormant = 5 170 IfOperStatusNotPresent = 6 171 IfOperStatusLowerLayerDown = 7 172 ) 173 174 const ( 175 // flags for CreateToolhelp32Snapshot 176 TH32CS_SNAPMODULE = 0x08 177 TH32CS_SNAPMODULE32 = 0x10 178 ) 179 180 const MAX_MODULE_NAME32 = 255 181 182 type ModuleEntry32 struct { 183 Size uint32 184 ModuleID uint32 185 ProcessID uint32 186 GlblcntUsage uint32 187 ProccntUsage uint32 188 ModBaseAddr uintptr 189 ModBaseSize uint32 190 ModuleHandle syscall.Handle 191 Module [MAX_MODULE_NAME32 + 1]uint16 192 ExePath [syscall.MAX_PATH]uint16 193 } 194 195 const SizeofModuleEntry32 = unsafe.Sizeof(ModuleEntry32{}) 196 197 const ( 198 WSA_FLAG_OVERLAPPED = 0x01 199 WSA_FLAG_NO_HANDLE_INHERIT = 0x80 200 201 WSAEINVAL syscall.Errno = 10022 202 WSAEMSGSIZE syscall.Errno = 10040 203 WSAEAFNOSUPPORT syscall.Errno = 10047 204 205 MSG_PEEK = 0x2 206 MSG_TRUNC = 0x0100 207 MSG_CTRUNC = 0x0200 208 ) 209 210 var WSAID_WSASENDMSG = syscall.GUID{ 211 Data1: 0xa441e712, 212 Data2: 0x754f, 213 Data3: 0x43ca, 214 Data4: [8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d}, 215 } 216 217 var WSAID_WSARECVMSG = syscall.GUID{ 218 Data1: 0xf689d7c8, 219 Data2: 0x6f1f, 220 Data3: 0x436b, 221 Data4: [8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22}, 222 } 223 224 type WSAMsg struct { 225 Name syscall.Pointer 226 Namelen int32 227 Buffers *syscall.WSABuf 228 BufferCount uint32 229 Control syscall.WSABuf 230 Flags uint32 231 } 232 233 func WSASendMsg(fd syscall.Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlapped *syscall.Overlapped, croutine *byte) error 234 235 func WSARecvMsg(fd syscall.Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *syscall.Overlapped, croutine *byte) error 236 237 const ( 238 ComputerNameNetBIOS = 0 239 ComputerNameDnsHostname = 1 240 ComputerNameDnsDomain = 2 241 ComputerNameDnsFullyQualified = 3 242 ComputerNamePhysicalNetBIOS = 4 243 ComputerNamePhysicalDnsHostname = 5 244 ComputerNamePhysicalDnsDomain = 6 245 ComputerNamePhysicalDnsFullyQualified = 7 246 ComputerNameMax = 8 247 248 MOVEFILE_REPLACE_EXISTING = 0x1 249 MOVEFILE_COPY_ALLOWED = 0x2 250 MOVEFILE_DELAY_UNTIL_REBOOT = 0x4 251 MOVEFILE_WRITE_THROUGH = 0x8 252 MOVEFILE_CREATE_HARDLINK = 0x10 253 MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20 254 ) 255 256 func Rename(oldpath, newpath string) error 257 258 const ( 259 LOCKFILE_FAIL_IMMEDIATELY = 0x00000001 260 LOCKFILE_EXCLUSIVE_LOCK = 0x00000002 261 ) 262 263 const MB_ERR_INVALID_CHARS = 8 264 265 // Constants from lmshare.h 266 const ( 267 STYPE_DISKTREE = 0x00 268 STYPE_TEMPORARY = 0x40000000 269 ) 270 271 type SHARE_INFO_2 struct { 272 Netname *uint16 273 Type uint32 274 Remark *uint16 275 Permissions uint32 276 MaxUses uint32 277 CurrentUses uint32 278 Path *uint16 279 Passwd *uint16 280 } 281 282 const ( 283 FILE_NAME_NORMALIZED = 0x0 284 FILE_NAME_OPENED = 0x8 285 286 VOLUME_NAME_DOS = 0x0 287 VOLUME_NAME_GUID = 0x1 288 VOLUME_NAME_NONE = 0x4 289 VOLUME_NAME_NT = 0x2 290 ) 291 292 func ErrorLoadingGetTempPath2() error 293 294 type FILE_ID_BOTH_DIR_INFO struct { 295 NextEntryOffset uint32 296 FileIndex uint32 297 CreationTime syscall.Filetime 298 LastAccessTime syscall.Filetime 299 LastWriteTime syscall.Filetime 300 ChangeTime syscall.Filetime 301 EndOfFile uint64 302 AllocationSize uint64 303 FileAttributes uint32 304 FileNameLength uint32 305 EaSize uint32 306 ShortNameLength uint32 307 ShortName [12]uint16 308 FileID uint64 309 FileName [1]uint16 310 } 311 312 type FILE_FULL_DIR_INFO struct { 313 NextEntryOffset uint32 314 FileIndex uint32 315 CreationTime syscall.Filetime 316 LastAccessTime syscall.Filetime 317 LastWriteTime syscall.Filetime 318 ChangeTime syscall.Filetime 319 EndOfFile uint64 320 AllocationSize uint64 321 FileAttributes uint32 322 FileNameLength uint32 323 EaSize uint32 324 FileName [1]uint16 325 } 326 327 type SERVICE_STATUS struct { 328 ServiceType uint32 329 CurrentState uint32 330 ControlsAccepted uint32 331 Win32ExitCode uint32 332 ServiceSpecificExitCode uint32 333 CheckPoint uint32 334 WaitHint uint32 335 } 336 337 const ( 338 SERVICE_RUNNING = 4 339 SERVICE_QUERY_STATUS = 4 340 )