authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 00:48:56-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-05-27 00:48:56-04:00
log6be79d79aab204718116428c9b23be7de54e14da
treefa420ee5e4869aa41151c8d0a522a3c94b47e3ba
parent0c6ab61b228211398841cf11912c7252362009b7
signaturelock-open Commit is signed but in an unrecognized format.

fixes for Windows and WASI


17 files changed, 638 insertions(+), 557 deletions(-)

CMakeLists.txt+1
...@@ -628,6 +628,7 @@ set(ZIG_STD_FILES...@@ -628,6 +628,7 @@ set(ZIG_STD_FILES
628 "os/wasi.zig"628 "os/wasi.zig"
629 "os/windows.zig"629 "os/windows.zig"
630 "os/windows/advapi32.zig"630 "os/windows/advapi32.zig"
631 "os/windows/bits.zig"
631 "os/windows/error.zig"632 "os/windows/error.zig"
632 "os/windows/kernel32.zig"633 "os/windows/kernel32.zig"
633 "os/windows/ntdll.zig"634 "os/windows/ntdll.zig"
std/debug.zig+9-9
...@@ -510,7 +510,7 @@ const TtyColor = enum {...@@ -510,7 +510,7 @@ const TtyColor = enum {
510510
511/// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt511/// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt
512fn setTtyColor(tty_color: TtyColor) void {512fn setTtyColor(tty_color: TtyColor) void {
513 if (os.supportsAnsiEscapeCodes(stderr_file.handle)) {513 if (stderr_file.supportsAnsiEscapeCodes()) {
514 switch (tty_color) {514 switch (tty_color) {
515 TtyColor.Red => {515 TtyColor.Red => {
516 stderr_file.write(RED) catch return;516 stderr_file.write(RED) catch return;
...@@ -540,29 +540,29 @@ fn setTtyColor(tty_color: TtyColor) void {...@@ -540,29 +540,29 @@ fn setTtyColor(tty_color: TtyColor) void {
540 S.init_attrs = true;540 S.init_attrs = true;
541 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;541 var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
542 // TODO handle error542 // TODO handle error
543 _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info);543 _ = windows.kernel32.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
544 S.attrs = info.wAttributes;544 S.attrs = info.wAttributes;
545 }545 }
546546
547 // TODO handle errors547 // TODO handle errors
548 switch (tty_color) {548 switch (tty_color) {
549 TtyColor.Red => {549 TtyColor.Red => {
550 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY);550 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY) catch {};
551 },551 },
552 TtyColor.Green => {552 TtyColor.Green => {
553 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY);553 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY) catch {};
554 },554 },
555 TtyColor.Cyan => {555 TtyColor.Cyan => {
556 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);556 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
557 },557 },
558 TtyColor.White, TtyColor.Bold => {558 TtyColor.White, TtyColor.Bold => {
559 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);559 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
560 },560 },
561 TtyColor.Dim => {561 TtyColor.Dim => {
562 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY);562 _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY) catch {};
563 },563 },
564 TtyColor.Reset => {564 TtyColor.Reset => {
565 _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs);565 _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs) catch {};
566 },566 },
567 }567 }
568 }568 }
...@@ -894,7 +894,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {...@@ -894,7 +894,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
894 if (this_record_len % 4 != 0) {894 if (this_record_len % 4 != 0) {
895 const round_to_next_4 = (this_record_len | 0x3) + 1;895 const round_to_next_4 = (this_record_len | 0x3) + 1;
896 const march_forward_bytes = round_to_next_4 - this_record_len;896 const march_forward_bytes = round_to_next_4 - this_record_len;
897 try dbi.seekBy(march_forward_bytes);897 try dbi.seekBy(@intCast(isize, march_forward_bytes));
898 this_record_len += march_forward_bytes;898 this_record_len += march_forward_bytes;
899 }899 }
900900
std/heap.zig+3-1
...@@ -92,12 +92,14 @@ pub const DirectAllocator = struct {...@@ -92,12 +92,14 @@ pub const DirectAllocator = struct {
92 // obtained some memory space that will cause the next92 // obtained some memory space that will cause the next
93 // VirtualAlloc call to fail. To handle this, we will retry93 // VirtualAlloc call to fail. To handle this, we will retry
94 // until it succeeds.94 // until it succeeds.
95 return w.VirtualAlloc(95 const ptr = w.VirtualAlloc(
96 @intToPtr(*c_void, aligned_addr),96 @intToPtr(*c_void, aligned_addr),
97 n,97 n,
98 w.MEM_COMMIT | w.MEM_RESERVE,98 w.MEM_COMMIT | w.MEM_RESERVE,
99 w.PAGE_READWRITE,99 w.PAGE_READWRITE,
100 ) catch continue;100 ) catch continue;
101
102 return @ptrCast([*]u8, ptr)[0..n];
101 };103 };
102104
103 return @ptrCast([*]u8, final_addr)[0..n];105 return @ptrCast([*]u8, final_addr)[0..n];
std/os.zig+2-1
...@@ -99,7 +99,8 @@ pub fn getrandom(buf: []u8) GetRandomError!void {...@@ -99,7 +99,8 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
99 }99 }
100 if (linux.is_the_target) {100 if (linux.is_the_target) {
101 while (true) {101 while (true) {
102 switch (errno(system.getrandom(buf.ptr, buf.len, 0))) {102 // Bypass libc because it's missing on even relatively new versions.
103 switch (linux.getErrno(linux.getrandom(buf.ptr, buf.len, 0))) {
103 0 => return,104 0 => return,
104 EINVAL => unreachable,105 EINVAL => unreachable,
105 EFAULT => unreachable,106 EFAULT => unreachable,
std/os/bits/wasi.zig+1-2
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1// Declarations that are intended to be imported into the POSIX namespace.1use @import("../bits.zig");
2// This includes WASI-only APIs.
32
4pub const STDIN_FILENO = 0;3pub const STDIN_FILENO = 0;
5pub const STDOUT_FILENO = 1;4pub const STDOUT_FILENO = 1;
std/os/bits/windows.zig+65-1
...@@ -1,8 +1,65 @@...@@ -1,8 +1,65 @@
1use @import("../windows.zig");1// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
2
3use @import("../windows/bits.zig");
24
3pub const fd_t = HANDLE;5pub const fd_t = HANDLE;
4pub const pid_t = HANDLE;6pub const pid_t = HANDLE;
57
8pub const sig_atomic_t = c_int;
9
10/// maximum signal number + 1
11pub const NSIG = 23;
12
13// Signal types
14
15/// interrupt
16pub const SIGINT = 2;
17
18/// illegal instruction - invalid function image
19pub const SIGILL = 4;
20
21/// floating point exception
22pub const SIGFPE = 8;
23
24/// segment violation
25pub const SIGSEGV = 11;
26
27/// Software termination signal from kill
28pub const SIGTERM = 15;
29
30/// Ctrl-Break sequence
31pub const SIGBREAK = 21;
32
33/// abnormal termination triggered by abort call
34pub const SIGABRT = 22;
35
36/// SIGABRT compatible with other platforms, same as SIGABRT
37pub const SIGABRT_COMPAT = 6;
38
39// Signal action codes
40
41/// default signal action
42pub const SIG_DFL = 0;
43
44/// ignore signal
45pub const SIG_IGN = 1;
46
47/// return current value
48pub const SIG_GET = 2;
49
50/// signal gets error
51pub const SIG_SGE = 3;
52
53/// acknowledge
54pub const SIG_ACK = 4;
55
56/// Signal error value (returned by signal call on error)
57pub const SIG_ERR = -1;
58
59pub const SEEK_SET = 0;
60pub const SEEK_CUR = 1;
61pub const SEEK_END = 2;
62
6pub const EPERM = 1;63pub const EPERM = 1;
7pub const ENOENT = 2;64pub const ENOENT = 2;
8pub const ESRCH = 3;65pub const ESRCH = 3;
...@@ -89,3 +146,10 @@ pub const ETIME = 137;...@@ -89,3 +146,10 @@ pub const ETIME = 137;
89pub const ETIMEDOUT = 138;146pub const ETIMEDOUT = 138;
90pub const ETXTBSY = 139;147pub const ETXTBSY = 139;
91pub const EWOULDBLOCK = 140;148pub const EWOULDBLOCK = 140;
149
150// These are workarounds for "use of undeclared identifier" compile errors
151// TODO make the compiler even more lazy. don't emit "use of undeclared identifier" errors
152// for if branches that aren't taken.
153pub const SIGKILL = @compileError("Windows libc does not have this");
154pub const EDQUOT = @compileError("Windows libc does not have this");
155pub const TIOCGWINSZ = @compileError("Windows libc does not have this");
std/os/windows.zig+15-528
...@@ -6,537 +6,19 @@...@@ -6,537 +6,19 @@
66
7const builtin = @import("builtin");7const builtin = @import("builtin");
8const std = @import("../std.zig");8const std = @import("../std.zig");
9const mem = std.mem;
9const assert = std.debug.assert;10const assert = std.debug.assert;
11const math = std.math;
10const maxInt = std.math.maxInt;12const maxInt = std.math.maxInt;
1113
12pub const is_the_target = builtin.os == .windows;14pub const is_the_target = builtin.os == .windows;
13
14pub const advapi32 = @import("windows/advapi32.zig");15pub const advapi32 = @import("windows/advapi32.zig");
15pub const kernel32 = @import("windows/kernel32.zig");16pub const kernel32 = @import("windows/kernel32.zig");
16pub const ntdll = @import("windows/ntdll.zig");17pub const ntdll = @import("windows/ntdll.zig");
17pub const ole32 = @import("windows/ole32.zig");18pub const ole32 = @import("windows/ole32.zig");
18pub const shell32 = @import("windows/shell32.zig");19pub const shell32 = @import("windows/shell32.zig");
1920
20pub const ERROR = @import("windows/error.zig");21pub use @import("windows/bits.zig");
21
22/// The standard input device. Initially, this is the console input buffer, CONIN$.
23pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
24
25/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
26pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
27
28/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
29pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
30
31pub const SHORT = c_short;
32pub const BOOL = c_int;
33pub const BOOLEAN = BYTE;
34pub const BYTE = u8;
35pub const CHAR = u8;
36pub const DWORD = u32;
37pub const FLOAT = f32;
38pub const HANDLE = *c_void;
39pub const HCRYPTPROV = ULONG_PTR;
40pub const HINSTANCE = *@OpaqueType();
41pub const HMODULE = *@OpaqueType();
42pub const FARPROC = *@OpaqueType();
43pub const INT = c_int;
44pub const LPBYTE = *BYTE;
45pub const LPCH = *CHAR;
46pub const LPCSTR = [*]const CHAR;
47pub const LPCTSTR = [*]const TCHAR;
48pub const LPCVOID = *const c_void;
49pub const LPDWORD = *DWORD;
50pub const LPSTR = [*]CHAR;
51pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
52pub const LPVOID = *c_void;
53pub const LPWSTR = [*]WCHAR;
54pub const LPCWSTR = [*]const WCHAR;
55pub const PVOID = *c_void;
56pub const PWSTR = [*]WCHAR;
57pub const SIZE_T = usize;
58pub const TCHAR = if (UNICODE) WCHAR else u8;
59pub const UINT = c_uint;
60pub const ULONG_PTR = usize;
61pub const DWORD_PTR = ULONG_PTR;
62pub const UNICODE = false;
63pub const WCHAR = u16;
64pub const WORD = u16;
65pub const LARGE_INTEGER = i64;
66pub const ULONG = u32;
67pub const LONG = i32;
68pub const ULONGLONG = u64;
69pub const LONGLONG = i64;
70
71pub const TRUE = 1;
72pub const FALSE = 0;
73
74pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
75
76pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
77
78pub const OVERLAPPED = extern struct {
79 Internal: ULONG_PTR,
80 InternalHigh: ULONG_PTR,
81 Offset: DWORD,
82 OffsetHigh: DWORD,
83 hEvent: ?HANDLE,
84};
85pub const LPOVERLAPPED = *OVERLAPPED;
86
87pub const MAX_PATH = 260;
88
89// TODO issue #305
90pub const FILE_INFO_BY_HANDLE_CLASS = u32;
91pub const FileBasicInfo = 0;
92pub const FileStandardInfo = 1;
93pub const FileNameInfo = 2;
94pub const FileRenameInfo = 3;
95pub const FileDispositionInfo = 4;
96pub const FileAllocationInfo = 5;
97pub const FileEndOfFileInfo = 6;
98pub const FileStreamInfo = 7;
99pub const FileCompressionInfo = 8;
100pub const FileAttributeTagInfo = 9;
101pub const FileIdBothDirectoryInfo = 10;
102pub const FileIdBothDirectoryRestartInfo = 11;
103pub const FileIoPriorityHintInfo = 12;
104pub const FileRemoteProtocolInfo = 13;
105pub const FileFullDirectoryInfo = 14;
106pub const FileFullDirectoryRestartInfo = 15;
107pub const FileStorageInfo = 16;
108pub const FileAlignmentInfo = 17;
109pub const FileIdInfo = 18;
110pub const FileIdExtdDirectoryInfo = 19;
111pub const FileIdExtdDirectoryRestartInfo = 20;
112
113pub const FILE_NAME_INFO = extern struct {
114 FileNameLength: DWORD,
115 FileName: [1]WCHAR,
116};
117
118/// Return the normalized drive name. This is the default.
119pub const FILE_NAME_NORMALIZED = 0x0;
120
121/// Return the opened file name (not normalized).
122pub const FILE_NAME_OPENED = 0x8;
123
124/// Return the path with the drive letter. This is the default.
125pub const VOLUME_NAME_DOS = 0x0;
126
127/// Return the path with a volume GUID path instead of the drive name.
128pub const VOLUME_NAME_GUID = 0x1;
129
130/// Return the path with no drive information.
131pub const VOLUME_NAME_NONE = 0x4;
132
133/// Return the path with the volume device path.
134pub const VOLUME_NAME_NT = 0x2;
135
136pub const SECURITY_ATTRIBUTES = extern struct {
137 nLength: DWORD,
138 lpSecurityDescriptor: ?*c_void,
139 bInheritHandle: BOOL,
140};
141pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
142pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
143
144pub const GENERIC_READ = 0x80000000;
145pub const GENERIC_WRITE = 0x40000000;
146pub const GENERIC_EXECUTE = 0x20000000;
147pub const GENERIC_ALL = 0x10000000;
148
149pub const FILE_SHARE_DELETE = 0x00000004;
150pub const FILE_SHARE_READ = 0x00000001;
151pub const FILE_SHARE_WRITE = 0x00000002;
152
153pub const CREATE_ALWAYS = 2;
154pub const CREATE_NEW = 1;
155pub const OPEN_ALWAYS = 4;
156pub const OPEN_EXISTING = 3;
157pub const TRUNCATE_EXISTING = 5;
158
159pub const FILE_ATTRIBUTE_ARCHIVE = 0x20;
160pub const FILE_ATTRIBUTE_COMPRESSED = 0x800;
161pub const FILE_ATTRIBUTE_DEVICE = 0x40;
162pub const FILE_ATTRIBUTE_DIRECTORY = 0x10;
163pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
164pub const FILE_ATTRIBUTE_HIDDEN = 0x2;
165pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000;
166pub const FILE_ATTRIBUTE_NORMAL = 0x80;
167pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000;
168pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000;
169pub const FILE_ATTRIBUTE_OFFLINE = 0x1000;
170pub const FILE_ATTRIBUTE_READONLY = 0x1;
171pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000;
172pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000;
173pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
174pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200;
175pub const FILE_ATTRIBUTE_SYSTEM = 0x4;
176pub const FILE_ATTRIBUTE_TEMPORARY = 0x100;
177pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000;
178
179pub const PROCESS_INFORMATION = extern struct {
180 hProcess: HANDLE,
181 hThread: HANDLE,
182 dwProcessId: DWORD,
183 dwThreadId: DWORD,
184};
185
186pub const STARTUPINFOW = extern struct {
187 cb: DWORD,
188 lpReserved: ?LPWSTR,
189 lpDesktop: ?LPWSTR,
190 lpTitle: ?LPWSTR,
191 dwX: DWORD,
192 dwY: DWORD,
193 dwXSize: DWORD,
194 dwYSize: DWORD,
195 dwXCountChars: DWORD,
196 dwYCountChars: DWORD,
197 dwFillAttribute: DWORD,
198 dwFlags: DWORD,
199 wShowWindow: WORD,
200 cbReserved2: WORD,
201 lpReserved2: ?LPBYTE,
202 hStdInput: ?HANDLE,
203 hStdOutput: ?HANDLE,
204 hStdError: ?HANDLE,
205};
206
207pub const STARTF_FORCEONFEEDBACK = 0x00000040;
208pub const STARTF_FORCEOFFFEEDBACK = 0x00000080;
209pub const STARTF_PREVENTPINNING = 0x00002000;
210pub const STARTF_RUNFULLSCREEN = 0x00000020;
211pub const STARTF_TITLEISAPPID = 0x00001000;
212pub const STARTF_TITLEISLINKNAME = 0x00000800;
213pub const STARTF_UNTRUSTEDSOURCE = 0x00008000;
214pub const STARTF_USECOUNTCHARS = 0x00000008;
215pub const STARTF_USEFILLATTRIBUTE = 0x00000010;
216pub const STARTF_USEHOTKEY = 0x00000200;
217pub const STARTF_USEPOSITION = 0x00000004;
218pub const STARTF_USESHOWWINDOW = 0x00000001;
219pub const STARTF_USESIZE = 0x00000002;
220pub const STARTF_USESTDHANDLES = 0x00000100;
221
222pub const INFINITE = 4294967295;
223
224pub const WAIT_ABANDONED = 0x00000080;
225pub const WAIT_OBJECT_0 = 0x00000000;
226pub const WAIT_TIMEOUT = 0x00000102;
227pub const WAIT_FAILED = 0xFFFFFFFF;
228
229pub const HANDLE_FLAG_INHERIT = 0x00000001;
230pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002;
231
232pub const MOVEFILE_COPY_ALLOWED = 2;
233pub const MOVEFILE_CREATE_HARDLINK = 16;
234pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
235pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
236pub const MOVEFILE_REPLACE_EXISTING = 1;
237pub const MOVEFILE_WRITE_THROUGH = 8;
238
239pub const FILE_BEGIN = 0;
240pub const FILE_CURRENT = 1;
241pub const FILE_END = 2;
242
243pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
244pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
245pub const HEAP_NO_SERIALIZE = 0x00000001;
246
247// AllocationType values
248pub const MEM_COMMIT = 0x1000;
249pub const MEM_RESERVE = 0x2000;
250pub const MEM_RESET = 0x80000;
251pub const MEM_RESET_UNDO = 0x1000000;
252pub const MEM_LARGE_PAGES = 0x20000000;
253pub const MEM_PHYSICAL = 0x400000;
254pub const MEM_TOP_DOWN = 0x100000;
255pub const MEM_WRITE_WATCH = 0x200000;
256
257// Protect values
258pub const PAGE_EXECUTE = 0x10;
259pub const PAGE_EXECUTE_READ = 0x20;
260pub const PAGE_EXECUTE_READWRITE = 0x40;
261pub const PAGE_EXECUTE_WRITECOPY = 0x80;
262pub const PAGE_NOACCESS = 0x01;
263pub const PAGE_READONLY = 0x02;
264pub const PAGE_READWRITE = 0x04;
265pub const PAGE_WRITECOPY = 0x08;
266pub const PAGE_TARGETS_INVALID = 0x40000000;
267pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID
268pub const PAGE_GUARD = 0x100;
269pub const PAGE_NOCACHE = 0x200;
270pub const PAGE_WRITECOMBINE = 0x400;
271
272// FreeType values
273pub const MEM_COALESCE_PLACEHOLDERS = 0x1;
274pub const MEM_RESERVE_PLACEHOLDERS = 0x2;
275pub const MEM_DECOMMIT = 0x4000;
276pub const MEM_RELEASE = 0x8000;
277
278pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
279pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
280
281pub const WIN32_FIND_DATAW = extern struct {
282 dwFileAttributes: DWORD,
283 ftCreationTime: FILETIME,
284 ftLastAccessTime: FILETIME,
285 ftLastWriteTime: FILETIME,
286 nFileSizeHigh: DWORD,
287 nFileSizeLow: DWORD,
288 dwReserved0: DWORD,
289 dwReserved1: DWORD,
290 cFileName: [260]u16,
291 cAlternateFileName: [14]u16,
292};
293
294pub const FILETIME = extern struct {
295 dwLowDateTime: DWORD,
296 dwHighDateTime: DWORD,
297};
298
299pub const SYSTEM_INFO = extern struct {
300 anon1: extern union {
301 dwOemId: DWORD,
302 anon2: extern struct {
303 wProcessorArchitecture: WORD,
304 wReserved: WORD,
305 },
306 },
307 dwPageSize: DWORD,
308 lpMinimumApplicationAddress: LPVOID,
309 lpMaximumApplicationAddress: LPVOID,
310 dwActiveProcessorMask: DWORD_PTR,
311 dwNumberOfProcessors: DWORD,
312 dwProcessorType: DWORD,
313 dwAllocationGranularity: DWORD,
314 wProcessorLevel: WORD,
315 wProcessorRevision: WORD,
316};
317
318pub const HRESULT = c_long;
319
320pub const KNOWNFOLDERID = GUID;
321pub const GUID = extern struct {
322 Data1: c_ulong,
323 Data2: c_ushort,
324 Data3: c_ushort,
325 Data4: [8]u8,
326
327 pub fn parse(str: []const u8) GUID {
328 var guid: GUID = undefined;
329 var index: usize = 0;
330 assert(str[index] == '{');
331 index += 1;
332
333 guid.Data1 = std.fmt.parseUnsigned(c_ulong, str[index .. index + 8], 16) catch unreachable;
334 index += 8;
335
336 assert(str[index] == '-');
337 index += 1;
338
339 guid.Data2 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
340 index += 4;
341
342 assert(str[index] == '-');
343 index += 1;
344
345 guid.Data3 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
346 index += 4;
347
348 assert(str[index] == '-');
349 index += 1;
350
351 guid.Data4[0] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
352 index += 2;
353 guid.Data4[1] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
354 index += 2;
355
356 assert(str[index] == '-');
357 index += 1;
358
359 var i: usize = 2;
360 while (i < guid.Data4.len) : (i += 1) {
361 guid.Data4[i] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
362 index += 2;
363 }
364
365 assert(str[index] == '}');
366 index += 1;
367 return guid;
368 }
369};
370
371pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}");
372
373pub const KF_FLAG_DEFAULT = 0;
374pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536;
375pub const KF_FLAG_CREATE = 32768;
376pub const KF_FLAG_DONT_VERIFY = 16384;
377pub const KF_FLAG_DONT_UNEXPAND = 8192;
378pub const KF_FLAG_NO_ALIAS = 4096;
379pub const KF_FLAG_INIT = 2048;
380pub const KF_FLAG_DEFAULT_PATH = 1024;
381pub const KF_FLAG_NOT_PARENT_RELATIVE = 512;
382pub const KF_FLAG_SIMPLE_IDLIST = 256;
383pub const KF_FLAG_ALIAS_ONLY = -2147483648;
384
385pub const S_OK = 0;
386pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
387pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
388pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
389pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
390pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
391pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
392pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
393pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
394pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
395pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
396
397pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
398pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
399pub const FILE_FLAG_NO_BUFFERING = 0x20000000;
400pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
401pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
402pub const FILE_FLAG_OVERLAPPED = 0x40000000;
403pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000;
404pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000;
405pub const FILE_FLAG_SESSION_AWARE = 0x00800000;
406pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
407pub const FILE_FLAG_WRITE_THROUGH = 0x80000000;
408
409pub const SMALL_RECT = extern struct {
410 Left: SHORT,
411 Top: SHORT,
412 Right: SHORT,
413 Bottom: SHORT,
414};
415
416pub const COORD = extern struct {
417 X: SHORT,
418 Y: SHORT,
419};
420
421pub const CREATE_UNICODE_ENVIRONMENT = 1024;
422
423pub const TLS_OUT_OF_INDEXES = 4294967295;
424pub const IMAGE_TLS_DIRECTORY = extern struct {
425 StartAddressOfRawData: usize,
426 EndAddressOfRawData: usize,
427 AddressOfIndex: usize,
428 AddressOfCallBacks: usize,
429 SizeOfZeroFill: u32,
430 Characteristics: u32,
431};
432pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY;
433pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY;
434
435pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void;
436
437pub const PROV_RSA_FULL = 1;
438
439pub const REGSAM = ACCESS_MASK;
440pub const ACCESS_MASK = DWORD;
441pub const PHKEY = *HKEY;
442pub const HKEY = *HKEY__;
443pub const HKEY__ = extern struct {
444 unused: c_int,
445};
446pub const LSTATUS = LONG;
447
448pub const FILE_NOTIFY_INFORMATION = extern struct {
449 NextEntryOffset: DWORD,
450 Action: DWORD,
451 FileNameLength: DWORD,
452 FileName: [1]WCHAR,
453};
454
455pub const FILE_ACTION_ADDED = 0x00000001;
456pub const FILE_ACTION_REMOVED = 0x00000002;
457pub const FILE_ACTION_MODIFIED = 0x00000003;
458pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
459pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
460
461pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
462
463pub const FILE_LIST_DIRECTORY = 1;
464
465pub const FILE_NOTIFY_CHANGE_CREATION = 64;
466pub const FILE_NOTIFY_CHANGE_SIZE = 8;
467pub const FILE_NOTIFY_CHANGE_SECURITY = 256;
468pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
469pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
470pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2;
471pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1;
472pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
473
474pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
475 dwSize: COORD,
476 dwCursorPosition: COORD,
477 wAttributes: WORD,
478 srWindow: SMALL_RECT,
479 dwMaximumWindowSize: COORD,
480};
481
482pub const FOREGROUND_BLUE = 1;
483pub const FOREGROUND_GREEN = 2;
484pub const FOREGROUND_RED = 4;
485pub const FOREGROUND_INTENSITY = 8;
486
487pub const LIST_ENTRY = extern struct {
488 Flink: *LIST_ENTRY,
489 Blink: *LIST_ENTRY,
490};
491
492pub const RTL_CRITICAL_SECTION_DEBUG = extern struct {
493 Type: WORD,
494 CreatorBackTraceIndex: WORD,
495 CriticalSection: *RTL_CRITICAL_SECTION,
496 ProcessLocksList: LIST_ENTRY,
497 EntryCount: DWORD,
498 ContentionCount: DWORD,
499 Flags: DWORD,
500 CreatorBackTraceIndexHigh: WORD,
501 SpareWORD: WORD,
502};
503
504pub const RTL_CRITICAL_SECTION = extern struct {
505 DebugInfo: *RTL_CRITICAL_SECTION_DEBUG,
506 LockCount: LONG,
507 RecursionCount: LONG,
508 OwningThread: HANDLE,
509 LockSemaphore: HANDLE,
510 SpinCount: ULONG_PTR,
511};
512
513pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
514pub const INIT_ONCE = RTL_RUN_ONCE;
515pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT;
516pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL;
517
518pub const RTL_RUN_ONCE = extern struct {
519 Ptr: ?*c_void,
520};
521
522pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null };
523
524pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED;
525pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED;
526pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE;
527pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY;
528pub const COINIT = extern enum {
529 COINIT_APARTMENTTHREADED = 2,
530 COINIT_MULTITHREADED = 0,
531 COINIT_DISABLE_OLE1DDE = 4,
532 COINIT_SPEED_OVER_MEMORY = 8,
533};
534
535/// > The maximum path of 32,767 characters is approximate, because the "\\?\"
536/// > prefix may be expanded to a longer string by the system at run time, and
537/// > this expansion applies to the total length.
538/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
539pub const PATH_MAX_WIDE = 32767;
54022
541pub const CreateFileError = error{23pub const CreateFileError = error{
542 SharingViolation,24 SharingViolation,
...@@ -765,7 +247,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {...@@ -765,7 +247,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
765 while (index < buffer.len) {247 while (index < buffer.len) {
766 const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));248 const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
767 var amt_read: DWORD = undefined;249 var amt_read: DWORD = undefined;
768 if (kernel32.ReadFile(fd, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {250 if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
769 switch (kernel32.GetLastError()) {251 switch (kernel32.GetLastError()) {
770 ERROR.OPERATION_ABORTED => continue,252 ERROR.OPERATION_ABORTED => continue,
771 ERROR.BROKEN_PIPE => return index,253 ERROR.BROKEN_PIPE => return index,
...@@ -787,7 +269,7 @@ pub const WriteFileError = error{...@@ -787,7 +269,7 @@ pub const WriteFileError = error{
787269
788/// This function is for blocking file descriptors only. For non-blocking, see270/// This function is for blocking file descriptors only. For non-blocking, see
789/// `WriteFileAsync`.271/// `WriteFileAsync`.
790pub fn WriteFile(in_hFile: HANDLE, bytes: []const u8) WriteFileError!void {272pub fn WriteFile(handle: HANDLE, bytes: []const u8) WriteFileError!void {
791 var bytes_written: DWORD = undefined;273 var bytes_written: DWORD = undefined;
792 // TODO replace this @intCast with a loop that writes all the bytes274 // TODO replace this @intCast with a loop that writes all the bytes
793 if (kernel32.WriteFile(handle, bytes.ptr, @intCast(u32, bytes.len), &bytes_written, null) == 0) {275 if (kernel32.WriteFile(handle, bytes.ptr, @intCast(u32, bytes.len), &bytes_written, null) == 0) {
...@@ -808,7 +290,7 @@ pub const GetCurrentDirectoryError = error{...@@ -808,7 +290,7 @@ pub const GetCurrentDirectoryError = error{
808 Unexpected,290 Unexpected,
809};291};
810292
811/// The result is a slice of out_buffer, indexed from 0.293/// The result is a slice of `buffer`, indexed from 0.
812pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {294pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {
813 var utf16le_buf: [PATH_MAX_WIDE]u16 = undefined;295 var utf16le_buf: [PATH_MAX_WIDE]u16 = undefined;
814 const result = kernel32.GetCurrentDirectoryW(utf16le_buf.len, &utf16le_buf);296 const result = kernel32.GetCurrentDirectoryW(utf16le_buf.len, &utf16le_buf);
...@@ -821,13 +303,14 @@ pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {...@@ -821,13 +303,14 @@ pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {
821 const utf16le_slice = utf16le_buf[0..result];303 const utf16le_slice = utf16le_buf[0..result];
822 // Trust that Windows gives us valid UTF-16LE.304 // Trust that Windows gives us valid UTF-16LE.
823 var end_index: usize = 0;305 var end_index: usize = 0;
824 var it = std.unicode.Utf16LeIterator.init(utf16le);306 var it = std.unicode.Utf16LeIterator.init(utf16le_slice);
825 while (it.nextCodepoint() catch unreachable) |codepoint| {307 while (it.nextCodepoint() catch unreachable) |codepoint| {
826 if (end_index + std.unicode.utf8CodepointSequenceLength(codepoint) >= out_buffer.len)308 const seq_len = std.unicode.utf8CodepointSequenceLength(codepoint) catch unreachable;
309 if (end_index + seq_len >= buffer.len)
827 return error.NameTooLong;310 return error.NameTooLong;
828 end_index += utf8Encode(codepoint, out_buffer[end_index..]) catch unreachable;311 end_index += std.unicode.utf8Encode(codepoint, buffer[end_index..]) catch unreachable;
829 }312 }
830 return out_buffer[0..end_index];313 return buffer[0..end_index];
831}314}
832315
833pub const CreateSymbolicLinkError = error{Unexpected};316pub const CreateSymbolicLinkError = error{Unexpected};
...@@ -1218,6 +701,10 @@ pub fn QueryPerformanceCounter() u64 {...@@ -1218,6 +701,10 @@ pub fn QueryPerformanceCounter() u64 {
1218 return @bitCast(u64, result);701 return @bitCast(u64, result);
1219}702}
1220703
704pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) void {
705 assert(kernel32.InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) != 0);
706}
707
1221pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {708pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
1222 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));709 return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
1223}710}
std/os/windows/advapi32.zig+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1use @import("../windows.zig");1use @import("bits.zig");
22
3pub extern "advapi32" stdcallcc fn RegOpenKeyExW(3pub extern "advapi32" stdcallcc fn RegOpenKeyExW(
4 hKey: HKEY,4 hKey: HKEY,
std/os/windows/bits.zig created+527
...@@ -0,0 +1,527 @@
1// Platform-dependent types and values that are used along with OS-specific APIs.
2
3const builtin = @import("builtin");
4const std = @import("../../std.zig");
5const assert = std.debug.assert;
6const maxInt = std.math.maxInt;
7
8pub const ERROR = @import("error.zig");
9
10/// The standard input device. Initially, this is the console input buffer, CONIN$.
11pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
12
13/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
14pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
15
16/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
17pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
18
19pub const SHORT = c_short;
20pub const BOOL = c_int;
21pub const BOOLEAN = BYTE;
22pub const BYTE = u8;
23pub const CHAR = u8;
24pub const DWORD = u32;
25pub const FLOAT = f32;
26pub const HANDLE = *c_void;
27pub const HCRYPTPROV = ULONG_PTR;
28pub const HINSTANCE = *@OpaqueType();
29pub const HMODULE = *@OpaqueType();
30pub const FARPROC = *@OpaqueType();
31pub const INT = c_int;
32pub const LPBYTE = *BYTE;
33pub const LPCH = *CHAR;
34pub const LPCSTR = [*]const CHAR;
35pub const LPCTSTR = [*]const TCHAR;
36pub const LPCVOID = *const c_void;
37pub const LPDWORD = *DWORD;
38pub const LPSTR = [*]CHAR;
39pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
40pub const LPVOID = *c_void;
41pub const LPWSTR = [*]WCHAR;
42pub const LPCWSTR = [*]const WCHAR;
43pub const PVOID = *c_void;
44pub const PWSTR = [*]WCHAR;
45pub const SIZE_T = usize;
46pub const TCHAR = if (UNICODE) WCHAR else u8;
47pub const UINT = c_uint;
48pub const ULONG_PTR = usize;
49pub const DWORD_PTR = ULONG_PTR;
50pub const UNICODE = false;
51pub const WCHAR = u16;
52pub const WORD = u16;
53pub const LARGE_INTEGER = i64;
54pub const ULONG = u32;
55pub const LONG = i32;
56pub const ULONGLONG = u64;
57pub const LONGLONG = i64;
58
59pub const TRUE = 1;
60pub const FALSE = 0;
61
62pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
63
64pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
65
66pub const OVERLAPPED = extern struct {
67 Internal: ULONG_PTR,
68 InternalHigh: ULONG_PTR,
69 Offset: DWORD,
70 OffsetHigh: DWORD,
71 hEvent: ?HANDLE,
72};
73pub const LPOVERLAPPED = *OVERLAPPED;
74
75pub const MAX_PATH = 260;
76
77// TODO issue #305
78pub const FILE_INFO_BY_HANDLE_CLASS = u32;
79pub const FileBasicInfo = 0;
80pub const FileStandardInfo = 1;
81pub const FileNameInfo = 2;
82pub const FileRenameInfo = 3;
83pub const FileDispositionInfo = 4;
84pub const FileAllocationInfo = 5;
85pub const FileEndOfFileInfo = 6;
86pub const FileStreamInfo = 7;
87pub const FileCompressionInfo = 8;
88pub const FileAttributeTagInfo = 9;
89pub const FileIdBothDirectoryInfo = 10;
90pub const FileIdBothDirectoryRestartInfo = 11;
91pub const FileIoPriorityHintInfo = 12;
92pub const FileRemoteProtocolInfo = 13;
93pub const FileFullDirectoryInfo = 14;
94pub const FileFullDirectoryRestartInfo = 15;
95pub const FileStorageInfo = 16;
96pub const FileAlignmentInfo = 17;
97pub const FileIdInfo = 18;
98pub const FileIdExtdDirectoryInfo = 19;
99pub const FileIdExtdDirectoryRestartInfo = 20;
100
101pub const FILE_NAME_INFO = extern struct {
102 FileNameLength: DWORD,
103 FileName: [1]WCHAR,
104};
105
106/// Return the normalized drive name. This is the default.
107pub const FILE_NAME_NORMALIZED = 0x0;
108
109/// Return the opened file name (not normalized).
110pub const FILE_NAME_OPENED = 0x8;
111
112/// Return the path with the drive letter. This is the default.
113pub const VOLUME_NAME_DOS = 0x0;
114
115/// Return the path with a volume GUID path instead of the drive name.
116pub const VOLUME_NAME_GUID = 0x1;
117
118/// Return the path with no drive information.
119pub const VOLUME_NAME_NONE = 0x4;
120
121/// Return the path with the volume device path.
122pub const VOLUME_NAME_NT = 0x2;
123
124pub const SECURITY_ATTRIBUTES = extern struct {
125 nLength: DWORD,
126 lpSecurityDescriptor: ?*c_void,
127 bInheritHandle: BOOL,
128};
129pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
130pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
131
132pub const GENERIC_READ = 0x80000000;
133pub const GENERIC_WRITE = 0x40000000;
134pub const GENERIC_EXECUTE = 0x20000000;
135pub const GENERIC_ALL = 0x10000000;
136
137pub const FILE_SHARE_DELETE = 0x00000004;
138pub const FILE_SHARE_READ = 0x00000001;
139pub const FILE_SHARE_WRITE = 0x00000002;
140
141pub const CREATE_ALWAYS = 2;
142pub const CREATE_NEW = 1;
143pub const OPEN_ALWAYS = 4;
144pub const OPEN_EXISTING = 3;
145pub const TRUNCATE_EXISTING = 5;
146
147pub const FILE_ATTRIBUTE_ARCHIVE = 0x20;
148pub const FILE_ATTRIBUTE_COMPRESSED = 0x800;
149pub const FILE_ATTRIBUTE_DEVICE = 0x40;
150pub const FILE_ATTRIBUTE_DIRECTORY = 0x10;
151pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
152pub const FILE_ATTRIBUTE_HIDDEN = 0x2;
153pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000;
154pub const FILE_ATTRIBUTE_NORMAL = 0x80;
155pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000;
156pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000;
157pub const FILE_ATTRIBUTE_OFFLINE = 0x1000;
158pub const FILE_ATTRIBUTE_READONLY = 0x1;
159pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000;
160pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000;
161pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
162pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200;
163pub const FILE_ATTRIBUTE_SYSTEM = 0x4;
164pub const FILE_ATTRIBUTE_TEMPORARY = 0x100;
165pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000;
166
167pub const PROCESS_INFORMATION = extern struct {
168 hProcess: HANDLE,
169 hThread: HANDLE,
170 dwProcessId: DWORD,
171 dwThreadId: DWORD,
172};
173
174pub const STARTUPINFOW = extern struct {
175 cb: DWORD,
176 lpReserved: ?LPWSTR,
177 lpDesktop: ?LPWSTR,
178 lpTitle: ?LPWSTR,
179 dwX: DWORD,
180 dwY: DWORD,
181 dwXSize: DWORD,
182 dwYSize: DWORD,
183 dwXCountChars: DWORD,
184 dwYCountChars: DWORD,
185 dwFillAttribute: DWORD,
186 dwFlags: DWORD,
187 wShowWindow: WORD,
188 cbReserved2: WORD,
189 lpReserved2: ?LPBYTE,
190 hStdInput: ?HANDLE,
191 hStdOutput: ?HANDLE,
192 hStdError: ?HANDLE,
193};
194
195pub const STARTF_FORCEONFEEDBACK = 0x00000040;
196pub const STARTF_FORCEOFFFEEDBACK = 0x00000080;
197pub const STARTF_PREVENTPINNING = 0x00002000;
198pub const STARTF_RUNFULLSCREEN = 0x00000020;
199pub const STARTF_TITLEISAPPID = 0x00001000;
200pub const STARTF_TITLEISLINKNAME = 0x00000800;
201pub const STARTF_UNTRUSTEDSOURCE = 0x00008000;
202pub const STARTF_USECOUNTCHARS = 0x00000008;
203pub const STARTF_USEFILLATTRIBUTE = 0x00000010;
204pub const STARTF_USEHOTKEY = 0x00000200;
205pub const STARTF_USEPOSITION = 0x00000004;
206pub const STARTF_USESHOWWINDOW = 0x00000001;
207pub const STARTF_USESIZE = 0x00000002;
208pub const STARTF_USESTDHANDLES = 0x00000100;
209
210pub const INFINITE = 4294967295;
211
212pub const WAIT_ABANDONED = 0x00000080;
213pub const WAIT_OBJECT_0 = 0x00000000;
214pub const WAIT_TIMEOUT = 0x00000102;
215pub const WAIT_FAILED = 0xFFFFFFFF;
216
217pub const HANDLE_FLAG_INHERIT = 0x00000001;
218pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002;
219
220pub const MOVEFILE_COPY_ALLOWED = 2;
221pub const MOVEFILE_CREATE_HARDLINK = 16;
222pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
223pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
224pub const MOVEFILE_REPLACE_EXISTING = 1;
225pub const MOVEFILE_WRITE_THROUGH = 8;
226
227pub const FILE_BEGIN = 0;
228pub const FILE_CURRENT = 1;
229pub const FILE_END = 2;
230
231pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
232pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
233pub const HEAP_NO_SERIALIZE = 0x00000001;
234
235// AllocationType values
236pub const MEM_COMMIT = 0x1000;
237pub const MEM_RESERVE = 0x2000;
238pub const MEM_RESET = 0x80000;
239pub const MEM_RESET_UNDO = 0x1000000;
240pub const MEM_LARGE_PAGES = 0x20000000;
241pub const MEM_PHYSICAL = 0x400000;
242pub const MEM_TOP_DOWN = 0x100000;
243pub const MEM_WRITE_WATCH = 0x200000;
244
245// Protect values
246pub const PAGE_EXECUTE = 0x10;
247pub const PAGE_EXECUTE_READ = 0x20;
248pub const PAGE_EXECUTE_READWRITE = 0x40;
249pub const PAGE_EXECUTE_WRITECOPY = 0x80;
250pub const PAGE_NOACCESS = 0x01;
251pub const PAGE_READONLY = 0x02;
252pub const PAGE_READWRITE = 0x04;
253pub const PAGE_WRITECOPY = 0x08;
254pub const PAGE_TARGETS_INVALID = 0x40000000;
255pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID
256pub const PAGE_GUARD = 0x100;
257pub const PAGE_NOCACHE = 0x200;
258pub const PAGE_WRITECOMBINE = 0x400;
259
260// FreeType values
261pub const MEM_COALESCE_PLACEHOLDERS = 0x1;
262pub const MEM_RESERVE_PLACEHOLDERS = 0x2;
263pub const MEM_DECOMMIT = 0x4000;
264pub const MEM_RELEASE = 0x8000;
265
266pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
267pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
268
269pub const WIN32_FIND_DATAW = extern struct {
270 dwFileAttributes: DWORD,
271 ftCreationTime: FILETIME,
272 ftLastAccessTime: FILETIME,
273 ftLastWriteTime: FILETIME,
274 nFileSizeHigh: DWORD,
275 nFileSizeLow: DWORD,
276 dwReserved0: DWORD,
277 dwReserved1: DWORD,
278 cFileName: [260]u16,
279 cAlternateFileName: [14]u16,
280};
281
282pub const FILETIME = extern struct {
283 dwLowDateTime: DWORD,
284 dwHighDateTime: DWORD,
285};
286
287pub const SYSTEM_INFO = extern struct {
288 anon1: extern union {
289 dwOemId: DWORD,
290 anon2: extern struct {
291 wProcessorArchitecture: WORD,
292 wReserved: WORD,
293 },
294 },
295 dwPageSize: DWORD,
296 lpMinimumApplicationAddress: LPVOID,
297 lpMaximumApplicationAddress: LPVOID,
298 dwActiveProcessorMask: DWORD_PTR,
299 dwNumberOfProcessors: DWORD,
300 dwProcessorType: DWORD,
301 dwAllocationGranularity: DWORD,
302 wProcessorLevel: WORD,
303 wProcessorRevision: WORD,
304};
305
306pub const HRESULT = c_long;
307
308pub const KNOWNFOLDERID = GUID;
309pub const GUID = extern struct {
310 Data1: c_ulong,
311 Data2: c_ushort,
312 Data3: c_ushort,
313 Data4: [8]u8,
314
315 pub fn parse(str: []const u8) GUID {
316 var guid: GUID = undefined;
317 var index: usize = 0;
318 assert(str[index] == '{');
319 index += 1;
320
321 guid.Data1 = std.fmt.parseUnsigned(c_ulong, str[index .. index + 8], 16) catch unreachable;
322 index += 8;
323
324 assert(str[index] == '-');
325 index += 1;
326
327 guid.Data2 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
328 index += 4;
329
330 assert(str[index] == '-');
331 index += 1;
332
333 guid.Data3 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
334 index += 4;
335
336 assert(str[index] == '-');
337 index += 1;
338
339 guid.Data4[0] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
340 index += 2;
341 guid.Data4[1] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
342 index += 2;
343
344 assert(str[index] == '-');
345 index += 1;
346
347 var i: usize = 2;
348 while (i < guid.Data4.len) : (i += 1) {
349 guid.Data4[i] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
350 index += 2;
351 }
352
353 assert(str[index] == '}');
354 index += 1;
355 return guid;
356 }
357};
358
359pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}");
360
361pub const KF_FLAG_DEFAULT = 0;
362pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536;
363pub const KF_FLAG_CREATE = 32768;
364pub const KF_FLAG_DONT_VERIFY = 16384;
365pub const KF_FLAG_DONT_UNEXPAND = 8192;
366pub const KF_FLAG_NO_ALIAS = 4096;
367pub const KF_FLAG_INIT = 2048;
368pub const KF_FLAG_DEFAULT_PATH = 1024;
369pub const KF_FLAG_NOT_PARENT_RELATIVE = 512;
370pub const KF_FLAG_SIMPLE_IDLIST = 256;
371pub const KF_FLAG_ALIAS_ONLY = -2147483648;
372
373pub const S_OK = 0;
374pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
375pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
376pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
377pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
378pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
379pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
380pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
381pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
382pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
383pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
384
385pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
386pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
387pub const FILE_FLAG_NO_BUFFERING = 0x20000000;
388pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
389pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
390pub const FILE_FLAG_OVERLAPPED = 0x40000000;
391pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000;
392pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000;
393pub const FILE_FLAG_SESSION_AWARE = 0x00800000;
394pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
395pub const FILE_FLAG_WRITE_THROUGH = 0x80000000;
396
397pub const SMALL_RECT = extern struct {
398 Left: SHORT,
399 Top: SHORT,
400 Right: SHORT,
401 Bottom: SHORT,
402};
403
404pub const COORD = extern struct {
405 X: SHORT,
406 Y: SHORT,
407};
408
409pub const CREATE_UNICODE_ENVIRONMENT = 1024;
410
411pub const TLS_OUT_OF_INDEXES = 4294967295;
412pub const IMAGE_TLS_DIRECTORY = extern struct {
413 StartAddressOfRawData: usize,
414 EndAddressOfRawData: usize,
415 AddressOfIndex: usize,
416 AddressOfCallBacks: usize,
417 SizeOfZeroFill: u32,
418 Characteristics: u32,
419};
420pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY;
421pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY;
422
423pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void;
424
425pub const PROV_RSA_FULL = 1;
426
427pub const REGSAM = ACCESS_MASK;
428pub const ACCESS_MASK = DWORD;
429pub const PHKEY = *HKEY;
430pub const HKEY = *HKEY__;
431pub const HKEY__ = extern struct {
432 unused: c_int,
433};
434pub const LSTATUS = LONG;
435
436pub const FILE_NOTIFY_INFORMATION = extern struct {
437 NextEntryOffset: DWORD,
438 Action: DWORD,
439 FileNameLength: DWORD,
440 FileName: [1]WCHAR,
441};
442
443pub const FILE_ACTION_ADDED = 0x00000001;
444pub const FILE_ACTION_REMOVED = 0x00000002;
445pub const FILE_ACTION_MODIFIED = 0x00000003;
446pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
447pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
448
449pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
450
451pub const FILE_LIST_DIRECTORY = 1;
452
453pub const FILE_NOTIFY_CHANGE_CREATION = 64;
454pub const FILE_NOTIFY_CHANGE_SIZE = 8;
455pub const FILE_NOTIFY_CHANGE_SECURITY = 256;
456pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
457pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
458pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2;
459pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1;
460pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
461
462pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
463 dwSize: COORD,
464 dwCursorPosition: COORD,
465 wAttributes: WORD,
466 srWindow: SMALL_RECT,
467 dwMaximumWindowSize: COORD,
468};
469
470pub const FOREGROUND_BLUE = 1;
471pub const FOREGROUND_GREEN = 2;
472pub const FOREGROUND_RED = 4;
473pub const FOREGROUND_INTENSITY = 8;
474
475pub const LIST_ENTRY = extern struct {
476 Flink: *LIST_ENTRY,
477 Blink: *LIST_ENTRY,
478};
479
480pub const RTL_CRITICAL_SECTION_DEBUG = extern struct {
481 Type: WORD,
482 CreatorBackTraceIndex: WORD,
483 CriticalSection: *RTL_CRITICAL_SECTION,
484 ProcessLocksList: LIST_ENTRY,
485 EntryCount: DWORD,
486 ContentionCount: DWORD,
487 Flags: DWORD,
488 CreatorBackTraceIndexHigh: WORD,
489 SpareWORD: WORD,
490};
491
492pub const RTL_CRITICAL_SECTION = extern struct {
493 DebugInfo: *RTL_CRITICAL_SECTION_DEBUG,
494 LockCount: LONG,
495 RecursionCount: LONG,
496 OwningThread: HANDLE,
497 LockSemaphore: HANDLE,
498 SpinCount: ULONG_PTR,
499};
500
501pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
502pub const INIT_ONCE = RTL_RUN_ONCE;
503pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT;
504pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL;
505
506pub const RTL_RUN_ONCE = extern struct {
507 Ptr: ?*c_void,
508};
509
510pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null };
511
512pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED;
513pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED;
514pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE;
515pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY;
516pub const COINIT = extern enum {
517 COINIT_APARTMENTTHREADED = 2,
518 COINIT_MULTITHREADED = 0,
519 COINIT_DISABLE_OLE1DDE = 4,
520 COINIT_SPEED_OVER_MEMORY = 8,
521};
522
523/// > The maximum path of 32,767 characters is approximate, because the "\\?\"
524/// > prefix may be expanded to a longer string by the system at run time, and
525/// > this expansion applies to the total length.
526/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
527pub const PATH_MAX_WIDE = 32767;
std/os/windows/kernel32.zig+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1use @import("../windows.zig");1use @import("bits.zig");
22
3pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL;3pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL;
44
std/os/windows/ntdll.zig+1-1
...@@ -1,3 +1,3 @@...@@ -1,3 +1,3 @@
1use @import("../windows.zig");1use @import("bits.zig");
22
3pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD;3pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD;
std/os/windows/ole32.zig+1-1
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1use @import("../windows.zig");1use @import("bits.zig");
22
3pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void;3pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void;
4pub extern "ole32" stdcallcc fn CoUninitialize() void;4pub extern "ole32" stdcallcc fn CoUninitialize() void;
std/os/windows/shell32.zig+1-1
...@@ -1,3 +1,3 @@...@@ -1,3 +1,3 @@
1use @import("../windows.zig");1use @import("bits.zig");
22
3pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;3pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;
std/pdb.zig+1-1
...@@ -662,7 +662,7 @@ const MsfStream = struct {...@@ -662,7 +662,7 @@ const MsfStream = struct {
662 }662 }
663663
664 fn seekBy(self: *MsfStream, len: i64) !void {664 fn seekBy(self: *MsfStream, len: i64) !void {
665 self.pos += len;665 self.pos = @intCast(u64, @intCast(i64, self.pos) + len);
666 if (self.pos >= self.blocks.len * self.block_size)666 if (self.pos >= self.blocks.len * self.block_size)
667 return error.EOF;667 return error.EOF;
668 }668 }
std/process.zig+2-2
...@@ -144,7 +144,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -144,7 +144,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
144 windows_buf_len,144 windows_buf_len,
145 ) catch |err| switch (err) {145 ) catch |err| switch (err) {
146 error.Unexpected => return error.EnvironmentVariableNotFound,146 error.Unexpected => return error.EnvironmentVariableNotFound,
147 else => return err,147 else => |e| return e,
148 };148 };
149149
150 if (result > buf.len) {150 if (result > buf.len) {
...@@ -156,7 +156,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned...@@ -156,7 +156,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
156 error.DanglingSurrogateHalf => return error.InvalidUtf8,156 error.DanglingSurrogateHalf => return error.InvalidUtf8,
157 error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,157 error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,
158 error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,158 error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,
159 else => return err,159 else => |e| return e,
160 };160 };
161 }161 }
162 } else {162 } else {
std/special/bootstrap.zig+1-1
...@@ -62,7 +62,7 @@ extern fn WinMainCRTStartup() noreturn {...@@ -62,7 +62,7 @@ extern fn WinMainCRTStartup() noreturn {
62 if (!builtin.single_threaded) {62 if (!builtin.single_threaded) {
63 _ = @import("bootstrap_windows_tls.zig");63 _ = @import("bootstrap_windows_tls.zig");
64 }64 }
65 std.os.windows.ExitProcess(callMain());65 std.os.windows.kernel32.ExitProcess(callMain());
66}66}
6767
68// TODO https://github.com/ziglang/zig/issues/26568// TODO https://github.com/ziglang/zig/issues/265
std/statically_initialized_mutex.zig+6-6
...@@ -23,7 +23,7 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {...@@ -23,7 +23,7 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {
23 mutex: *StaticallyInitializedMutex,23 mutex: *StaticallyInitializedMutex,
2424
25 pub fn release(self: Held) void {25 pub fn release(self: Held) void {
26 windows.LeaveCriticalSection(&self.mutex.lock);26 windows.kernel32.LeaveCriticalSection(&self.mutex.lock);
27 }27 }
28 };28 };
2929
...@@ -40,20 +40,20 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {...@@ -40,20 +40,20 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {
40 Context: ?*c_void,40 Context: ?*c_void,
41 ) windows.BOOL {41 ) windows.BOOL {
42 const lock = @ptrCast(*windows.CRITICAL_SECTION, @alignCast(@alignOf(windows.CRITICAL_SECTION), Parameter));42 const lock = @ptrCast(*windows.CRITICAL_SECTION, @alignCast(@alignOf(windows.CRITICAL_SECTION), Parameter));
43 windows.InitializeCriticalSection(lock);43 windows.kernel32.InitializeCriticalSection(lock);
44 return windows.TRUE;44 return windows.TRUE;
45 }45 }
4646
47 /// TODO: once https://github.com/ziglang/zig/issues/287 is solved and std.Mutex has a better47 /// TODO: once https://github.com/ziglang/zig/issues/287 is solved and std.Mutex has a better
48 /// implementation of a runtime initialized mutex, remove this function.48 /// implementation of a runtime initialized mutex, remove this function.
49 pub fn deinit(self: *StaticallyInitializedMutex) void {49 pub fn deinit(self: *StaticallyInitializedMutex) void {
50 assert(windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null) != 0);50 windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
51 windows.DeleteCriticalSection(&self.lock);51 windows.kernel32.DeleteCriticalSection(&self.lock);
52 }52 }
5353
54 pub fn acquire(self: *StaticallyInitializedMutex) Held {54 pub fn acquire(self: *StaticallyInitializedMutex) Held {
55 assert(windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null) != 0);55 windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
56 windows.EnterCriticalSection(&self.lock);56 windows.kernel32.EnterCriticalSection(&self.lock);
57 return Held{ .mutex = self };57 return Held{ .mutex = self };
58 }58 }
59 },59 },