blob: 99b85f6dd611eab225ec3e668484755afa4b1c5b [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001// 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 (
8 "net"
9 "syscall"
10 "unsafe"
11)
12
13const (
14 // Invented values to support what package os expects.
15 O_RDONLY = 0x00000
16 O_WRONLY = 0x00001
17 O_RDWR = 0x00002
18 O_CREAT = 0x00040
19 O_EXCL = 0x00080
20 O_NOCTTY = 0x00100
21 O_TRUNC = 0x00200
22 O_NONBLOCK = 0x00800
23 O_APPEND = 0x00400
24 O_SYNC = 0x01000
25 O_ASYNC = 0x02000
26 O_CLOEXEC = 0x80000
27)
28
29const (
30 // More invented values for signals
31 SIGHUP = Signal(0x1)
32 SIGINT = Signal(0x2)
33 SIGQUIT = Signal(0x3)
34 SIGILL = Signal(0x4)
35 SIGTRAP = Signal(0x5)
36 SIGABRT = Signal(0x6)
37 SIGBUS = Signal(0x7)
38 SIGFPE = Signal(0x8)
39 SIGKILL = Signal(0x9)
40 SIGSEGV = Signal(0xb)
41 SIGPIPE = Signal(0xd)
42 SIGALRM = Signal(0xe)
43 SIGTERM = Signal(0xf)
44)
45
46var signals = [...]string{
47 1: "hangup",
48 2: "interrupt",
49 3: "quit",
50 4: "illegal instruction",
51 5: "trace/breakpoint trap",
52 6: "aborted",
53 7: "bus error",
54 8: "floating point exception",
55 9: "killed",
56 10: "user defined signal 1",
57 11: "segmentation fault",
58 12: "user defined signal 2",
59 13: "broken pipe",
60 14: "alarm clock",
61 15: "terminated",
62}
63
64const (
65 GENERIC_READ = 0x80000000
66 GENERIC_WRITE = 0x40000000
67 GENERIC_EXECUTE = 0x20000000
68 GENERIC_ALL = 0x10000000
69
70 FILE_LIST_DIRECTORY = 0x00000001
71 FILE_APPEND_DATA = 0x00000004
72 FILE_WRITE_ATTRIBUTES = 0x00000100
73
74 FILE_SHARE_READ = 0x00000001
75 FILE_SHARE_WRITE = 0x00000002
76 FILE_SHARE_DELETE = 0x00000004
77
78 FILE_ATTRIBUTE_READONLY = 0x00000001
79 FILE_ATTRIBUTE_HIDDEN = 0x00000002
80 FILE_ATTRIBUTE_SYSTEM = 0x00000004
81 FILE_ATTRIBUTE_DIRECTORY = 0x00000010
82 FILE_ATTRIBUTE_ARCHIVE = 0x00000020
83 FILE_ATTRIBUTE_DEVICE = 0x00000040
84 FILE_ATTRIBUTE_NORMAL = 0x00000080
85 FILE_ATTRIBUTE_TEMPORARY = 0x00000100
86 FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200
87 FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400
88 FILE_ATTRIBUTE_COMPRESSED = 0x00000800
89 FILE_ATTRIBUTE_OFFLINE = 0x00001000
90 FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000
91 FILE_ATTRIBUTE_ENCRYPTED = 0x00004000
92 FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00008000
93 FILE_ATTRIBUTE_VIRTUAL = 0x00010000
94 FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000
95 FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x00040000
96 FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000
97
98 INVALID_FILE_ATTRIBUTES = 0xffffffff
99
100 CREATE_NEW = 1
101 CREATE_ALWAYS = 2
102 OPEN_EXISTING = 3
103 OPEN_ALWAYS = 4
104 TRUNCATE_EXISTING = 5
105
106 FILE_FLAG_OPEN_REQUIRING_OPLOCK = 0x00040000
107 FILE_FLAG_FIRST_PIPE_INSTANCE = 0x00080000
108 FILE_FLAG_OPEN_NO_RECALL = 0x00100000
109 FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000
110 FILE_FLAG_SESSION_AWARE = 0x00800000
111 FILE_FLAG_POSIX_SEMANTICS = 0x01000000
112 FILE_FLAG_BACKUP_SEMANTICS = 0x02000000
113 FILE_FLAG_DELETE_ON_CLOSE = 0x04000000
114 FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000
115 FILE_FLAG_RANDOM_ACCESS = 0x10000000
116 FILE_FLAG_NO_BUFFERING = 0x20000000
117 FILE_FLAG_OVERLAPPED = 0x40000000
118 FILE_FLAG_WRITE_THROUGH = 0x80000000
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_ABANDONED = 0x00000080
158 WAIT_OBJECT_0 = 0x00000000
159 WAIT_FAILED = 0xFFFFFFFF
160
161 PROCESS_TERMINATE = 1
162 PROCESS_QUERY_INFORMATION = 0x00000400
163 SYNCHRONIZE = 0x00100000
164
165 FILE_MAP_COPY = 0x01
166 FILE_MAP_WRITE = 0x02
167 FILE_MAP_READ = 0x04
168 FILE_MAP_EXECUTE = 0x20
169
170 CTRL_C_EVENT = 0
171 CTRL_BREAK_EVENT = 1
172
173 // Windows reserves errors >= 1<<29 for application use.
174 APPLICATION_ERROR = 1 << 29
175)
176
177const (
178 // Process creation flags.
179 CREATE_BREAKAWAY_FROM_JOB = 0x01000000
180 CREATE_DEFAULT_ERROR_MODE = 0x04000000
181 CREATE_NEW_CONSOLE = 0x00000010
182 CREATE_NEW_PROCESS_GROUP = 0x00000200
183 CREATE_NO_WINDOW = 0x08000000
184 CREATE_PROTECTED_PROCESS = 0x00040000
185 CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000
186 CREATE_SEPARATE_WOW_VDM = 0x00000800
187 CREATE_SHARED_WOW_VDM = 0x00001000
188 CREATE_SUSPENDED = 0x00000004
189 CREATE_UNICODE_ENVIRONMENT = 0x00000400
190 DEBUG_ONLY_THIS_PROCESS = 0x00000002
191 DEBUG_PROCESS = 0x00000001
192 DETACHED_PROCESS = 0x00000008
193 EXTENDED_STARTUPINFO_PRESENT = 0x00080000
194 INHERIT_PARENT_AFFINITY = 0x00010000
195)
196
197const (
198 // flags for CreateToolhelp32Snapshot
199 TH32CS_SNAPHEAPLIST = 0x01
200 TH32CS_SNAPPROCESS = 0x02
201 TH32CS_SNAPTHREAD = 0x04
202 TH32CS_SNAPMODULE = 0x08
203 TH32CS_SNAPMODULE32 = 0x10
204 TH32CS_SNAPALL = TH32CS_SNAPHEAPLIST | TH32CS_SNAPMODULE | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD
205 TH32CS_INHERIT = 0x80000000
206)
207
208const (
209 // filters for ReadDirectoryChangesW
210 FILE_NOTIFY_CHANGE_FILE_NAME = 0x001
211 FILE_NOTIFY_CHANGE_DIR_NAME = 0x002
212 FILE_NOTIFY_CHANGE_ATTRIBUTES = 0x004
213 FILE_NOTIFY_CHANGE_SIZE = 0x008
214 FILE_NOTIFY_CHANGE_LAST_WRITE = 0x010
215 FILE_NOTIFY_CHANGE_LAST_ACCESS = 0x020
216 FILE_NOTIFY_CHANGE_CREATION = 0x040
217 FILE_NOTIFY_CHANGE_SECURITY = 0x100
218)
219
220const (
221 // do not reorder
222 FILE_ACTION_ADDED = iota + 1
223 FILE_ACTION_REMOVED
224 FILE_ACTION_MODIFIED
225 FILE_ACTION_RENAMED_OLD_NAME
226 FILE_ACTION_RENAMED_NEW_NAME
227)
228
229const (
230 // wincrypt.h
231 PROV_RSA_FULL = 1
232 PROV_RSA_SIG = 2
233 PROV_DSS = 3
234 PROV_FORTEZZA = 4
235 PROV_MS_EXCHANGE = 5
236 PROV_SSL = 6
237 PROV_RSA_SCHANNEL = 12
238 PROV_DSS_DH = 13
239 PROV_EC_ECDSA_SIG = 14
240 PROV_EC_ECNRA_SIG = 15
241 PROV_EC_ECDSA_FULL = 16
242 PROV_EC_ECNRA_FULL = 17
243 PROV_DH_SCHANNEL = 18
244 PROV_SPYRUS_LYNKS = 20
245 PROV_RNG = 21
246 PROV_INTEL_SEC = 22
247 PROV_REPLACE_OWF = 23
248 PROV_RSA_AES = 24
249 CRYPT_VERIFYCONTEXT = 0xF0000000
250 CRYPT_NEWKEYSET = 0x00000008
251 CRYPT_DELETEKEYSET = 0x00000010
252 CRYPT_MACHINE_KEYSET = 0x00000020
253 CRYPT_SILENT = 0x00000040
254 CRYPT_DEFAULT_CONTAINER_OPTIONAL = 0x00000080
255
256 USAGE_MATCH_TYPE_AND = 0
257 USAGE_MATCH_TYPE_OR = 1
258
259 /* msgAndCertEncodingType values for CertOpenStore function */
260 X509_ASN_ENCODING = 0x00000001
261 PKCS_7_ASN_ENCODING = 0x00010000
262
263 /* storeProvider values for CertOpenStore function */
264 CERT_STORE_PROV_MSG = 1
265 CERT_STORE_PROV_MEMORY = 2
266 CERT_STORE_PROV_FILE = 3
267 CERT_STORE_PROV_REG = 4
268 CERT_STORE_PROV_PKCS7 = 5
269 CERT_STORE_PROV_SERIALIZED = 6
270 CERT_STORE_PROV_FILENAME_A = 7
271 CERT_STORE_PROV_FILENAME_W = 8
272 CERT_STORE_PROV_FILENAME = CERT_STORE_PROV_FILENAME_W
273 CERT_STORE_PROV_SYSTEM_A = 9
274 CERT_STORE_PROV_SYSTEM_W = 10
275 CERT_STORE_PROV_SYSTEM = CERT_STORE_PROV_SYSTEM_W
276 CERT_STORE_PROV_COLLECTION = 11
277 CERT_STORE_PROV_SYSTEM_REGISTRY_A = 12
278 CERT_STORE_PROV_SYSTEM_REGISTRY_W = 13
279 CERT_STORE_PROV_SYSTEM_REGISTRY = CERT_STORE_PROV_SYSTEM_REGISTRY_W
280 CERT_STORE_PROV_PHYSICAL_W = 14
281 CERT_STORE_PROV_PHYSICAL = CERT_STORE_PROV_PHYSICAL_W
282 CERT_STORE_PROV_SMART_CARD_W = 15
283 CERT_STORE_PROV_SMART_CARD = CERT_STORE_PROV_SMART_CARD_W
284 CERT_STORE_PROV_LDAP_W = 16
285 CERT_STORE_PROV_LDAP = CERT_STORE_PROV_LDAP_W
286 CERT_STORE_PROV_PKCS12 = 17
287
288 /* store characteristics (low WORD of flag) for CertOpenStore function */
289 CERT_STORE_NO_CRYPT_RELEASE_FLAG = 0x00000001
290 CERT_STORE_SET_LOCALIZED_NAME_FLAG = 0x00000002
291 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004
292 CERT_STORE_DELETE_FLAG = 0x00000010
293 CERT_STORE_UNSAFE_PHYSICAL_FLAG = 0x00000020
294 CERT_STORE_SHARE_STORE_FLAG = 0x00000040
295 CERT_STORE_SHARE_CONTEXT_FLAG = 0x00000080
296 CERT_STORE_MANIFOLD_FLAG = 0x00000100
297 CERT_STORE_ENUM_ARCHIVED_FLAG = 0x00000200
298 CERT_STORE_UPDATE_KEYID_FLAG = 0x00000400
299 CERT_STORE_BACKUP_RESTORE_FLAG = 0x00000800
300 CERT_STORE_MAXIMUM_ALLOWED_FLAG = 0x00001000
301 CERT_STORE_CREATE_NEW_FLAG = 0x00002000
302 CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000
303 CERT_STORE_READONLY_FLAG = 0x00008000
304
305 /* store locations (high WORD of flag) for CertOpenStore function */
306 CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000
307 CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000
308 CERT_SYSTEM_STORE_CURRENT_SERVICE = 0x00040000
309 CERT_SYSTEM_STORE_SERVICES = 0x00050000
310 CERT_SYSTEM_STORE_USERS = 0x00060000
311 CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY = 0x00070000
312 CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 0x00080000
313 CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = 0x00090000
314 CERT_SYSTEM_STORE_UNPROTECTED_FLAG = 0x40000000
315 CERT_SYSTEM_STORE_RELOCATE_FLAG = 0x80000000
316
317 /* Miscellaneous high-WORD flags for CertOpenStore function */
318 CERT_REGISTRY_STORE_REMOTE_FLAG = 0x00010000
319 CERT_REGISTRY_STORE_SERIALIZED_FLAG = 0x00020000
320 CERT_REGISTRY_STORE_ROAMING_FLAG = 0x00040000
321 CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = 0x00080000
322 CERT_REGISTRY_STORE_LM_GPT_FLAG = 0x01000000
323 CERT_REGISTRY_STORE_CLIENT_GPT_FLAG = 0x80000000
324 CERT_FILE_STORE_COMMIT_ENABLE_FLAG = 0x00010000
325 CERT_LDAP_STORE_SIGN_FLAG = 0x00010000
326 CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG = 0x00020000
327 CERT_LDAP_STORE_OPENED_FLAG = 0x00040000
328 CERT_LDAP_STORE_UNBIND_FLAG = 0x00080000
329
330 /* addDisposition values for CertAddCertificateContextToStore function */
331 CERT_STORE_ADD_NEW = 1
332 CERT_STORE_ADD_USE_EXISTING = 2
333 CERT_STORE_ADD_REPLACE_EXISTING = 3
334 CERT_STORE_ADD_ALWAYS = 4
335 CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES = 5
336 CERT_STORE_ADD_NEWER = 6
337 CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES = 7
338
339 /* ErrorStatus values for CertTrustStatus struct */
340 CERT_TRUST_NO_ERROR = 0x00000000
341 CERT_TRUST_IS_NOT_TIME_VALID = 0x00000001
342 CERT_TRUST_IS_REVOKED = 0x00000004
343 CERT_TRUST_IS_NOT_SIGNATURE_VALID = 0x00000008
344 CERT_TRUST_IS_NOT_VALID_FOR_USAGE = 0x00000010
345 CERT_TRUST_IS_UNTRUSTED_ROOT = 0x00000020
346 CERT_TRUST_REVOCATION_STATUS_UNKNOWN = 0x00000040
347 CERT_TRUST_IS_CYCLIC = 0x00000080
348 CERT_TRUST_INVALID_EXTENSION = 0x00000100
349 CERT_TRUST_INVALID_POLICY_CONSTRAINTS = 0x00000200
350 CERT_TRUST_INVALID_BASIC_CONSTRAINTS = 0x00000400
351 CERT_TRUST_INVALID_NAME_CONSTRAINTS = 0x00000800
352 CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT = 0x00001000
353 CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 0x00002000
354 CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000
355 CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 0x00008000
356 CERT_TRUST_IS_PARTIAL_CHAIN = 0x00010000
357 CERT_TRUST_CTL_IS_NOT_TIME_VALID = 0x00020000
358 CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID = 0x00040000
359 CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 0x00080000
360 CERT_TRUST_HAS_WEAK_SIGNATURE = 0x00100000
361 CERT_TRUST_IS_OFFLINE_REVOCATION = 0x01000000
362 CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 0x02000000
363 CERT_TRUST_IS_EXPLICIT_DISTRUST = 0x04000000
364 CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 0x08000000
365
366 /* InfoStatus values for CertTrustStatus struct */
367 CERT_TRUST_HAS_EXACT_MATCH_ISSUER = 0x00000001
368 CERT_TRUST_HAS_KEY_MATCH_ISSUER = 0x00000002
369 CERT_TRUST_HAS_NAME_MATCH_ISSUER = 0x00000004
370 CERT_TRUST_IS_SELF_SIGNED = 0x00000008
371 CERT_TRUST_HAS_PREFERRED_ISSUER = 0x00000100
372 CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY = 0x00000400
373 CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS = 0x00000400
374 CERT_TRUST_IS_PEER_TRUSTED = 0x00000800
375 CERT_TRUST_HAS_CRL_VALIDITY_EXTENDED = 0x00001000
376 CERT_TRUST_IS_FROM_EXCLUSIVE_TRUST_STORE = 0x00002000
377 CERT_TRUST_IS_CA_TRUSTED = 0x00004000
378 CERT_TRUST_IS_COMPLEX_CHAIN = 0x00010000
379
380 /* policyOID values for CertVerifyCertificateChainPolicy function */
381 CERT_CHAIN_POLICY_BASE = 1
382 CERT_CHAIN_POLICY_AUTHENTICODE = 2
383 CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3
384 CERT_CHAIN_POLICY_SSL = 4
385 CERT_CHAIN_POLICY_BASIC_CONSTRAINTS = 5
386 CERT_CHAIN_POLICY_NT_AUTH = 6
387 CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7
388 CERT_CHAIN_POLICY_EV = 8
389 CERT_CHAIN_POLICY_SSL_F12 = 9
390
391 /* AuthType values for SSLExtraCertChainPolicyPara struct */
392 AUTHTYPE_CLIENT = 1
393 AUTHTYPE_SERVER = 2
394
395 /* Checks values for SSLExtraCertChainPolicyPara struct */
396 SECURITY_FLAG_IGNORE_REVOCATION = 0x00000080
397 SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100
398 SECURITY_FLAG_IGNORE_WRONG_USAGE = 0x00000200
399 SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000
400 SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000
401)
402
403const (
404 // flags for SetErrorMode
405 SEM_FAILCRITICALERRORS = 0x0001
406 SEM_NOALIGNMENTFAULTEXCEPT = 0x0004
407 SEM_NOGPFAULTERRORBOX = 0x0002
408 SEM_NOOPENFILEERRORBOX = 0x8000
409)
410
411const (
412 // Priority class.
413 ABOVE_NORMAL_PRIORITY_CLASS = 0x00008000
414 BELOW_NORMAL_PRIORITY_CLASS = 0x00004000
415 HIGH_PRIORITY_CLASS = 0x00000080
416 IDLE_PRIORITY_CLASS = 0x00000040
417 NORMAL_PRIORITY_CLASS = 0x00000020
418 PROCESS_MODE_BACKGROUND_BEGIN = 0x00100000
419 PROCESS_MODE_BACKGROUND_END = 0x00200000
420 REALTIME_PRIORITY_CLASS = 0x00000100
421)
422
423var (
424 OID_PKIX_KP_SERVER_AUTH = []byte("1.3.6.1.5.5.7.3.1\x00")
425 OID_SERVER_GATED_CRYPTO = []byte("1.3.6.1.4.1.311.10.3.3\x00")
426 OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00")
427)
428
429// Pointer represents a pointer to an arbitrary Windows type.
430//
431// Pointer-typed fields may point to one of many different types. It's
432// up to the caller to provide a pointer to the appropriate type, cast
433// to Pointer. The caller must obey the unsafe.Pointer rules while
434// doing so.
435type Pointer *struct{}
436
437// Invented values to support what package os expects.
438type Timeval struct {
439 Sec int32
440 Usec int32
441}
442
443func (tv *Timeval) Nanoseconds() int64 {
444 return (int64(tv.Sec)*1e6 + int64(tv.Usec)) * 1e3
445}
446
447func NsecToTimeval(nsec int64) (tv Timeval) {
448 tv.Sec = int32(nsec / 1e9)
449 tv.Usec = int32(nsec % 1e9 / 1e3)
450 return
451}
452
453type SecurityAttributes struct {
454 Length uint32
455 SecurityDescriptor uintptr
456 InheritHandle uint32
457}
458
459type Overlapped struct {
460 Internal uintptr
461 InternalHigh uintptr
462 Offset uint32
463 OffsetHigh uint32
464 HEvent Handle
465}
466
467type FileNotifyInformation struct {
468 NextEntryOffset uint32
469 Action uint32
470 FileNameLength uint32
471 FileName uint16
472}
473
474type Filetime struct {
475 LowDateTime uint32
476 HighDateTime uint32
477}
478
479// Nanoseconds returns Filetime ft in nanoseconds
480// since Epoch (00:00:00 UTC, January 1, 1970).
481func (ft *Filetime) Nanoseconds() int64 {
482 // 100-nanosecond intervals since January 1, 1601
483 nsec := int64(ft.HighDateTime)<<32 + int64(ft.LowDateTime)
484 // change starting time to the Epoch (00:00:00 UTC, January 1, 1970)
485 nsec -= 116444736000000000
486 // convert into nanoseconds
487 nsec *= 100
488 return nsec
489}
490
491func NsecToFiletime(nsec int64) (ft Filetime) {
492 // convert into 100-nanosecond
493 nsec /= 100
494 // change starting time to January 1, 1601
495 nsec += 116444736000000000
496 // split into high / low
497 ft.LowDateTime = uint32(nsec & 0xffffffff)
498 ft.HighDateTime = uint32(nsec >> 32 & 0xffffffff)
499 return ft
500}
501
502type Win32finddata struct {
503 FileAttributes uint32
504 CreationTime Filetime
505 LastAccessTime Filetime
506 LastWriteTime Filetime
507 FileSizeHigh uint32
508 FileSizeLow uint32
509 Reserved0 uint32
510 Reserved1 uint32
511 FileName [MAX_PATH - 1]uint16
512 AlternateFileName [13]uint16
513}
514
515// This is the actual system call structure.
516// Win32finddata is what we committed to in Go 1.
517type win32finddata1 struct {
518 FileAttributes uint32
519 CreationTime Filetime
520 LastAccessTime Filetime
521 LastWriteTime Filetime
522 FileSizeHigh uint32
523 FileSizeLow uint32
524 Reserved0 uint32
525 Reserved1 uint32
526 FileName [MAX_PATH]uint16
527 AlternateFileName [14]uint16
528}
529
530func copyFindData(dst *Win32finddata, src *win32finddata1) {
531 dst.FileAttributes = src.FileAttributes
532 dst.CreationTime = src.CreationTime
533 dst.LastAccessTime = src.LastAccessTime
534 dst.LastWriteTime = src.LastWriteTime
535 dst.FileSizeHigh = src.FileSizeHigh
536 dst.FileSizeLow = src.FileSizeLow
537 dst.Reserved0 = src.Reserved0
538 dst.Reserved1 = src.Reserved1
539
540 // The src is 1 element bigger than dst, but it must be NUL.
541 copy(dst.FileName[:], src.FileName[:])
542 copy(dst.AlternateFileName[:], src.AlternateFileName[:])
543}
544
545type ByHandleFileInformation struct {
546 FileAttributes uint32
547 CreationTime Filetime
548 LastAccessTime Filetime
549 LastWriteTime Filetime
550 VolumeSerialNumber uint32
551 FileSizeHigh uint32
552 FileSizeLow uint32
553 NumberOfLinks uint32
554 FileIndexHigh uint32
555 FileIndexLow uint32
556}
557
558const (
559 GetFileExInfoStandard = 0
560 GetFileExMaxInfoLevel = 1
561)
562
563type Win32FileAttributeData struct {
564 FileAttributes uint32
565 CreationTime Filetime
566 LastAccessTime Filetime
567 LastWriteTime Filetime
568 FileSizeHigh uint32
569 FileSizeLow uint32
570}
571
572// ShowWindow constants
573const (
574 // winuser.h
575 SW_HIDE = 0
576 SW_NORMAL = 1
577 SW_SHOWNORMAL = 1
578 SW_SHOWMINIMIZED = 2
579 SW_SHOWMAXIMIZED = 3
580 SW_MAXIMIZE = 3
581 SW_SHOWNOACTIVATE = 4
582 SW_SHOW = 5
583 SW_MINIMIZE = 6
584 SW_SHOWMINNOACTIVE = 7
585 SW_SHOWNA = 8
586 SW_RESTORE = 9
587 SW_SHOWDEFAULT = 10
588 SW_FORCEMINIMIZE = 11
589)
590
591type StartupInfo struct {
592 Cb uint32
593 _ *uint16
594 Desktop *uint16
595 Title *uint16
596 X uint32
597 Y uint32
598 XSize uint32
599 YSize uint32
600 XCountChars uint32
601 YCountChars uint32
602 FillAttribute uint32
603 Flags uint32
604 ShowWindow uint16
605 _ uint16
606 _ *byte
607 StdInput Handle
608 StdOutput Handle
609 StdErr Handle
610}
611
612type ProcessInformation struct {
613 Process Handle
614 Thread Handle
615 ProcessId uint32
616 ThreadId uint32
617}
618
619type ProcessEntry32 struct {
620 Size uint32
621 Usage uint32
622 ProcessID uint32
623 DefaultHeapID uintptr
624 ModuleID uint32
625 Threads uint32
626 ParentProcessID uint32
627 PriClassBase int32
628 Flags uint32
629 ExeFile [MAX_PATH]uint16
630}
631
632type Systemtime struct {
633 Year uint16
634 Month uint16
635 DayOfWeek uint16
636 Day uint16
637 Hour uint16
638 Minute uint16
639 Second uint16
640 Milliseconds uint16
641}
642
643type Timezoneinformation struct {
644 Bias int32
645 StandardName [32]uint16
646 StandardDate Systemtime
647 StandardBias int32
648 DaylightName [32]uint16
649 DaylightDate Systemtime
650 DaylightBias int32
651}
652
653// Socket related.
654
655const (
656 AF_UNSPEC = 0
657 AF_UNIX = 1
658 AF_INET = 2
659 AF_INET6 = 23
660 AF_NETBIOS = 17
661
662 SOCK_STREAM = 1
663 SOCK_DGRAM = 2
664 SOCK_RAW = 3
665 SOCK_SEQPACKET = 5
666
667 IPPROTO_IP = 0
668 IPPROTO_IPV6 = 0x29
669 IPPROTO_TCP = 6
670 IPPROTO_UDP = 17
671
672 SOL_SOCKET = 0xffff
673 SO_REUSEADDR = 4
674 SO_KEEPALIVE = 8
675 SO_DONTROUTE = 16
676 SO_BROADCAST = 32
677 SO_LINGER = 128
678 SO_RCVBUF = 0x1002
679 SO_SNDBUF = 0x1001
680 SO_UPDATE_ACCEPT_CONTEXT = 0x700b
681 SO_UPDATE_CONNECT_CONTEXT = 0x7010
682
683 IOC_OUT = 0x40000000
684 IOC_IN = 0x80000000
685 IOC_VENDOR = 0x18000000
686 IOC_INOUT = IOC_IN | IOC_OUT
687 IOC_WS2 = 0x08000000
688 SIO_GET_EXTENSION_FUNCTION_POINTER = IOC_INOUT | IOC_WS2 | 6
689 SIO_KEEPALIVE_VALS = IOC_IN | IOC_VENDOR | 4
690 SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12
691
692 // cf. http://support.microsoft.com/default.aspx?scid=kb;en-us;257460
693
694 IP_TOS = 0x3
695 IP_TTL = 0x4
696 IP_MULTICAST_IF = 0x9
697 IP_MULTICAST_TTL = 0xa
698 IP_MULTICAST_LOOP = 0xb
699 IP_ADD_MEMBERSHIP = 0xc
700 IP_DROP_MEMBERSHIP = 0xd
701
702 IPV6_V6ONLY = 0x1b
703 IPV6_UNICAST_HOPS = 0x4
704 IPV6_MULTICAST_IF = 0x9
705 IPV6_MULTICAST_HOPS = 0xa
706 IPV6_MULTICAST_LOOP = 0xb
707 IPV6_JOIN_GROUP = 0xc
708 IPV6_LEAVE_GROUP = 0xd
709
710 MSG_OOB = 0x1
711 MSG_PEEK = 0x2
712 MSG_DONTROUTE = 0x4
713 MSG_WAITALL = 0x8
714
715 MSG_TRUNC = 0x0100
716 MSG_CTRUNC = 0x0200
717 MSG_BCAST = 0x0400
718 MSG_MCAST = 0x0800
719
720 SOMAXCONN = 0x7fffffff
721
722 TCP_NODELAY = 1
723
724 SHUT_RD = 0
725 SHUT_WR = 1
726 SHUT_RDWR = 2
727
728 WSADESCRIPTION_LEN = 256
729 WSASYS_STATUS_LEN = 128
730)
731
732type WSABuf struct {
733 Len uint32
734 Buf *byte
735}
736
737type WSAMsg struct {
738 Name *syscall.RawSockaddrAny
739 Namelen int32
740 Buffers *WSABuf
741 BufferCount uint32
742 Control WSABuf
743 Flags uint32
744}
745
746// Invented values to support what package os expects.
747const (
748 S_IFMT = 0x1f000
749 S_IFIFO = 0x1000
750 S_IFCHR = 0x2000
751 S_IFDIR = 0x4000
752 S_IFBLK = 0x6000
753 S_IFREG = 0x8000
754 S_IFLNK = 0xa000
755 S_IFSOCK = 0xc000
756 S_ISUID = 0x800
757 S_ISGID = 0x400
758 S_ISVTX = 0x200
759 S_IRUSR = 0x100
760 S_IWRITE = 0x80
761 S_IWUSR = 0x80
762 S_IXUSR = 0x40
763)
764
765const (
766 FILE_TYPE_CHAR = 0x0002
767 FILE_TYPE_DISK = 0x0001
768 FILE_TYPE_PIPE = 0x0003
769 FILE_TYPE_REMOTE = 0x8000
770 FILE_TYPE_UNKNOWN = 0x0000
771)
772
773type Hostent struct {
774 Name *byte
775 Aliases **byte
776 AddrType uint16
777 Length uint16
778 AddrList **byte
779}
780
781type Protoent struct {
782 Name *byte
783 Aliases **byte
784 Proto uint16
785}
786
787const (
788 DNS_TYPE_A = 0x0001
789 DNS_TYPE_NS = 0x0002
790 DNS_TYPE_MD = 0x0003
791 DNS_TYPE_MF = 0x0004
792 DNS_TYPE_CNAME = 0x0005
793 DNS_TYPE_SOA = 0x0006
794 DNS_TYPE_MB = 0x0007
795 DNS_TYPE_MG = 0x0008
796 DNS_TYPE_MR = 0x0009
797 DNS_TYPE_NULL = 0x000a
798 DNS_TYPE_WKS = 0x000b
799 DNS_TYPE_PTR = 0x000c
800 DNS_TYPE_HINFO = 0x000d
801 DNS_TYPE_MINFO = 0x000e
802 DNS_TYPE_MX = 0x000f
803 DNS_TYPE_TEXT = 0x0010
804 DNS_TYPE_RP = 0x0011
805 DNS_TYPE_AFSDB = 0x0012
806 DNS_TYPE_X25 = 0x0013
807 DNS_TYPE_ISDN = 0x0014
808 DNS_TYPE_RT = 0x0015
809 DNS_TYPE_NSAP = 0x0016
810 DNS_TYPE_NSAPPTR = 0x0017
811 DNS_TYPE_SIG = 0x0018
812 DNS_TYPE_KEY = 0x0019
813 DNS_TYPE_PX = 0x001a
814 DNS_TYPE_GPOS = 0x001b
815 DNS_TYPE_AAAA = 0x001c
816 DNS_TYPE_LOC = 0x001d
817 DNS_TYPE_NXT = 0x001e
818 DNS_TYPE_EID = 0x001f
819 DNS_TYPE_NIMLOC = 0x0020
820 DNS_TYPE_SRV = 0x0021
821 DNS_TYPE_ATMA = 0x0022
822 DNS_TYPE_NAPTR = 0x0023
823 DNS_TYPE_KX = 0x0024
824 DNS_TYPE_CERT = 0x0025
825 DNS_TYPE_A6 = 0x0026
826 DNS_TYPE_DNAME = 0x0027
827 DNS_TYPE_SINK = 0x0028
828 DNS_TYPE_OPT = 0x0029
829 DNS_TYPE_DS = 0x002B
830 DNS_TYPE_RRSIG = 0x002E
831 DNS_TYPE_NSEC = 0x002F
832 DNS_TYPE_DNSKEY = 0x0030
833 DNS_TYPE_DHCID = 0x0031
834 DNS_TYPE_UINFO = 0x0064
835 DNS_TYPE_UID = 0x0065
836 DNS_TYPE_GID = 0x0066
837 DNS_TYPE_UNSPEC = 0x0067
838 DNS_TYPE_ADDRS = 0x00f8
839 DNS_TYPE_TKEY = 0x00f9
840 DNS_TYPE_TSIG = 0x00fa
841 DNS_TYPE_IXFR = 0x00fb
842 DNS_TYPE_AXFR = 0x00fc
843 DNS_TYPE_MAILB = 0x00fd
844 DNS_TYPE_MAILA = 0x00fe
845 DNS_TYPE_ALL = 0x00ff
846 DNS_TYPE_ANY = 0x00ff
847 DNS_TYPE_WINS = 0xff01
848 DNS_TYPE_WINSR = 0xff02
849 DNS_TYPE_NBSTAT = 0xff01
850)
851
852const (
853 // flags inside DNSRecord.Dw
854 DnsSectionQuestion = 0x0000
855 DnsSectionAnswer = 0x0001
856 DnsSectionAuthority = 0x0002
857 DnsSectionAdditional = 0x0003
858)
859
860type DNSSRVData struct {
861 Target *uint16
862 Priority uint16
863 Weight uint16
864 Port uint16
865 Pad uint16
866}
867
868type DNSPTRData struct {
869 Host *uint16
870}
871
872type DNSMXData struct {
873 NameExchange *uint16
874 Preference uint16
875 Pad uint16
876}
877
878type DNSTXTData struct {
879 StringCount uint16
880 StringArray [1]*uint16
881}
882
883type DNSRecord struct {
884 Next *DNSRecord
885 Name *uint16
886 Type uint16
887 Length uint16
888 Dw uint32
889 Ttl uint32
890 Reserved uint32
891 Data [40]byte
892}
893
894const (
895 TF_DISCONNECT = 1
896 TF_REUSE_SOCKET = 2
897 TF_WRITE_BEHIND = 4
898 TF_USE_DEFAULT_WORKER = 0
899 TF_USE_SYSTEM_THREAD = 16
900 TF_USE_KERNEL_APC = 32
901)
902
903type TransmitFileBuffers struct {
904 Head uintptr
905 HeadLength uint32
906 Tail uintptr
907 TailLength uint32
908}
909
910const (
911 IFF_UP = 1
912 IFF_BROADCAST = 2
913 IFF_LOOPBACK = 4
914 IFF_POINTTOPOINT = 8
915 IFF_MULTICAST = 16
916)
917
918const SIO_GET_INTERFACE_LIST = 0x4004747F
919
920// TODO(mattn): SockaddrGen is union of sockaddr/sockaddr_in/sockaddr_in6_old.
921// will be fixed to change variable type as suitable.
922
923type SockaddrGen [24]byte
924
925type InterfaceInfo struct {
926 Flags uint32
927 Address SockaddrGen
928 BroadcastAddress SockaddrGen
929 Netmask SockaddrGen
930}
931
932type IpAddressString struct {
933 String [16]byte
934}
935
936type IpMaskString IpAddressString
937
938type IpAddrString struct {
939 Next *IpAddrString
940 IpAddress IpAddressString
941 IpMask IpMaskString
942 Context uint32
943}
944
945const MAX_ADAPTER_NAME_LENGTH = 256
946const MAX_ADAPTER_DESCRIPTION_LENGTH = 128
947const MAX_ADAPTER_ADDRESS_LENGTH = 8
948
949type IpAdapterInfo struct {
950 Next *IpAdapterInfo
951 ComboIndex uint32
952 AdapterName [MAX_ADAPTER_NAME_LENGTH + 4]byte
953 Description [MAX_ADAPTER_DESCRIPTION_LENGTH + 4]byte
954 AddressLength uint32
955 Address [MAX_ADAPTER_ADDRESS_LENGTH]byte
956 Index uint32
957 Type uint32
958 DhcpEnabled uint32
959 CurrentIpAddress *IpAddrString
960 IpAddressList IpAddrString
961 GatewayList IpAddrString
962 DhcpServer IpAddrString
963 HaveWins bool
964 PrimaryWinsServer IpAddrString
965 SecondaryWinsServer IpAddrString
966 LeaseObtained int64
967 LeaseExpires int64
968}
969
970const MAXLEN_PHYSADDR = 8
971const MAX_INTERFACE_NAME_LEN = 256
972const MAXLEN_IFDESCR = 256
973
974type MibIfRow struct {
975 Name [MAX_INTERFACE_NAME_LEN]uint16
976 Index uint32
977 Type uint32
978 Mtu uint32
979 Speed uint32
980 PhysAddrLen uint32
981 PhysAddr [MAXLEN_PHYSADDR]byte
982 AdminStatus uint32
983 OperStatus uint32
984 LastChange uint32
985 InOctets uint32
986 InUcastPkts uint32
987 InNUcastPkts uint32
988 InDiscards uint32
989 InErrors uint32
990 InUnknownProtos uint32
991 OutOctets uint32
992 OutUcastPkts uint32
993 OutNUcastPkts uint32
994 OutDiscards uint32
995 OutErrors uint32
996 OutQLen uint32
997 DescrLen uint32
998 Descr [MAXLEN_IFDESCR]byte
999}
1000
1001type CertInfo struct {
1002 // Not implemented
1003}
1004
1005type CertContext struct {
1006 EncodingType uint32
1007 EncodedCert *byte
1008 Length uint32
1009 CertInfo *CertInfo
1010 Store Handle
1011}
1012
1013type CertChainContext struct {
1014 Size uint32
1015 TrustStatus CertTrustStatus
1016 ChainCount uint32
1017 Chains **CertSimpleChain
1018 LowerQualityChainCount uint32
1019 LowerQualityChains **CertChainContext
1020 HasRevocationFreshnessTime uint32
1021 RevocationFreshnessTime uint32
1022}
1023
1024type CertTrustListInfo struct {
1025 // Not implemented
1026}
1027
1028type CertSimpleChain struct {
1029 Size uint32
1030 TrustStatus CertTrustStatus
1031 NumElements uint32
1032 Elements **CertChainElement
1033 TrustListInfo *CertTrustListInfo
1034 HasRevocationFreshnessTime uint32
1035 RevocationFreshnessTime uint32
1036}
1037
1038type CertChainElement struct {
1039 Size uint32
1040 CertContext *CertContext
1041 TrustStatus CertTrustStatus
1042 RevocationInfo *CertRevocationInfo
1043 IssuanceUsage *CertEnhKeyUsage
1044 ApplicationUsage *CertEnhKeyUsage
1045 ExtendedErrorInfo *uint16
1046}
1047
1048type CertRevocationCrlInfo struct {
1049 // Not implemented
1050}
1051
1052type CertRevocationInfo struct {
1053 Size uint32
1054 RevocationResult uint32
1055 RevocationOid *byte
1056 OidSpecificInfo Pointer
1057 HasFreshnessTime uint32
1058 FreshnessTime uint32
1059 CrlInfo *CertRevocationCrlInfo
1060}
1061
1062type CertTrustStatus struct {
1063 ErrorStatus uint32
1064 InfoStatus uint32
1065}
1066
1067type CertUsageMatch struct {
1068 Type uint32
1069 Usage CertEnhKeyUsage
1070}
1071
1072type CertEnhKeyUsage struct {
1073 Length uint32
1074 UsageIdentifiers **byte
1075}
1076
1077type CertChainPara struct {
1078 Size uint32
1079 RequestedUsage CertUsageMatch
1080 RequstedIssuancePolicy CertUsageMatch
1081 URLRetrievalTimeout uint32
1082 CheckRevocationFreshnessTime uint32
1083 RevocationFreshnessTime uint32
1084 CacheResync *Filetime
1085}
1086
1087type CertChainPolicyPara struct {
1088 Size uint32
1089 Flags uint32
1090 ExtraPolicyPara Pointer
1091}
1092
1093type SSLExtraCertChainPolicyPara struct {
1094 Size uint32
1095 AuthType uint32
1096 Checks uint32
1097 ServerName *uint16
1098}
1099
1100type CertChainPolicyStatus struct {
1101 Size uint32
1102 Error uint32
1103 ChainIndex uint32
1104 ElementIndex uint32
1105 ExtraPolicyStatus Pointer
1106}
1107
1108const (
1109 // do not reorder
1110 HKEY_CLASSES_ROOT = 0x80000000 + iota
1111 HKEY_CURRENT_USER
1112 HKEY_LOCAL_MACHINE
1113 HKEY_USERS
1114 HKEY_PERFORMANCE_DATA
1115 HKEY_CURRENT_CONFIG
1116 HKEY_DYN_DATA
1117
1118 KEY_QUERY_VALUE = 1
1119 KEY_SET_VALUE = 2
1120 KEY_CREATE_SUB_KEY = 4
1121 KEY_ENUMERATE_SUB_KEYS = 8
1122 KEY_NOTIFY = 16
1123 KEY_CREATE_LINK = 32
1124 KEY_WRITE = 0x20006
1125 KEY_EXECUTE = 0x20019
1126 KEY_READ = 0x20019
1127 KEY_WOW64_64KEY = 0x0100
1128 KEY_WOW64_32KEY = 0x0200
1129 KEY_ALL_ACCESS = 0xf003f
1130)
1131
1132const (
1133 // do not reorder
1134 REG_NONE = iota
1135 REG_SZ
1136 REG_EXPAND_SZ
1137 REG_BINARY
1138 REG_DWORD_LITTLE_ENDIAN
1139 REG_DWORD_BIG_ENDIAN
1140 REG_LINK
1141 REG_MULTI_SZ
1142 REG_RESOURCE_LIST
1143 REG_FULL_RESOURCE_DESCRIPTOR
1144 REG_RESOURCE_REQUIREMENTS_LIST
1145 REG_QWORD_LITTLE_ENDIAN
1146 REG_DWORD = REG_DWORD_LITTLE_ENDIAN
1147 REG_QWORD = REG_QWORD_LITTLE_ENDIAN
1148)
1149
1150type AddrinfoW struct {
1151 Flags int32
1152 Family int32
1153 Socktype int32
1154 Protocol int32
1155 Addrlen uintptr
1156 Canonname *uint16
1157 Addr uintptr
1158 Next *AddrinfoW
1159}
1160
1161const (
1162 AI_PASSIVE = 1
1163 AI_CANONNAME = 2
1164 AI_NUMERICHOST = 4
1165)
1166
1167type GUID struct {
1168 Data1 uint32
1169 Data2 uint16
1170 Data3 uint16
1171 Data4 [8]byte
1172}
1173
1174var WSAID_CONNECTEX = GUID{
1175 0x25a207b9,
1176 0xddf3,
1177 0x4660,
1178 [8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e},
1179}
1180
1181var WSAID_WSASENDMSG = GUID{
1182 0xa441e712,
1183 0x754f,
1184 0x43ca,
1185 [8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d},
1186}
1187
1188var WSAID_WSARECVMSG = GUID{
1189 0xf689d7c8,
1190 0x6f1f,
1191 0x436b,
1192 [8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22},
1193}
1194
1195const (
1196 FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1
1197 FILE_SKIP_SET_EVENT_ON_HANDLE = 2
1198)
1199
1200const (
1201 WSAPROTOCOL_LEN = 255
1202 MAX_PROTOCOL_CHAIN = 7
1203 BASE_PROTOCOL = 1
1204 LAYERED_PROTOCOL = 0
1205
1206 XP1_CONNECTIONLESS = 0x00000001
1207 XP1_GUARANTEED_DELIVERY = 0x00000002
1208 XP1_GUARANTEED_ORDER = 0x00000004
1209 XP1_MESSAGE_ORIENTED = 0x00000008
1210 XP1_PSEUDO_STREAM = 0x00000010
1211 XP1_GRACEFUL_CLOSE = 0x00000020
1212 XP1_EXPEDITED_DATA = 0x00000040
1213 XP1_CONNECT_DATA = 0x00000080
1214 XP1_DISCONNECT_DATA = 0x00000100
1215 XP1_SUPPORT_BROADCAST = 0x00000200
1216 XP1_SUPPORT_MULTIPOINT = 0x00000400
1217 XP1_MULTIPOINT_CONTROL_PLANE = 0x00000800
1218 XP1_MULTIPOINT_DATA_PLANE = 0x00001000
1219 XP1_QOS_SUPPORTED = 0x00002000
1220 XP1_UNI_SEND = 0x00008000
1221 XP1_UNI_RECV = 0x00010000
1222 XP1_IFS_HANDLES = 0x00020000
1223 XP1_PARTIAL_MESSAGE = 0x00040000
1224 XP1_SAN_SUPPORT_SDP = 0x00080000
1225
1226 PFL_MULTIPLE_PROTO_ENTRIES = 0x00000001
1227 PFL_RECOMMENDED_PROTO_ENTRY = 0x00000002
1228 PFL_HIDDEN = 0x00000004
1229 PFL_MATCHES_PROTOCOL_ZERO = 0x00000008
1230 PFL_NETWORKDIRECT_PROVIDER = 0x00000010
1231)
1232
1233type WSAProtocolInfo struct {
1234 ServiceFlags1 uint32
1235 ServiceFlags2 uint32
1236 ServiceFlags3 uint32
1237 ServiceFlags4 uint32
1238 ProviderFlags uint32
1239 ProviderId GUID
1240 CatalogEntryId uint32
1241 ProtocolChain WSAProtocolChain
1242 Version int32
1243 AddressFamily int32
1244 MaxSockAddr int32
1245 MinSockAddr int32
1246 SocketType int32
1247 Protocol int32
1248 ProtocolMaxOffset int32
1249 NetworkByteOrder int32
1250 SecurityScheme int32
1251 MessageSize uint32
1252 ProviderReserved uint32
1253 ProtocolName [WSAPROTOCOL_LEN + 1]uint16
1254}
1255
1256type WSAProtocolChain struct {
1257 ChainLen int32
1258 ChainEntries [MAX_PROTOCOL_CHAIN]uint32
1259}
1260
1261type TCPKeepalive struct {
1262 OnOff uint32
1263 Time uint32
1264 Interval uint32
1265}
1266
1267type symbolicLinkReparseBuffer struct {
1268 SubstituteNameOffset uint16
1269 SubstituteNameLength uint16
1270 PrintNameOffset uint16
1271 PrintNameLength uint16
1272 Flags uint32
1273 PathBuffer [1]uint16
1274}
1275
1276type mountPointReparseBuffer struct {
1277 SubstituteNameOffset uint16
1278 SubstituteNameLength uint16
1279 PrintNameOffset uint16
1280 PrintNameLength uint16
1281 PathBuffer [1]uint16
1282}
1283
1284type reparseDataBuffer struct {
1285 ReparseTag uint32
1286 ReparseDataLength uint16
1287 Reserved uint16
1288
1289 // GenericReparseBuffer
1290 reparseBuffer byte
1291}
1292
1293const (
1294 FSCTL_GET_REPARSE_POINT = 0x900A8
1295 MAXIMUM_REPARSE_DATA_BUFFER_SIZE = 16 * 1024
1296 IO_REPARSE_TAG_MOUNT_POINT = 0xA0000003
1297 IO_REPARSE_TAG_SYMLINK = 0xA000000C
1298 SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1
1299)
1300
1301const (
1302 ComputerNameNetBIOS = 0
1303 ComputerNameDnsHostname = 1
1304 ComputerNameDnsDomain = 2
1305 ComputerNameDnsFullyQualified = 3
1306 ComputerNamePhysicalNetBIOS = 4
1307 ComputerNamePhysicalDnsHostname = 5
1308 ComputerNamePhysicalDnsDomain = 6
1309 ComputerNamePhysicalDnsFullyQualified = 7
1310 ComputerNameMax = 8
1311)
1312
1313// For MessageBox()
1314const (
1315 MB_OK = 0x00000000
1316 MB_OKCANCEL = 0x00000001
1317 MB_ABORTRETRYIGNORE = 0x00000002
1318 MB_YESNOCANCEL = 0x00000003
1319 MB_YESNO = 0x00000004
1320 MB_RETRYCANCEL = 0x00000005
1321 MB_CANCELTRYCONTINUE = 0x00000006
1322 MB_ICONHAND = 0x00000010
1323 MB_ICONQUESTION = 0x00000020
1324 MB_ICONEXCLAMATION = 0x00000030
1325 MB_ICONASTERISK = 0x00000040
1326 MB_USERICON = 0x00000080
1327 MB_ICONWARNING = MB_ICONEXCLAMATION
1328 MB_ICONERROR = MB_ICONHAND
1329 MB_ICONINFORMATION = MB_ICONASTERISK
1330 MB_ICONSTOP = MB_ICONHAND
1331 MB_DEFBUTTON1 = 0x00000000
1332 MB_DEFBUTTON2 = 0x00000100
1333 MB_DEFBUTTON3 = 0x00000200
1334 MB_DEFBUTTON4 = 0x00000300
1335 MB_APPLMODAL = 0x00000000
1336 MB_SYSTEMMODAL = 0x00001000
1337 MB_TASKMODAL = 0x00002000
1338 MB_HELP = 0x00004000
1339 MB_NOFOCUS = 0x00008000
1340 MB_SETFOREGROUND = 0x00010000
1341 MB_DEFAULT_DESKTOP_ONLY = 0x00020000
1342 MB_TOPMOST = 0x00040000
1343 MB_RIGHT = 0x00080000
1344 MB_RTLREADING = 0x00100000
1345 MB_SERVICE_NOTIFICATION = 0x00200000
1346)
1347
1348const (
1349 MOVEFILE_REPLACE_EXISTING = 0x1
1350 MOVEFILE_COPY_ALLOWED = 0x2
1351 MOVEFILE_DELAY_UNTIL_REBOOT = 0x4
1352 MOVEFILE_WRITE_THROUGH = 0x8
1353 MOVEFILE_CREATE_HARDLINK = 0x10
1354 MOVEFILE_FAIL_IF_NOT_TRACKABLE = 0x20
1355)
1356
1357const GAA_FLAG_INCLUDE_PREFIX = 0x00000010
1358
1359const (
1360 IF_TYPE_OTHER = 1
1361 IF_TYPE_ETHERNET_CSMACD = 6
1362 IF_TYPE_ISO88025_TOKENRING = 9
1363 IF_TYPE_PPP = 23
1364 IF_TYPE_SOFTWARE_LOOPBACK = 24
1365 IF_TYPE_ATM = 37
1366 IF_TYPE_IEEE80211 = 71
1367 IF_TYPE_TUNNEL = 131
1368 IF_TYPE_IEEE1394 = 144
1369)
1370
1371type SocketAddress struct {
1372 Sockaddr *syscall.RawSockaddrAny
1373 SockaddrLength int32
1374}
1375
1376// IP returns an IPv4 or IPv6 address, or nil if the underlying SocketAddress is neither.
1377func (addr *SocketAddress) IP() net.IP {
1378 if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet4{}) && addr.Sockaddr.Addr.Family == AF_INET {
1379 return (*RawSockaddrInet4)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
1380 } else if uintptr(addr.SockaddrLength) >= unsafe.Sizeof(RawSockaddrInet6{}) && addr.Sockaddr.Addr.Family == AF_INET6 {
1381 return (*RawSockaddrInet6)(unsafe.Pointer(addr.Sockaddr)).Addr[:]
1382 }
1383 return nil
1384}
1385
1386type IpAdapterUnicastAddress struct {
1387 Length uint32
1388 Flags uint32
1389 Next *IpAdapterUnicastAddress
1390 Address SocketAddress
1391 PrefixOrigin int32
1392 SuffixOrigin int32
1393 DadState int32
1394 ValidLifetime uint32
1395 PreferredLifetime uint32
1396 LeaseLifetime uint32
1397 OnLinkPrefixLength uint8
1398}
1399
1400type IpAdapterAnycastAddress struct {
1401 Length uint32
1402 Flags uint32
1403 Next *IpAdapterAnycastAddress
1404 Address SocketAddress
1405}
1406
1407type IpAdapterMulticastAddress struct {
1408 Length uint32
1409 Flags uint32
1410 Next *IpAdapterMulticastAddress
1411 Address SocketAddress
1412}
1413
1414type IpAdapterDnsServerAdapter struct {
1415 Length uint32
1416 Reserved uint32
1417 Next *IpAdapterDnsServerAdapter
1418 Address SocketAddress
1419}
1420
1421type IpAdapterPrefix struct {
1422 Length uint32
1423 Flags uint32
1424 Next *IpAdapterPrefix
1425 Address SocketAddress
1426 PrefixLength uint32
1427}
1428
1429type IpAdapterAddresses struct {
1430 Length uint32
1431 IfIndex uint32
1432 Next *IpAdapterAddresses
1433 AdapterName *byte
1434 FirstUnicastAddress *IpAdapterUnicastAddress
1435 FirstAnycastAddress *IpAdapterAnycastAddress
1436 FirstMulticastAddress *IpAdapterMulticastAddress
1437 FirstDnsServerAddress *IpAdapterDnsServerAdapter
1438 DnsSuffix *uint16
1439 Description *uint16
1440 FriendlyName *uint16
1441 PhysicalAddress [syscall.MAX_ADAPTER_ADDRESS_LENGTH]byte
1442 PhysicalAddressLength uint32
1443 Flags uint32
1444 Mtu uint32
1445 IfType uint32
1446 OperStatus uint32
1447 Ipv6IfIndex uint32
1448 ZoneIndices [16]uint32
1449 FirstPrefix *IpAdapterPrefix
1450 /* more fields might be present here. */
1451}
1452
1453const (
1454 IfOperStatusUp = 1
1455 IfOperStatusDown = 2
1456 IfOperStatusTesting = 3
1457 IfOperStatusUnknown = 4
1458 IfOperStatusDormant = 5
1459 IfOperStatusNotPresent = 6
1460 IfOperStatusLowerLayerDown = 7
1461)
1462
1463// Console related constants used for the mode parameter to SetConsoleMode. See
1464// https://docs.microsoft.com/en-us/windows/console/setconsolemode for details.
1465
1466const (
1467 ENABLE_PROCESSED_INPUT = 0x1
1468 ENABLE_LINE_INPUT = 0x2
1469 ENABLE_ECHO_INPUT = 0x4
1470 ENABLE_WINDOW_INPUT = 0x8
1471 ENABLE_MOUSE_INPUT = 0x10
1472 ENABLE_INSERT_MODE = 0x20
1473 ENABLE_QUICK_EDIT_MODE = 0x40
1474 ENABLE_EXTENDED_FLAGS = 0x80
1475 ENABLE_AUTO_POSITION = 0x100
1476 ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200
1477
1478 ENABLE_PROCESSED_OUTPUT = 0x1
1479 ENABLE_WRAP_AT_EOL_OUTPUT = 0x2
1480 ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
1481 DISABLE_NEWLINE_AUTO_RETURN = 0x8
1482 ENABLE_LVB_GRID_WORLDWIDE = 0x10
1483)
1484
1485type Coord struct {
1486 X int16
1487 Y int16
1488}
1489
1490type SmallRect struct {
1491 Left int16
1492 Top int16
1493 Right int16
1494 Bottom int16
1495}
1496
1497// Used with GetConsoleScreenBuffer to retrieve information about a console
1498// screen buffer. See
1499// https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str
1500// for details.
1501
1502type ConsoleScreenBufferInfo struct {
1503 Size Coord
1504 CursorPosition Coord
1505 Attributes uint16
1506 Window SmallRect
1507 MaximumWindowSize Coord
1508}
1509
1510const UNIX_PATH_MAX = 108 // defined in afunix.h
1511
1512const (
1513 // flags for JOBOBJECT_BASIC_LIMIT_INFORMATION.LimitFlags
1514 JOB_OBJECT_LIMIT_ACTIVE_PROCESS = 0x00000008
1515 JOB_OBJECT_LIMIT_AFFINITY = 0x00000010
1516 JOB_OBJECT_LIMIT_BREAKAWAY_OK = 0x00000800
1517 JOB_OBJECT_LIMIT_DIE_ON_UNHANDLED_EXCEPTION = 0x00000400
1518 JOB_OBJECT_LIMIT_JOB_MEMORY = 0x00000200
1519 JOB_OBJECT_LIMIT_JOB_TIME = 0x00000004
1520 JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE = 0x00002000
1521 JOB_OBJECT_LIMIT_PRESERVE_JOB_TIME = 0x00000040
1522 JOB_OBJECT_LIMIT_PRIORITY_CLASS = 0x00000020
1523 JOB_OBJECT_LIMIT_PROCESS_MEMORY = 0x00000100
1524 JOB_OBJECT_LIMIT_PROCESS_TIME = 0x00000002
1525 JOB_OBJECT_LIMIT_SCHEDULING_CLASS = 0x00000080
1526 JOB_OBJECT_LIMIT_SILENT_BREAKAWAY_OK = 0x00001000
1527 JOB_OBJECT_LIMIT_SUBSET_AFFINITY = 0x00004000
1528 JOB_OBJECT_LIMIT_WORKINGSET = 0x00000001
1529)
1530
1531type JOBOBJECT_BASIC_LIMIT_INFORMATION struct {
1532 PerProcessUserTimeLimit int64
1533 PerJobUserTimeLimit int64
1534 LimitFlags uint32
1535 MinimumWorkingSetSize uintptr
1536 MaximumWorkingSetSize uintptr
1537 ActiveProcessLimit uint32
1538 Affinity uintptr
1539 PriorityClass uint32
1540 SchedulingClass uint32
1541}
1542
1543type IO_COUNTERS struct {
1544 ReadOperationCount uint64
1545 WriteOperationCount uint64
1546 OtherOperationCount uint64
1547 ReadTransferCount uint64
1548 WriteTransferCount uint64
1549 OtherTransferCount uint64
1550}
1551
1552type JOBOBJECT_EXTENDED_LIMIT_INFORMATION struct {
1553 BasicLimitInformation JOBOBJECT_BASIC_LIMIT_INFORMATION
1554 IoInfo IO_COUNTERS
1555 ProcessMemoryLimit uintptr
1556 JobMemoryLimit uintptr
1557 PeakProcessMemoryUsed uintptr
1558 PeakJobMemoryUsed uintptr
1559}
1560
1561const (
1562 // UIRestrictionsClass
1563 JOB_OBJECT_UILIMIT_DESKTOP = 0x00000040
1564 JOB_OBJECT_UILIMIT_DISPLAYSETTINGS = 0x00000010
1565 JOB_OBJECT_UILIMIT_EXITWINDOWS = 0x00000080
1566 JOB_OBJECT_UILIMIT_GLOBALATOMS = 0x00000020
1567 JOB_OBJECT_UILIMIT_HANDLES = 0x00000001
1568 JOB_OBJECT_UILIMIT_READCLIPBOARD = 0x00000002
1569 JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS = 0x00000008
1570 JOB_OBJECT_UILIMIT_WRITECLIPBOARD = 0x00000004
1571)
1572
1573type JOBOBJECT_BASIC_UI_RESTRICTIONS struct {
1574 UIRestrictionsClass uint32
1575}
1576
1577const (
1578 // JobObjectInformationClass
1579 JobObjectAssociateCompletionPortInformation = 7
1580 JobObjectBasicLimitInformation = 2
1581 JobObjectBasicUIRestrictions = 4
1582 JobObjectCpuRateControlInformation = 15
1583 JobObjectEndOfJobTimeInformation = 6
1584 JobObjectExtendedLimitInformation = 9
1585 JobObjectGroupInformation = 11
1586 JobObjectGroupInformationEx = 14
1587 JobObjectLimitViolationInformation2 = 35
1588 JobObjectNetRateControlInformation = 32
1589 JobObjectNotificationLimitInformation = 12
1590 JobObjectNotificationLimitInformation2 = 34
1591 JobObjectSecurityLimitInformation = 5
1592)