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 windows
6
7import "syscall"
8
9const (
10	// Windows errors.
11	ERROR_FILE_NOT_FOUND         syscall.Errno = 2
12	ERROR_PATH_NOT_FOUND         syscall.Errno = 3
13	ERROR_ACCESS_DENIED          syscall.Errno = 5
14	ERROR_NO_MORE_FILES          syscall.Errno = 18
15	ERROR_HANDLE_EOF             syscall.Errno = 38
16	ERROR_NETNAME_DELETED        syscall.Errno = 64
17	ERROR_FILE_EXISTS            syscall.Errno = 80
18	ERROR_BROKEN_PIPE            syscall.Errno = 109
19	ERROR_BUFFER_OVERFLOW        syscall.Errno = 111
20	ERROR_INSUFFICIENT_BUFFER    syscall.Errno = 122
21	ERROR_MOD_NOT_FOUND          syscall.Errno = 126
22	ERROR_PROC_NOT_FOUND         syscall.Errno = 127
23	ERROR_ALREADY_EXISTS         syscall.Errno = 183
24	ERROR_ENVVAR_NOT_FOUND       syscall.Errno = 203
25	ERROR_MORE_DATA              syscall.Errno = 234
26	ERROR_OPERATION_ABORTED      syscall.Errno = 995
27	ERROR_IO_PENDING             syscall.Errno = 997
28	ERROR_SERVICE_SPECIFIC_ERROR syscall.Errno = 1066
29	ERROR_NOT_FOUND              syscall.Errno = 1168
30	ERROR_PRIVILEGE_NOT_HELD     syscall.Errno = 1314
31	WSAEACCES                    syscall.Errno = 10013
32	WSAEMSGSIZE                  syscall.Errno = 10040
33	WSAECONNRESET                syscall.Errno = 10054
34)
35
36const (
37	// Invented values to support what package os expects.
38	O_RDONLY   = 0x00000
39	O_WRONLY   = 0x00001
40	O_RDWR     = 0x00002
41	O_CREAT    = 0x00040
42	O_EXCL     = 0x00080
43	O_NOCTTY   = 0x00100
44	O_TRUNC    = 0x00200
45	O_NONBLOCK = 0x00800
46	O_APPEND   = 0x00400
47	O_SYNC     = 0x01000
48	O_ASYNC    = 0x02000
49	O_CLOEXEC  = 0x80000
50)
51
52const (
53	// More invented values for signals
54	SIGHUP  = Signal(0x1)
55	SIGINT  = Signal(0x2)
56	SIGQUIT = Signal(0x3)
57	SIGILL  = Signal(0x4)
58	SIGTRAP = Signal(0x5)
59	SIGABRT = Signal(0x6)
60	SIGBUS  = Signal(0x7)
61	SIGFPE  = Signal(0x8)
62	SIGKILL = Signal(0x9)
63	SIGSEGV = Signal(0xb)
64	SIGPIPE = Signal(0xd)
65	SIGALRM = Signal(0xe)
66	SIGTERM = Signal(0xf)
67)
68
69var signals = [...]string{
70	1:  "hangup",
71	2:  "interrupt",
72	3:  "quit",
73	4:  "illegal instruction",
74	5:  "trace/breakpoint trap",
75	6:  "aborted",
76	7:  "bus error",
77	8:  "floating point exception",
78	9:  "killed",
79	10: "user defined signal 1",
80	11: "segmentation fault",
81	12: "user defined signal 2",
82	13: "broken pipe",
83	14: "alarm clock",
84	15: "terminated",
85}
86
87const (
88	GENERIC_READ    = 0x80000000
89	GENERIC_WRITE   = 0x40000000
90	GENERIC_EXECUTE = 0x20000000
91	GENERIC_ALL     = 0x10000000
92
93	FILE_LIST_DIRECTORY   = 0x00000001
94	FILE_APPEND_DATA      = 0x00000004
95	FILE_WRITE_ATTRIBUTES = 0x00000100
96
97	FILE_SHARE_READ              = 0x00000001
98	FILE_SHARE_WRITE             = 0x00000002
99	FILE_SHARE_DELETE            = 0x00000004
100	FILE_ATTRIBUTE_READONLY      = 0x00000001
101	FILE_ATTRIBUTE_HIDDEN        = 0x00000002
102	FILE_ATTRIBUTE_SYSTEM        = 0x00000004
103	FILE_ATTRIBUTE_DIRECTORY     = 0x00000010
104	FILE_ATTRIBUTE_ARCHIVE       = 0x00000020
105	FILE_ATTRIBUTE_NORMAL        = 0x00000080
106	FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
107
108	INVALID_FILE_ATTRIBUTES = 0xffffffff
109
110	CREATE_NEW        = 1
111	CREATE_ALWAYS     = 2
112	OPEN_EXISTING     = 3
113	OPEN_ALWAYS       = 4
114	TRUNCATE_EXISTING = 5
115
116	FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
117	FILE_FLAG_BACKUP_SEMANTICS   = 0x02000000
118	FILE_FLAG_OVERLAPPED         = 0x40000000
119
120	HANDLE_FLAG_INHERIT    = 0x00000001
121	STARTF_USESTDHANDLES   = 0x00000100
122	STARTF_USESHOWWINDOW   = 0x00000001
123	DUPLICATE_CLOSE_SOURCE = 0x00000001
124	DUPLICATE_SAME_ACCESS  = 0x00000002
125
126	STD_INPUT_HANDLE  = -10 & (1<<32 - 1)
127	STD_OUTPUT_HANDLE = -11 & (1<<32 - 1)
128	STD_ERROR_HANDLE  = -12 & (1<<32 - 1)
129
130	FILE_BEGIN   = 0
131	FILE_CURRENT = 1
132	FILE_END     = 2
133
134	LANG_ENGLISH       = 0x09
135	SUBLANG_ENGLISH_US = 0x01
136
137	FORMAT_MESSAGE_ALLOCATE_BUFFER = 256
138	FORMAT_MESSAGE_IGNORE_INSERTS  = 512
139	FORMAT_MESSAGE_FROM_STRING     = 1024
140	FORMAT_MESSAGE_FROM_HMODULE    = 2048
141	FORMAT_MESSAGE_FROM_SYSTEM     = 4096
142	FORMAT_MESSAGE_ARGUMENT_ARRAY  = 8192
143	FORMAT_MESSAGE_MAX_WIDTH_MASK  = 255
144
145	MAX_PATH      = 260
146	MAX_LONG_PATH = 32768
147
148	MAX_COMPUTERNAME_LENGTH = 15
149
150	TIME_ZONE_ID_UNKNOWN  = 0
151	TIME_ZONE_ID_STANDARD = 1
152
153	TIME_ZONE_ID_DAYLIGHT = 2
154	IGNORE                = 0
155	INFINITE              = 0xffffffff
156
157	WAIT_TIMEOUT   = 258
158	WAIT_ABANDONED = 0x00000080
159	WAIT_OBJECT_0  = 0x00000000
160	WAIT_FAILED    = 0xFFFFFFFF
161
162	PROCESS_TERMINATE         = 1
163	PROCESS_QUERY_INFORMATION = 0x00000400
164	SYNCHRONIZE               = 0x00100000
165
166	FILE_MAP_COPY    = 0x01
167	FILE_MAP_WRITE   = 0x02
168	FILE_MAP_READ    = 0x04
169	FILE_MAP_EXECUTE = 0x20
170
171	CTRL_C_EVENT     = 0
172	CTRL_BREAK_EVENT = 1
173
174	// Windows reserves errors >= 1<<29 for application use.
175	APPLICATION_ERROR = 1 << 29
176)
177
178const (
179	// Process creation flags.
180	CREATE_BREAKAWAY_FROM_JOB        = 0x01000000
181	CREATE_DEFAULT_ERROR_MODE        = 0x04000000
182	CREATE_NEW_CONSOLE               = 0x00000010
183	CREATE_NEW_PROCESS_GROUP         = 0x00000200
184	CREATE_NO_WINDOW                 = 0x08000000
185	CREATE_PROTECTED_PROCESS         = 0x00040000
186	CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
187	CREATE_SEPARATE_WOW_VDM          = 0x00000800
188	CREATE_SHARED_WOW_VDM            = 0x00001000
189	CREATE_SUSPENDED                 = 0x00000004
190	CREATE_UNICODE_ENVIRONMENT       = 0x00000400
191	DEBUG_ONLY_THIS_PROCESS          = 0x00000002
192	DEBUG_PROCESS                    = 0x00000001
193	DETACHED_PROCESS                 = 0x00000008
194	EXTENDED_STARTUPINFO_PRESENT     = 0x00080000
195	INHERIT_PARENT_AFFINITY          = 0x00010000
196)
197
198const (
199	// flags for CreateToolhelp32Snapshot
200	TH32CS_SNAPHEAPLIST = 0x01
201	TH32CS_SNAPPROCESS  = 0x02
202	TH32CS_SNAPTHREAD   = 0x04
203	TH32CS_SNAPMODULE   = 0x08
204	TH32CS_SNAPMODULE32 = 0x10
205	TH32CS_SNAPALL      = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
206	TH32CS_INHERIT      = 0x80000000
207)
208
209const (
210	// filters for ReadDirectoryChangesW
211	FILE_NOTIFY_CHANGE_FILE_NAME   = 0x001
212	FILE_NOTIFY_CHANGE_DIR_NAME    = 0x002
213	FILE_NOTIFY_CHANGE_ATTRIBUTES  = 0x004
214	FILE_NOTIFY_CHANGE_SIZE        = 0x008
215	FILE_NOTIFY_CHANGE_LAST_WRITE  = 0x010
216	FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020
217	FILE_NOTIFY_CHANGE_CREATION    = 0x040
218	FILE_NOTIFY_CHANGE_SECURITY    = 0x100
219)
220
221const (
222	// do not reorder
223	FILE_ACTION_ADDED = iota + 1
224	FILE_ACTION_REMOVED
225	FILE_ACTION_MODIFIED
226	FILE_ACTION_RENAMED_OLD_NAME
227	FILE_ACTION_RENAMED_NEW_NAME
228)
229
230const (
231	// wincrypt.h
232	PROV_RSA_FULL                    = 1
233	PROV_RSA_SIG                     = 2
234	PROV_DSS                         = 3
235	PROV_FORTEZZA                    = 4
236	PROV_MS_EXCHANGE                 = 5
237	PROV_SSL                         = 6
238	PROV_RSA_SCHANNEL                = 12
239	PROV_DSS_DH                      = 13
240	PROV_EC_ECDSA_SIG                = 14
241	PROV_EC_ECNRA_SIG                = 15
242	PROV_EC_ECDSA_FULL               = 16
243	PROV_EC_ECNRA_FULL               = 17
244	PROV_DH_SCHANNEL                 = 18
245	PROV_SPYRUS_LYNKS                = 20
246	PROV_RNG                         = 21
247	PROV_INTEL_SEC                   = 22
248	PROV_REPLACE_OWF                 = 23
249	PROV_RSA_AES                     = 24
250	CRYPT_VERIFYCONTEXT              = 0xF0000000
251	CRYPT_NEWKEYSET                  = 0x00000008
252	CRYPT_DELETEKEYSET               = 0x00000010
253	CRYPT_MACHINE_KEYSET             = 0x00000020
254	CRYPT_SILENT                     = 0x00000040
255	CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080
256
257	USAGE_MATCH_TYPE_AND = 0
258	USAGE_MATCH_TYPE_OR  = 1
259
260	X509_ASN_ENCODING   = 0x00000001
261	PKCS_7_ASN_ENCODING = 0x00010000
262
263	CERT_STORE_PROV_MEMORY = 2
264
265	CERT_STORE_ADD_ALWAYS = 4
266
267	CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004
268
269	CERT_TRUST_NO_ERROR                          = 0x00000000
270	CERT_TRUST_IS_NOT_TIME_VALID                 = 0x00000001
271	CERT_TRUST_IS_REVOKED                        = 0x00000004
272	CERT_TRUST_IS_NOT_SIGNATURE_VALID            = 0x00000008
273	CERT_TRUST_IS_NOT_VALID_FOR_USAGE            = 0x00000010
274	CERT_TRUST_IS_UNTRUSTED_ROOT                 = 0x00000020
275	CERT_TRUST_REVOCATION_STATUS_UNKNOWN         = 0x00000040
276	CERT_TRUST_IS_CYCLIC                         = 0x00000080
277	CERT_TRUST_INVALID_EXTENSION                 = 0x00000100
278	CERT_TRUST_INVALID_POLICY_CONSTRAINTS        = 0x00000200
279	CERT_TRUST_INVALID_BASIC_CONSTRAINTS         = 0x00000400
280	CERT_TRUST_INVALID_NAME_CONSTRAINTS          = 0x00000800
281	CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000
282	CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT   = 0x00002000
283	CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000
284	CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT      = 0x00008000
285	CERT_TRUST_IS_OFFLINE_REVOCATION             = 0x01000000
286	CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY          = 0x02000000
287	CERT_TRUST_IS_EXPLICIT_DISTRUST              = 0x04000000
288	CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT    = 0x08000000
289
290	CERT_CHAIN_POLICY_BASE              = 1
291	CERT_CHAIN_POLICY_AUTHENTICODE      = 2
292	CERT_CHAIN_POLICY_AUTHENTICODE_TS   = 3
293	CERT_CHAIN_POLICY_SSL               = 4
294	CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5
295	CERT_CHAIN_POLICY_NT_AUTH           = 6
296	CERT_CHAIN_POLICY_MICROSOFT_ROOT    = 7
297	CERT_CHAIN_POLICY_EV                = 8
298
299	CERT_E_EXPIRED       = 0x800B0101
300	CERT_E_ROLE          = 0x800B0103
301	CERT_E_PURPOSE       = 0x800B0106
302	CERT_E_UNTRUSTEDROOT = 0x800B0109
303	CERT_E_CN_NO_MATCH   = 0x800B010F
304
305	AUTHTYPE_CLIENT = 1
306	AUTHTYPE_SERVER = 2
307)
308
309var (
310	OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00")
311	OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00")
312	OID_SGC_NETSCAPE        = []byte("2.16.840.1.113730.4.1\x00")
313)
314
315// Invented values to support what package os expects.
316type Timeval struct {
317	Sec  int32
318	Usec int32
319}
320
321func (tv *Timeval) Nanoseconds() int64 {
322	return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
323}
324
325func NsecToTimeval(nsec int64) (tv Timeval) {
326	tv.Sec = int32(nsec / 1e9)
327	tv.Usec = int32(nsec % 1e9 / 1e3)
328	return
329}
330
331type SecurityAttributes struct {
332	Length             uint32
333	SecurityDescriptor uintptr
334	InheritHandle      uint32
335}
336
337type Overlapped struct {
338	Internal     uintptr
339	InternalHigh uintptr
340	Offset       uint32
341	OffsetHigh   uint32
342	HEvent       Handle
343}
344
345type FileNotifyInformation struct {
346	NextEntryOffset uint32
347	Action          uint32
348	FileNameLength  uint32
349	FileName        uint16
350}
351
352type Filetime struct {
353	LowDateTime  uint32
354	HighDateTime uint32
355}
356
357// Nanoseconds returns Filetime ft in nanoseconds
358// since Epoch (00:00:00 UTC, January 1, 1970).
359func (ft *Filetime) Nanoseconds() int64 {
360	// 100-nanosecond intervals since January 1, 1601
361	nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
362	// change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
363	nsec -= 116444736000000000
364	// convert into nanoseconds
365	nsec *= 100
366	return nsec
367}
368
369func NsecToFiletime(nsec int64) (ft Filetime) {
370	// convert into 100-nanosecond
371	nsec /= 100
372	// change starting time to January 1, 1601
373	nsec += 116444736000000000
374	// split into high / low
375	ft.LowDateTime = uint32(nsec & 0xffffffff)
376	ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
377	return ft
378}
379
380type Win32finddata struct {
381	FileAttributes    uint32
382	CreationTime      Filetime
383	LastAccessTime    Filetime
384	LastWriteTime     Filetime
385	FileSizeHigh      uint32
386	FileSizeLow       uint32
387	Reserved0         uint32
388	Reserved1         uint32
389	FileName          [MAX_PATH - 1]uint16
390	AlternateFileName [13]uint16
391}
392
393// This is the actual system call structure.
394// Win32finddata is what we committed to in Go 1.
395type win32finddata1 struct {
396	FileAttributes    uint32
397	CreationTime      Filetime
398	LastAccessTime    Filetime
399	LastWriteTime     Filetime
400	FileSizeHigh      uint32
401	FileSizeLow       uint32
402	Reserved0         uint32
403	Reserved1         uint32
404	FileName          [MAX_PATH]uint16
405	AlternateFileName [14]uint16
406}
407
408func copyFindData(dst *Win32finddata, src *win32finddata1) {
409	dst.FileAttributes = src.FileAttributes
410	dst.CreationTime = src.CreationTime
411	dst.LastAccessTime = src.LastAccessTime
412	dst.LastWriteTime = src.LastWriteTime
413	dst.FileSizeHigh = src.FileSizeHigh
414	dst.FileSizeLow = src.FileSizeLow
415	dst.Reserved0 = src.Reserved0
416	dst.Reserved1 = src.Reserved1
417
418	// The src is 1 element bigger than dst, but it must be NUL.
419	copy(dst.FileName[:], src.FileName[:])
420	copy(dst.AlternateFileName[:], src.AlternateFileName[:])
421}
422
423type ByHandleFileInformation struct {
424	FileAttributes     uint32
425	CreationTime       Filetime
426	LastAccessTime     Filetime
427	LastWriteTime      Filetime
428	VolumeSerialNumber uint32
429	FileSizeHigh       uint32
430	FileSizeLow        uint32
431	NumberOfLinks      uint32
432	FileIndexHigh      uint32
433	FileIndexLow       uint32
434}
435
436const (
437	GetFileExInfoStandard = 0
438	GetFileExMaxInfoLevel = 1
439)
440
441type Win32FileAttributeData struct {
442	FileAttributes uint32
443	CreationTime   Filetime
444	LastAccessTime Filetime
445	LastWriteTime  Filetime
446	FileSizeHigh   uint32
447	FileSizeLow    uint32
448}
449
450// ShowWindow constants
451const (
452	// winuser.h
453	SW_HIDE            = 0
454	SW_NORMAL          = 1
455	SW_SHOWNORMAL      = 1
456	SW_SHOWMINIMIZED   = 2
457	SW_SHOWMAXIMIZED   = 3
458	SW_MAXIMIZE        = 3
459	SW_SHOWNOACTIVATE  = 4
460	SW_SHOW            = 5
461	SW_MINIMIZE        = 6
462	SW_SHOWMINNOACTIVE = 7
463	SW_SHOWNA          = 8
464	SW_RESTORE         = 9
465	SW_SHOWDEFAULT     = 10
466	SW_FORCEMINIMIZE   = 11
467)
468
469type StartupInfo struct {
470	Cb            uint32
471	_             *uint16
472	Desktop       *uint16
473	Title         *uint16
474	X             uint32
475	Y             uint32
476	XSize         uint32
477	YSize         uint32
478	XCountChars   uint32
479	YCountChars   uint32
480	FillAttribute uint32
481	Flags         uint32
482	ShowWindow    uint16
483	_             uint16
484	_             *byte
485	StdInput      Handle
486	StdOutput     Handle
487	StdErr        Handle
488}
489
490type ProcessInformation struct {
491	Process   Handle
492	Thread    Handle
493	ProcessId uint32
494	ThreadId  uint32
495}
496
497type ProcessEntry32 struct {
498	Size            uint32
499	Usage           uint32
500	ProcessID       uint32
501	DefaultHeapID   uintptr
502	ModuleID        uint32
503	Threads         uint32
504	ParentProcessID uint32
505	PriClassBase    int32
506	Flags           uint32
507	ExeFile         [MAX_PATH]uint16
508}
509
510type Systemtime struct {
511	Year         uint16
512	Month        uint16
513	DayOfWeek    uint16
514	Day          uint16
515	Hour         uint16
516	Minute       uint16
517	Second       uint16
518	Milliseconds uint16
519}
520
521type Timezoneinformation struct {
522	Bias         int32
523	StandardName [32]uint16
524	StandardDate Systemtime
525	StandardBias int32
526	DaylightName [32]uint16
527	DaylightDate Systemtime
528	DaylightBias int32
529}
530
531// Socket related.
532
533const (
534	AF_UNSPEC  = 0
535	AF_UNIX    = 1
536	AF_INET    = 2
537	AF_INET6   = 23
538	AF_NETBIOS = 17
539
540	SOCK_STREAM    = 1
541	SOCK_DGRAM     = 2
542	SOCK_RAW       = 3
543	SOCK_SEQPACKET = 5
544
545	IPPROTO_IP   = 0
546	IPPROTO_IPV6 = 0x29
547	IPPROTO_TCP  = 6
548	IPPROTO_UDP  = 17
549
550	SOL_SOCKET                = 0xffff
551	SO_REUSEADDR              = 4
552	SO_KEEPALIVE              = 8
553	SO_DONTROUTE              = 16
554	SO_BROADCAST              = 32
555	SO_LINGER                 = 128
556	SO_RCVBUF                 = 0x1002
557	SO_SNDBUF                 = 0x1001
558	SO_UPDATE_ACCEPT_CONTEXT  = 0x700b
559	SO_UPDATE_CONNECT_CONTEXT = 0x7010
560
561	IOC_OUT                            = 0x40000000
562	IOC_IN                             = 0x80000000
563	IOC_VENDOR                         = 0x18000000
564	IOC_INOUT                          = IOC_IN | IOC_OUT
565	IOC_WS2                            = 0x08000000
566	SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
567	SIO_KEEPALIVE_VALS                 = IOC_IN | IOC_VENDOR | 4
568	SIO_UDP_CONNRESET                  = IOC_IN | IOC_VENDOR | 12
569
570	// cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
571
572	IP_TOS             = 0x3
573	IP_TTL             = 0x4
574	IP_MULTICAST_IF    = 0x9
575	IP_MULTICAST_TTL   = 0xa
576	IP_MULTICAST_LOOP  = 0xb
577	IP_ADD_MEMBERSHIP  = 0xc
578	IP_DROP_MEMBERSHIP = 0xd
579
580	IPV6_V6ONLY         = 0x1b
581	IPV6_UNICAST_HOPS   = 0x4
582	IPV6_MULTICAST_IF   = 0x9
583	IPV6_MULTICAST_HOPS = 0xa
584	IPV6_MULTICAST_LOOP = 0xb
585	IPV6_JOIN_GROUP     = 0xc
586	IPV6_LEAVE_GROUP    = 0xd
587
588	MSG_OOB       = 0x1
589	MSG_PEEK      = 0x2
590	MSG_DONTROUTE = 0x4
591	MSG_WAITALL   = 0x8
592
593	MSG_TRUNC  = 0x0100
594	MSG_CTRUNC = 0x0200
595	MSG_BCAST  = 0x0400
596	MSG_MCAST  = 0x0800
597
598	SOMAXCONN = 0x7fffffff
599
600	TCP_NODELAY = 1
601
602	SHUT_RD   = 0
603	SHUT_WR   = 1
604	SHUT_RDWR = 2
605
606	WSADESCRIPTION_LEN = 256
607	WSASYS_STATUS_LEN  = 128
608)
609
610type WSABuf struct {
611	Len uint32
612	Buf *byte
613}
614
615type WSAMsg struct {
616	Name        *syscall.RawSockaddrAny
617	Namelen     int32
618	Buffers     *WSABuf
619	BufferCount uint32
620	Control     WSABuf
621	Flags       uint32
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 CertContext struct {
884	EncodingType uint32
885	EncodedCert  *byte
886	Length       uint32
887	CertInfo     uintptr
888	Store        Handle
889}
890
891type CertChainContext struct {
892	Size                       uint32
893	TrustStatus                CertTrustStatus
894	ChainCount                 uint32
895	Chains                     **CertSimpleChain
896	LowerQualityChainCount     uint32
897	LowerQualityChains         **CertChainContext
898	HasRevocationFreshnessTime uint32
899	RevocationFreshnessTime    uint32
900}
901
902type CertSimpleChain struct {
903	Size                       uint32
904	TrustStatus                CertTrustStatus
905	NumElements                uint32
906	Elements                   **CertChainElement
907	TrustListInfo              uintptr
908	HasRevocationFreshnessTime uint32
909	RevocationFreshnessTime    uint32
910}
911
912type CertChainElement struct {
913	Size              uint32
914	CertContext       *CertContext
915	TrustStatus       CertTrustStatus
916	RevocationInfo    *CertRevocationInfo
917	IssuanceUsage     *CertEnhKeyUsage
918	ApplicationUsage  *CertEnhKeyUsage
919	ExtendedErrorInfo *uint16
920}
921
922type CertRevocationInfo struct {
923	Size             uint32
924	RevocationResult uint32
925	RevocationOid    *byte
926	OidSpecificInfo  uintptr
927	HasFreshnessTime uint32
928	FreshnessTime    uint32
929	CrlInfo          uintptr // *CertRevocationCrlInfo
930}
931
932type CertTrustStatus struct {
933	ErrorStatus uint32
934	InfoStatus  uint32
935}
936
937type CertUsageMatch struct {
938	Type  uint32
939	Usage CertEnhKeyUsage
940}
941
942type CertEnhKeyUsage struct {
943	Length           uint32
944	UsageIdentifiers **byte
945}
946
947type CertChainPara struct {
948	Size                         uint32
949	RequestedUsage               CertUsageMatch
950	RequstedIssuancePolicy       CertUsageMatch
951	URLRetrievalTimeout          uint32
952	CheckRevocationFreshnessTime uint32
953	RevocationFreshnessTime      uint32
954	CacheResync                  *Filetime
955}
956
957type CertChainPolicyPara struct {
958	Size            uint32
959	Flags           uint32
960	ExtraPolicyPara uintptr
961}
962
963type SSLExtraCertChainPolicyPara struct {
964	Size       uint32
965	AuthType   uint32
966	Checks     uint32
967	ServerName *uint16
968}
969
970type CertChainPolicyStatus struct {
971	Size              uint32
972	Error             uint32
973	ChainIndex        uint32
974	ElementIndex      uint32
975	ExtraPolicyStatus uintptr
976}
977
978const (
979	// do not reorder
980	HKEY_CLASSES_ROOT = 0x80000000 + iota
981	HKEY_CURRENT_USER
982	HKEY_LOCAL_MACHINE
983	HKEY_USERS
984	HKEY_PERFORMANCE_DATA
985	HKEY_CURRENT_CONFIG
986	HKEY_DYN_DATA
987
988	KEY_QUERY_VALUE        = 1
989	KEY_SET_VALUE          = 2
990	KEY_CREATE_SUB_KEY     = 4
991	KEY_ENUMERATE_SUB_KEYS = 8
992	KEY_NOTIFY             = 16
993	KEY_CREATE_LINK        = 32
994	KEY_WRITE              = 0x20006
995	KEY_EXECUTE            = 0x20019
996	KEY_READ               = 0x20019
997	KEY_WOW64_64KEY        = 0x0100
998	KEY_WOW64_32KEY        = 0x0200
999	KEY_ALL_ACCESS         = 0xf003f
1000)
1001
1002const (
1003	// do not reorder
1004	REG_NONE = iota
1005	REG_SZ
1006	REG_EXPAND_SZ
1007	REG_BINARY
1008	REG_DWORD_LITTLE_ENDIAN
1009	REG_DWORD_BIG_ENDIAN
1010	REG_LINK
1011	REG_MULTI_SZ
1012	REG_RESOURCE_LIST
1013	REG_FULL_RESOURCE_DESCRIPTOR
1014	REG_RESOURCE_REQUIREMENTS_LIST
1015	REG_QWORD_LITTLE_ENDIAN
1016	REG_DWORD = REG_DWORD_LITTLE_ENDIAN
1017	REG_QWORD = REG_QWORD_LITTLE_ENDIAN
1018)
1019
1020type AddrinfoW struct {
1021	Flags     int32
1022	Family    int32
1023	Socktype  int32
1024	Protocol  int32
1025	Addrlen   uintptr
1026	Canonname *uint16
1027	Addr      uintptr
1028	Next      *AddrinfoW
1029}
1030
1031const (
1032	AI_PASSIVE     = 1
1033	AI_CANONNAME   = 2
1034	AI_NUMERICHOST = 4
1035)
1036
1037type GUID struct {
1038	Data1 uint32
1039	Data2 uint16
1040	Data3 uint16
1041	Data4 [8]byte
1042}
1043
1044var WSAID_CONNECTEX = GUID{
1045	0x25a207b9,
1046	0xddf3,
1047	0x4660,
1048	[8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
1049}
1050
1051var WSAID_WSASENDMSG = GUID{
1052	0xa441e712,
1053	0x754f,
1054	0x43ca,
1055	[8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d},
1056}
1057
1058var WSAID_WSARECVMSG = GUID{
1059	0xf689d7c8,
1060	0x6f1f,
1061	0x436b,
1062	[8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22},
1063}
1064
1065const (
1066	FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
1067	FILE_SKIP_SET_EVENT_ON_HANDLE        = 2
1068)
1069
1070const (
1071	WSAPROTOCOL_LEN    = 255
1072	MAX_PROTOCOL_CHAIN = 7
1073	BASE_PROTOCOL      = 1
1074	LAYERED_PROTOCOL   = 0
1075
1076	XP1_CONNECTIONLESS           = 0x00000001
1077	XP1_GUARANTEED_DELIVERY      = 0x00000002
1078	XP1_GUARANTEED_ORDER         = 0x00000004
1079	XP1_MESSAGE_ORIENTED         = 0x00000008
1080	XP1_PSEUDO_STREAM            = 0x00000010
1081	XP1_GRACEFUL_CLOSE           = 0x00000020
1082	XP1_EXPEDITED_DATA           = 0x00000040
1083	XP1_CONNECT_DATA             = 0x00000080
1084	XP1_DISCONNECT_DATA          = 0x00000100
1085	XP1_SUPPORT_BROADCAST        = 0x00000200
1086	XP1_SUPPORT_MULTIPOINT       = 0x00000400
1087	XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800
1088	XP1_MULTIPOINT_DATA_PLANE    = 0x00001000
1089	XP1_QOS_SUPPORTED            = 0x00002000
1090	XP1_UNI_SEND                 = 0x00008000
1091	XP1_UNI_RECV                 = 0x00010000
1092	XP1_IFS_HANDLES              = 0x00020000
1093	XP1_PARTIAL_MESSAGE          = 0x00040000
1094	XP1_SAN_SUPPORT_SDP          = 0x00080000
1095
1096	PFL_MULTIPLE_PROTO_ENTRIES  = 0x00000001
1097	PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002
1098	PFL_HIDDEN                  = 0x00000004
1099	PFL_MATCHES_PROTOCOL_ZERO   = 0x00000008
1100	PFL_NETWORKDIRECT_PROVIDER  = 0x00000010
1101)
1102
1103type WSAProtocolInfo struct {
1104	ServiceFlags1     uint32
1105	ServiceFlags2     uint32
1106	ServiceFlags3     uint32
1107	ServiceFlags4     uint32
1108	ProviderFlags     uint32
1109	ProviderId        GUID
1110	CatalogEntryId    uint32
1111	ProtocolChain     WSAProtocolChain
1112	Version           int32
1113	AddressFamily     int32
1114	MaxSockAddr       int32
1115	MinSockAddr       int32
1116	SocketType        int32
1117	Protocol          int32
1118	ProtocolMaxOffset int32
1119	NetworkByteOrder  int32
1120	SecurityScheme    int32
1121	MessageSize       uint32
1122	ProviderReserved  uint32
1123	ProtocolName      [WSAPROTOCOL_LEN + 1]uint16
1124}
1125
1126type WSAProtocolChain struct {
1127	ChainLen     int32
1128	ChainEntries [MAX_PROTOCOL_CHAIN]uint32
1129}
1130
1131type TCPKeepalive struct {
1132	OnOff    uint32
1133	Time     uint32
1134	Interval uint32
1135}
1136
1137type symbolicLinkReparseBuffer struct {
1138	SubstituteNameOffset uint16
1139	SubstituteNameLength uint16
1140	PrintNameOffset      uint16
1141	PrintNameLength      uint16
1142	Flags                uint32
1143	PathBuffer           [1]uint16
1144}
1145
1146type mountPointReparseBuffer struct {
1147	SubstituteNameOffset uint16
1148	SubstituteNameLength uint16
1149	PrintNameOffset      uint16
1150	PrintNameLength      uint16
1151	PathBuffer           [1]uint16
1152}
1153
1154type reparseDataBuffer struct {
1155	ReparseTag        uint32
1156	ReparseDataLength uint16
1157	Reserved          uint16
1158
1159	// GenericReparseBuffer
1160	reparseBuffer byte
1161}
1162
1163const (
1164	FSCTL_GET_REPARSE_POINT          = 0x900A8
1165	MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024
1166	IO_REPARSE_TAG_MOUNT_POINT       = 0xA0000003
1167	IO_REPARSE_TAG_SYMLINK           = 0xA000000C
1168	SYMBOLIC_LINK_FLAG_DIRECTORY     = 0x1
1169)
1170
1171const (
1172	ComputerNameNetBIOS                   = 0
1173	ComputerNameDnsHostname               = 1
1174	ComputerNameDnsDomain                 = 2
1175	ComputerNameDnsFullyQualified         = 3
1176	ComputerNamePhysicalNetBIOS           = 4
1177	ComputerNamePhysicalDnsHostname       = 5
1178	ComputerNamePhysicalDnsDomain         = 6
1179	ComputerNamePhysicalDnsFullyQualified = 7
1180	ComputerNameMax                       = 8
1181)
1182
1183const (
1184	MOVEFILE_REPLACE_EXISTING      = 0x1
1185	MOVEFILE_COPY_ALLOWED          = 0x2
1186	MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
1187	MOVEFILE_WRITE_THROUGH         = 0x8
1188	MOVEFILE_CREATE_HARDLINK       = 0x10
1189	MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
1190)
1191
1192const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
1193
1194const (
1195	IF_TYPE_OTHER              = 1
1196	IF_TYPE_ETHERNET_CSMACD    = 6
1197	IF_TYPE_ISO88025_TOKENRING = 9
1198	IF_TYPE_PPP                = 23
1199	IF_TYPE_SOFTWARE_LOOPBACK  = 24
1200	IF_TYPE_ATM                = 37
1201	IF_TYPE_IEEE80211          = 71
1202	IF_TYPE_TUNNEL             = 131
1203	IF_TYPE_IEEE1394           = 144
1204)
1205
1206type SocketAddress struct {
1207	Sockaddr       *syscall.RawSockaddrAny
1208	SockaddrLength int32
1209}
1210
1211type IpAdapterUnicastAddress struct {
1212	Length             uint32
1213	Flags              uint32
1214	Next               *IpAdapterUnicastAddress
1215	Address            SocketAddress
1216	PrefixOrigin       int32
1217	SuffixOrigin       int32
1218	DadState           int32
1219	ValidLifetime      uint32
1220	PreferredLifetime  uint32
1221	LeaseLifetime      uint32
1222	OnLinkPrefixLength uint8
1223}
1224
1225type IpAdapterAnycastAddress struct {
1226	Length  uint32
1227	Flags   uint32
1228	Next    *IpAdapterAnycastAddress
1229	Address SocketAddress
1230}
1231
1232type IpAdapterMulticastAddress struct {
1233	Length  uint32
1234	Flags   uint32
1235	Next    *IpAdapterMulticastAddress
1236	Address SocketAddress
1237}
1238
1239type IpAdapterDnsServerAdapter struct {
1240	Length   uint32
1241	Reserved uint32
1242	Next     *IpAdapterDnsServerAdapter
1243	Address  SocketAddress
1244}
1245
1246type IpAdapterPrefix struct {
1247	Length       uint32
1248	Flags        uint32
1249	Next         *IpAdapterPrefix
1250	Address      SocketAddress
1251	PrefixLength uint32
1252}
1253
1254type IpAdapterAddresses struct {
1255	Length                uint32
1256	IfIndex               uint32
1257	Next                  *IpAdapterAddresses
1258	AdapterName           *byte
1259	FirstUnicastAddress   *IpAdapterUnicastAddress
1260	FirstAnycastAddress   *IpAdapterAnycastAddress
1261	FirstMulticastAddress *IpAdapterMulticastAddress
1262	FirstDnsServerAddress *IpAdapterDnsServerAdapter
1263	DnsSuffix             *uint16
1264	Description           *uint16
1265	FriendlyName          *uint16
1266	PhysicalAddress       [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
1267	PhysicalAddressLength uint32
1268	Flags                 uint32
1269	Mtu                   uint32
1270	IfType                uint32
1271	OperStatus            uint32
1272	Ipv6IfIndex           uint32
1273	ZoneIndices           [16]uint32
1274	FirstPrefix           *IpAdapterPrefix
1275	/* more fields might be present here. */
1276}
1277
1278const (
1279	IfOperStatusUp             = 1
1280	IfOperStatusDown           = 2
1281	IfOperStatusTesting        = 3
1282	IfOperStatusUnknown        = 4
1283	IfOperStatusDormant        = 5
1284	IfOperStatusNotPresent     = 6
1285	IfOperStatusLowerLayerDown = 7
1286)
1287
1288// Console related constants used for the mode parameter to SetConsoleMode. See
1289// https://docs.microsoft.com/en-us/windows/console/setconsolemode for details.
1290
1291const (
1292	ENABLE_PROCESSED_INPUT        = 0x1
1293	ENABLE_LINE_INPUT             = 0x2
1294	ENABLE_ECHO_INPUT             = 0x4
1295	ENABLE_WINDOW_INPUT           = 0x8
1296	ENABLE_MOUSE_INPUT            = 0x10
1297	ENABLE_INSERT_MODE            = 0x20
1298	ENABLE_QUICK_EDIT_MODE        = 0x40
1299	ENABLE_EXTENDED_FLAGS         = 0x80
1300	ENABLE_AUTO_POSITION          = 0x100
1301	ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200
1302
1303	ENABLE_PROCESSED_OUTPUT            = 0x1
1304	ENABLE_WRAP_AT_EOL_OUTPUT          = 0x2
1305	ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
1306	DISABLE_NEWLINE_AUTO_RETURN        = 0x8
1307	ENABLE_LVB_GRID_WORLDWIDE          = 0x10
1308)
1309
1310type Coord struct {
1311	X int16
1312	Y int16
1313}
1314
1315type SmallRect struct {
1316	Left   int16
1317	Top    int16
1318	Right  int16
1319	Bottom int16
1320}
1321
1322// Used with GetConsoleScreenBuffer to retreive information about a console
1323// screen buffer. See
1324// https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str
1325// for details.
1326
1327type ConsoleScreenBufferInfo struct {
1328	Size              Coord
1329	CursorPosition    Coord
1330	Attributes        uint16
1331	Window            SmallRect
1332	MaximumWindowSize Coord
1333}
1334