| author | |
| committer | |
| log | 6be79d79aab204718116428c9b23be7de54e14da |
| tree | fa420ee5e4869aa41151c8d0a522a3c94b47e3ba |
| parent | 0c6ab61b228211398841cf11912c7252362009b7 |
| signature | Commit is signed but in an unrecognized format. |
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 { |
| 510 | 510 | ||
| 511 | /// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt | 511 | /// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt |
| 512 | fn setTtyColor(tty_color: TtyColor) void { | 512 | fn 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 error | 542 | // 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 | } |
| 546 | 546 | ||
| 547 | // TODO handle errors | 547 | // 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 | } |
| 900 | 900 |
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 next | 92 | // obtained some memory space that will cause the next |
| 93 | // VirtualAlloc call to fail. To handle this, we will retry | 93 | // 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 | }; |
| 102 | 104 | ||
| 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. | 1 | use @import("../bits.zig"); |
| 2 | // This includes WASI-only APIs. | ||
| 3 | 2 | ||
| 4 | pub const STDIN_FILENO = 0; | 3 | pub const STDIN_FILENO = 0; |
| 5 | pub const STDOUT_FILENO = 1; | 4 | pub const STDOUT_FILENO = 1; |
std/os/bits/windows.zig+65-1| ... | @@ -1,8 +1,65 @@ | ... | @@ -1,8 +1,65 @@ |
| 1 | use @import("../windows.zig"); | 1 | // The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime). |
| 2 | |||
| 3 | use @import("../windows/bits.zig"); | ||
| 2 | 4 | ||
| 3 | pub const fd_t = HANDLE; | 5 | pub const fd_t = HANDLE; |
| 4 | pub const pid_t = HANDLE; | 6 | pub const pid_t = HANDLE; |
| 5 | 7 | ||
| 8 | pub const sig_atomic_t = c_int; | ||
| 9 | |||
| 10 | /// maximum signal number + 1 | ||
| 11 | pub const NSIG = 23; | ||
| 12 | |||
| 13 | // Signal types | ||
| 14 | |||
| 15 | /// interrupt | ||
| 16 | pub const SIGINT = 2; | ||
| 17 | |||
| 18 | /// illegal instruction - invalid function image | ||
| 19 | pub const SIGILL = 4; | ||
| 20 | |||
| 21 | /// floating point exception | ||
| 22 | pub const SIGFPE = 8; | ||
| 23 | |||
| 24 | /// segment violation | ||
| 25 | pub const SIGSEGV = 11; | ||
| 26 | |||
| 27 | /// Software termination signal from kill | ||
| 28 | pub const SIGTERM = 15; | ||
| 29 | |||
| 30 | /// Ctrl-Break sequence | ||
| 31 | pub const SIGBREAK = 21; | ||
| 32 | |||
| 33 | /// abnormal termination triggered by abort call | ||
| 34 | pub const SIGABRT = 22; | ||
| 35 | |||
| 36 | /// SIGABRT compatible with other platforms, same as SIGABRT | ||
| 37 | pub const SIGABRT_COMPAT = 6; | ||
| 38 | |||
| 39 | // Signal action codes | ||
| 40 | |||
| 41 | /// default signal action | ||
| 42 | pub const SIG_DFL = 0; | ||
| 43 | |||
| 44 | /// ignore signal | ||
| 45 | pub const SIG_IGN = 1; | ||
| 46 | |||
| 47 | /// return current value | ||
| 48 | pub const SIG_GET = 2; | ||
| 49 | |||
| 50 | /// signal gets error | ||
| 51 | pub const SIG_SGE = 3; | ||
| 52 | |||
| 53 | /// acknowledge | ||
| 54 | pub const SIG_ACK = 4; | ||
| 55 | |||
| 56 | /// Signal error value (returned by signal call on error) | ||
| 57 | pub const SIG_ERR = -1; | ||
| 58 | |||
| 59 | pub const SEEK_SET = 0; | ||
| 60 | pub const SEEK_CUR = 1; | ||
| 61 | pub const SEEK_END = 2; | ||
| 62 | |||
| 6 | pub const EPERM = 1; | 63 | pub const EPERM = 1; |
| 7 | pub const ENOENT = 2; | 64 | pub const ENOENT = 2; |
| 8 | pub const ESRCH = 3; | 65 | pub const ESRCH = 3; |
| ... | @@ -89,3 +146,10 @@ pub const ETIME = 137; | ... | @@ -89,3 +146,10 @@ pub const ETIME = 137; |
| 89 | pub const ETIMEDOUT = 138; | 146 | pub const ETIMEDOUT = 138; |
| 90 | pub const ETXTBSY = 139; | 147 | pub const ETXTBSY = 139; |
| 91 | pub const EWOULDBLOCK = 140; | 148 | pub 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. | ||
| 153 | pub const SIGKILL = @compileError("Windows libc does not have this"); | ||
| 154 | pub const EDQUOT = @compileError("Windows libc does not have this"); | ||
| 155 | pub const TIOCGWINSZ = @compileError("Windows libc does not have this"); |
std/os/windows.zig+15-528| ... | @@ -6,537 +6,19 @@ | ... | @@ -6,537 +6,19 @@ |
| 6 | 6 | ||
| 7 | const builtin = @import("builtin"); | 7 | const builtin = @import("builtin"); |
| 8 | const std = @import("../std.zig"); | 8 | const std = @import("../std.zig"); |
| 9 | const mem = std.mem; | ||
| 9 | const assert = std.debug.assert; | 10 | const assert = std.debug.assert; |
| 11 | const math = std.math; | ||
| 10 | const maxInt = std.math.maxInt; | 12 | const maxInt = std.math.maxInt; |
| 11 | 13 | ||
| 12 | pub const is_the_target = builtin.os == .windows; | 14 | pub const is_the_target = builtin.os == .windows; |
| 13 | |||
| 14 | pub const advapi32 = @import("windows/advapi32.zig"); | 15 | pub const advapi32 = @import("windows/advapi32.zig"); |
| 15 | pub const kernel32 = @import("windows/kernel32.zig"); | 16 | pub const kernel32 = @import("windows/kernel32.zig"); |
| 16 | pub const ntdll = @import("windows/ntdll.zig"); | 17 | pub const ntdll = @import("windows/ntdll.zig"); |
| 17 | pub const ole32 = @import("windows/ole32.zig"); | 18 | pub const ole32 = @import("windows/ole32.zig"); |
| 18 | pub const shell32 = @import("windows/shell32.zig"); | 19 | pub const shell32 = @import("windows/shell32.zig"); |
| 19 | 20 | ||
| 20 | pub const ERROR = @import("windows/error.zig"); | 21 | pub use @import("windows/bits.zig"); |
| 21 | |||
| 22 | /// The standard input device. Initially, this is the console input buffer, CONIN$. | ||
| 23 | pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; | ||
| 24 | |||
| 25 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 26 | pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; | ||
| 27 | |||
| 28 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 29 | pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; | ||
| 30 | |||
| 31 | pub const SHORT = c_short; | ||
| 32 | pub const BOOL = c_int; | ||
| 33 | pub const BOOLEAN = BYTE; | ||
| 34 | pub const BYTE = u8; | ||
| 35 | pub const CHAR = u8; | ||
| 36 | pub const DWORD = u32; | ||
| 37 | pub const FLOAT = f32; | ||
| 38 | pub const HANDLE = *c_void; | ||
| 39 | pub const HCRYPTPROV = ULONG_PTR; | ||
| 40 | pub const HINSTANCE = *@OpaqueType(); | ||
| 41 | pub const HMODULE = *@OpaqueType(); | ||
| 42 | pub const FARPROC = *@OpaqueType(); | ||
| 43 | pub const INT = c_int; | ||
| 44 | pub const LPBYTE = *BYTE; | ||
| 45 | pub const LPCH = *CHAR; | ||
| 46 | pub const LPCSTR = [*]const CHAR; | ||
| 47 | pub const LPCTSTR = [*]const TCHAR; | ||
| 48 | pub const LPCVOID = *const c_void; | ||
| 49 | pub const LPDWORD = *DWORD; | ||
| 50 | pub const LPSTR = [*]CHAR; | ||
| 51 | pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR; | ||
| 52 | pub const LPVOID = *c_void; | ||
| 53 | pub const LPWSTR = [*]WCHAR; | ||
| 54 | pub const LPCWSTR = [*]const WCHAR; | ||
| 55 | pub const PVOID = *c_void; | ||
| 56 | pub const PWSTR = [*]WCHAR; | ||
| 57 | pub const SIZE_T = usize; | ||
| 58 | pub const TCHAR = if (UNICODE) WCHAR else u8; | ||
| 59 | pub const UINT = c_uint; | ||
| 60 | pub const ULONG_PTR = usize; | ||
| 61 | pub const DWORD_PTR = ULONG_PTR; | ||
| 62 | pub const UNICODE = false; | ||
| 63 | pub const WCHAR = u16; | ||
| 64 | pub const WORD = u16; | ||
| 65 | pub const LARGE_INTEGER = i64; | ||
| 66 | pub const ULONG = u32; | ||
| 67 | pub const LONG = i32; | ||
| 68 | pub const ULONGLONG = u64; | ||
| 69 | pub const LONGLONG = i64; | ||
| 70 | |||
| 71 | pub const TRUE = 1; | ||
| 72 | pub const FALSE = 0; | ||
| 73 | |||
| 74 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); | ||
| 75 | |||
| 76 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); | ||
| 77 | |||
| 78 | pub const OVERLAPPED = extern struct { | ||
| 79 | Internal: ULONG_PTR, | ||
| 80 | InternalHigh: ULONG_PTR, | ||
| 81 | Offset: DWORD, | ||
| 82 | OffsetHigh: DWORD, | ||
| 83 | hEvent: ?HANDLE, | ||
| 84 | }; | ||
| 85 | pub const LPOVERLAPPED = *OVERLAPPED; | ||
| 86 | |||
| 87 | pub const MAX_PATH = 260; | ||
| 88 | |||
| 89 | // TODO issue #305 | ||
| 90 | pub const FILE_INFO_BY_HANDLE_CLASS = u32; | ||
| 91 | pub const FileBasicInfo = 0; | ||
| 92 | pub const FileStandardInfo = 1; | ||
| 93 | pub const FileNameInfo = 2; | ||
| 94 | pub const FileRenameInfo = 3; | ||
| 95 | pub const FileDispositionInfo = 4; | ||
| 96 | pub const FileAllocationInfo = 5; | ||
| 97 | pub const FileEndOfFileInfo = 6; | ||
| 98 | pub const FileStreamInfo = 7; | ||
| 99 | pub const FileCompressionInfo = 8; | ||
| 100 | pub const FileAttributeTagInfo = 9; | ||
| 101 | pub const FileIdBothDirectoryInfo = 10; | ||
| 102 | pub const FileIdBothDirectoryRestartInfo = 11; | ||
| 103 | pub const FileIoPriorityHintInfo = 12; | ||
| 104 | pub const FileRemoteProtocolInfo = 13; | ||
| 105 | pub const FileFullDirectoryInfo = 14; | ||
| 106 | pub const FileFullDirectoryRestartInfo = 15; | ||
| 107 | pub const FileStorageInfo = 16; | ||
| 108 | pub const FileAlignmentInfo = 17; | ||
| 109 | pub const FileIdInfo = 18; | ||
| 110 | pub const FileIdExtdDirectoryInfo = 19; | ||
| 111 | pub const FileIdExtdDirectoryRestartInfo = 20; | ||
| 112 | |||
| 113 | pub 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. | ||
| 119 | pub const FILE_NAME_NORMALIZED = 0x0; | ||
| 120 | |||
| 121 | /// Return the opened file name (not normalized). | ||
| 122 | pub const FILE_NAME_OPENED = 0x8; | ||
| 123 | |||
| 124 | /// Return the path with the drive letter. This is the default. | ||
| 125 | pub const VOLUME_NAME_DOS = 0x0; | ||
| 126 | |||
| 127 | /// Return the path with a volume GUID path instead of the drive name. | ||
| 128 | pub const VOLUME_NAME_GUID = 0x1; | ||
| 129 | |||
| 130 | /// Return the path with no drive information. | ||
| 131 | pub const VOLUME_NAME_NONE = 0x4; | ||
| 132 | |||
| 133 | /// Return the path with the volume device path. | ||
| 134 | pub const VOLUME_NAME_NT = 0x2; | ||
| 135 | |||
| 136 | pub const SECURITY_ATTRIBUTES = extern struct { | ||
| 137 | nLength: DWORD, | ||
| 138 | lpSecurityDescriptor: ?*c_void, | ||
| 139 | bInheritHandle: BOOL, | ||
| 140 | }; | ||
| 141 | pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; | ||
| 142 | pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; | ||
| 143 | |||
| 144 | pub const GENERIC_READ = 0x80000000; | ||
| 145 | pub const GENERIC_WRITE = 0x40000000; | ||
| 146 | pub const GENERIC_EXECUTE = 0x20000000; | ||
| 147 | pub const GENERIC_ALL = 0x10000000; | ||
| 148 | |||
| 149 | pub const FILE_SHARE_DELETE = 0x00000004; | ||
| 150 | pub const FILE_SHARE_READ = 0x00000001; | ||
| 151 | pub const FILE_SHARE_WRITE = 0x00000002; | ||
| 152 | |||
| 153 | pub const CREATE_ALWAYS = 2; | ||
| 154 | pub const CREATE_NEW = 1; | ||
| 155 | pub const OPEN_ALWAYS = 4; | ||
| 156 | pub const OPEN_EXISTING = 3; | ||
| 157 | pub const TRUNCATE_EXISTING = 5; | ||
| 158 | |||
| 159 | pub const FILE_ATTRIBUTE_ARCHIVE = 0x20; | ||
| 160 | pub const FILE_ATTRIBUTE_COMPRESSED = 0x800; | ||
| 161 | pub const FILE_ATTRIBUTE_DEVICE = 0x40; | ||
| 162 | pub const FILE_ATTRIBUTE_DIRECTORY = 0x10; | ||
| 163 | pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000; | ||
| 164 | pub const FILE_ATTRIBUTE_HIDDEN = 0x2; | ||
| 165 | pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000; | ||
| 166 | pub const FILE_ATTRIBUTE_NORMAL = 0x80; | ||
| 167 | pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000; | ||
| 168 | pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000; | ||
| 169 | pub const FILE_ATTRIBUTE_OFFLINE = 0x1000; | ||
| 170 | pub const FILE_ATTRIBUTE_READONLY = 0x1; | ||
| 171 | pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000; | ||
| 172 | pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000; | ||
| 173 | pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400; | ||
| 174 | pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200; | ||
| 175 | pub const FILE_ATTRIBUTE_SYSTEM = 0x4; | ||
| 176 | pub const FILE_ATTRIBUTE_TEMPORARY = 0x100; | ||
| 177 | pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000; | ||
| 178 | |||
| 179 | pub const PROCESS_INFORMATION = extern struct { | ||
| 180 | hProcess: HANDLE, | ||
| 181 | hThread: HANDLE, | ||
| 182 | dwProcessId: DWORD, | ||
| 183 | dwThreadId: DWORD, | ||
| 184 | }; | ||
| 185 | |||
| 186 | pub 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 | |||
| 207 | pub const STARTF_FORCEONFEEDBACK = 0x00000040; | ||
| 208 | pub const STARTF_FORCEOFFFEEDBACK = 0x00000080; | ||
| 209 | pub const STARTF_PREVENTPINNING = 0x00002000; | ||
| 210 | pub const STARTF_RUNFULLSCREEN = 0x00000020; | ||
| 211 | pub const STARTF_TITLEISAPPID = 0x00001000; | ||
| 212 | pub const STARTF_TITLEISLINKNAME = 0x00000800; | ||
| 213 | pub const STARTF_UNTRUSTEDSOURCE = 0x00008000; | ||
| 214 | pub const STARTF_USECOUNTCHARS = 0x00000008; | ||
| 215 | pub const STARTF_USEFILLATTRIBUTE = 0x00000010; | ||
| 216 | pub const STARTF_USEHOTKEY = 0x00000200; | ||
| 217 | pub const STARTF_USEPOSITION = 0x00000004; | ||
| 218 | pub const STARTF_USESHOWWINDOW = 0x00000001; | ||
| 219 | pub const STARTF_USESIZE = 0x00000002; | ||
| 220 | pub const STARTF_USESTDHANDLES = 0x00000100; | ||
| 221 | |||
| 222 | pub const INFINITE = 4294967295; | ||
| 223 | |||
| 224 | pub const WAIT_ABANDONED = 0x00000080; | ||
| 225 | pub const WAIT_OBJECT_0 = 0x00000000; | ||
| 226 | pub const WAIT_TIMEOUT = 0x00000102; | ||
| 227 | pub const WAIT_FAILED = 0xFFFFFFFF; | ||
| 228 | |||
| 229 | pub const HANDLE_FLAG_INHERIT = 0x00000001; | ||
| 230 | pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002; | ||
| 231 | |||
| 232 | pub const MOVEFILE_COPY_ALLOWED = 2; | ||
| 233 | pub const MOVEFILE_CREATE_HARDLINK = 16; | ||
| 234 | pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4; | ||
| 235 | pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32; | ||
| 236 | pub const MOVEFILE_REPLACE_EXISTING = 1; | ||
| 237 | pub const MOVEFILE_WRITE_THROUGH = 8; | ||
| 238 | |||
| 239 | pub const FILE_BEGIN = 0; | ||
| 240 | pub const FILE_CURRENT = 1; | ||
| 241 | pub const FILE_END = 2; | ||
| 242 | |||
| 243 | pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000; | ||
| 244 | pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004; | ||
| 245 | pub const HEAP_NO_SERIALIZE = 0x00000001; | ||
| 246 | |||
| 247 | // AllocationType values | ||
| 248 | pub const MEM_COMMIT = 0x1000; | ||
| 249 | pub const MEM_RESERVE = 0x2000; | ||
| 250 | pub const MEM_RESET = 0x80000; | ||
| 251 | pub const MEM_RESET_UNDO = 0x1000000; | ||
| 252 | pub const MEM_LARGE_PAGES = 0x20000000; | ||
| 253 | pub const MEM_PHYSICAL = 0x400000; | ||
| 254 | pub const MEM_TOP_DOWN = 0x100000; | ||
| 255 | pub const MEM_WRITE_WATCH = 0x200000; | ||
| 256 | |||
| 257 | // Protect values | ||
| 258 | pub const PAGE_EXECUTE = 0x10; | ||
| 259 | pub const PAGE_EXECUTE_READ = 0x20; | ||
| 260 | pub const PAGE_EXECUTE_READWRITE = 0x40; | ||
| 261 | pub const PAGE_EXECUTE_WRITECOPY = 0x80; | ||
| 262 | pub const PAGE_NOACCESS = 0x01; | ||
| 263 | pub const PAGE_READONLY = 0x02; | ||
| 264 | pub const PAGE_READWRITE = 0x04; | ||
| 265 | pub const PAGE_WRITECOPY = 0x08; | ||
| 266 | pub const PAGE_TARGETS_INVALID = 0x40000000; | ||
| 267 | pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID | ||
| 268 | pub const PAGE_GUARD = 0x100; | ||
| 269 | pub const PAGE_NOCACHE = 0x200; | ||
| 270 | pub const PAGE_WRITECOMBINE = 0x400; | ||
| 271 | |||
| 272 | // FreeType values | ||
| 273 | pub const MEM_COALESCE_PLACEHOLDERS = 0x1; | ||
| 274 | pub const MEM_RESERVE_PLACEHOLDERS = 0x2; | ||
| 275 | pub const MEM_DECOMMIT = 0x4000; | ||
| 276 | pub const MEM_RELEASE = 0x8000; | ||
| 277 | |||
| 278 | pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD; | ||
| 279 | pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE; | ||
| 280 | |||
| 281 | pub 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 | |||
| 294 | pub const FILETIME = extern struct { | ||
| 295 | dwLowDateTime: DWORD, | ||
| 296 | dwHighDateTime: DWORD, | ||
| 297 | }; | ||
| 298 | |||
| 299 | pub 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 | |||
| 318 | pub const HRESULT = c_long; | ||
| 319 | |||
| 320 | pub const KNOWNFOLDERID = GUID; | ||
| 321 | pub 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 | |||
| 371 | pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}"); | ||
| 372 | |||
| 373 | pub const KF_FLAG_DEFAULT = 0; | ||
| 374 | pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536; | ||
| 375 | pub const KF_FLAG_CREATE = 32768; | ||
| 376 | pub const KF_FLAG_DONT_VERIFY = 16384; | ||
| 377 | pub const KF_FLAG_DONT_UNEXPAND = 8192; | ||
| 378 | pub const KF_FLAG_NO_ALIAS = 4096; | ||
| 379 | pub const KF_FLAG_INIT = 2048; | ||
| 380 | pub const KF_FLAG_DEFAULT_PATH = 1024; | ||
| 381 | pub const KF_FLAG_NOT_PARENT_RELATIVE = 512; | ||
| 382 | pub const KF_FLAG_SIMPLE_IDLIST = 256; | ||
| 383 | pub const KF_FLAG_ALIAS_ONLY = -2147483648; | ||
| 384 | |||
| 385 | pub const S_OK = 0; | ||
| 386 | pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001)); | ||
| 387 | pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002)); | ||
| 388 | pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003)); | ||
| 389 | pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004)); | ||
| 390 | pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005)); | ||
| 391 | pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF)); | ||
| 392 | pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005)); | ||
| 393 | pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006)); | ||
| 394 | pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E)); | ||
| 395 | pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057)); | ||
| 396 | |||
| 397 | pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; | ||
| 398 | pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; | ||
| 399 | pub const FILE_FLAG_NO_BUFFERING = 0x20000000; | ||
| 400 | pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000; | ||
| 401 | pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000; | ||
| 402 | pub const FILE_FLAG_OVERLAPPED = 0x40000000; | ||
| 403 | pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000; | ||
| 404 | pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000; | ||
| 405 | pub const FILE_FLAG_SESSION_AWARE = 0x00800000; | ||
| 406 | pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000; | ||
| 407 | pub const FILE_FLAG_WRITE_THROUGH = 0x80000000; | ||
| 408 | |||
| 409 | pub const SMALL_RECT = extern struct { | ||
| 410 | Left: SHORT, | ||
| 411 | Top: SHORT, | ||
| 412 | Right: SHORT, | ||
| 413 | Bottom: SHORT, | ||
| 414 | }; | ||
| 415 | |||
| 416 | pub const COORD = extern struct { | ||
| 417 | X: SHORT, | ||
| 418 | Y: SHORT, | ||
| 419 | }; | ||
| 420 | |||
| 421 | pub const CREATE_UNICODE_ENVIRONMENT = 1024; | ||
| 422 | |||
| 423 | pub const TLS_OUT_OF_INDEXES = 4294967295; | ||
| 424 | pub 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 | }; | ||
| 432 | pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY; | ||
| 433 | pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY; | ||
| 434 | |||
| 435 | pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void; | ||
| 436 | |||
| 437 | pub const PROV_RSA_FULL = 1; | ||
| 438 | |||
| 439 | pub const REGSAM = ACCESS_MASK; | ||
| 440 | pub const ACCESS_MASK = DWORD; | ||
| 441 | pub const PHKEY = *HKEY; | ||
| 442 | pub const HKEY = *HKEY__; | ||
| 443 | pub const HKEY__ = extern struct { | ||
| 444 | unused: c_int, | ||
| 445 | }; | ||
| 446 | pub const LSTATUS = LONG; | ||
| 447 | |||
| 448 | pub const FILE_NOTIFY_INFORMATION = extern struct { | ||
| 449 | NextEntryOffset: DWORD, | ||
| 450 | Action: DWORD, | ||
| 451 | FileNameLength: DWORD, | ||
| 452 | FileName: [1]WCHAR, | ||
| 453 | }; | ||
| 454 | |||
| 455 | pub const FILE_ACTION_ADDED = 0x00000001; | ||
| 456 | pub const FILE_ACTION_REMOVED = 0x00000002; | ||
| 457 | pub const FILE_ACTION_MODIFIED = 0x00000003; | ||
| 458 | pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; | ||
| 459 | pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; | ||
| 460 | |||
| 461 | pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void; | ||
| 462 | |||
| 463 | pub const FILE_LIST_DIRECTORY = 1; | ||
| 464 | |||
| 465 | pub const FILE_NOTIFY_CHANGE_CREATION = 64; | ||
| 466 | pub const FILE_NOTIFY_CHANGE_SIZE = 8; | ||
| 467 | pub const FILE_NOTIFY_CHANGE_SECURITY = 256; | ||
| 468 | pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32; | ||
| 469 | pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16; | ||
| 470 | pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; | ||
| 471 | pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; | ||
| 472 | pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; | ||
| 473 | |||
| 474 | pub 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 | |||
| 482 | pub const FOREGROUND_BLUE = 1; | ||
| 483 | pub const FOREGROUND_GREEN = 2; | ||
| 484 | pub const FOREGROUND_RED = 4; | ||
| 485 | pub const FOREGROUND_INTENSITY = 8; | ||
| 486 | |||
| 487 | pub const LIST_ENTRY = extern struct { | ||
| 488 | Flink: *LIST_ENTRY, | ||
| 489 | Blink: *LIST_ENTRY, | ||
| 490 | }; | ||
| 491 | |||
| 492 | pub 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 | |||
| 504 | pub 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 | |||
| 513 | pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION; | ||
| 514 | pub const INIT_ONCE = RTL_RUN_ONCE; | ||
| 515 | pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT; | ||
| 516 | pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL; | ||
| 517 | |||
| 518 | pub const RTL_RUN_ONCE = extern struct { | ||
| 519 | Ptr: ?*c_void, | ||
| 520 | }; | ||
| 521 | |||
| 522 | pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null }; | ||
| 523 | |||
| 524 | pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED; | ||
| 525 | pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED; | ||
| 526 | pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE; | ||
| 527 | pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY; | ||
| 528 | pub 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 | ||
| 539 | pub const PATH_MAX_WIDE = 32767; | ||
| 540 | 22 | ||
| 541 | pub const CreateFileError = error{ | 23 | pub 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{ |
| 787 | 269 | ||
| 788 | /// This function is for blocking file descriptors only. For non-blocking, see | 270 | /// This function is for blocking file descriptors only. For non-blocking, see |
| 789 | /// `WriteFileAsync`. | 271 | /// `WriteFileAsync`. |
| 790 | pub fn WriteFile(in_hFile: HANDLE, bytes: []const u8) WriteFileError!void { | 272 | pub 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 bytes | 274 | // 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 | }; |
| 810 | 292 | ||
| 811 | /// The result is a slice of out_buffer, indexed from 0. | 293 | /// The result is a slice of `buffer`, indexed from 0. |
| 812 | pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 { | 294 | pub 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 | } |
| 832 | 315 | ||
| 833 | pub const CreateSymbolicLinkError = error{Unexpected}; | 316 | pub 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 | } |
| 1220 | 703 | ||
| 704 | pub 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 | |||
| 1221 | pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 { | 708 | pub 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 @@ |
| 1 | use @import("../windows.zig"); | 1 | use @import("bits.zig"); |
| 2 | 2 | ||
| 3 | pub extern "advapi32" stdcallcc fn RegOpenKeyExW( | 3 | pub 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 | |||
| 3 | const builtin = @import("builtin"); | ||
| 4 | const std = @import("../../std.zig"); | ||
| 5 | const assert = std.debug.assert; | ||
| 6 | const maxInt = std.math.maxInt; | ||
| 7 | |||
| 8 | pub const ERROR = @import("error.zig"); | ||
| 9 | |||
| 10 | /// The standard input device. Initially, this is the console input buffer, CONIN$. | ||
| 11 | pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1; | ||
| 12 | |||
| 13 | /// The standard output device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 14 | pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1; | ||
| 15 | |||
| 16 | /// The standard error device. Initially, this is the active console screen buffer, CONOUT$. | ||
| 17 | pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1; | ||
| 18 | |||
| 19 | pub const SHORT = c_short; | ||
| 20 | pub const BOOL = c_int; | ||
| 21 | pub const BOOLEAN = BYTE; | ||
| 22 | pub const BYTE = u8; | ||
| 23 | pub const CHAR = u8; | ||
| 24 | pub const DWORD = u32; | ||
| 25 | pub const FLOAT = f32; | ||
| 26 | pub const HANDLE = *c_void; | ||
| 27 | pub const HCRYPTPROV = ULONG_PTR; | ||
| 28 | pub const HINSTANCE = *@OpaqueType(); | ||
| 29 | pub const HMODULE = *@OpaqueType(); | ||
| 30 | pub const FARPROC = *@OpaqueType(); | ||
| 31 | pub const INT = c_int; | ||
| 32 | pub const LPBYTE = *BYTE; | ||
| 33 | pub const LPCH = *CHAR; | ||
| 34 | pub const LPCSTR = [*]const CHAR; | ||
| 35 | pub const LPCTSTR = [*]const TCHAR; | ||
| 36 | pub const LPCVOID = *const c_void; | ||
| 37 | pub const LPDWORD = *DWORD; | ||
| 38 | pub const LPSTR = [*]CHAR; | ||
| 39 | pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR; | ||
| 40 | pub const LPVOID = *c_void; | ||
| 41 | pub const LPWSTR = [*]WCHAR; | ||
| 42 | pub const LPCWSTR = [*]const WCHAR; | ||
| 43 | pub const PVOID = *c_void; | ||
| 44 | pub const PWSTR = [*]WCHAR; | ||
| 45 | pub const SIZE_T = usize; | ||
| 46 | pub const TCHAR = if (UNICODE) WCHAR else u8; | ||
| 47 | pub const UINT = c_uint; | ||
| 48 | pub const ULONG_PTR = usize; | ||
| 49 | pub const DWORD_PTR = ULONG_PTR; | ||
| 50 | pub const UNICODE = false; | ||
| 51 | pub const WCHAR = u16; | ||
| 52 | pub const WORD = u16; | ||
| 53 | pub const LARGE_INTEGER = i64; | ||
| 54 | pub const ULONG = u32; | ||
| 55 | pub const LONG = i32; | ||
| 56 | pub const ULONGLONG = u64; | ||
| 57 | pub const LONGLONG = i64; | ||
| 58 | |||
| 59 | pub const TRUE = 1; | ||
| 60 | pub const FALSE = 0; | ||
| 61 | |||
| 62 | pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize)); | ||
| 63 | |||
| 64 | pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD)); | ||
| 65 | |||
| 66 | pub const OVERLAPPED = extern struct { | ||
| 67 | Internal: ULONG_PTR, | ||
| 68 | InternalHigh: ULONG_PTR, | ||
| 69 | Offset: DWORD, | ||
| 70 | OffsetHigh: DWORD, | ||
| 71 | hEvent: ?HANDLE, | ||
| 72 | }; | ||
| 73 | pub const LPOVERLAPPED = *OVERLAPPED; | ||
| 74 | |||
| 75 | pub const MAX_PATH = 260; | ||
| 76 | |||
| 77 | // TODO issue #305 | ||
| 78 | pub const FILE_INFO_BY_HANDLE_CLASS = u32; | ||
| 79 | pub const FileBasicInfo = 0; | ||
| 80 | pub const FileStandardInfo = 1; | ||
| 81 | pub const FileNameInfo = 2; | ||
| 82 | pub const FileRenameInfo = 3; | ||
| 83 | pub const FileDispositionInfo = 4; | ||
| 84 | pub const FileAllocationInfo = 5; | ||
| 85 | pub const FileEndOfFileInfo = 6; | ||
| 86 | pub const FileStreamInfo = 7; | ||
| 87 | pub const FileCompressionInfo = 8; | ||
| 88 | pub const FileAttributeTagInfo = 9; | ||
| 89 | pub const FileIdBothDirectoryInfo = 10; | ||
| 90 | pub const FileIdBothDirectoryRestartInfo = 11; | ||
| 91 | pub const FileIoPriorityHintInfo = 12; | ||
| 92 | pub const FileRemoteProtocolInfo = 13; | ||
| 93 | pub const FileFullDirectoryInfo = 14; | ||
| 94 | pub const FileFullDirectoryRestartInfo = 15; | ||
| 95 | pub const FileStorageInfo = 16; | ||
| 96 | pub const FileAlignmentInfo = 17; | ||
| 97 | pub const FileIdInfo = 18; | ||
| 98 | pub const FileIdExtdDirectoryInfo = 19; | ||
| 99 | pub const FileIdExtdDirectoryRestartInfo = 20; | ||
| 100 | |||
| 101 | pub 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. | ||
| 107 | pub const FILE_NAME_NORMALIZED = 0x0; | ||
| 108 | |||
| 109 | /// Return the opened file name (not normalized). | ||
| 110 | pub const FILE_NAME_OPENED = 0x8; | ||
| 111 | |||
| 112 | /// Return the path with the drive letter. This is the default. | ||
| 113 | pub const VOLUME_NAME_DOS = 0x0; | ||
| 114 | |||
| 115 | /// Return the path with a volume GUID path instead of the drive name. | ||
| 116 | pub const VOLUME_NAME_GUID = 0x1; | ||
| 117 | |||
| 118 | /// Return the path with no drive information. | ||
| 119 | pub const VOLUME_NAME_NONE = 0x4; | ||
| 120 | |||
| 121 | /// Return the path with the volume device path. | ||
| 122 | pub const VOLUME_NAME_NT = 0x2; | ||
| 123 | |||
| 124 | pub const SECURITY_ATTRIBUTES = extern struct { | ||
| 125 | nLength: DWORD, | ||
| 126 | lpSecurityDescriptor: ?*c_void, | ||
| 127 | bInheritHandle: BOOL, | ||
| 128 | }; | ||
| 129 | pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; | ||
| 130 | pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES; | ||
| 131 | |||
| 132 | pub const GENERIC_READ = 0x80000000; | ||
| 133 | pub const GENERIC_WRITE = 0x40000000; | ||
| 134 | pub const GENERIC_EXECUTE = 0x20000000; | ||
| 135 | pub const GENERIC_ALL = 0x10000000; | ||
| 136 | |||
| 137 | pub const FILE_SHARE_DELETE = 0x00000004; | ||
| 138 | pub const FILE_SHARE_READ = 0x00000001; | ||
| 139 | pub const FILE_SHARE_WRITE = 0x00000002; | ||
| 140 | |||
| 141 | pub const CREATE_ALWAYS = 2; | ||
| 142 | pub const CREATE_NEW = 1; | ||
| 143 | pub const OPEN_ALWAYS = 4; | ||
| 144 | pub const OPEN_EXISTING = 3; | ||
| 145 | pub const TRUNCATE_EXISTING = 5; | ||
| 146 | |||
| 147 | pub const FILE_ATTRIBUTE_ARCHIVE = 0x20; | ||
| 148 | pub const FILE_ATTRIBUTE_COMPRESSED = 0x800; | ||
| 149 | pub const FILE_ATTRIBUTE_DEVICE = 0x40; | ||
| 150 | pub const FILE_ATTRIBUTE_DIRECTORY = 0x10; | ||
| 151 | pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000; | ||
| 152 | pub const FILE_ATTRIBUTE_HIDDEN = 0x2; | ||
| 153 | pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000; | ||
| 154 | pub const FILE_ATTRIBUTE_NORMAL = 0x80; | ||
| 155 | pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000; | ||
| 156 | pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000; | ||
| 157 | pub const FILE_ATTRIBUTE_OFFLINE = 0x1000; | ||
| 158 | pub const FILE_ATTRIBUTE_READONLY = 0x1; | ||
| 159 | pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000; | ||
| 160 | pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000; | ||
| 161 | pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400; | ||
| 162 | pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200; | ||
| 163 | pub const FILE_ATTRIBUTE_SYSTEM = 0x4; | ||
| 164 | pub const FILE_ATTRIBUTE_TEMPORARY = 0x100; | ||
| 165 | pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000; | ||
| 166 | |||
| 167 | pub const PROCESS_INFORMATION = extern struct { | ||
| 168 | hProcess: HANDLE, | ||
| 169 | hThread: HANDLE, | ||
| 170 | dwProcessId: DWORD, | ||
| 171 | dwThreadId: DWORD, | ||
| 172 | }; | ||
| 173 | |||
| 174 | pub 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 | |||
| 195 | pub const STARTF_FORCEONFEEDBACK = 0x00000040; | ||
| 196 | pub const STARTF_FORCEOFFFEEDBACK = 0x00000080; | ||
| 197 | pub const STARTF_PREVENTPINNING = 0x00002000; | ||
| 198 | pub const STARTF_RUNFULLSCREEN = 0x00000020; | ||
| 199 | pub const STARTF_TITLEISAPPID = 0x00001000; | ||
| 200 | pub const STARTF_TITLEISLINKNAME = 0x00000800; | ||
| 201 | pub const STARTF_UNTRUSTEDSOURCE = 0x00008000; | ||
| 202 | pub const STARTF_USECOUNTCHARS = 0x00000008; | ||
| 203 | pub const STARTF_USEFILLATTRIBUTE = 0x00000010; | ||
| 204 | pub const STARTF_USEHOTKEY = 0x00000200; | ||
| 205 | pub const STARTF_USEPOSITION = 0x00000004; | ||
| 206 | pub const STARTF_USESHOWWINDOW = 0x00000001; | ||
| 207 | pub const STARTF_USESIZE = 0x00000002; | ||
| 208 | pub const STARTF_USESTDHANDLES = 0x00000100; | ||
| 209 | |||
| 210 | pub const INFINITE = 4294967295; | ||
| 211 | |||
| 212 | pub const WAIT_ABANDONED = 0x00000080; | ||
| 213 | pub const WAIT_OBJECT_0 = 0x00000000; | ||
| 214 | pub const WAIT_TIMEOUT = 0x00000102; | ||
| 215 | pub const WAIT_FAILED = 0xFFFFFFFF; | ||
| 216 | |||
| 217 | pub const HANDLE_FLAG_INHERIT = 0x00000001; | ||
| 218 | pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002; | ||
| 219 | |||
| 220 | pub const MOVEFILE_COPY_ALLOWED = 2; | ||
| 221 | pub const MOVEFILE_CREATE_HARDLINK = 16; | ||
| 222 | pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4; | ||
| 223 | pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32; | ||
| 224 | pub const MOVEFILE_REPLACE_EXISTING = 1; | ||
| 225 | pub const MOVEFILE_WRITE_THROUGH = 8; | ||
| 226 | |||
| 227 | pub const FILE_BEGIN = 0; | ||
| 228 | pub const FILE_CURRENT = 1; | ||
| 229 | pub const FILE_END = 2; | ||
| 230 | |||
| 231 | pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000; | ||
| 232 | pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004; | ||
| 233 | pub const HEAP_NO_SERIALIZE = 0x00000001; | ||
| 234 | |||
| 235 | // AllocationType values | ||
| 236 | pub const MEM_COMMIT = 0x1000; | ||
| 237 | pub const MEM_RESERVE = 0x2000; | ||
| 238 | pub const MEM_RESET = 0x80000; | ||
| 239 | pub const MEM_RESET_UNDO = 0x1000000; | ||
| 240 | pub const MEM_LARGE_PAGES = 0x20000000; | ||
| 241 | pub const MEM_PHYSICAL = 0x400000; | ||
| 242 | pub const MEM_TOP_DOWN = 0x100000; | ||
| 243 | pub const MEM_WRITE_WATCH = 0x200000; | ||
| 244 | |||
| 245 | // Protect values | ||
| 246 | pub const PAGE_EXECUTE = 0x10; | ||
| 247 | pub const PAGE_EXECUTE_READ = 0x20; | ||
| 248 | pub const PAGE_EXECUTE_READWRITE = 0x40; | ||
| 249 | pub const PAGE_EXECUTE_WRITECOPY = 0x80; | ||
| 250 | pub const PAGE_NOACCESS = 0x01; | ||
| 251 | pub const PAGE_READONLY = 0x02; | ||
| 252 | pub const PAGE_READWRITE = 0x04; | ||
| 253 | pub const PAGE_WRITECOPY = 0x08; | ||
| 254 | pub const PAGE_TARGETS_INVALID = 0x40000000; | ||
| 255 | pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID | ||
| 256 | pub const PAGE_GUARD = 0x100; | ||
| 257 | pub const PAGE_NOCACHE = 0x200; | ||
| 258 | pub const PAGE_WRITECOMBINE = 0x400; | ||
| 259 | |||
| 260 | // FreeType values | ||
| 261 | pub const MEM_COALESCE_PLACEHOLDERS = 0x1; | ||
| 262 | pub const MEM_RESERVE_PLACEHOLDERS = 0x2; | ||
| 263 | pub const MEM_DECOMMIT = 0x4000; | ||
| 264 | pub const MEM_RELEASE = 0x8000; | ||
| 265 | |||
| 266 | pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD; | ||
| 267 | pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE; | ||
| 268 | |||
| 269 | pub 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 | |||
| 282 | pub const FILETIME = extern struct { | ||
| 283 | dwLowDateTime: DWORD, | ||
| 284 | dwHighDateTime: DWORD, | ||
| 285 | }; | ||
| 286 | |||
| 287 | pub 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 | |||
| 306 | pub const HRESULT = c_long; | ||
| 307 | |||
| 308 | pub const KNOWNFOLDERID = GUID; | ||
| 309 | pub 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 | |||
| 359 | pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}"); | ||
| 360 | |||
| 361 | pub const KF_FLAG_DEFAULT = 0; | ||
| 362 | pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536; | ||
| 363 | pub const KF_FLAG_CREATE = 32768; | ||
| 364 | pub const KF_FLAG_DONT_VERIFY = 16384; | ||
| 365 | pub const KF_FLAG_DONT_UNEXPAND = 8192; | ||
| 366 | pub const KF_FLAG_NO_ALIAS = 4096; | ||
| 367 | pub const KF_FLAG_INIT = 2048; | ||
| 368 | pub const KF_FLAG_DEFAULT_PATH = 1024; | ||
| 369 | pub const KF_FLAG_NOT_PARENT_RELATIVE = 512; | ||
| 370 | pub const KF_FLAG_SIMPLE_IDLIST = 256; | ||
| 371 | pub const KF_FLAG_ALIAS_ONLY = -2147483648; | ||
| 372 | |||
| 373 | pub const S_OK = 0; | ||
| 374 | pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001)); | ||
| 375 | pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002)); | ||
| 376 | pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003)); | ||
| 377 | pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004)); | ||
| 378 | pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005)); | ||
| 379 | pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF)); | ||
| 380 | pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005)); | ||
| 381 | pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006)); | ||
| 382 | pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E)); | ||
| 383 | pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057)); | ||
| 384 | |||
| 385 | pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000; | ||
| 386 | pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000; | ||
| 387 | pub const FILE_FLAG_NO_BUFFERING = 0x20000000; | ||
| 388 | pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000; | ||
| 389 | pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000; | ||
| 390 | pub const FILE_FLAG_OVERLAPPED = 0x40000000; | ||
| 391 | pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000; | ||
| 392 | pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000; | ||
| 393 | pub const FILE_FLAG_SESSION_AWARE = 0x00800000; | ||
| 394 | pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000; | ||
| 395 | pub const FILE_FLAG_WRITE_THROUGH = 0x80000000; | ||
| 396 | |||
| 397 | pub const SMALL_RECT = extern struct { | ||
| 398 | Left: SHORT, | ||
| 399 | Top: SHORT, | ||
| 400 | Right: SHORT, | ||
| 401 | Bottom: SHORT, | ||
| 402 | }; | ||
| 403 | |||
| 404 | pub const COORD = extern struct { | ||
| 405 | X: SHORT, | ||
| 406 | Y: SHORT, | ||
| 407 | }; | ||
| 408 | |||
| 409 | pub const CREATE_UNICODE_ENVIRONMENT = 1024; | ||
| 410 | |||
| 411 | pub const TLS_OUT_OF_INDEXES = 4294967295; | ||
| 412 | pub 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 | }; | ||
| 420 | pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY; | ||
| 421 | pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY; | ||
| 422 | |||
| 423 | pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void; | ||
| 424 | |||
| 425 | pub const PROV_RSA_FULL = 1; | ||
| 426 | |||
| 427 | pub const REGSAM = ACCESS_MASK; | ||
| 428 | pub const ACCESS_MASK = DWORD; | ||
| 429 | pub const PHKEY = *HKEY; | ||
| 430 | pub const HKEY = *HKEY__; | ||
| 431 | pub const HKEY__ = extern struct { | ||
| 432 | unused: c_int, | ||
| 433 | }; | ||
| 434 | pub const LSTATUS = LONG; | ||
| 435 | |||
| 436 | pub const FILE_NOTIFY_INFORMATION = extern struct { | ||
| 437 | NextEntryOffset: DWORD, | ||
| 438 | Action: DWORD, | ||
| 439 | FileNameLength: DWORD, | ||
| 440 | FileName: [1]WCHAR, | ||
| 441 | }; | ||
| 442 | |||
| 443 | pub const FILE_ACTION_ADDED = 0x00000001; | ||
| 444 | pub const FILE_ACTION_REMOVED = 0x00000002; | ||
| 445 | pub const FILE_ACTION_MODIFIED = 0x00000003; | ||
| 446 | pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004; | ||
| 447 | pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005; | ||
| 448 | |||
| 449 | pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void; | ||
| 450 | |||
| 451 | pub const FILE_LIST_DIRECTORY = 1; | ||
| 452 | |||
| 453 | pub const FILE_NOTIFY_CHANGE_CREATION = 64; | ||
| 454 | pub const FILE_NOTIFY_CHANGE_SIZE = 8; | ||
| 455 | pub const FILE_NOTIFY_CHANGE_SECURITY = 256; | ||
| 456 | pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32; | ||
| 457 | pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16; | ||
| 458 | pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2; | ||
| 459 | pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1; | ||
| 460 | pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4; | ||
| 461 | |||
| 462 | pub 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 | |||
| 470 | pub const FOREGROUND_BLUE = 1; | ||
| 471 | pub const FOREGROUND_GREEN = 2; | ||
| 472 | pub const FOREGROUND_RED = 4; | ||
| 473 | pub const FOREGROUND_INTENSITY = 8; | ||
| 474 | |||
| 475 | pub const LIST_ENTRY = extern struct { | ||
| 476 | Flink: *LIST_ENTRY, | ||
| 477 | Blink: *LIST_ENTRY, | ||
| 478 | }; | ||
| 479 | |||
| 480 | pub 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 | |||
| 492 | pub 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 | |||
| 501 | pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION; | ||
| 502 | pub const INIT_ONCE = RTL_RUN_ONCE; | ||
| 503 | pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT; | ||
| 504 | pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL; | ||
| 505 | |||
| 506 | pub const RTL_RUN_ONCE = extern struct { | ||
| 507 | Ptr: ?*c_void, | ||
| 508 | }; | ||
| 509 | |||
| 510 | pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null }; | ||
| 511 | |||
| 512 | pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED; | ||
| 513 | pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED; | ||
| 514 | pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE; | ||
| 515 | pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY; | ||
| 516 | pub 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 | ||
| 527 | pub const PATH_MAX_WIDE = 32767; | ||
std/os/windows/kernel32.zig+1-1| ... | @@ -1,4 +1,4 @@ | ... | @@ -1,4 +1,4 @@ |
| 1 | use @import("../windows.zig"); | 1 | use @import("bits.zig"); |
| 2 | 2 | ||
| 3 | pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL; | 3 | pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL; |
| 4 | 4 |
std/os/windows/ntdll.zig+1-1| ... | @@ -1,3 +1,3 @@ | ... | @@ -1,3 +1,3 @@ |
| 1 | use @import("../windows.zig"); | 1 | use @import("bits.zig"); |
| 2 | 2 | ||
| 3 | pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD; | 3 | pub 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 @@ |
| 1 | use @import("../windows.zig"); | 1 | use @import("bits.zig"); |
| 2 | 2 | ||
| 3 | pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void; | 3 | pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void; |
| 4 | pub extern "ole32" stdcallcc fn CoUninitialize() void; | 4 | pub extern "ole32" stdcallcc fn CoUninitialize() void; |
std/os/windows/shell32.zig+1-1| ... | @@ -1,3 +1,3 @@ | ... | @@ -1,3 +1,3 @@ |
| 1 | use @import("../windows.zig"); | 1 | use @import("bits.zig"); |
| 2 | 2 | ||
| 3 | pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT; | 3 | pub 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 | } |
| 663 | 663 | ||
| 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 | }; |
| 149 | 149 | ||
| 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 | } |
| 67 | 67 | ||
| 68 | // TODO https://github.com/ziglang/zig/issues/265 | 68 | // 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, |
| 24 | 24 | ||
| 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 | }; |
| 29 | 29 | ||
| ... | @@ -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 | } |
| 46 | 46 | ||
| 47 | /// TODO: once https://github.com/ziglang/zig/issues/287 is solved and std.Mutex has a better | 47 | /// 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 | } |
| 53 | 53 | ||
| 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 | }, |