1// Copyright 2011 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 5package syscall 6 7const ( 8 // Windows errors. 9 ERROR_FILE_NOT_FOUND Errno = 2 10 ERROR_PATH_NOT_FOUND Errno = 3 11 ERROR_ACCESS_DENIED Errno = 5 12 ERROR_NO_MORE_FILES Errno = 18 13 ERROR_HANDLE_EOF Errno = 38 14 ERROR_NETNAME_DELETED Errno = 64 15 ERROR_FILE_EXISTS Errno = 80 16 ERROR_BROKEN_PIPE Errno = 109 17 ERROR_BUFFER_OVERFLOW Errno = 111 18 ERROR_INSUFFICIENT_BUFFER Errno = 122 19 ERROR_MOD_NOT_FOUND Errno = 126 20 ERROR_PROC_NOT_FOUND Errno = 127 21 ERROR_DIR_NOT_EMPTY Errno = 145 22 ERROR_ALREADY_EXISTS Errno = 183 23 ERROR_ENVVAR_NOT_FOUND Errno = 203 24 ERROR_MORE_DATA Errno = 234 25 ERROR_OPERATION_ABORTED Errno = 995 26 ERROR_IO_PENDING Errno = 997 27 ERROR_NOT_FOUND Errno = 1168 28 ERROR_PRIVILEGE_NOT_HELD Errno = 1314 29 WSAEACCES Errno = 10013 30 WSAENOPROTOOPT Errno = 10042 31 WSAECONNABORTED Errno = 10053 32 WSAECONNRESET Errno = 10054 33) 34 35const ( 36 // Invented values to support what package os expects. 37 O_RDONLY = 0x00000 38 O_WRONLY = 0x00001 39 O_RDWR = 0x00002 40 O_CREAT = 0x00040 41 O_EXCL = 0x00080 42 O_NOCTTY = 0x00100 43 O_TRUNC = 0x00200 44 O_NONBLOCK = 0x00800 45 O_APPEND = 0x00400 46 O_SYNC = 0x01000 47 O_ASYNC = 0x02000 48 O_CLOEXEC = 0x80000 49) 50 51const ( 52 // More invented values for signals 53 SIGHUP = Signal(0x1) 54 SIGINT = Signal(0x2) 55 SIGQUIT = Signal(0x3) 56 SIGILL = Signal(0x4) 57 SIGTRAP = Signal(0x5) 58 SIGABRT = Signal(0x6) 59 SIGBUS = Signal(0x7) 60 SIGFPE = Signal(0x8) 61 SIGKILL = Signal(0x9) 62 SIGSEGV = Signal(0xb) 63 SIGPIPE = Signal(0xd) 64 SIGALRM = Signal(0xe) 65 SIGTERM = Signal(0xf) 66) 67 68var signals = [...]string{ 69 1: "hangup", 70 2: "interrupt", 71 3: "quit", 72 4: "illegal instruction", 73 5: "trace/breakpoint trap", 74 6: "aborted", 75 7: "bus error", 76 8: "floating point exception", 77 9: "killed", 78 10: "user defined signal 1", 79 11: "segmentation fault", 80 12: "user defined signal 2", 81 13: "broken pipe", 82 14: "alarm clock", 83 15: "terminated", 84} 85 86const ( 87 GENERIC_READ = 0x80000000 88 GENERIC_WRITE = 0x40000000 89 GENERIC_EXECUTE = 0x20000000 90 GENERIC_ALL = 0x10000000 91 92 FILE_LIST_DIRECTORY = 0x00000001 93 FILE_APPEND_DATA = 0x00000004 94 FILE_WRITE_ATTRIBUTES = 0x00000100 95 96 FILE_SHARE_READ = 0x00000001 97 FILE_SHARE_WRITE = 0x00000002 98 FILE_SHARE_DELETE = 0x00000004 99 FILE_ATTRIBUTE_READONLY = 0x00000001 100 FILE_ATTRIBUTE_HIDDEN = 0x00000002 101 FILE_ATTRIBUTE_SYSTEM = 0x00000004 102 FILE_ATTRIBUTE_DIRECTORY = 0x00000010 103 FILE_ATTRIBUTE_ARCHIVE = 0x00000020 104 FILE_ATTRIBUTE_NORMAL = 0x00000080 105 FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 106 107 INVALID_FILE_ATTRIBUTES = 0xffffffff 108 109 CREATE_NEW = 1 110 CREATE_ALWAYS = 2 111 OPEN_EXISTING = 3 112 OPEN_ALWAYS = 4 113 TRUNCATE_EXISTING = 5 114 115 FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000 116 FILE_FLAG_BACKUP_SEMANTICS = 0x02000000 117 FILE_FLAG_OVERLAPPED = 0x40000000 118 119 HANDLE_FLAG_INHERIT = 0x00000001 120 STARTF_USESTDHANDLES = 0x00000100 121 STARTF_USESHOWWINDOW = 0x00000001 122 DUPLICATE_CLOSE_SOURCE = 0x00000001 123 DUPLICATE_SAME_ACCESS = 0x00000002 124 125 STD_INPUT_HANDLE = -10 126 STD_OUTPUT_HANDLE = -11 127 STD_ERROR_HANDLE = -12 128 129 FILE_BEGIN = 0 130 FILE_CURRENT = 1 131 FILE_END = 2 132 133 LANG_ENGLISH = 0x09 134 SUBLANG_ENGLISH_US = 0x01 135 136 FORMAT_MESSAGE_ALLOCATE_BUFFER = 256 137 FORMAT_MESSAGE_IGNORE_INSERTS = 512 138 FORMAT_MESSAGE_FROM_STRING = 1024 139 FORMAT_MESSAGE_FROM_HMODULE = 2048 140 FORMAT_MESSAGE_FROM_SYSTEM = 4096 141 FORMAT_MESSAGE_ARGUMENT_ARRAY = 8192 142 FORMAT_MESSAGE_MAX_WIDTH_MASK = 255 143 144 MAX_PATH = 260 145 MAX_LONG_PATH = 32768 146 147 MAX_COMPUTERNAME_LENGTH = 15 148 149 TIME_ZONE_ID_UNKNOWN = 0 150 TIME_ZONE_ID_STANDARD = 1 151 152 TIME_ZONE_ID_DAYLIGHT = 2 153 IGNORE = 0 154 INFINITE = 0xffffffff 155 156 WAIT_TIMEOUT = 258 157 WAIT_ABANDONED = 0x00000080 158 WAIT_OBJECT_0 = 0x00000000 159 WAIT_FAILED = 0xFFFFFFFF 160 161 CREATE_NEW_PROCESS_GROUP = 0x00000200 162 CREATE_UNICODE_ENVIRONMENT = 0x00000400 163 164 PROCESS_TERMINATE = 1 165 PROCESS_QUERY_INFORMATION = 0x00000400 166 SYNCHRONIZE = 0x00100000 167 168 PAGE_READONLY = 0x02 169 PAGE_READWRITE = 0x04 170 PAGE_WRITECOPY = 0x08 171 PAGE_EXECUTE_READ = 0x20 172 PAGE_EXECUTE_READWRITE = 0x40 173 PAGE_EXECUTE_WRITECOPY = 0x80 174 175 FILE_MAP_COPY = 0x01 176 FILE_MAP_WRITE = 0x02 177 FILE_MAP_READ = 0x04 178 FILE_MAP_EXECUTE = 0x20 179 180 CTRL_C_EVENT = 0 181 CTRL_BREAK_EVENT = 1 182 CTRL_CLOSE_EVENT = 2 183 CTRL_LOGOFF_EVENT = 5 184 CTRL_SHUTDOWN_EVENT = 6 185) 186 187const ( 188 // flags for CreateToolhelp32Snapshot 189 TH32CS_SNAPHEAPLIST = 0x01 190 TH32CS_SNAPPROCESS = 0x02 191 TH32CS_SNAPTHREAD = 0x04 192 TH32CS_SNAPMODULE = 0x08 193 TH32CS_SNAPMODULE32 = 0x10 194 TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD 195 TH32CS_INHERIT = 0x80000000 196) 197 198const ( 199 // do not reorder 200 FILE_NOTIFY_CHANGE_FILE_NAME = 1 << iota 201 FILE_NOTIFY_CHANGE_DIR_NAME 202 FILE_NOTIFY_CHANGE_ATTRIBUTES 203 FILE_NOTIFY_CHANGE_SIZE 204 FILE_NOTIFY_CHANGE_LAST_WRITE 205 FILE_NOTIFY_CHANGE_LAST_ACCESS 206 FILE_NOTIFY_CHANGE_CREATION 207) 208 209const ( 210 // do not reorder 211 FILE_ACTION_ADDED = iota + 1 212 FILE_ACTION_REMOVED 213 FILE_ACTION_MODIFIED 214 FILE_ACTION_RENAMED_OLD_NAME 215 FILE_ACTION_RENAMED_NEW_NAME 216) 217 218const ( 219 // wincrypt.h 220 PROV_RSA_FULL = 1 221 PROV_RSA_SIG = 2 222 PROV_DSS = 3 223 PROV_FORTEZZA = 4 224 PROV_MS_EXCHANGE = 5 225 PROV_SSL = 6 226 PROV_RSA_SCHANNEL = 12 227 PROV_DSS_DH = 13 228 PROV_EC_ECDSA_SIG = 14 229 PROV_EC_ECNRA_SIG = 15 230 PROV_EC_ECDSA_FULL = 16 231 PROV_EC_ECNRA_FULL = 17 232 PROV_DH_SCHANNEL = 18 233 PROV_SPYRUS_LYNKS = 20 234 PROV_RNG = 21 235 PROV_INTEL_SEC = 22 236 PROV_REPLACE_OWF = 23 237 PROV_RSA_AES = 24 238 CRYPT_VERIFYCONTEXT = 0xF0000000 239 CRYPT_NEWKEYSET = 0x00000008 240 CRYPT_DELETEKEYSET = 0x00000010 241 CRYPT_MACHINE_KEYSET = 0x00000020 242 CRYPT_SILENT = 0x00000040 243 CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080 244 245 USAGE_MATCH_TYPE_AND = 0 246 USAGE_MATCH_TYPE_OR = 1 247 248 X509_ASN_ENCODING = 0x00000001 249 PKCS_7_ASN_ENCODING = 0x00010000 250 251 CERT_STORE_PROV_MEMORY = 2 252 253 CERT_STORE_ADD_ALWAYS = 4 254 255 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004 256 257 CERT_TRUST_NO_ERROR = 0x00000000 258 CERT_TRUST_IS_NOT_TIME_VALID = 0x00000001 259 CERT_TRUST_IS_REVOKED = 0x00000004 260 CERT_TRUST_IS_NOT_SIGNATURE_VALID = 0x00000008 261 CERT_TRUST_IS_NOT_VALID_FOR_USAGE = 0x00000010 262 CERT_TRUST_IS_UNTRUSTED_ROOT = 0x00000020 263 CERT_TRUST_REVOCATION_STATUS_UNKNOWN = 0x00000040 264 CERT_TRUST_IS_CYCLIC = 0x00000080 265 CERT_TRUST_INVALID_EXTENSION = 0x00000100 266 CERT_TRUST_INVALID_POLICY_CONSTRAINTS = 0x00000200 267 CERT_TRUST_INVALID_BASIC_CONSTRAINTS = 0x00000400 268 CERT_TRUST_INVALID_NAME_CONSTRAINTS = 0x00000800 269 CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000 270 CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 0x00002000 271 CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000 272 CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 0x00008000 273 CERT_TRUST_IS_OFFLINE_REVOCATION = 0x01000000 274 CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 0x02000000 275 CERT_TRUST_IS_EXPLICIT_DISTRUST = 0x04000000 276 CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 0x08000000 277 278 CERT_CHAIN_POLICY_BASE = 1 279 CERT_CHAIN_POLICY_AUTHENTICODE = 2 280 CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3 281 CERT_CHAIN_POLICY_SSL = 4 282 CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5 283 CERT_CHAIN_POLICY_NT_AUTH = 6 284 CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7 285 CERT_CHAIN_POLICY_EV = 8 286 287 CERT_E_EXPIRED = 0x800B0101 288 CERT_E_ROLE = 0x800B0103 289 CERT_E_PURPOSE = 0x800B0106 290 CERT_E_UNTRUSTEDROOT = 0x800B0109 291 CERT_E_CN_NO_MATCH = 0x800B010F 292 293 AUTHTYPE_CLIENT = 1 294 AUTHTYPE_SERVER = 2 295) 296 297var ( 298 OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00") 299 OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00") 300 OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00") 301) 302 303// Pointer represents a pointer to an arbitrary Windows type. 304// 305// Pointer-typed fields may point to one of many different types. It's 306// up to the caller to provide a pointer to the appropriate type, cast 307// to Pointer. The caller must obey the unsafe.Pointer rules while 308// doing so. 309type Pointer *struct{} 310 311// Invented values to support what package os expects. 312type Timeval struct { 313 Sec int32 314 Usec int32 315} 316 317func (tv *Timeval) Nanoseconds() int64 { 318 return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3 319} 320 321func NsecToTimeval(nsec int64) (tv Timeval) { 322 tv.Sec = int32(nsec / 1e9) 323 tv.Usec = int32(nsec % 1e9 / 1e3) 324 return 325} 326 327type SecurityAttributes struct { 328 Length uint32 329 SecurityDescriptor uintptr 330 InheritHandle uint32 331} 332 333type Overlapped struct { 334 Internal uintptr 335 InternalHigh uintptr 336 Offset uint32 337 OffsetHigh uint32 338 HEvent Handle 339} 340 341type FileNotifyInformation struct { 342 NextEntryOffset uint32 343 Action uint32 344 FileNameLength uint32 345 FileName uint16 346} 347 348type Filetime struct { 349 LowDateTime uint32 350 HighDateTime uint32 351} 352 353// Nanoseconds returns Filetime ft in nanoseconds 354// since Epoch (00:00:00 UTC, January 1, 1970). 355func (ft *Filetime) Nanoseconds() int64 { 356 // 100-nanosecond intervals since January 1, 1601 357 nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime) 358 // change starting time to the Epoch (00:00:00 UTC, January 1, 1970) 359 nsec -= 116444736000000000 360 // convert into nanoseconds 361 nsec *= 100 362 return nsec 363} 364 365func NsecToFiletime(nsec int64) (ft Filetime) { 366 // convert into 100-nanosecond 367 nsec /= 100 368 // change starting time to January 1, 1601 369 nsec += 116444736000000000 370 // split into high / low 371 ft.LowDateTime = uint32(nsec & 0xffffffff) 372 ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff) 373 return ft 374} 375 376type Win32finddata struct { 377 FileAttributes uint32 378 CreationTime Filetime 379 LastAccessTime Filetime 380 LastWriteTime Filetime 381 FileSizeHigh uint32 382 FileSizeLow uint32 383 Reserved0 uint32 384 Reserved1 uint32 385 FileName [MAX_PATH - 1]uint16 386 AlternateFileName [13]uint16 387} 388 389// This is the actual system call structure. 390// Win32finddata is what we committed to in Go 1. 391type win32finddata1 struct { 392 FileAttributes uint32 393 CreationTime Filetime 394 LastAccessTime Filetime 395 LastWriteTime Filetime 396 FileSizeHigh uint32 397 FileSizeLow uint32 398 Reserved0 uint32 399 Reserved1 uint32 400 FileName [MAX_PATH]uint16 401 AlternateFileName [14]uint16 402 403 // The Microsoft documentation for this struct¹ describes three additional 404 // fields: dwFileType, dwCreatorType, and wFinderFlags. However, those fields 405 // are empirically only present in the macOS port of the Win32 API,² and thus 406 // not needed for binaries built for Windows. 407 // 408 // ¹ https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-win32_find_dataw 409 // ² https://golang.org/issue/42637#issuecomment-760715755 410} 411 412func copyFindData(dst *Win32finddata, src *win32finddata1) { 413 dst.FileAttributes = src.FileAttributes 414 dst.CreationTime = src.CreationTime 415 dst.LastAccessTime = src.LastAccessTime 416 dst.LastWriteTime = src.LastWriteTime 417 dst.FileSizeHigh = src.FileSizeHigh 418 dst.FileSizeLow = src.FileSizeLow 419 dst.Reserved0 = src.Reserved0 420 dst.Reserved1 = src.Reserved1 421 422 // The src is 1 element bigger than dst, but it must be NUL. 423 copy(dst.FileName[:], src.FileName[:]) 424 copy(dst.AlternateFileName[:], src.AlternateFileName[:]) 425} 426 427type ByHandleFileInformation struct { 428 FileAttributes uint32 429 CreationTime Filetime 430 LastAccessTime Filetime 431 LastWriteTime Filetime 432 VolumeSerialNumber uint32 433 FileSizeHigh uint32 434 FileSizeLow uint32 435 NumberOfLinks uint32 436 FileIndexHigh uint32 437 FileIndexLow uint32 438} 439 440const ( 441 GetFileExInfoStandard = 0 442 GetFileExMaxInfoLevel = 1 443) 444 445type Win32FileAttributeData struct { 446 FileAttributes uint32 447 CreationTime Filetime 448 LastAccessTime Filetime 449 LastWriteTime Filetime 450 FileSizeHigh uint32 451 FileSizeLow uint32 452} 453 454// ShowWindow constants 455const ( 456 // winuser.h 457 SW_HIDE = 0 458 SW_NORMAL = 1 459 SW_SHOWNORMAL = 1 460 SW_SHOWMINIMIZED = 2 461 SW_SHOWMAXIMIZED = 3 462 SW_MAXIMIZE = 3 463 SW_SHOWNOACTIVATE = 4 464 SW_SHOW = 5 465 SW_MINIMIZE = 6 466 SW_SHOWMINNOACTIVE = 7 467 SW_SHOWNA = 8 468 SW_RESTORE = 9 469 SW_SHOWDEFAULT = 10 470 SW_FORCEMINIMIZE = 11 471) 472 473type StartupInfo struct { 474 Cb uint32 475 _ *uint16 476 Desktop *uint16 477 Title *uint16 478 X uint32 479 Y uint32 480 XSize uint32 481 YSize uint32 482 XCountChars uint32 483 YCountChars uint32 484 FillAttribute uint32 485 Flags uint32 486 ShowWindow uint16 487 _ uint16 488 _ *byte 489 StdInput Handle 490 StdOutput Handle 491 StdErr Handle 492} 493 494type _PROC_THREAD_ATTRIBUTE_LIST struct { 495 _ [1]byte 496} 497 498const ( 499 _PROC_THREAD_ATTRIBUTE_PARENT_PROCESS = 0x00020000 500 _PROC_THREAD_ATTRIBUTE_HANDLE_LIST = 0x00020002 501) 502 503type _STARTUPINFOEXW struct { 504 StartupInfo 505 ProcThreadAttributeList *_PROC_THREAD_ATTRIBUTE_LIST 506} 507 508const _EXTENDED_STARTUPINFO_PRESENT = 0x00080000 509 510type ProcessInformation struct { 511 Process Handle 512 Thread Handle 513 ProcessId uint32 514 ThreadId uint32 515} 516 517type ProcessEntry32 struct { 518 Size uint32 519 Usage uint32 520 ProcessID uint32 521 DefaultHeapID uintptr 522 ModuleID uint32 523 Threads uint32 524 ParentProcessID uint32 525 PriClassBase int32 526 Flags uint32 527 ExeFile [MAX_PATH]uint16 528} 529 530type Systemtime struct { 531 Year uint16 532 Month uint16 533 DayOfWeek uint16 534 Day uint16 535 Hour uint16 536 Minute uint16 537 Second uint16 538 Milliseconds uint16 539} 540 541type Timezoneinformation struct { 542 Bias int32 543 StandardName [32]uint16 544 StandardDate Systemtime 545 StandardBias int32 546 DaylightName [32]uint16 547 DaylightDate Systemtime 548 DaylightBias int32 549} 550 551// Socket related. 552 553const ( 554 AF_UNSPEC = 0 555 AF_UNIX = 1 556 AF_INET = 2 557 AF_INET6 = 23 558 AF_NETBIOS = 17 559 560 SOCK_STREAM = 1 561 SOCK_DGRAM = 2 562 SOCK_RAW = 3 563 SOCK_SEQPACKET = 5 564 565 IPPROTO_IP = 0 566 IPPROTO_IPV6 = 0x29 567 IPPROTO_TCP = 6 568 IPPROTO_UDP = 17 569 570 SOL_SOCKET = 0xffff 571 SO_REUSEADDR = 4 572 SO_KEEPALIVE = 8 573 SO_DONTROUTE = 16 574 SO_BROADCAST = 32 575 SO_LINGER = 128 576 SO_RCVBUF = 0x1002 577 SO_SNDBUF = 0x1001 578 SO_UPDATE_ACCEPT_CONTEXT = 0x700b 579 SO_UPDATE_CONNECT_CONTEXT = 0x7010 580 581 IOC_OUT = 0x40000000 582 IOC_IN = 0x80000000 583 IOC_VENDOR = 0x18000000 584 IOC_INOUT = IOC_IN | IOC_OUT 585 IOC_WS2 = 0x08000000 586 SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6 587 SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4 588 SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12 589 590 // cf. https://learn.microsoft.com/en-US/troubleshoot/windows/win32/header-library-requirement-socket-ipproto-ip 591 592 IP_TOS = 0x3 593 IP_TTL = 0x4 594 IP_MULTICAST_IF = 0x9 595 IP_MULTICAST_TTL = 0xa 596 IP_MULTICAST_LOOP = 0xb 597 IP_ADD_MEMBERSHIP = 0xc 598 IP_DROP_MEMBERSHIP = 0xd 599 600 IPV6_V6ONLY = 0x1b 601 IPV6_UNICAST_HOPS = 0x4 602 IPV6_MULTICAST_IF = 0x9 603 IPV6_MULTICAST_HOPS = 0xa 604 IPV6_MULTICAST_LOOP = 0xb 605 IPV6_JOIN_GROUP = 0xc 606 IPV6_LEAVE_GROUP = 0xd 607 608 SOMAXCONN = 0x7fffffff 609 610 TCP_NODELAY = 1 611 612 SHUT_RD = 0 613 SHUT_WR = 1 614 SHUT_RDWR = 2 615 616 WSADESCRIPTION_LEN = 256 617 WSASYS_STATUS_LEN = 128 618) 619 620type WSABuf struct { 621 Len uint32 622 Buf *byte 623} 624 625// Invented values to support what package os expects. 626const ( 627 S_IFMT = 0x1f000 628 S_IFIFO = 0x1000 629 S_IFCHR = 0x2000 630 S_IFDIR = 0x4000 631 S_IFBLK = 0x6000 632 S_IFREG = 0x8000 633 S_IFLNK = 0xa000 634 S_IFSOCK = 0xc000 635 S_ISUID = 0x800 636 S_ISGID = 0x400 637 S_ISVTX = 0x200 638 S_IRUSR = 0x100 639 S_IWRITE = 0x80 640 S_IWUSR = 0x80 641 S_IXUSR = 0x40 642) 643 644const ( 645 FILE_TYPE_CHAR = 0x0002 646 FILE_TYPE_DISK = 0x0001 647 FILE_TYPE_PIPE = 0x0003 648 FILE_TYPE_REMOTE = 0x8000 649 FILE_TYPE_UNKNOWN = 0x0000 650) 651 652type Hostent struct { 653 Name *byte 654 Aliases **byte 655 AddrType uint16 656 Length uint16 657 AddrList **byte 658} 659 660type Protoent struct { 661 Name *byte 662 Aliases **byte 663 Proto uint16 664} 665 666const ( 667 DNS_TYPE_A = 0x0001 668 DNS_TYPE_NS = 0x0002 669 DNS_TYPE_MD = 0x0003 670 DNS_TYPE_MF = 0x0004 671 DNS_TYPE_CNAME = 0x0005 672 DNS_TYPE_SOA = 0x0006 673 DNS_TYPE_MB = 0x0007 674 DNS_TYPE_MG = 0x0008 675 DNS_TYPE_MR = 0x0009 676 DNS_TYPE_NULL = 0x000a 677 DNS_TYPE_WKS = 0x000b 678 DNS_TYPE_PTR = 0x000c 679 DNS_TYPE_HINFO = 0x000d 680 DNS_TYPE_MINFO = 0x000e 681 DNS_TYPE_MX = 0x000f 682 DNS_TYPE_TEXT = 0x0010 683 DNS_TYPE_RP = 0x0011 684 DNS_TYPE_AFSDB = 0x0012 685 DNS_TYPE_X25 = 0x0013 686 DNS_TYPE_ISDN = 0x0014 687 DNS_TYPE_RT = 0x0015 688 DNS_TYPE_NSAP = 0x0016 689 DNS_TYPE_NSAPPTR = 0x0017 690 DNS_TYPE_SIG = 0x0018 691 DNS_TYPE_KEY = 0x0019 692 DNS_TYPE_PX = 0x001a 693 DNS_TYPE_GPOS = 0x001b 694 DNS_TYPE_AAAA = 0x001c 695 DNS_TYPE_LOC = 0x001d 696 DNS_TYPE_NXT = 0x001e 697 DNS_TYPE_EID = 0x001f 698 DNS_TYPE_NIMLOC = 0x0020 699 DNS_TYPE_SRV = 0x0021 700 DNS_TYPE_ATMA = 0x0022 701 DNS_TYPE_NAPTR = 0x0023 702 DNS_TYPE_KX = 0x0024 703 DNS_TYPE_CERT = 0x0025 704 DNS_TYPE_A6 = 0x0026 705 DNS_TYPE_DNAME = 0x0027 706 DNS_TYPE_SINK = 0x0028 707 DNS_TYPE_OPT = 0x0029 708 DNS_TYPE_DS = 0x002B 709 DNS_TYPE_RRSIG = 0x002E 710 DNS_TYPE_NSEC = 0x002F 711 DNS_TYPE_DNSKEY = 0x0030 712 DNS_TYPE_DHCID = 0x0031 713 DNS_TYPE_UINFO = 0x0064 714 DNS_TYPE_UID = 0x0065 715 DNS_TYPE_GID = 0x0066 716 DNS_TYPE_UNSPEC = 0x0067 717 DNS_TYPE_ADDRS = 0x00f8 718 DNS_TYPE_TKEY = 0x00f9 719 DNS_TYPE_TSIG = 0x00fa 720 DNS_TYPE_IXFR = 0x00fb 721 DNS_TYPE_AXFR = 0x00fc 722 DNS_TYPE_MAILB = 0x00fd 723 DNS_TYPE_MAILA = 0x00fe 724 DNS_TYPE_ALL = 0x00ff 725 DNS_TYPE_ANY = 0x00ff 726 DNS_TYPE_WINS = 0xff01 727 DNS_TYPE_WINSR = 0xff02 728 DNS_TYPE_NBSTAT = 0xff01 729) 730 731const ( 732 DNS_INFO_NO_RECORDS = 0x251D 733) 734 735const ( 736 // flags inside DNSRecord.Dw 737 DnsSectionQuestion = 0x0000 738 DnsSectionAnswer = 0x0001 739 DnsSectionAuthority = 0x0002 740 DnsSectionAdditional = 0x0003 741) 742 743type DNSSRVData struct { 744 Target *uint16 745 Priority uint16 746 Weight uint16 747 Port uint16 748 Pad uint16 749} 750 751type DNSPTRData struct { 752 Host *uint16 753} 754 755type DNSMXData struct { 756 NameExchange *uint16 757 Preference uint16 758 Pad uint16 759} 760 761type DNSTXTData struct { 762 StringCount uint16 763 StringArray [1]*uint16 764} 765 766type DNSRecord struct { 767 Next *DNSRecord 768 Name *uint16 769 Type uint16 770 Length uint16 771 Dw uint32 772 Ttl uint32 773 Reserved uint32 774 Data [40]byte 775} 776 777const ( 778 TF_DISCONNECT = 1 779 TF_REUSE_SOCKET = 2 780 TF_WRITE_BEHIND = 4 781 TF_USE_DEFAULT_WORKER = 0 782 TF_USE_SYSTEM_THREAD = 16 783 TF_USE_KERNEL_APC = 32 784) 785 786type TransmitFileBuffers struct { 787 Head uintptr 788 HeadLength uint32 789 Tail uintptr 790 TailLength uint32 791} 792 793const ( 794 IFF_UP = 1 795 IFF_BROADCAST = 2 796 IFF_LOOPBACK = 4 797 IFF_POINTTOPOINT = 8 798 IFF_MULTICAST = 16 799) 800 801const SIO_GET_INTERFACE_LIST = 0x4004747F 802 803// TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old. 804// will be fixed to change variable type as suitable. 805 806type SockaddrGen [24]byte 807 808type InterfaceInfo struct { 809 Flags uint32 810 Address SockaddrGen 811 BroadcastAddress SockaddrGen 812 Netmask SockaddrGen 813} 814 815type IpAddressString struct { 816 String [16]byte 817} 818 819type IpMaskString IpAddressString 820 821type IpAddrString struct { 822 Next *IpAddrString 823 IpAddress IpAddressString 824 IpMask IpMaskString 825 Context uint32 826} 827 828const MAX_ADAPTER_NAME_LENGTH = 256 829const MAX_ADAPTER_DESCRIPTION_LENGTH = 128 830const MAX_ADAPTER_ADDRESS_LENGTH = 8 831 832type IpAdapterInfo struct { 833 Next *IpAdapterInfo 834 ComboIndex uint32 835 AdapterName [MAX_ADAPTER_NAME_LENGTH + 4]byte 836 Description [MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte 837 AddressLength uint32 838 Address [MAX_ADAPTER_ADDRESS_LENGTH]byte 839 Index uint32 840 Type uint32 841 DhcpEnabled uint32 842 CurrentIpAddress *IpAddrString 843 IpAddressList IpAddrString 844 GatewayList IpAddrString 845 DhcpServer IpAddrString 846 HaveWins bool 847 PrimaryWinsServer IpAddrString 848 SecondaryWinsServer IpAddrString 849 LeaseObtained int64 850 LeaseExpires int64 851} 852 853const MAXLEN_PHYSADDR = 8 854const MAX_INTERFACE_NAME_LEN = 256 855const MAXLEN_IFDESCR = 256 856 857type MibIfRow struct { 858 Name [MAX_INTERFACE_NAME_LEN]uint16 859 Index uint32 860 Type uint32 861 Mtu uint32 862 Speed uint32 863 PhysAddrLen uint32 864 PhysAddr [MAXLEN_PHYSADDR]byte 865 AdminStatus uint32 866 OperStatus uint32 867 LastChange uint32 868 InOctets uint32 869 InUcastPkts uint32 870 InNUcastPkts uint32 871 InDiscards uint32 872 InErrors uint32 873 InUnknownProtos uint32 874 OutOctets uint32 875 OutUcastPkts uint32 876 OutNUcastPkts uint32 877 OutDiscards uint32 878 OutErrors uint32 879 OutQLen uint32 880 DescrLen uint32 881 Descr [MAXLEN_IFDESCR]byte 882} 883 884type CertInfo struct { 885 // Not implemented 886} 887 888type CertContext struct { 889 EncodingType uint32 890 EncodedCert *byte 891 Length uint32 892 CertInfo *CertInfo 893 Store Handle 894} 895 896type CertChainContext struct { 897 Size uint32 898 TrustStatus CertTrustStatus 899 ChainCount uint32 900 Chains **CertSimpleChain 901 LowerQualityChainCount uint32 902 LowerQualityChains **CertChainContext 903 HasRevocationFreshnessTime uint32 904 RevocationFreshnessTime uint32 905} 906 907type CertTrustListInfo struct { 908 // Not implemented 909} 910 911type CertSimpleChain struct { 912 Size uint32 913 TrustStatus CertTrustStatus 914 NumElements uint32 915 Elements **CertChainElement 916 TrustListInfo *CertTrustListInfo 917 HasRevocationFreshnessTime uint32 918 RevocationFreshnessTime uint32 919} 920 921type CertChainElement struct { 922 Size uint32 923 CertContext *CertContext 924 TrustStatus CertTrustStatus 925 RevocationInfo *CertRevocationInfo 926 IssuanceUsage *CertEnhKeyUsage 927 ApplicationUsage *CertEnhKeyUsage 928 ExtendedErrorInfo *uint16 929} 930 931type CertRevocationCrlInfo struct { 932 // Not implemented 933} 934 935type CertRevocationInfo struct { 936 Size uint32 937 RevocationResult uint32 938 RevocationOid *byte 939 OidSpecificInfo Pointer 940 HasFreshnessTime uint32 941 FreshnessTime uint32 942 CrlInfo *CertRevocationCrlInfo 943} 944 945type CertTrustStatus struct { 946 ErrorStatus uint32 947 InfoStatus uint32 948} 949 950type CertUsageMatch struct { 951 Type uint32 952 Usage CertEnhKeyUsage 953} 954 955type CertEnhKeyUsage struct { 956 Length uint32 957 UsageIdentifiers **byte 958} 959 960type CertChainPara struct { 961 Size uint32 962 RequestedUsage CertUsageMatch 963 RequstedIssuancePolicy CertUsageMatch 964 URLRetrievalTimeout uint32 965 CheckRevocationFreshnessTime uint32 966 RevocationFreshnessTime uint32 967 CacheResync *Filetime 968} 969 970type CertChainPolicyPara struct { 971 Size uint32 972 Flags uint32 973 ExtraPolicyPara Pointer 974} 975 976type SSLExtraCertChainPolicyPara struct { 977 Size uint32 978 AuthType uint32 979 Checks uint32 980 ServerName *uint16 981} 982 983type CertChainPolicyStatus struct { 984 Size uint32 985 Error uint32 986 ChainIndex uint32 987 ElementIndex uint32 988 ExtraPolicyStatus Pointer 989} 990 991const ( 992 // do not reorder 993 HKEY_CLASSES_ROOT = 0x80000000 + iota 994 HKEY_CURRENT_USER 995 HKEY_LOCAL_MACHINE 996 HKEY_USERS 997 HKEY_PERFORMANCE_DATA 998 HKEY_CURRENT_CONFIG 999 HKEY_DYN_DATA 1000 1001 KEY_QUERY_VALUE = 1 1002 KEY_SET_VALUE = 2 1003 KEY_CREATE_SUB_KEY = 4 1004 KEY_ENUMERATE_SUB_KEYS = 8 1005 KEY_NOTIFY = 16 1006 KEY_CREATE_LINK = 32 1007 KEY_WRITE = 0x20006 1008 KEY_EXECUTE = 0x20019 1009 KEY_READ = 0x20019 1010 KEY_WOW64_64KEY = 0x0100 1011 KEY_WOW64_32KEY = 0x0200 1012 KEY_ALL_ACCESS = 0xf003f 1013) 1014 1015const ( 1016 // do not reorder 1017 REG_NONE = iota 1018 REG_SZ 1019 REG_EXPAND_SZ 1020 REG_BINARY 1021 REG_DWORD_LITTLE_ENDIAN 1022 REG_DWORD_BIG_ENDIAN 1023 REG_LINK 1024 REG_MULTI_SZ 1025 REG_RESOURCE_LIST 1026 REG_FULL_RESOURCE_DESCRIPTOR 1027 REG_RESOURCE_REQUIREMENTS_LIST 1028 REG_QWORD_LITTLE_ENDIAN 1029 REG_DWORD = REG_DWORD_LITTLE_ENDIAN 1030 REG_QWORD = REG_QWORD_LITTLE_ENDIAN 1031) 1032 1033type AddrinfoW struct { 1034 Flags int32 1035 Family int32 1036 Socktype int32 1037 Protocol int32 1038 Addrlen uintptr 1039 Canonname *uint16 1040 Addr Pointer 1041 Next *AddrinfoW 1042} 1043 1044const ( 1045 AI_PASSIVE = 1 1046 AI_CANONNAME = 2 1047 AI_NUMERICHOST = 4 1048) 1049 1050type GUID struct { 1051 Data1 uint32 1052 Data2 uint16 1053 Data3 uint16 1054 Data4 [8]byte 1055} 1056 1057var WSAID_CONNECTEX = GUID{ 1058 0x25a207b9, 1059 0xddf3, 1060 0x4660, 1061 [8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}, 1062} 1063 1064const ( 1065 FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1 1066 FILE_SKIP_SET_EVENT_ON_HANDLE = 2 1067) 1068 1069const ( 1070 WSAPROTOCOL_LEN = 255 1071 MAX_PROTOCOL_CHAIN = 7 1072 BASE_PROTOCOL = 1 1073 LAYERED_PROTOCOL = 0 1074 1075 XP1_CONNECTIONLESS = 0x00000001 1076 XP1_GUARANTEED_DELIVERY = 0x00000002 1077 XP1_GUARANTEED_ORDER = 0x00000004 1078 XP1_MESSAGE_ORIENTED = 0x00000008 1079 XP1_PSEUDO_STREAM = 0x00000010 1080 XP1_GRACEFUL_CLOSE = 0x00000020 1081 XP1_EXPEDITED_DATA = 0x00000040 1082 XP1_CONNECT_DATA = 0x00000080 1083 XP1_DISCONNECT_DATA = 0x00000100 1084 XP1_SUPPORT_BROADCAST = 0x00000200 1085 XP1_SUPPORT_MULTIPOINT = 0x00000400 1086 XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800 1087 XP1_MULTIPOINT_DATA_PLANE = 0x00001000 1088 XP1_QOS_SUPPORTED = 0x00002000 1089 XP1_UNI_SEND = 0x00008000 1090 XP1_UNI_RECV = 0x00010000 1091 XP1_IFS_HANDLES = 0x00020000 1092 XP1_PARTIAL_MESSAGE = 0x00040000 1093 XP1_SAN_SUPPORT_SDP = 0x00080000 1094 1095 PFL_MULTIPLE_PROTO_ENTRIES = 0x00000001 1096 PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002 1097 PFL_HIDDEN = 0x00000004 1098 PFL_MATCHES_PROTOCOL_ZERO = 0x00000008 1099 PFL_NETWORKDIRECT_PROVIDER = 0x00000010 1100) 1101 1102type WSAProtocolInfo struct { 1103 ServiceFlags1 uint32 1104 ServiceFlags2 uint32 1105 ServiceFlags3 uint32 1106 ServiceFlags4 uint32 1107 ProviderFlags uint32 1108 ProviderId GUID 1109 CatalogEntryId uint32 1110 ProtocolChain WSAProtocolChain 1111 Version int32 1112 AddressFamily int32 1113 MaxSockAddr int32 1114 MinSockAddr int32 1115 SocketType int32 1116 Protocol int32 1117 ProtocolMaxOffset int32 1118 NetworkByteOrder int32 1119 SecurityScheme int32 1120 MessageSize uint32 1121 ProviderReserved uint32 1122 ProtocolName [WSAPROTOCOL_LEN + 1]uint16 1123} 1124 1125type WSAProtocolChain struct { 1126 ChainLen int32 1127 ChainEntries [MAX_PROTOCOL_CHAIN]uint32 1128} 1129 1130type TCPKeepalive struct { 1131 OnOff uint32 1132 Time uint32 1133 Interval uint32 1134} 1135 1136type symbolicLinkReparseBuffer struct { 1137 SubstituteNameOffset uint16 1138 SubstituteNameLength uint16 1139 PrintNameOffset uint16 1140 PrintNameLength uint16 1141 Flags uint32 1142 PathBuffer [1]uint16 1143} 1144 1145type mountPointReparseBuffer struct { 1146 SubstituteNameOffset uint16 1147 SubstituteNameLength uint16 1148 PrintNameOffset uint16 1149 PrintNameLength uint16 1150 PathBuffer [1]uint16 1151} 1152 1153type reparseDataBuffer struct { 1154 ReparseTag uint32 1155 ReparseDataLength uint16 1156 Reserved uint16 1157 1158 // GenericReparseBuffer 1159 reparseBuffer byte 1160} 1161 1162const ( 1163 FSCTL_GET_REPARSE_POINT = 0x900A8 1164 MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024 1165 _IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003 1166 IO_REPARSE_TAG_SYMLINK = 0xA000000C 1167 SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 1168 _SYMLINK_FLAG_RELATIVE = 1 1169) 1170 1171const UNIX_PATH_MAX = 108 // defined in afunix.h 1172