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