added support for string type
[govpp.git] / vendor / golang.org / x / sys / windows / ztypes_windows.go
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
5 package windows
6
7 import "syscall"
8
9 const (
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         WSAECONNRESET                syscall.Errno = 10054
33 )
34
35 const (
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
51 const (
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
68 var 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
86 const (
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 & (1<<32 - 1)
126         STD_OUTPUT_HANDLE = -11 & (1<<32 - 1)
127         STD_ERROR_HANDLE  = -12 & (1<<32 - 1)
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
183         // Windows reserves errors >= 1<<29 for application use.
184         APPLICATION_ERROR = 1 << 29
185 )
186
187 const (
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
198 const (
199         // filters for ReadDirectoryChangesW
200         FILE_NOTIFY_CHANGE_FILE_NAME   = 0x001
201         FILE_NOTIFY_CHANGE_DIR_NAME    = 0x002
202         FILE_NOTIFY_CHANGE_ATTRIBUTES  = 0x004
203         FILE_NOTIFY_CHANGE_SIZE        = 0x008
204         FILE_NOTIFY_CHANGE_LAST_WRITE  = 0x010
205         FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020
206         FILE_NOTIFY_CHANGE_CREATION    = 0x040
207         FILE_NOTIFY_CHANGE_SECURITY    = 0x100
208 )
209
210 const (
211         // do not reorder
212         FILE_ACTION_ADDED = iota + 1
213         FILE_ACTION_REMOVED
214         FILE_ACTION_MODIFIED
215         FILE_ACTION_RENAMED_OLD_NAME
216         FILE_ACTION_RENAMED_NEW_NAME
217 )
218
219 const (
220         // wincrypt.h
221         PROV_RSA_FULL                    = 1
222         PROV_RSA_SIG                     = 2
223         PROV_DSS                         = 3
224         PROV_FORTEZZA                    = 4
225         PROV_MS_EXCHANGE                 = 5
226         PROV_SSL                         = 6
227         PROV_RSA_SCHANNEL                = 12
228         PROV_DSS_DH                      = 13
229         PROV_EC_ECDSA_SIG                = 14
230         PROV_EC_ECNRA_SIG                = 15
231         PROV_EC_ECDSA_FULL               = 16
232         PROV_EC_ECNRA_FULL               = 17
233         PROV_DH_SCHANNEL                 = 18
234         PROV_SPYRUS_LYNKS                = 20
235         PROV_RNG                         = 21
236         PROV_INTEL_SEC                   = 22
237         PROV_REPLACE_OWF                 = 23
238         PROV_RSA_AES                     = 24
239         CRYPT_VERIFYCONTEXT              = 0xF0000000
240         CRYPT_NEWKEYSET                  = 0x00000008
241         CRYPT_DELETEKEYSET               = 0x00000010
242         CRYPT_MACHINE_KEYSET             = 0x00000020
243         CRYPT_SILENT                     = 0x00000040
244         CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080
245
246         USAGE_MATCH_TYPE_AND = 0
247         USAGE_MATCH_TYPE_OR  = 1
248
249         X509_ASN_ENCODING   = 0x00000001
250         PKCS_7_ASN_ENCODING = 0x00010000
251
252         CERT_STORE_PROV_MEMORY = 2
253
254         CERT_STORE_ADD_ALWAYS = 4
255
256         CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004
257
258         CERT_TRUST_NO_ERROR                          = 0x00000000
259         CERT_TRUST_IS_NOT_TIME_VALID                 = 0x00000001
260         CERT_TRUST_IS_REVOKED                        = 0x00000004
261         CERT_TRUST_IS_NOT_SIGNATURE_VALID            = 0x00000008
262         CERT_TRUST_IS_NOT_VALID_FOR_USAGE            = 0x00000010
263         CERT_TRUST_IS_UNTRUSTED_ROOT                 = 0x00000020
264         CERT_TRUST_REVOCATION_STATUS_UNKNOWN         = 0x00000040
265         CERT_TRUST_IS_CYCLIC                         = 0x00000080
266         CERT_TRUST_INVALID_EXTENSION                 = 0x00000100
267         CERT_TRUST_INVALID_POLICY_CONSTRAINTS        = 0x00000200
268         CERT_TRUST_INVALID_BASIC_CONSTRAINTS         = 0x00000400
269         CERT_TRUST_INVALID_NAME_CONSTRAINTS          = 0x00000800
270         CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000
271         CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT   = 0x00002000
272         CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000
273         CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT      = 0x00008000
274         CERT_TRUST_IS_OFFLINE_REVOCATION             = 0x01000000
275         CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY          = 0x02000000
276         CERT_TRUST_IS_EXPLICIT_DISTRUST              = 0x04000000
277         CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT    = 0x08000000
278
279         CERT_CHAIN_POLICY_BASE              = 1
280         CERT_CHAIN_POLICY_AUTHENTICODE      = 2
281         CERT_CHAIN_POLICY_AUTHENTICODE_TS   = 3
282         CERT_CHAIN_POLICY_SSL               = 4
283         CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5
284         CERT_CHAIN_POLICY_NT_AUTH           = 6
285         CERT_CHAIN_POLICY_MICROSOFT_ROOT    = 7
286         CERT_CHAIN_POLICY_EV                = 8
287
288         CERT_E_EXPIRED       = 0x800B0101
289         CERT_E_ROLE          = 0x800B0103
290         CERT_E_PURPOSE       = 0x800B0106
291         CERT_E_UNTRUSTEDROOT = 0x800B0109
292         CERT_E_CN_NO_MATCH   = 0x800B010F
293
294         AUTHTYPE_CLIENT = 1
295         AUTHTYPE_SERVER = 2
296 )
297
298 var (
299         OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00")
300         OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00")
301         OID_SGC_NETSCAPE        = []byte("2.16.840.1.113730.4.1\x00")
302 )
303
304 // Invented values to support what package os expects.
305 type Timeval struct {
306         Sec  int32
307         Usec int32
308 }
309
310 func (tv *Timeval) Nanoseconds() int64 {
311         return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
312 }
313
314 func NsecToTimeval(nsec int64) (tv Timeval) {
315         tv.Sec = int32(nsec / 1e9)
316         tv.Usec = int32(nsec % 1e9 / 1e3)
317         return
318 }
319
320 type SecurityAttributes struct {
321         Length             uint32
322         SecurityDescriptor uintptr
323         InheritHandle      uint32
324 }
325
326 type Overlapped struct {
327         Internal     uintptr
328         InternalHigh uintptr
329         Offset       uint32
330         OffsetHigh   uint32
331         HEvent       Handle
332 }
333
334 type FileNotifyInformation struct {
335         NextEntryOffset uint32
336         Action          uint32
337         FileNameLength  uint32
338         FileName        uint16
339 }
340
341 type Filetime struct {
342         LowDateTime  uint32
343         HighDateTime uint32
344 }
345
346 // Nanoseconds returns Filetime ft in nanoseconds
347 // since Epoch (00:00:00 UTC, January 1, 1970).
348 func (ft *Filetime) Nanoseconds() int64 {
349         // 100-nanosecond intervals since January 1, 1601
350         nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
351         // change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
352         nsec -= 116444736000000000
353         // convert into nanoseconds
354         nsec *= 100
355         return nsec
356 }
357
358 func NsecToFiletime(nsec int64) (ft Filetime) {
359         // convert into 100-nanosecond
360         nsec /= 100
361         // change starting time to January 1, 1601
362         nsec += 116444736000000000
363         // split into high / low
364         ft.LowDateTime = uint32(nsec & 0xffffffff)
365         ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
366         return ft
367 }
368
369 type Win32finddata struct {
370         FileAttributes    uint32
371         CreationTime      Filetime
372         LastAccessTime    Filetime
373         LastWriteTime     Filetime
374         FileSizeHigh      uint32
375         FileSizeLow       uint32
376         Reserved0         uint32
377         Reserved1         uint32
378         FileName          [MAX_PATH - 1]uint16
379         AlternateFileName [13]uint16
380 }
381
382 // This is the actual system call structure.
383 // Win32finddata is what we committed to in Go 1.
384 type win32finddata1 struct {
385         FileAttributes    uint32
386         CreationTime      Filetime
387         LastAccessTime    Filetime
388         LastWriteTime     Filetime
389         FileSizeHigh      uint32
390         FileSizeLow       uint32
391         Reserved0         uint32
392         Reserved1         uint32
393         FileName          [MAX_PATH]uint16
394         AlternateFileName [14]uint16
395 }
396
397 func copyFindData(dst *Win32finddata, src *win32finddata1) {
398         dst.FileAttributes = src.FileAttributes
399         dst.CreationTime = src.CreationTime
400         dst.LastAccessTime = src.LastAccessTime
401         dst.LastWriteTime = src.LastWriteTime
402         dst.FileSizeHigh = src.FileSizeHigh
403         dst.FileSizeLow = src.FileSizeLow
404         dst.Reserved0 = src.Reserved0
405         dst.Reserved1 = src.Reserved1
406
407         // The src is 1 element bigger than dst, but it must be NUL.
408         copy(dst.FileName[:], src.FileName[:])
409         copy(dst.AlternateFileName[:], src.AlternateFileName[:])
410 }
411
412 type ByHandleFileInformation struct {
413         FileAttributes     uint32
414         CreationTime       Filetime
415         LastAccessTime     Filetime
416         LastWriteTime      Filetime
417         VolumeSerialNumber uint32
418         FileSizeHigh       uint32
419         FileSizeLow        uint32
420         NumberOfLinks      uint32
421         FileIndexHigh      uint32
422         FileIndexLow       uint32
423 }
424
425 const (
426         GetFileExInfoStandard = 0
427         GetFileExMaxInfoLevel = 1
428 )
429
430 type Win32FileAttributeData struct {
431         FileAttributes uint32
432         CreationTime   Filetime
433         LastAccessTime Filetime
434         LastWriteTime  Filetime
435         FileSizeHigh   uint32
436         FileSizeLow    uint32
437 }
438
439 // ShowWindow constants
440 const (
441         // winuser.h
442         SW_HIDE            = 0
443         SW_NORMAL          = 1
444         SW_SHOWNORMAL      = 1
445         SW_SHOWMINIMIZED   = 2
446         SW_SHOWMAXIMIZED   = 3
447         SW_MAXIMIZE        = 3
448         SW_SHOWNOACTIVATE  = 4
449         SW_SHOW            = 5
450         SW_MINIMIZE        = 6
451         SW_SHOWMINNOACTIVE = 7
452         SW_SHOWNA          = 8
453         SW_RESTORE         = 9
454         SW_SHOWDEFAULT     = 10
455         SW_FORCEMINIMIZE   = 11
456 )
457
458 type StartupInfo struct {
459         Cb            uint32
460         _             *uint16
461         Desktop       *uint16
462         Title         *uint16
463         X             uint32
464         Y             uint32
465         XSize         uint32
466         YSize         uint32
467         XCountChars   uint32
468         YCountChars   uint32
469         FillAttribute uint32
470         Flags         uint32
471         ShowWindow    uint16
472         _             uint16
473         _             *byte
474         StdInput      Handle
475         StdOutput     Handle
476         StdErr        Handle
477 }
478
479 type ProcessInformation struct {
480         Process   Handle
481         Thread    Handle
482         ProcessId uint32
483         ThreadId  uint32
484 }
485
486 type ProcessEntry32 struct {
487         Size            uint32
488         Usage           uint32
489         ProcessID       uint32
490         DefaultHeapID   uintptr
491         ModuleID        uint32
492         Threads         uint32
493         ParentProcessID uint32
494         PriClassBase    int32
495         Flags           uint32
496         ExeFile         [MAX_PATH]uint16
497 }
498
499 type Systemtime struct {
500         Year         uint16
501         Month        uint16
502         DayOfWeek    uint16
503         Day          uint16
504         Hour         uint16
505         Minute       uint16
506         Second       uint16
507         Milliseconds uint16
508 }
509
510 type Timezoneinformation struct {
511         Bias         int32
512         StandardName [32]uint16
513         StandardDate Systemtime
514         StandardBias int32
515         DaylightName [32]uint16
516         DaylightDate Systemtime
517         DaylightBias int32
518 }
519
520 // Socket related.
521
522 const (
523         AF_UNSPEC  = 0
524         AF_UNIX    = 1
525         AF_INET    = 2
526         AF_INET6   = 23
527         AF_NETBIOS = 17
528
529         SOCK_STREAM    = 1
530         SOCK_DGRAM     = 2
531         SOCK_RAW       = 3
532         SOCK_SEQPACKET = 5
533
534         IPPROTO_IP   = 0
535         IPPROTO_IPV6 = 0x29
536         IPPROTO_TCP  = 6
537         IPPROTO_UDP  = 17
538
539         SOL_SOCKET                = 0xffff
540         SO_REUSEADDR              = 4
541         SO_KEEPALIVE              = 8
542         SO_DONTROUTE              = 16
543         SO_BROADCAST              = 32
544         SO_LINGER                 = 128
545         SO_RCVBUF                 = 0x1002
546         SO_SNDBUF                 = 0x1001
547         SO_UPDATE_ACCEPT_CONTEXT  = 0x700b
548         SO_UPDATE_CONNECT_CONTEXT = 0x7010
549
550         IOC_OUT                            = 0x40000000
551         IOC_IN                             = 0x80000000
552         IOC_VENDOR                         = 0x18000000
553         IOC_INOUT                          = IOC_IN | IOC_OUT
554         IOC_WS2                            = 0x08000000
555         SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
556         SIO_KEEPALIVE_VALS                 = IOC_IN | IOC_VENDOR | 4
557         SIO_UDP_CONNRESET                  = IOC_IN | IOC_VENDOR | 12
558
559         // cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
560
561         IP_TOS             = 0x3
562         IP_TTL             = 0x4
563         IP_MULTICAST_IF    = 0x9
564         IP_MULTICAST_TTL   = 0xa
565         IP_MULTICAST_LOOP  = 0xb
566         IP_ADD_MEMBERSHIP  = 0xc
567         IP_DROP_MEMBERSHIP = 0xd
568
569         IPV6_V6ONLY         = 0x1b
570         IPV6_UNICAST_HOPS   = 0x4
571         IPV6_MULTICAST_IF   = 0x9
572         IPV6_MULTICAST_HOPS = 0xa
573         IPV6_MULTICAST_LOOP = 0xb
574         IPV6_JOIN_GROUP     = 0xc
575         IPV6_LEAVE_GROUP    = 0xd
576
577         SOMAXCONN = 0x7fffffff
578
579         TCP_NODELAY = 1
580
581         SHUT_RD   = 0
582         SHUT_WR   = 1
583         SHUT_RDWR = 2
584
585         WSADESCRIPTION_LEN = 256
586         WSASYS_STATUS_LEN  = 128
587 )
588
589 type WSABuf struct {
590         Len uint32
591         Buf *byte
592 }
593
594 // Invented values to support what package os expects.
595 const (
596         S_IFMT   = 0x1f000
597         S_IFIFO  = 0x1000
598         S_IFCHR  = 0x2000
599         S_IFDIR  = 0x4000
600         S_IFBLK  = 0x6000
601         S_IFREG  = 0x8000
602         S_IFLNK  = 0xa000
603         S_IFSOCK = 0xc000
604         S_ISUID  = 0x800
605         S_ISGID  = 0x400
606         S_ISVTX  = 0x200
607         S_IRUSR  = 0x100
608         S_IWRITE = 0x80
609         S_IWUSR  = 0x80
610         S_IXUSR  = 0x40
611 )
612
613 const (
614         FILE_TYPE_CHAR    = 0x0002
615         FILE_TYPE_DISK    = 0x0001
616         FILE_TYPE_PIPE    = 0x0003
617         FILE_TYPE_REMOTE  = 0x8000
618         FILE_TYPE_UNKNOWN = 0x0000
619 )
620
621 type Hostent struct {
622         Name     *byte
623         Aliases  **byte
624         AddrType uint16
625         Length   uint16
626         AddrList **byte
627 }
628
629 type Protoent struct {
630         Name    *byte
631         Aliases **byte
632         Proto   uint16
633 }
634
635 const (
636         DNS_TYPE_A       = 0x0001
637         DNS_TYPE_NS      = 0x0002
638         DNS_TYPE_MD      = 0x0003
639         DNS_TYPE_MF      = 0x0004
640         DNS_TYPE_CNAME   = 0x0005
641         DNS_TYPE_SOA     = 0x0006
642         DNS_TYPE_MB      = 0x0007
643         DNS_TYPE_MG      = 0x0008
644         DNS_TYPE_MR      = 0x0009
645         DNS_TYPE_NULL    = 0x000a
646         DNS_TYPE_WKS     = 0x000b
647         DNS_TYPE_PTR     = 0x000c
648         DNS_TYPE_HINFO   = 0x000d
649         DNS_TYPE_MINFO   = 0x000e
650         DNS_TYPE_MX      = 0x000f
651         DNS_TYPE_TEXT    = 0x0010
652         DNS_TYPE_RP      = 0x0011
653         DNS_TYPE_AFSDB   = 0x0012
654         DNS_TYPE_X25     = 0x0013
655         DNS_TYPE_ISDN    = 0x0014
656         DNS_TYPE_RT      = 0x0015
657         DNS_TYPE_NSAP    = 0x0016
658         DNS_TYPE_NSAPPTR = 0x0017
659         DNS_TYPE_SIG     = 0x0018
660         DNS_TYPE_KEY     = 0x0019
661         DNS_TYPE_PX      = 0x001a
662         DNS_TYPE_GPOS    = 0x001b
663         DNS_TYPE_AAAA    = 0x001c
664         DNS_TYPE_LOC     = 0x001d
665         DNS_TYPE_NXT     = 0x001e
666         DNS_TYPE_EID     = 0x001f
667         DNS_TYPE_NIMLOC  = 0x0020
668         DNS_TYPE_SRV     = 0x0021
669         DNS_TYPE_ATMA    = 0x0022
670         DNS_TYPE_NAPTR   = 0x0023
671         DNS_TYPE_KX      = 0x0024
672         DNS_TYPE_CERT    = 0x0025
673         DNS_TYPE_A6      = 0x0026
674         DNS_TYPE_DNAME   = 0x0027
675         DNS_TYPE_SINK    = 0x0028
676         DNS_TYPE_OPT     = 0x0029
677         DNS_TYPE_DS      = 0x002B
678         DNS_TYPE_RRSIG   = 0x002E
679         DNS_TYPE_NSEC    = 0x002F
680         DNS_TYPE_DNSKEY  = 0x0030
681         DNS_TYPE_DHCID   = 0x0031
682         DNS_TYPE_UINFO   = 0x0064
683         DNS_TYPE_UID     = 0x0065
684         DNS_TYPE_GID     = 0x0066
685         DNS_TYPE_UNSPEC  = 0x0067
686         DNS_TYPE_ADDRS   = 0x00f8
687         DNS_TYPE_TKEY    = 0x00f9
688         DNS_TYPE_TSIG    = 0x00fa
689         DNS_TYPE_IXFR    = 0x00fb
690         DNS_TYPE_AXFR    = 0x00fc
691         DNS_TYPE_MAILB   = 0x00fd
692         DNS_TYPE_MAILA   = 0x00fe
693         DNS_TYPE_ALL     = 0x00ff
694         DNS_TYPE_ANY     = 0x00ff
695         DNS_TYPE_WINS    = 0xff01
696         DNS_TYPE_WINSR   = 0xff02
697         DNS_TYPE_NBSTAT  = 0xff01
698 )
699
700 const (
701         DNS_INFO_NO_RECORDS = 0x251D
702 )
703
704 const (
705         // flags inside DNSRecord.Dw
706         DnsSectionQuestion   = 0x0000
707         DnsSectionAnswer     = 0x0001
708         DnsSectionAuthority  = 0x0002
709         DnsSectionAdditional = 0x0003
710 )
711
712 type DNSSRVData struct {
713         Target   *uint16
714         Priority uint16
715         Weight   uint16
716         Port     uint16
717         Pad      uint16
718 }
719
720 type DNSPTRData struct {
721         Host *uint16
722 }
723
724 type DNSMXData struct {
725         NameExchange *uint16
726         Preference   uint16
727         Pad          uint16
728 }
729
730 type DNSTXTData struct {
731         StringCount uint16
732         StringArray [1]*uint16
733 }
734
735 type DNSRecord struct {
736         Next     *DNSRecord
737         Name     *uint16
738         Type     uint16
739         Length   uint16
740         Dw       uint32
741         Ttl      uint32
742         Reserved uint32
743         Data     [40]byte
744 }
745
746 const (
747         TF_DISCONNECT         = 1
748         TF_REUSE_SOCKET       = 2
749         TF_WRITE_BEHIND       = 4
750         TF_USE_DEFAULT_WORKER = 0
751         TF_USE_SYSTEM_THREAD  = 16
752         TF_USE_KERNEL_APC     = 32
753 )
754
755 type TransmitFileBuffers struct {
756         Head       uintptr
757         HeadLength uint32
758         Tail       uintptr
759         TailLength uint32
760 }
761
762 const (
763         IFF_UP           = 1
764         IFF_BROADCAST    = 2
765         IFF_LOOPBACK     = 4
766         IFF_POINTTOPOINT = 8
767         IFF_MULTICAST    = 16
768 )
769
770 const SIO_GET_INTERFACE_LIST = 0x4004747F
771
772 // TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old.
773 // will be fixed to change variable type as suitable.
774
775 type SockaddrGen [24]byte
776
777 type InterfaceInfo struct {
778         Flags            uint32
779         Address          SockaddrGen
780         BroadcastAddress SockaddrGen
781         Netmask          SockaddrGen
782 }
783
784 type IpAddressString struct {
785         String [16]byte
786 }
787
788 type IpMaskString IpAddressString
789
790 type IpAddrString struct {
791         Next      *IpAddrString
792         IpAddress IpAddressString
793         IpMask    IpMaskString
794         Context   uint32
795 }
796
797 const MAX_ADAPTER_NAME_LENGTH = 256
798 const MAX_ADAPTER_DESCRIPTION_LENGTH = 128
799 const MAX_ADAPTER_ADDRESS_LENGTH = 8
800
801 type IpAdapterInfo struct {
802         Next                *IpAdapterInfo
803         ComboIndex          uint32
804         AdapterName         [MAX_ADAPTER_NAME_LENGTH + 4]byte
805         Description         [MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte
806         AddressLength       uint32
807         Address             [MAX_ADAPTER_ADDRESS_LENGTH]byte
808         Index               uint32
809         Type                uint32
810         DhcpEnabled         uint32
811         CurrentIpAddress    *IpAddrString
812         IpAddressList       IpAddrString
813         GatewayList         IpAddrString
814         DhcpServer          IpAddrString
815         HaveWins            bool
816         PrimaryWinsServer   IpAddrString
817         SecondaryWinsServer IpAddrString
818         LeaseObtained       int64
819         LeaseExpires        int64
820 }
821
822 const MAXLEN_PHYSADDR = 8
823 const MAX_INTERFACE_NAME_LEN = 256
824 const MAXLEN_IFDESCR = 256
825
826 type MibIfRow struct {
827         Name            [MAX_INTERFACE_NAME_LEN]uint16
828         Index           uint32
829         Type            uint32
830         Mtu             uint32
831         Speed           uint32
832         PhysAddrLen     uint32
833         PhysAddr        [MAXLEN_PHYSADDR]byte
834         AdminStatus     uint32
835         OperStatus      uint32
836         LastChange      uint32
837         InOctets        uint32
838         InUcastPkts     uint32
839         InNUcastPkts    uint32
840         InDiscards      uint32
841         InErrors        uint32
842         InUnknownProtos uint32
843         OutOctets       uint32
844         OutUcastPkts    uint32
845         OutNUcastPkts   uint32
846         OutDiscards     uint32
847         OutErrors       uint32
848         OutQLen         uint32
849         DescrLen        uint32
850         Descr           [MAXLEN_IFDESCR]byte
851 }
852
853 type CertContext struct {
854         EncodingType uint32
855         EncodedCert  *byte
856         Length       uint32
857         CertInfo     uintptr
858         Store        Handle
859 }
860
861 type CertChainContext struct {
862         Size                       uint32
863         TrustStatus                CertTrustStatus
864         ChainCount                 uint32
865         Chains                     **CertSimpleChain
866         LowerQualityChainCount     uint32
867         LowerQualityChains         **CertChainContext
868         HasRevocationFreshnessTime uint32
869         RevocationFreshnessTime    uint32
870 }
871
872 type CertSimpleChain struct {
873         Size                       uint32
874         TrustStatus                CertTrustStatus
875         NumElements                uint32
876         Elements                   **CertChainElement
877         TrustListInfo              uintptr
878         HasRevocationFreshnessTime uint32
879         RevocationFreshnessTime    uint32
880 }
881
882 type CertChainElement struct {
883         Size              uint32
884         CertContext       *CertContext
885         TrustStatus       CertTrustStatus
886         RevocationInfo    *CertRevocationInfo
887         IssuanceUsage     *CertEnhKeyUsage
888         ApplicationUsage  *CertEnhKeyUsage
889         ExtendedErrorInfo *uint16
890 }
891
892 type CertRevocationInfo struct {
893         Size             uint32
894         RevocationResult uint32
895         RevocationOid    *byte
896         OidSpecificInfo  uintptr
897         HasFreshnessTime uint32
898         FreshnessTime    uint32
899         CrlInfo          uintptr // *CertRevocationCrlInfo
900 }
901
902 type CertTrustStatus struct {
903         ErrorStatus uint32
904         InfoStatus  uint32
905 }
906
907 type CertUsageMatch struct {
908         Type  uint32
909         Usage CertEnhKeyUsage
910 }
911
912 type CertEnhKeyUsage struct {
913         Length           uint32
914         UsageIdentifiers **byte
915 }
916
917 type CertChainPara struct {
918         Size                         uint32
919         RequestedUsage               CertUsageMatch
920         RequstedIssuancePolicy       CertUsageMatch
921         URLRetrievalTimeout          uint32
922         CheckRevocationFreshnessTime uint32
923         RevocationFreshnessTime      uint32
924         CacheResync                  *Filetime
925 }
926
927 type CertChainPolicyPara struct {
928         Size            uint32
929         Flags           uint32
930         ExtraPolicyPara uintptr
931 }
932
933 type SSLExtraCertChainPolicyPara struct {
934         Size       uint32
935         AuthType   uint32
936         Checks     uint32
937         ServerName *uint16
938 }
939
940 type CertChainPolicyStatus struct {
941         Size              uint32
942         Error             uint32
943         ChainIndex        uint32
944         ElementIndex      uint32
945         ExtraPolicyStatus uintptr
946 }
947
948 const (
949         // do not reorder
950         HKEY_CLASSES_ROOT = 0x80000000 + iota
951         HKEY_CURRENT_USER
952         HKEY_LOCAL_MACHINE
953         HKEY_USERS
954         HKEY_PERFORMANCE_DATA
955         HKEY_CURRENT_CONFIG
956         HKEY_DYN_DATA
957
958         KEY_QUERY_VALUE        = 1
959         KEY_SET_VALUE          = 2
960         KEY_CREATE_SUB_KEY     = 4
961         KEY_ENUMERATE_SUB_KEYS = 8
962         KEY_NOTIFY             = 16
963         KEY_CREATE_LINK        = 32
964         KEY_WRITE              = 0x20006
965         KEY_EXECUTE            = 0x20019
966         KEY_READ               = 0x20019
967         KEY_WOW64_64KEY        = 0x0100
968         KEY_WOW64_32KEY        = 0x0200
969         KEY_ALL_ACCESS         = 0xf003f
970 )
971
972 const (
973         // do not reorder
974         REG_NONE = iota
975         REG_SZ
976         REG_EXPAND_SZ
977         REG_BINARY
978         REG_DWORD_LITTLE_ENDIAN
979         REG_DWORD_BIG_ENDIAN
980         REG_LINK
981         REG_MULTI_SZ
982         REG_RESOURCE_LIST
983         REG_FULL_RESOURCE_DESCRIPTOR
984         REG_RESOURCE_REQUIREMENTS_LIST
985         REG_QWORD_LITTLE_ENDIAN
986         REG_DWORD = REG_DWORD_LITTLE_ENDIAN
987         REG_QWORD = REG_QWORD_LITTLE_ENDIAN
988 )
989
990 type AddrinfoW struct {
991         Flags     int32
992         Family    int32
993         Socktype  int32
994         Protocol  int32
995         Addrlen   uintptr
996         Canonname *uint16
997         Addr      uintptr
998         Next      *AddrinfoW
999 }
1000
1001 const (
1002         AI_PASSIVE     = 1
1003         AI_CANONNAME   = 2
1004         AI_NUMERICHOST = 4
1005 )
1006
1007 type GUID struct {
1008         Data1 uint32
1009         Data2 uint16
1010         Data3 uint16
1011         Data4 [8]byte
1012 }
1013
1014 var WSAID_CONNECTEX = GUID{
1015         0x25a207b9,
1016         0xddf3,
1017         0x4660,
1018         [8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
1019 }
1020
1021 const (
1022         FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
1023         FILE_SKIP_SET_EVENT_ON_HANDLE        = 2
1024 )
1025
1026 const (
1027         WSAPROTOCOL_LEN    = 255
1028         MAX_PROTOCOL_CHAIN = 7
1029         BASE_PROTOCOL      = 1
1030         LAYERED_PROTOCOL   = 0
1031
1032         XP1_CONNECTIONLESS           = 0x00000001
1033         XP1_GUARANTEED_DELIVERY      = 0x00000002
1034         XP1_GUARANTEED_ORDER         = 0x00000004
1035         XP1_MESSAGE_ORIENTED         = 0x00000008
1036         XP1_PSEUDO_STREAM            = 0x00000010
1037         XP1_GRACEFUL_CLOSE           = 0x00000020
1038         XP1_EXPEDITED_DATA           = 0x00000040
1039         XP1_CONNECT_DATA             = 0x00000080
1040         XP1_DISCONNECT_DATA          = 0x00000100
1041         XP1_SUPPORT_BROADCAST        = 0x00000200
1042         XP1_SUPPORT_MULTIPOINT       = 0x00000400
1043         XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800
1044         XP1_MULTIPOINT_DATA_PLANE    = 0x00001000
1045         XP1_QOS_SUPPORTED            = 0x00002000
1046         XP1_UNI_SEND                 = 0x00008000
1047         XP1_UNI_RECV                 = 0x00010000
1048         XP1_IFS_HANDLES              = 0x00020000
1049         XP1_PARTIAL_MESSAGE          = 0x00040000
1050         XP1_SAN_SUPPORT_SDP          = 0x00080000
1051
1052         PFL_MULTIPLE_PROTO_ENTRIES  = 0x00000001
1053         PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002
1054         PFL_HIDDEN                  = 0x00000004
1055         PFL_MATCHES_PROTOCOL_ZERO   = 0x00000008
1056         PFL_NETWORKDIRECT_PROVIDER  = 0x00000010
1057 )
1058
1059 type WSAProtocolInfo struct {
1060         ServiceFlags1     uint32
1061         ServiceFlags2     uint32
1062         ServiceFlags3     uint32
1063         ServiceFlags4     uint32
1064         ProviderFlags     uint32
1065         ProviderId        GUID
1066         CatalogEntryId    uint32
1067         ProtocolChain     WSAProtocolChain
1068         Version           int32
1069         AddressFamily     int32
1070         MaxSockAddr       int32
1071         MinSockAddr       int32
1072         SocketType        int32
1073         Protocol          int32
1074         ProtocolMaxOffset int32
1075         NetworkByteOrder  int32
1076         SecurityScheme    int32
1077         MessageSize       uint32
1078         ProviderReserved  uint32
1079         ProtocolName      [WSAPROTOCOL_LEN + 1]uint16
1080 }
1081
1082 type WSAProtocolChain struct {
1083         ChainLen     int32
1084         ChainEntries [MAX_PROTOCOL_CHAIN]uint32
1085 }
1086
1087 type TCPKeepalive struct {
1088         OnOff    uint32
1089         Time     uint32
1090         Interval uint32
1091 }
1092
1093 type symbolicLinkReparseBuffer struct {
1094         SubstituteNameOffset uint16
1095         SubstituteNameLength uint16
1096         PrintNameOffset      uint16
1097         PrintNameLength      uint16
1098         Flags                uint32
1099         PathBuffer           [1]uint16
1100 }
1101
1102 type mountPointReparseBuffer struct {
1103         SubstituteNameOffset uint16
1104         SubstituteNameLength uint16
1105         PrintNameOffset      uint16
1106         PrintNameLength      uint16
1107         PathBuffer           [1]uint16
1108 }
1109
1110 type reparseDataBuffer struct {
1111         ReparseTag        uint32
1112         ReparseDataLength uint16
1113         Reserved          uint16
1114
1115         // GenericReparseBuffer
1116         reparseBuffer byte
1117 }
1118
1119 const (
1120         FSCTL_GET_REPARSE_POINT          = 0x900A8
1121         MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024
1122         IO_REPARSE_TAG_MOUNT_POINT       = 0xA0000003
1123         IO_REPARSE_TAG_SYMLINK           = 0xA000000C
1124         SYMBOLIC_LINK_FLAG_DIRECTORY     = 0x1
1125 )
1126
1127 const (
1128         ComputerNameNetBIOS                   = 0
1129         ComputerNameDnsHostname               = 1
1130         ComputerNameDnsDomain                 = 2
1131         ComputerNameDnsFullyQualified         = 3
1132         ComputerNamePhysicalNetBIOS           = 4
1133         ComputerNamePhysicalDnsHostname       = 5
1134         ComputerNamePhysicalDnsDomain         = 6
1135         ComputerNamePhysicalDnsFullyQualified = 7
1136         ComputerNameMax                       = 8
1137 )
1138
1139 const (
1140         MOVEFILE_REPLACE_EXISTING      = 0x1
1141         MOVEFILE_COPY_ALLOWED          = 0x2
1142         MOVEFILE_DELAY_UNTIL_REBOOT    = 0x4
1143         MOVEFILE_WRITE_THROUGH         = 0x8
1144         MOVEFILE_CREATE_HARDLINK       = 0x10
1145         MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
1146 )
1147
1148 const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
1149
1150 const (
1151         IF_TYPE_OTHER              = 1
1152         IF_TYPE_ETHERNET_CSMACD    = 6
1153         IF_TYPE_ISO88025_TOKENRING = 9
1154         IF_TYPE_PPP                = 23
1155         IF_TYPE_SOFTWARE_LOOPBACK  = 24
1156         IF_TYPE_ATM                = 37
1157         IF_TYPE_IEEE80211          = 71
1158         IF_TYPE_TUNNEL             = 131
1159         IF_TYPE_IEEE1394           = 144
1160 )
1161
1162 type SocketAddress struct {
1163         Sockaddr       *syscall.RawSockaddrAny
1164         SockaddrLength int32
1165 }
1166
1167 type IpAdapterUnicastAddress struct {
1168         Length             uint32
1169         Flags              uint32
1170         Next               *IpAdapterUnicastAddress
1171         Address            SocketAddress
1172         PrefixOrigin       int32
1173         SuffixOrigin       int32
1174         DadState           int32
1175         ValidLifetime      uint32
1176         PreferredLifetime  uint32
1177         LeaseLifetime      uint32
1178         OnLinkPrefixLength uint8
1179 }
1180
1181 type IpAdapterAnycastAddress struct {
1182         Length  uint32
1183         Flags   uint32
1184         Next    *IpAdapterAnycastAddress
1185         Address SocketAddress
1186 }
1187
1188 type IpAdapterMulticastAddress struct {
1189         Length  uint32
1190         Flags   uint32
1191         Next    *IpAdapterMulticastAddress
1192         Address SocketAddress
1193 }
1194
1195 type IpAdapterDnsServerAdapter struct {
1196         Length   uint32
1197         Reserved uint32
1198         Next     *IpAdapterDnsServerAdapter
1199         Address  SocketAddress
1200 }
1201
1202 type IpAdapterPrefix struct {
1203         Length       uint32
1204         Flags        uint32
1205         Next         *IpAdapterPrefix
1206         Address      SocketAddress
1207         PrefixLength uint32
1208 }
1209
1210 type IpAdapterAddresses struct {
1211         Length                uint32
1212         IfIndex               uint32
1213         Next                  *IpAdapterAddresses
1214         AdapterName           *byte
1215         FirstUnicastAddress   *IpAdapterUnicastAddress
1216         FirstAnycastAddress   *IpAdapterAnycastAddress
1217         FirstMulticastAddress *IpAdapterMulticastAddress
1218         FirstDnsServerAddress *IpAdapterDnsServerAdapter
1219         DnsSuffix             *uint16
1220         Description           *uint16
1221         FriendlyName          *uint16
1222         PhysicalAddress       [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
1223         PhysicalAddressLength uint32
1224         Flags                 uint32
1225         Mtu                   uint32
1226         IfType                uint32
1227         OperStatus            uint32
1228         Ipv6IfIndex           uint32
1229         ZoneIndices           [16]uint32
1230         FirstPrefix           *IpAdapterPrefix
1231         /* more fields might be present here. */
1232 }
1233
1234 const (
1235         IfOperStatusUp             = 1
1236         IfOperStatusDown           = 2
1237         IfOperStatusTesting        = 3
1238         IfOperStatusUnknown        = 4
1239         IfOperStatusDormant        = 5
1240         IfOperStatusNotPresent     = 6
1241         IfOperStatusLowerLayerDown = 7
1242 )