Commit 6be79d79aa
Changed files (17)
std/os/bits/wasi.zig
@@ -1,5 +1,4 @@
-// Declarations that are intended to be imported into the POSIX namespace.
-// This includes WASI-only APIs.
+use @import("../bits.zig");
pub const STDIN_FILENO = 0;
pub const STDOUT_FILENO = 1;
std/os/bits/windows.zig
@@ -1,8 +1,65 @@
-use @import("../windows.zig");
+// The reference for these types and values is Microsoft Windows's ucrt (Universal C RunTime).
+
+use @import("../windows/bits.zig");
pub const fd_t = HANDLE;
pub const pid_t = HANDLE;
+pub const sig_atomic_t = c_int;
+
+/// maximum signal number + 1
+pub const NSIG = 23;
+
+// Signal types
+
+/// interrupt
+pub const SIGINT = 2;
+
+/// illegal instruction - invalid function image
+pub const SIGILL = 4;
+
+/// floating point exception
+pub const SIGFPE = 8;
+
+/// segment violation
+pub const SIGSEGV = 11;
+
+/// Software termination signal from kill
+pub const SIGTERM = 15;
+
+/// Ctrl-Break sequence
+pub const SIGBREAK = 21;
+
+/// abnormal termination triggered by abort call
+pub const SIGABRT = 22;
+
+/// SIGABRT compatible with other platforms, same as SIGABRT
+pub const SIGABRT_COMPAT = 6;
+
+// Signal action codes
+
+/// default signal action
+pub const SIG_DFL = 0;
+
+/// ignore signal
+pub const SIG_IGN = 1;
+
+/// return current value
+pub const SIG_GET = 2;
+
+/// signal gets error
+pub const SIG_SGE = 3;
+
+/// acknowledge
+pub const SIG_ACK = 4;
+
+/// Signal error value (returned by signal call on error)
+pub const SIG_ERR = -1;
+
+pub const SEEK_SET = 0;
+pub const SEEK_CUR = 1;
+pub const SEEK_END = 2;
+
pub const EPERM = 1;
pub const ENOENT = 2;
pub const ESRCH = 3;
@@ -89,3 +146,10 @@ pub const ETIME = 137;
pub const ETIMEDOUT = 138;
pub const ETXTBSY = 139;
pub const EWOULDBLOCK = 140;
+
+// These are workarounds for "use of undeclared identifier" compile errors
+// TODO make the compiler even more lazy. don't emit "use of undeclared identifier" errors
+// for if branches that aren't taken.
+pub const SIGKILL = @compileError("Windows libc does not have this");
+pub const EDQUOT = @compileError("Windows libc does not have this");
+pub const TIOCGWINSZ = @compileError("Windows libc does not have this");
std/os/windows/advapi32.zig
@@ -1,4 +1,4 @@
-use @import("../windows.zig");
+use @import("bits.zig");
pub extern "advapi32" stdcallcc fn RegOpenKeyExW(
hKey: HKEY,
std/os/windows/bits.zig
@@ -0,0 +1,527 @@
+// Platform-dependent types and values that are used along with OS-specific APIs.
+
+const builtin = @import("builtin");
+const std = @import("../../std.zig");
+const assert = std.debug.assert;
+const maxInt = std.math.maxInt;
+
+pub const ERROR = @import("error.zig");
+
+/// The standard input device. Initially, this is the console input buffer, CONIN$.
+pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
+
+/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
+pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
+
+/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
+pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
+
+pub const SHORT = c_short;
+pub const BOOL = c_int;
+pub const BOOLEAN = BYTE;
+pub const BYTE = u8;
+pub const CHAR = u8;
+pub const DWORD = u32;
+pub const FLOAT = f32;
+pub const HANDLE = *c_void;
+pub const HCRYPTPROV = ULONG_PTR;
+pub const HINSTANCE = *@OpaqueType();
+pub const HMODULE = *@OpaqueType();
+pub const FARPROC = *@OpaqueType();
+pub const INT = c_int;
+pub const LPBYTE = *BYTE;
+pub const LPCH = *CHAR;
+pub const LPCSTR = [*]const CHAR;
+pub const LPCTSTR = [*]const TCHAR;
+pub const LPCVOID = *const c_void;
+pub const LPDWORD = *DWORD;
+pub const LPSTR = [*]CHAR;
+pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
+pub const LPVOID = *c_void;
+pub const LPWSTR = [*]WCHAR;
+pub const LPCWSTR = [*]const WCHAR;
+pub const PVOID = *c_void;
+pub const PWSTR = [*]WCHAR;
+pub const SIZE_T = usize;
+pub const TCHAR = if (UNICODE) WCHAR else u8;
+pub const UINT = c_uint;
+pub const ULONG_PTR = usize;
+pub const DWORD_PTR = ULONG_PTR;
+pub const UNICODE = false;
+pub const WCHAR = u16;
+pub const WORD = u16;
+pub const LARGE_INTEGER = i64;
+pub const ULONG = u32;
+pub const LONG = i32;
+pub const ULONGLONG = u64;
+pub const LONGLONG = i64;
+
+pub const TRUE = 1;
+pub const FALSE = 0;
+
+pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
+
+pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
+
+pub const OVERLAPPED = extern struct {
+ Internal: ULONG_PTR,
+ InternalHigh: ULONG_PTR,
+ Offset: DWORD,
+ OffsetHigh: DWORD,
+ hEvent: ?HANDLE,
+};
+pub const LPOVERLAPPED = *OVERLAPPED;
+
+pub const MAX_PATH = 260;
+
+// TODO issue #305
+pub const FILE_INFO_BY_HANDLE_CLASS = u32;
+pub const FileBasicInfo = 0;
+pub const FileStandardInfo = 1;
+pub const FileNameInfo = 2;
+pub const FileRenameInfo = 3;
+pub const FileDispositionInfo = 4;
+pub const FileAllocationInfo = 5;
+pub const FileEndOfFileInfo = 6;
+pub const FileStreamInfo = 7;
+pub const FileCompressionInfo = 8;
+pub const FileAttributeTagInfo = 9;
+pub const FileIdBothDirectoryInfo = 10;
+pub const FileIdBothDirectoryRestartInfo = 11;
+pub const FileIoPriorityHintInfo = 12;
+pub const FileRemoteProtocolInfo = 13;
+pub const FileFullDirectoryInfo = 14;
+pub const FileFullDirectoryRestartInfo = 15;
+pub const FileStorageInfo = 16;
+pub const FileAlignmentInfo = 17;
+pub const FileIdInfo = 18;
+pub const FileIdExtdDirectoryInfo = 19;
+pub const FileIdExtdDirectoryRestartInfo = 20;
+
+pub const FILE_NAME_INFO = extern struct {
+ FileNameLength: DWORD,
+ FileName: [1]WCHAR,
+};
+
+/// Return the normalized drive name. This is the default.
+pub const FILE_NAME_NORMALIZED = 0x0;
+
+/// Return the opened file name (not normalized).
+pub const FILE_NAME_OPENED = 0x8;
+
+/// Return the path with the drive letter. This is the default.
+pub const VOLUME_NAME_DOS = 0x0;
+
+/// Return the path with a volume GUID path instead of the drive name.
+pub const VOLUME_NAME_GUID = 0x1;
+
+/// Return the path with no drive information.
+pub const VOLUME_NAME_NONE = 0x4;
+
+/// Return the path with the volume device path.
+pub const VOLUME_NAME_NT = 0x2;
+
+pub const SECURITY_ATTRIBUTES = extern struct {
+ nLength: DWORD,
+ lpSecurityDescriptor: ?*c_void,
+ bInheritHandle: BOOL,
+};
+pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
+pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
+
+pub const GENERIC_READ = 0x80000000;
+pub const GENERIC_WRITE = 0x40000000;
+pub const GENERIC_EXECUTE = 0x20000000;
+pub const GENERIC_ALL = 0x10000000;
+
+pub const FILE_SHARE_DELETE = 0x00000004;
+pub const FILE_SHARE_READ = 0x00000001;
+pub const FILE_SHARE_WRITE = 0x00000002;
+
+pub const CREATE_ALWAYS = 2;
+pub const CREATE_NEW = 1;
+pub const OPEN_ALWAYS = 4;
+pub const OPEN_EXISTING = 3;
+pub const TRUNCATE_EXISTING = 5;
+
+pub const FILE_ATTRIBUTE_ARCHIVE = 0x20;
+pub const FILE_ATTRIBUTE_COMPRESSED = 0x800;
+pub const FILE_ATTRIBUTE_DEVICE = 0x40;
+pub const FILE_ATTRIBUTE_DIRECTORY = 0x10;
+pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
+pub const FILE_ATTRIBUTE_HIDDEN = 0x2;
+pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000;
+pub const FILE_ATTRIBUTE_NORMAL = 0x80;
+pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000;
+pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000;
+pub const FILE_ATTRIBUTE_OFFLINE = 0x1000;
+pub const FILE_ATTRIBUTE_READONLY = 0x1;
+pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000;
+pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000;
+pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
+pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200;
+pub const FILE_ATTRIBUTE_SYSTEM = 0x4;
+pub const FILE_ATTRIBUTE_TEMPORARY = 0x100;
+pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000;
+
+pub const PROCESS_INFORMATION = extern struct {
+ hProcess: HANDLE,
+ hThread: HANDLE,
+ dwProcessId: DWORD,
+ dwThreadId: DWORD,
+};
+
+pub const STARTUPINFOW = extern struct {
+ cb: DWORD,
+ lpReserved: ?LPWSTR,
+ lpDesktop: ?LPWSTR,
+ lpTitle: ?LPWSTR,
+ dwX: DWORD,
+ dwY: DWORD,
+ dwXSize: DWORD,
+ dwYSize: DWORD,
+ dwXCountChars: DWORD,
+ dwYCountChars: DWORD,
+ dwFillAttribute: DWORD,
+ dwFlags: DWORD,
+ wShowWindow: WORD,
+ cbReserved2: WORD,
+ lpReserved2: ?LPBYTE,
+ hStdInput: ?HANDLE,
+ hStdOutput: ?HANDLE,
+ hStdError: ?HANDLE,
+};
+
+pub const STARTF_FORCEONFEEDBACK = 0x00000040;
+pub const STARTF_FORCEOFFFEEDBACK = 0x00000080;
+pub const STARTF_PREVENTPINNING = 0x00002000;
+pub const STARTF_RUNFULLSCREEN = 0x00000020;
+pub const STARTF_TITLEISAPPID = 0x00001000;
+pub const STARTF_TITLEISLINKNAME = 0x00000800;
+pub const STARTF_UNTRUSTEDSOURCE = 0x00008000;
+pub const STARTF_USECOUNTCHARS = 0x00000008;
+pub const STARTF_USEFILLATTRIBUTE = 0x00000010;
+pub const STARTF_USEHOTKEY = 0x00000200;
+pub const STARTF_USEPOSITION = 0x00000004;
+pub const STARTF_USESHOWWINDOW = 0x00000001;
+pub const STARTF_USESIZE = 0x00000002;
+pub const STARTF_USESTDHANDLES = 0x00000100;
+
+pub const INFINITE = 4294967295;
+
+pub const WAIT_ABANDONED = 0x00000080;
+pub const WAIT_OBJECT_0 = 0x00000000;
+pub const WAIT_TIMEOUT = 0x00000102;
+pub const WAIT_FAILED = 0xFFFFFFFF;
+
+pub const HANDLE_FLAG_INHERIT = 0x00000001;
+pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002;
+
+pub const MOVEFILE_COPY_ALLOWED = 2;
+pub const MOVEFILE_CREATE_HARDLINK = 16;
+pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
+pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
+pub const MOVEFILE_REPLACE_EXISTING = 1;
+pub const MOVEFILE_WRITE_THROUGH = 8;
+
+pub const FILE_BEGIN = 0;
+pub const FILE_CURRENT = 1;
+pub const FILE_END = 2;
+
+pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
+pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
+pub const HEAP_NO_SERIALIZE = 0x00000001;
+
+// AllocationType values
+pub const MEM_COMMIT = 0x1000;
+pub const MEM_RESERVE = 0x2000;
+pub const MEM_RESET = 0x80000;
+pub const MEM_RESET_UNDO = 0x1000000;
+pub const MEM_LARGE_PAGES = 0x20000000;
+pub const MEM_PHYSICAL = 0x400000;
+pub const MEM_TOP_DOWN = 0x100000;
+pub const MEM_WRITE_WATCH = 0x200000;
+
+// Protect values
+pub const PAGE_EXECUTE = 0x10;
+pub const PAGE_EXECUTE_READ = 0x20;
+pub const PAGE_EXECUTE_READWRITE = 0x40;
+pub const PAGE_EXECUTE_WRITECOPY = 0x80;
+pub const PAGE_NOACCESS = 0x01;
+pub const PAGE_READONLY = 0x02;
+pub const PAGE_READWRITE = 0x04;
+pub const PAGE_WRITECOPY = 0x08;
+pub const PAGE_TARGETS_INVALID = 0x40000000;
+pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID
+pub const PAGE_GUARD = 0x100;
+pub const PAGE_NOCACHE = 0x200;
+pub const PAGE_WRITECOMBINE = 0x400;
+
+// FreeType values
+pub const MEM_COALESCE_PLACEHOLDERS = 0x1;
+pub const MEM_RESERVE_PLACEHOLDERS = 0x2;
+pub const MEM_DECOMMIT = 0x4000;
+pub const MEM_RELEASE = 0x8000;
+
+pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
+pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
+
+pub const WIN32_FIND_DATAW = extern struct {
+ dwFileAttributes: DWORD,
+ ftCreationTime: FILETIME,
+ ftLastAccessTime: FILETIME,
+ ftLastWriteTime: FILETIME,
+ nFileSizeHigh: DWORD,
+ nFileSizeLow: DWORD,
+ dwReserved0: DWORD,
+ dwReserved1: DWORD,
+ cFileName: [260]u16,
+ cAlternateFileName: [14]u16,
+};
+
+pub const FILETIME = extern struct {
+ dwLowDateTime: DWORD,
+ dwHighDateTime: DWORD,
+};
+
+pub const SYSTEM_INFO = extern struct {
+ anon1: extern union {
+ dwOemId: DWORD,
+ anon2: extern struct {
+ wProcessorArchitecture: WORD,
+ wReserved: WORD,
+ },
+ },
+ dwPageSize: DWORD,
+ lpMinimumApplicationAddress: LPVOID,
+ lpMaximumApplicationAddress: LPVOID,
+ dwActiveProcessorMask: DWORD_PTR,
+ dwNumberOfProcessors: DWORD,
+ dwProcessorType: DWORD,
+ dwAllocationGranularity: DWORD,
+ wProcessorLevel: WORD,
+ wProcessorRevision: WORD,
+};
+
+pub const HRESULT = c_long;
+
+pub const KNOWNFOLDERID = GUID;
+pub const GUID = extern struct {
+ Data1: c_ulong,
+ Data2: c_ushort,
+ Data3: c_ushort,
+ Data4: [8]u8,
+
+ pub fn parse(str: []const u8) GUID {
+ var guid: GUID = undefined;
+ var index: usize = 0;
+ assert(str[index] == '{');
+ index += 1;
+
+ guid.Data1 = std.fmt.parseUnsigned(c_ulong, str[index .. index + 8], 16) catch unreachable;
+ index += 8;
+
+ assert(str[index] == '-');
+ index += 1;
+
+ guid.Data2 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
+ index += 4;
+
+ assert(str[index] == '-');
+ index += 1;
+
+ guid.Data3 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
+ index += 4;
+
+ assert(str[index] == '-');
+ index += 1;
+
+ guid.Data4[0] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
+ index += 2;
+ guid.Data4[1] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
+ index += 2;
+
+ assert(str[index] == '-');
+ index += 1;
+
+ var i: usize = 2;
+ while (i < guid.Data4.len) : (i += 1) {
+ guid.Data4[i] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
+ index += 2;
+ }
+
+ assert(str[index] == '}');
+ index += 1;
+ return guid;
+ }
+};
+
+pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}");
+
+pub const KF_FLAG_DEFAULT = 0;
+pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536;
+pub const KF_FLAG_CREATE = 32768;
+pub const KF_FLAG_DONT_VERIFY = 16384;
+pub const KF_FLAG_DONT_UNEXPAND = 8192;
+pub const KF_FLAG_NO_ALIAS = 4096;
+pub const KF_FLAG_INIT = 2048;
+pub const KF_FLAG_DEFAULT_PATH = 1024;
+pub const KF_FLAG_NOT_PARENT_RELATIVE = 512;
+pub const KF_FLAG_SIMPLE_IDLIST = 256;
+pub const KF_FLAG_ALIAS_ONLY = -2147483648;
+
+pub const S_OK = 0;
+pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
+pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
+pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
+pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
+pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
+pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
+pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
+pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
+pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
+pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
+
+pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
+pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
+pub const FILE_FLAG_NO_BUFFERING = 0x20000000;
+pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
+pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
+pub const FILE_FLAG_OVERLAPPED = 0x40000000;
+pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000;
+pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000;
+pub const FILE_FLAG_SESSION_AWARE = 0x00800000;
+pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
+pub const FILE_FLAG_WRITE_THROUGH = 0x80000000;
+
+pub const SMALL_RECT = extern struct {
+ Left: SHORT,
+ Top: SHORT,
+ Right: SHORT,
+ Bottom: SHORT,
+};
+
+pub const COORD = extern struct {
+ X: SHORT,
+ Y: SHORT,
+};
+
+pub const CREATE_UNICODE_ENVIRONMENT = 1024;
+
+pub const TLS_OUT_OF_INDEXES = 4294967295;
+pub const IMAGE_TLS_DIRECTORY = extern struct {
+ StartAddressOfRawData: usize,
+ EndAddressOfRawData: usize,
+ AddressOfIndex: usize,
+ AddressOfCallBacks: usize,
+ SizeOfZeroFill: u32,
+ Characteristics: u32,
+};
+pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY;
+pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY;
+
+pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void;
+
+pub const PROV_RSA_FULL = 1;
+
+pub const REGSAM = ACCESS_MASK;
+pub const ACCESS_MASK = DWORD;
+pub const PHKEY = *HKEY;
+pub const HKEY = *HKEY__;
+pub const HKEY__ = extern struct {
+ unused: c_int,
+};
+pub const LSTATUS = LONG;
+
+pub const FILE_NOTIFY_INFORMATION = extern struct {
+ NextEntryOffset: DWORD,
+ Action: DWORD,
+ FileNameLength: DWORD,
+ FileName: [1]WCHAR,
+};
+
+pub const FILE_ACTION_ADDED = 0x00000001;
+pub const FILE_ACTION_REMOVED = 0x00000002;
+pub const FILE_ACTION_MODIFIED = 0x00000003;
+pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
+pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
+
+pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
+
+pub const FILE_LIST_DIRECTORY = 1;
+
+pub const FILE_NOTIFY_CHANGE_CREATION = 64;
+pub const FILE_NOTIFY_CHANGE_SIZE = 8;
+pub const FILE_NOTIFY_CHANGE_SECURITY = 256;
+pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
+pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
+pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2;
+pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1;
+pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
+
+pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
+ dwSize: COORD,
+ dwCursorPosition: COORD,
+ wAttributes: WORD,
+ srWindow: SMALL_RECT,
+ dwMaximumWindowSize: COORD,
+};
+
+pub const FOREGROUND_BLUE = 1;
+pub const FOREGROUND_GREEN = 2;
+pub const FOREGROUND_RED = 4;
+pub const FOREGROUND_INTENSITY = 8;
+
+pub const LIST_ENTRY = extern struct {
+ Flink: *LIST_ENTRY,
+ Blink: *LIST_ENTRY,
+};
+
+pub const RTL_CRITICAL_SECTION_DEBUG = extern struct {
+ Type: WORD,
+ CreatorBackTraceIndex: WORD,
+ CriticalSection: *RTL_CRITICAL_SECTION,
+ ProcessLocksList: LIST_ENTRY,
+ EntryCount: DWORD,
+ ContentionCount: DWORD,
+ Flags: DWORD,
+ CreatorBackTraceIndexHigh: WORD,
+ SpareWORD: WORD,
+};
+
+pub const RTL_CRITICAL_SECTION = extern struct {
+ DebugInfo: *RTL_CRITICAL_SECTION_DEBUG,
+ LockCount: LONG,
+ RecursionCount: LONG,
+ OwningThread: HANDLE,
+ LockSemaphore: HANDLE,
+ SpinCount: ULONG_PTR,
+};
+
+pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
+pub const INIT_ONCE = RTL_RUN_ONCE;
+pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT;
+pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL;
+
+pub const RTL_RUN_ONCE = extern struct {
+ Ptr: ?*c_void,
+};
+
+pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null };
+
+pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED;
+pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED;
+pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE;
+pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY;
+pub const COINIT = extern enum {
+ COINIT_APARTMENTTHREADED = 2,
+ COINIT_MULTITHREADED = 0,
+ COINIT_DISABLE_OLE1DDE = 4,
+ COINIT_SPEED_OVER_MEMORY = 8,
+};
+
+/// > The maximum path of 32,767 characters is approximate, because the "\\?\"
+/// > prefix may be expanded to a longer string by the system at run time, and
+/// > this expansion applies to the total length.
+/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
+pub const PATH_MAX_WIDE = 32767;
std/os/windows/kernel32.zig
@@ -1,4 +1,4 @@
-use @import("../windows.zig");
+use @import("bits.zig");
pub extern "kernel32" stdcallcc fn CancelIoEx(hFile: HANDLE, lpOverlapped: LPOVERLAPPED) BOOL;
std/os/windows/ntdll.zig
@@ -1,3 +1,3 @@
-use @import("../windows.zig");
+use @import("bits.zig");
pub extern "NtDll" stdcallcc fn RtlCaptureStackBackTrace(FramesToSkip: DWORD, FramesToCapture: DWORD, BackTrace: **c_void, BackTraceHash: ?*DWORD) WORD;
std/os/windows/ole32.zig
@@ -1,4 +1,4 @@
-use @import("../windows.zig");
+use @import("bits.zig");
pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: LPVOID) void;
pub extern "ole32" stdcallcc fn CoUninitialize() void;
std/os/windows/shell32.zig
@@ -1,3 +1,3 @@
-use @import("../windows.zig");
+use @import("bits.zig");
pub extern "shell32" stdcallcc fn SHGetKnownFolderPath(rfid: *const KNOWNFOLDERID, dwFlags: DWORD, hToken: ?HANDLE, ppszPath: *[*]WCHAR) HRESULT;
std/os/windows.zig
@@ -6,537 +6,19 @@
const builtin = @import("builtin");
const std = @import("../std.zig");
+const mem = std.mem;
const assert = std.debug.assert;
+const math = std.math;
const maxInt = std.math.maxInt;
pub const is_the_target = builtin.os == .windows;
-
pub const advapi32 = @import("windows/advapi32.zig");
pub const kernel32 = @import("windows/kernel32.zig");
pub const ntdll = @import("windows/ntdll.zig");
pub const ole32 = @import("windows/ole32.zig");
pub const shell32 = @import("windows/shell32.zig");
-pub const ERROR = @import("windows/error.zig");
-
-/// The standard input device. Initially, this is the console input buffer, CONIN$.
-pub const STD_INPUT_HANDLE = maxInt(DWORD) - 10 + 1;
-
-/// The standard output device. Initially, this is the active console screen buffer, CONOUT$.
-pub const STD_OUTPUT_HANDLE = maxInt(DWORD) - 11 + 1;
-
-/// The standard error device. Initially, this is the active console screen buffer, CONOUT$.
-pub const STD_ERROR_HANDLE = maxInt(DWORD) - 12 + 1;
-
-pub const SHORT = c_short;
-pub const BOOL = c_int;
-pub const BOOLEAN = BYTE;
-pub const BYTE = u8;
-pub const CHAR = u8;
-pub const DWORD = u32;
-pub const FLOAT = f32;
-pub const HANDLE = *c_void;
-pub const HCRYPTPROV = ULONG_PTR;
-pub const HINSTANCE = *@OpaqueType();
-pub const HMODULE = *@OpaqueType();
-pub const FARPROC = *@OpaqueType();
-pub const INT = c_int;
-pub const LPBYTE = *BYTE;
-pub const LPCH = *CHAR;
-pub const LPCSTR = [*]const CHAR;
-pub const LPCTSTR = [*]const TCHAR;
-pub const LPCVOID = *const c_void;
-pub const LPDWORD = *DWORD;
-pub const LPSTR = [*]CHAR;
-pub const LPTSTR = if (UNICODE) LPWSTR else LPSTR;
-pub const LPVOID = *c_void;
-pub const LPWSTR = [*]WCHAR;
-pub const LPCWSTR = [*]const WCHAR;
-pub const PVOID = *c_void;
-pub const PWSTR = [*]WCHAR;
-pub const SIZE_T = usize;
-pub const TCHAR = if (UNICODE) WCHAR else u8;
-pub const UINT = c_uint;
-pub const ULONG_PTR = usize;
-pub const DWORD_PTR = ULONG_PTR;
-pub const UNICODE = false;
-pub const WCHAR = u16;
-pub const WORD = u16;
-pub const LARGE_INTEGER = i64;
-pub const ULONG = u32;
-pub const LONG = i32;
-pub const ULONGLONG = u64;
-pub const LONGLONG = i64;
-
-pub const TRUE = 1;
-pub const FALSE = 0;
-
-pub const INVALID_HANDLE_VALUE = @intToPtr(HANDLE, maxInt(usize));
-
-pub const INVALID_FILE_ATTRIBUTES = DWORD(maxInt(DWORD));
-
-pub const OVERLAPPED = extern struct {
- Internal: ULONG_PTR,
- InternalHigh: ULONG_PTR,
- Offset: DWORD,
- OffsetHigh: DWORD,
- hEvent: ?HANDLE,
-};
-pub const LPOVERLAPPED = *OVERLAPPED;
-
-pub const MAX_PATH = 260;
-
-// TODO issue #305
-pub const FILE_INFO_BY_HANDLE_CLASS = u32;
-pub const FileBasicInfo = 0;
-pub const FileStandardInfo = 1;
-pub const FileNameInfo = 2;
-pub const FileRenameInfo = 3;
-pub const FileDispositionInfo = 4;
-pub const FileAllocationInfo = 5;
-pub const FileEndOfFileInfo = 6;
-pub const FileStreamInfo = 7;
-pub const FileCompressionInfo = 8;
-pub const FileAttributeTagInfo = 9;
-pub const FileIdBothDirectoryInfo = 10;
-pub const FileIdBothDirectoryRestartInfo = 11;
-pub const FileIoPriorityHintInfo = 12;
-pub const FileRemoteProtocolInfo = 13;
-pub const FileFullDirectoryInfo = 14;
-pub const FileFullDirectoryRestartInfo = 15;
-pub const FileStorageInfo = 16;
-pub const FileAlignmentInfo = 17;
-pub const FileIdInfo = 18;
-pub const FileIdExtdDirectoryInfo = 19;
-pub const FileIdExtdDirectoryRestartInfo = 20;
-
-pub const FILE_NAME_INFO = extern struct {
- FileNameLength: DWORD,
- FileName: [1]WCHAR,
-};
-
-/// Return the normalized drive name. This is the default.
-pub const FILE_NAME_NORMALIZED = 0x0;
-
-/// Return the opened file name (not normalized).
-pub const FILE_NAME_OPENED = 0x8;
-
-/// Return the path with the drive letter. This is the default.
-pub const VOLUME_NAME_DOS = 0x0;
-
-/// Return the path with a volume GUID path instead of the drive name.
-pub const VOLUME_NAME_GUID = 0x1;
-
-/// Return the path with no drive information.
-pub const VOLUME_NAME_NONE = 0x4;
-
-/// Return the path with the volume device path.
-pub const VOLUME_NAME_NT = 0x2;
-
-pub const SECURITY_ATTRIBUTES = extern struct {
- nLength: DWORD,
- lpSecurityDescriptor: ?*c_void,
- bInheritHandle: BOOL,
-};
-pub const PSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
-pub const LPSECURITY_ATTRIBUTES = *SECURITY_ATTRIBUTES;
-
-pub const GENERIC_READ = 0x80000000;
-pub const GENERIC_WRITE = 0x40000000;
-pub const GENERIC_EXECUTE = 0x20000000;
-pub const GENERIC_ALL = 0x10000000;
-
-pub const FILE_SHARE_DELETE = 0x00000004;
-pub const FILE_SHARE_READ = 0x00000001;
-pub const FILE_SHARE_WRITE = 0x00000002;
-
-pub const CREATE_ALWAYS = 2;
-pub const CREATE_NEW = 1;
-pub const OPEN_ALWAYS = 4;
-pub const OPEN_EXISTING = 3;
-pub const TRUNCATE_EXISTING = 5;
-
-pub const FILE_ATTRIBUTE_ARCHIVE = 0x20;
-pub const FILE_ATTRIBUTE_COMPRESSED = 0x800;
-pub const FILE_ATTRIBUTE_DEVICE = 0x40;
-pub const FILE_ATTRIBUTE_DIRECTORY = 0x10;
-pub const FILE_ATTRIBUTE_ENCRYPTED = 0x4000;
-pub const FILE_ATTRIBUTE_HIDDEN = 0x2;
-pub const FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x8000;
-pub const FILE_ATTRIBUTE_NORMAL = 0x80;
-pub const FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x2000;
-pub const FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x20000;
-pub const FILE_ATTRIBUTE_OFFLINE = 0x1000;
-pub const FILE_ATTRIBUTE_READONLY = 0x1;
-pub const FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x400000;
-pub const FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x40000;
-pub const FILE_ATTRIBUTE_REPARSE_POINT = 0x400;
-pub const FILE_ATTRIBUTE_SPARSE_FILE = 0x200;
-pub const FILE_ATTRIBUTE_SYSTEM = 0x4;
-pub const FILE_ATTRIBUTE_TEMPORARY = 0x100;
-pub const FILE_ATTRIBUTE_VIRTUAL = 0x10000;
-
-pub const PROCESS_INFORMATION = extern struct {
- hProcess: HANDLE,
- hThread: HANDLE,
- dwProcessId: DWORD,
- dwThreadId: DWORD,
-};
-
-pub const STARTUPINFOW = extern struct {
- cb: DWORD,
- lpReserved: ?LPWSTR,
- lpDesktop: ?LPWSTR,
- lpTitle: ?LPWSTR,
- dwX: DWORD,
- dwY: DWORD,
- dwXSize: DWORD,
- dwYSize: DWORD,
- dwXCountChars: DWORD,
- dwYCountChars: DWORD,
- dwFillAttribute: DWORD,
- dwFlags: DWORD,
- wShowWindow: WORD,
- cbReserved2: WORD,
- lpReserved2: ?LPBYTE,
- hStdInput: ?HANDLE,
- hStdOutput: ?HANDLE,
- hStdError: ?HANDLE,
-};
-
-pub const STARTF_FORCEONFEEDBACK = 0x00000040;
-pub const STARTF_FORCEOFFFEEDBACK = 0x00000080;
-pub const STARTF_PREVENTPINNING = 0x00002000;
-pub const STARTF_RUNFULLSCREEN = 0x00000020;
-pub const STARTF_TITLEISAPPID = 0x00001000;
-pub const STARTF_TITLEISLINKNAME = 0x00000800;
-pub const STARTF_UNTRUSTEDSOURCE = 0x00008000;
-pub const STARTF_USECOUNTCHARS = 0x00000008;
-pub const STARTF_USEFILLATTRIBUTE = 0x00000010;
-pub const STARTF_USEHOTKEY = 0x00000200;
-pub const STARTF_USEPOSITION = 0x00000004;
-pub const STARTF_USESHOWWINDOW = 0x00000001;
-pub const STARTF_USESIZE = 0x00000002;
-pub const STARTF_USESTDHANDLES = 0x00000100;
-
-pub const INFINITE = 4294967295;
-
-pub const WAIT_ABANDONED = 0x00000080;
-pub const WAIT_OBJECT_0 = 0x00000000;
-pub const WAIT_TIMEOUT = 0x00000102;
-pub const WAIT_FAILED = 0xFFFFFFFF;
-
-pub const HANDLE_FLAG_INHERIT = 0x00000001;
-pub const HANDLE_FLAG_PROTECT_FROM_CLOSE = 0x00000002;
-
-pub const MOVEFILE_COPY_ALLOWED = 2;
-pub const MOVEFILE_CREATE_HARDLINK = 16;
-pub const MOVEFILE_DELAY_UNTIL_REBOOT = 4;
-pub const MOVEFILE_FAIL_IF_NOT_TRACKABLE = 32;
-pub const MOVEFILE_REPLACE_EXISTING = 1;
-pub const MOVEFILE_WRITE_THROUGH = 8;
-
-pub const FILE_BEGIN = 0;
-pub const FILE_CURRENT = 1;
-pub const FILE_END = 2;
-
-pub const HEAP_CREATE_ENABLE_EXECUTE = 0x00040000;
-pub const HEAP_GENERATE_EXCEPTIONS = 0x00000004;
-pub const HEAP_NO_SERIALIZE = 0x00000001;
-
-// AllocationType values
-pub const MEM_COMMIT = 0x1000;
-pub const MEM_RESERVE = 0x2000;
-pub const MEM_RESET = 0x80000;
-pub const MEM_RESET_UNDO = 0x1000000;
-pub const MEM_LARGE_PAGES = 0x20000000;
-pub const MEM_PHYSICAL = 0x400000;
-pub const MEM_TOP_DOWN = 0x100000;
-pub const MEM_WRITE_WATCH = 0x200000;
-
-// Protect values
-pub const PAGE_EXECUTE = 0x10;
-pub const PAGE_EXECUTE_READ = 0x20;
-pub const PAGE_EXECUTE_READWRITE = 0x40;
-pub const PAGE_EXECUTE_WRITECOPY = 0x80;
-pub const PAGE_NOACCESS = 0x01;
-pub const PAGE_READONLY = 0x02;
-pub const PAGE_READWRITE = 0x04;
-pub const PAGE_WRITECOPY = 0x08;
-pub const PAGE_TARGETS_INVALID = 0x40000000;
-pub const PAGE_TARGETS_NO_UPDATE = 0x40000000; // Same as PAGE_TARGETS_INVALID
-pub const PAGE_GUARD = 0x100;
-pub const PAGE_NOCACHE = 0x200;
-pub const PAGE_WRITECOMBINE = 0x400;
-
-// FreeType values
-pub const MEM_COALESCE_PLACEHOLDERS = 0x1;
-pub const MEM_RESERVE_PLACEHOLDERS = 0x2;
-pub const MEM_DECOMMIT = 0x4000;
-pub const MEM_RELEASE = 0x8000;
-
-pub const PTHREAD_START_ROUTINE = extern fn (LPVOID) DWORD;
-pub const LPTHREAD_START_ROUTINE = PTHREAD_START_ROUTINE;
-
-pub const WIN32_FIND_DATAW = extern struct {
- dwFileAttributes: DWORD,
- ftCreationTime: FILETIME,
- ftLastAccessTime: FILETIME,
- ftLastWriteTime: FILETIME,
- nFileSizeHigh: DWORD,
- nFileSizeLow: DWORD,
- dwReserved0: DWORD,
- dwReserved1: DWORD,
- cFileName: [260]u16,
- cAlternateFileName: [14]u16,
-};
-
-pub const FILETIME = extern struct {
- dwLowDateTime: DWORD,
- dwHighDateTime: DWORD,
-};
-
-pub const SYSTEM_INFO = extern struct {
- anon1: extern union {
- dwOemId: DWORD,
- anon2: extern struct {
- wProcessorArchitecture: WORD,
- wReserved: WORD,
- },
- },
- dwPageSize: DWORD,
- lpMinimumApplicationAddress: LPVOID,
- lpMaximumApplicationAddress: LPVOID,
- dwActiveProcessorMask: DWORD_PTR,
- dwNumberOfProcessors: DWORD,
- dwProcessorType: DWORD,
- dwAllocationGranularity: DWORD,
- wProcessorLevel: WORD,
- wProcessorRevision: WORD,
-};
-
-pub const HRESULT = c_long;
-
-pub const KNOWNFOLDERID = GUID;
-pub const GUID = extern struct {
- Data1: c_ulong,
- Data2: c_ushort,
- Data3: c_ushort,
- Data4: [8]u8,
-
- pub fn parse(str: []const u8) GUID {
- var guid: GUID = undefined;
- var index: usize = 0;
- assert(str[index] == '{');
- index += 1;
-
- guid.Data1 = std.fmt.parseUnsigned(c_ulong, str[index .. index + 8], 16) catch unreachable;
- index += 8;
-
- assert(str[index] == '-');
- index += 1;
-
- guid.Data2 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
- index += 4;
-
- assert(str[index] == '-');
- index += 1;
-
- guid.Data3 = std.fmt.parseUnsigned(c_ushort, str[index .. index + 4], 16) catch unreachable;
- index += 4;
-
- assert(str[index] == '-');
- index += 1;
-
- guid.Data4[0] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
- index += 2;
- guid.Data4[1] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
- index += 2;
-
- assert(str[index] == '-');
- index += 1;
-
- var i: usize = 2;
- while (i < guid.Data4.len) : (i += 1) {
- guid.Data4[i] = std.fmt.parseUnsigned(u8, str[index .. index + 2], 16) catch unreachable;
- index += 2;
- }
-
- assert(str[index] == '}');
- index += 1;
- return guid;
- }
-};
-
-pub const FOLDERID_LocalAppData = GUID.parse("{F1B32785-6FBA-4FCF-9D55-7B8E7F157091}");
-
-pub const KF_FLAG_DEFAULT = 0;
-pub const KF_FLAG_NO_APPCONTAINER_REDIRECTION = 65536;
-pub const KF_FLAG_CREATE = 32768;
-pub const KF_FLAG_DONT_VERIFY = 16384;
-pub const KF_FLAG_DONT_UNEXPAND = 8192;
-pub const KF_FLAG_NO_ALIAS = 4096;
-pub const KF_FLAG_INIT = 2048;
-pub const KF_FLAG_DEFAULT_PATH = 1024;
-pub const KF_FLAG_NOT_PARENT_RELATIVE = 512;
-pub const KF_FLAG_SIMPLE_IDLIST = 256;
-pub const KF_FLAG_ALIAS_ONLY = -2147483648;
-
-pub const S_OK = 0;
-pub const E_NOTIMPL = @bitCast(c_long, c_ulong(0x80004001));
-pub const E_NOINTERFACE = @bitCast(c_long, c_ulong(0x80004002));
-pub const E_POINTER = @bitCast(c_long, c_ulong(0x80004003));
-pub const E_ABORT = @bitCast(c_long, c_ulong(0x80004004));
-pub const E_FAIL = @bitCast(c_long, c_ulong(0x80004005));
-pub const E_UNEXPECTED = @bitCast(c_long, c_ulong(0x8000FFFF));
-pub const E_ACCESSDENIED = @bitCast(c_long, c_ulong(0x80070005));
-pub const E_HANDLE = @bitCast(c_long, c_ulong(0x80070006));
-pub const E_OUTOFMEMORY = @bitCast(c_long, c_ulong(0x8007000E));
-pub const E_INVALIDARG = @bitCast(c_long, c_ulong(0x80070057));
-
-pub const FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
-pub const FILE_FLAG_DELETE_ON_CLOSE = 0x04000000;
-pub const FILE_FLAG_NO_BUFFERING = 0x20000000;
-pub const FILE_FLAG_OPEN_NO_RECALL = 0x00100000;
-pub const FILE_FLAG_OPEN_REPARSE_POINT = 0x00200000;
-pub const FILE_FLAG_OVERLAPPED = 0x40000000;
-pub const FILE_FLAG_POSIX_SEMANTICS = 0x0100000;
-pub const FILE_FLAG_RANDOM_ACCESS = 0x10000000;
-pub const FILE_FLAG_SESSION_AWARE = 0x00800000;
-pub const FILE_FLAG_SEQUENTIAL_SCAN = 0x08000000;
-pub const FILE_FLAG_WRITE_THROUGH = 0x80000000;
-
-pub const SMALL_RECT = extern struct {
- Left: SHORT,
- Top: SHORT,
- Right: SHORT,
- Bottom: SHORT,
-};
-
-pub const COORD = extern struct {
- X: SHORT,
- Y: SHORT,
-};
-
-pub const CREATE_UNICODE_ENVIRONMENT = 1024;
-
-pub const TLS_OUT_OF_INDEXES = 4294967295;
-pub const IMAGE_TLS_DIRECTORY = extern struct {
- StartAddressOfRawData: usize,
- EndAddressOfRawData: usize,
- AddressOfIndex: usize,
- AddressOfCallBacks: usize,
- SizeOfZeroFill: u32,
- Characteristics: u32,
-};
-pub const IMAGE_TLS_DIRECTORY64 = IMAGE_TLS_DIRECTORY;
-pub const IMAGE_TLS_DIRECTORY32 = IMAGE_TLS_DIRECTORY;
-
-pub const PIMAGE_TLS_CALLBACK = ?extern fn (PVOID, DWORD, PVOID) void;
-
-pub const PROV_RSA_FULL = 1;
-
-pub const REGSAM = ACCESS_MASK;
-pub const ACCESS_MASK = DWORD;
-pub const PHKEY = *HKEY;
-pub const HKEY = *HKEY__;
-pub const HKEY__ = extern struct {
- unused: c_int,
-};
-pub const LSTATUS = LONG;
-
-pub const FILE_NOTIFY_INFORMATION = extern struct {
- NextEntryOffset: DWORD,
- Action: DWORD,
- FileNameLength: DWORD,
- FileName: [1]WCHAR,
-};
-
-pub const FILE_ACTION_ADDED = 0x00000001;
-pub const FILE_ACTION_REMOVED = 0x00000002;
-pub const FILE_ACTION_MODIFIED = 0x00000003;
-pub const FILE_ACTION_RENAMED_OLD_NAME = 0x00000004;
-pub const FILE_ACTION_RENAMED_NEW_NAME = 0x00000005;
-
-pub const LPOVERLAPPED_COMPLETION_ROUTINE = ?extern fn (DWORD, DWORD, *OVERLAPPED) void;
-
-pub const FILE_LIST_DIRECTORY = 1;
-
-pub const FILE_NOTIFY_CHANGE_CREATION = 64;
-pub const FILE_NOTIFY_CHANGE_SIZE = 8;
-pub const FILE_NOTIFY_CHANGE_SECURITY = 256;
-pub const FILE_NOTIFY_CHANGE_LAST_ACCESS = 32;
-pub const FILE_NOTIFY_CHANGE_LAST_WRITE = 16;
-pub const FILE_NOTIFY_CHANGE_DIR_NAME = 2;
-pub const FILE_NOTIFY_CHANGE_FILE_NAME = 1;
-pub const FILE_NOTIFY_CHANGE_ATTRIBUTES = 4;
-
-pub const CONSOLE_SCREEN_BUFFER_INFO = extern struct {
- dwSize: COORD,
- dwCursorPosition: COORD,
- wAttributes: WORD,
- srWindow: SMALL_RECT,
- dwMaximumWindowSize: COORD,
-};
-
-pub const FOREGROUND_BLUE = 1;
-pub const FOREGROUND_GREEN = 2;
-pub const FOREGROUND_RED = 4;
-pub const FOREGROUND_INTENSITY = 8;
-
-pub const LIST_ENTRY = extern struct {
- Flink: *LIST_ENTRY,
- Blink: *LIST_ENTRY,
-};
-
-pub const RTL_CRITICAL_SECTION_DEBUG = extern struct {
- Type: WORD,
- CreatorBackTraceIndex: WORD,
- CriticalSection: *RTL_CRITICAL_SECTION,
- ProcessLocksList: LIST_ENTRY,
- EntryCount: DWORD,
- ContentionCount: DWORD,
- Flags: DWORD,
- CreatorBackTraceIndexHigh: WORD,
- SpareWORD: WORD,
-};
-
-pub const RTL_CRITICAL_SECTION = extern struct {
- DebugInfo: *RTL_CRITICAL_SECTION_DEBUG,
- LockCount: LONG,
- RecursionCount: LONG,
- OwningThread: HANDLE,
- LockSemaphore: HANDLE,
- SpinCount: ULONG_PTR,
-};
-
-pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
-pub const INIT_ONCE = RTL_RUN_ONCE;
-pub const INIT_ONCE_STATIC_INIT = RTL_RUN_ONCE_INIT;
-pub const INIT_ONCE_FN = extern fn (InitOnce: *INIT_ONCE, Parameter: ?*c_void, Context: ?*c_void) BOOL;
-
-pub const RTL_RUN_ONCE = extern struct {
- Ptr: ?*c_void,
-};
-
-pub const RTL_RUN_ONCE_INIT = RTL_RUN_ONCE{ .Ptr = null };
-
-pub const COINIT_APARTMENTTHREADED = COINIT.COINIT_APARTMENTTHREADED;
-pub const COINIT_MULTITHREADED = COINIT.COINIT_MULTITHREADED;
-pub const COINIT_DISABLE_OLE1DDE = COINIT.COINIT_DISABLE_OLE1DDE;
-pub const COINIT_SPEED_OVER_MEMORY = COINIT.COINIT_SPEED_OVER_MEMORY;
-pub const COINIT = extern enum {
- COINIT_APARTMENTTHREADED = 2,
- COINIT_MULTITHREADED = 0,
- COINIT_DISABLE_OLE1DDE = 4,
- COINIT_SPEED_OVER_MEMORY = 8,
-};
-
-/// > The maximum path of 32,767 characters is approximate, because the "\\?\"
-/// > prefix may be expanded to a longer string by the system at run time, and
-/// > this expansion applies to the total length.
-/// from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
-pub const PATH_MAX_WIDE = 32767;
+pub use @import("windows/bits.zig");
pub const CreateFileError = error{
SharingViolation,
@@ -765,7 +247,7 @@ pub fn ReadFile(in_hFile: HANDLE, buffer: []u8) ReadFileError!usize {
while (index < buffer.len) {
const want_read_count = @intCast(DWORD, math.min(DWORD(maxInt(DWORD)), buffer.len - index));
var amt_read: DWORD = undefined;
- if (kernel32.ReadFile(fd, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
+ if (kernel32.ReadFile(in_hFile, buffer.ptr + index, want_read_count, &amt_read, null) == 0) {
switch (kernel32.GetLastError()) {
ERROR.OPERATION_ABORTED => continue,
ERROR.BROKEN_PIPE => return index,
@@ -787,7 +269,7 @@ pub const WriteFileError = error{
/// This function is for blocking file descriptors only. For non-blocking, see
/// `WriteFileAsync`.
-pub fn WriteFile(in_hFile: HANDLE, bytes: []const u8) WriteFileError!void {
+pub fn WriteFile(handle: HANDLE, bytes: []const u8) WriteFileError!void {
var bytes_written: DWORD = undefined;
// TODO replace this @intCast with a loop that writes all the bytes
if (kernel32.WriteFile(handle, bytes.ptr, @intCast(u32, bytes.len), &bytes_written, null) == 0) {
@@ -808,7 +290,7 @@ pub const GetCurrentDirectoryError = error{
Unexpected,
};
-/// The result is a slice of out_buffer, indexed from 0.
+/// The result is a slice of `buffer`, indexed from 0.
pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {
var utf16le_buf: [PATH_MAX_WIDE]u16 = undefined;
const result = kernel32.GetCurrentDirectoryW(utf16le_buf.len, &utf16le_buf);
@@ -821,13 +303,14 @@ pub fn GetCurrentDirectory(buffer: []u8) GetCurrentDirectoryError![]u8 {
const utf16le_slice = utf16le_buf[0..result];
// Trust that Windows gives us valid UTF-16LE.
var end_index: usize = 0;
- var it = std.unicode.Utf16LeIterator.init(utf16le);
+ var it = std.unicode.Utf16LeIterator.init(utf16le_slice);
while (it.nextCodepoint() catch unreachable) |codepoint| {
- if (end_index + std.unicode.utf8CodepointSequenceLength(codepoint) >= out_buffer.len)
+ const seq_len = std.unicode.utf8CodepointSequenceLength(codepoint) catch unreachable;
+ if (end_index + seq_len >= buffer.len)
return error.NameTooLong;
- end_index += utf8Encode(codepoint, out_buffer[end_index..]) catch unreachable;
+ end_index += std.unicode.utf8Encode(codepoint, buffer[end_index..]) catch unreachable;
}
- return out_buffer[0..end_index];
+ return buffer[0..end_index];
}
pub const CreateSymbolicLinkError = error{Unexpected};
@@ -1218,6 +701,10 @@ pub fn QueryPerformanceCounter() u64 {
return @bitCast(u64, result);
}
+pub fn InitOnceExecuteOnce(InitOnce: *INIT_ONCE, InitFn: INIT_ONCE_FN, Parameter: ?*c_void, Context: ?*c_void) void {
+ assert(kernel32.InitOnceExecuteOnce(InitOnce, InitFn, Parameter, Context) != 0);
+}
+
pub fn cStrToPrefixedFileW(s: [*]const u8) ![PATH_MAX_WIDE + 1]u16 {
return sliceToPrefixedFileW(mem.toSliceConst(u8, s));
}
std/special/bootstrap.zig
@@ -62,7 +62,7 @@ extern fn WinMainCRTStartup() noreturn {
if (!builtin.single_threaded) {
_ = @import("bootstrap_windows_tls.zig");
}
- std.os.windows.ExitProcess(callMain());
+ std.os.windows.kernel32.ExitProcess(callMain());
}
// TODO https://github.com/ziglang/zig/issues/265
std/debug.zig
@@ -510,7 +510,7 @@ const TtyColor = enum {
/// TODO this is a special case hack right now. clean it up and maybe make it part of std.fmt
fn setTtyColor(tty_color: TtyColor) void {
- if (os.supportsAnsiEscapeCodes(stderr_file.handle)) {
+ if (stderr_file.supportsAnsiEscapeCodes()) {
switch (tty_color) {
TtyColor.Red => {
stderr_file.write(RED) catch return;
@@ -540,29 +540,29 @@ fn setTtyColor(tty_color: TtyColor) void {
S.init_attrs = true;
var info: windows.CONSOLE_SCREEN_BUFFER_INFO = undefined;
// TODO handle error
- _ = windows.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
+ _ = windows.kernel32.GetConsoleScreenBufferInfo(stderr_file.handle, &info);
S.attrs = info.wAttributes;
}
// TODO handle errors
switch (tty_color) {
TtyColor.Red => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_INTENSITY) catch {};
},
TtyColor.Green => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_INTENSITY) catch {};
},
TtyColor.Cyan => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
},
TtyColor.White, TtyColor.Bold => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_RED | windows.FOREGROUND_GREEN | windows.FOREGROUND_BLUE | windows.FOREGROUND_INTENSITY) catch {};
},
TtyColor.Dim => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, windows.FOREGROUND_INTENSITY) catch {};
},
TtyColor.Reset => {
- _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs);
+ _ = windows.SetConsoleTextAttribute(stderr_file.handle, S.attrs) catch {};
},
}
}
@@ -894,7 +894,7 @@ fn openSelfDebugInfoWindows(allocator: *mem.Allocator) !DebugInfo {
if (this_record_len % 4 != 0) {
const round_to_next_4 = (this_record_len | 0x3) + 1;
const march_forward_bytes = round_to_next_4 - this_record_len;
- try dbi.seekBy(march_forward_bytes);
+ try dbi.seekBy(@intCast(isize, march_forward_bytes));
this_record_len += march_forward_bytes;
}
std/heap.zig
@@ -92,12 +92,14 @@ pub const DirectAllocator = struct {
// obtained some memory space that will cause the next
// VirtualAlloc call to fail. To handle this, we will retry
// until it succeeds.
- return w.VirtualAlloc(
+ const ptr = w.VirtualAlloc(
@intToPtr(*c_void, aligned_addr),
n,
w.MEM_COMMIT | w.MEM_RESERVE,
w.PAGE_READWRITE,
) catch continue;
+
+ return @ptrCast([*]u8, ptr)[0..n];
};
return @ptrCast([*]u8, final_addr)[0..n];
std/os.zig
@@ -99,7 +99,8 @@ pub fn getrandom(buf: []u8) GetRandomError!void {
}
if (linux.is_the_target) {
while (true) {
- switch (errno(system.getrandom(buf.ptr, buf.len, 0))) {
+ // Bypass libc because it's missing on even relatively new versions.
+ switch (linux.getErrno(linux.getrandom(buf.ptr, buf.len, 0))) {
0 => return,
EINVAL => unreachable,
EFAULT => unreachable,
std/pdb.zig
@@ -662,7 +662,7 @@ const MsfStream = struct {
}
fn seekBy(self: *MsfStream, len: i64) !void {
- self.pos += len;
+ self.pos = @intCast(u64, @intCast(i64, self.pos) + len);
if (self.pos >= self.blocks.len * self.block_size)
return error.EOF;
}
std/process.zig
@@ -144,7 +144,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
windows_buf_len,
) catch |err| switch (err) {
error.Unexpected => return error.EnvironmentVariableNotFound,
- else => return err,
+ else => |e| return e,
};
if (result > buf.len) {
@@ -156,7 +156,7 @@ pub fn getEnvVarOwned(allocator: *mem.Allocator, key: []const u8) GetEnvVarOwned
error.DanglingSurrogateHalf => return error.InvalidUtf8,
error.ExpectedSecondSurrogateHalf => return error.InvalidUtf8,
error.UnexpectedSecondSurrogateHalf => return error.InvalidUtf8,
- else => return err,
+ else => |e| return e,
};
}
} else {
std/statically_initialized_mutex.zig
@@ -23,7 +23,7 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {
mutex: *StaticallyInitializedMutex,
pub fn release(self: Held) void {
- windows.LeaveCriticalSection(&self.mutex.lock);
+ windows.kernel32.LeaveCriticalSection(&self.mutex.lock);
}
};
@@ -40,20 +40,20 @@ pub const StaticallyInitializedMutex = switch (builtin.os) {
Context: ?*c_void,
) windows.BOOL {
const lock = @ptrCast(*windows.CRITICAL_SECTION, @alignCast(@alignOf(windows.CRITICAL_SECTION), Parameter));
- windows.InitializeCriticalSection(lock);
+ windows.kernel32.InitializeCriticalSection(lock);
return windows.TRUE;
}
/// TODO: once https://github.com/ziglang/zig/issues/287 is solved and std.Mutex has a better
/// implementation of a runtime initialized mutex, remove this function.
pub fn deinit(self: *StaticallyInitializedMutex) void {
- assert(windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null) != 0);
- windows.DeleteCriticalSection(&self.lock);
+ windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
+ windows.kernel32.DeleteCriticalSection(&self.lock);
}
pub fn acquire(self: *StaticallyInitializedMutex) Held {
- assert(windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null) != 0);
- windows.EnterCriticalSection(&self.lock);
+ windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, &self.lock, null);
+ windows.kernel32.EnterCriticalSection(&self.lock);
return Held{ .mutex = self };
}
},
CMakeLists.txt
@@ -628,6 +628,7 @@ set(ZIG_STD_FILES
"os/wasi.zig"
"os/windows.zig"
"os/windows/advapi32.zig"
+ "os/windows/bits.zig"
"os/windows/error.zig"
"os/windows/kernel32.zig"
"os/windows/ntdll.zig"