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