diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2020-03-07 12:18:41 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2020-03-07 12:18:41 -0500 |
| commit | 96c07674fc2293fa040212ab797c05436dc515b1 (patch) | |
| tree | 67b0bc649f4b4c384259a031269254a90078c0bd /lib/std/os | |
| parent | bc75c0de6c8227d1c01b59c0d63f4d012e05496f (diff) | |
| parent | abe7305e169be2047d65f96e6525d3828684f058 (diff) | |
| download | zig-96c07674fc2293fa040212ab797c05436dc515b1.tar.gz zig-96c07674fc2293fa040212ab797c05436dc515b1.zip | |
Merge remote-tracking branch 'origin/master' into llvm10
Diffstat (limited to 'lib/std/os')
| -rw-r--r-- | lib/std/os/windows.zig | 35 | ||||
| -rw-r--r-- | lib/std/os/windows/bits.zig | 13 | ||||
| -rw-r--r-- | lib/std/os/windows/kernel32.zig | 2 |
3 files changed, 33 insertions, 17 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index b8e14a220d..ba55845a4f 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -1083,23 +1083,26 @@ pub fn SetFileTime( } } +pub fn teb() *TEB { + return switch (builtin.arch) { + .i386 => asm volatile ( + \\ movl %%fs:0x18, %[ptr] + : [ptr] "=r" (-> *TEB) + ), + .x86_64 => asm volatile ( + \\ movq %%gs:0x30, %[ptr] + : [ptr] "=r" (-> *TEB) + ), + .aarch64 => asm volatile ( + \\ mov %[ptr], x18 + : [ptr] "=r" (-> *TEB) + ), + else => @compileError("unsupported arch"), + }; +} + pub fn peb() *PEB { - switch (builtin.arch) { - .i386 => { - return asm ( - \\ mov %%fs:0x18, %[ptr] - \\ mov %%ds:0x30(%[ptr]), %[ptr] - : [ptr] "=r" (-> *PEB) - ); - }, - .x86_64 => { - return asm ( - \\ mov %%gs:0x60, %[ptr] - : [ptr] "=r" (-> *PEB) - ); - }, - else => @compileError("unsupported architecture"), - } + return teb().ProcessEnvironmentBlock; } /// A file time is a 64-bit value that represents the number of 100-nanosecond diff --git a/lib/std/os/windows/bits.zig b/lib/std/os/windows/bits.zig index f9ba6cf40e..41466234ed 100644 --- a/lib/std/os/windows/bits.zig +++ b/lib/std/os/windows/bits.zig @@ -1154,6 +1154,19 @@ const RTL_BITMAP = @OpaqueType(); pub const PRTL_BITMAP = *RTL_BITMAP; const KAFFINITY = usize; +pub const TEB = extern struct { + Reserved1: [12]PVOID, + ProcessEnvironmentBlock: *PEB, + Reserved2: [399]PVOID, + Reserved3: [1952]u8, + TlsSlots: [64]PVOID, + Reserved4: [8]u8, + Reserved5: [26]PVOID, + ReservedForOle: PVOID, + Reserved6: [4]PVOID, + TlsExpansionSlots: PVOID, +}; + /// Process Environment Block /// Microsoft documentation of this is incomplete, the fields here are taken from various resources including: /// - https://github.com/wine-mirror/wine/blob/1aff1e6a370ee8c0213a0fd4b220d121da8527aa/include/winternl.h#L269 diff --git a/lib/std/os/windows/kernel32.zig b/lib/std/os/windows/kernel32.zig index 3f65e4d73c..05a7a8f6a3 100644 --- a/lib/std/os/windows/kernel32.zig +++ b/lib/std/os/windows/kernel32.zig @@ -102,7 +102,7 @@ pub extern "kernel32" fn GetFileAttributesW(lpFileName: [*]const WCHAR) callconv pub extern "kernel32" fn GetModuleFileNameW(hModule: ?HMODULE, lpFilename: [*]u16, nSize: DWORD) callconv(.Stdcall) DWORD; -pub extern "kernel32" fn GetModuleHandleW(lpModuleName: ?[*]const WCHAR) callconv(.Stdcall) HMODULE; +pub extern "kernel32" fn GetModuleHandleW(lpModuleName: ?[*]const WCHAR) callconv(.Stdcall) ?HMODULE; pub extern "kernel32" fn GetLastError() callconv(.Stdcall) Win32Error; |
