aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-11-03 13:36:11 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2024-11-04 11:59:38 +0100
commit6b2c8fc6886cdf251146aa3674e87f6ca3111e24 (patch)
treec50ecbbf8651c996e79299cee58cea55e225fe05 /lib/std
parent814a41b48f157fff1f48c4a14e92142d1e6e5748 (diff)
downloadzig-6b2c8fc6886cdf251146aa3674e87f6ca3111e24.tar.gz
zig-6b2c8fc6886cdf251146aa3674e87f6ca3111e24.zip
zig.h: Improve portability of zig_*_windows_teb() helpers.
* Make it work for thumb and aarch64. * Clean up std.os.windows.teb() a bit. I also updated stage1/zig.h since the changes are backwards-compatible and are necessary due to the std.os.windows changes that call the newly-added functions.
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/os/windows.zig58
1 files changed, 30 insertions, 28 deletions
diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig
index 010bbcd005..9a18c31363 100644
--- a/lib/std/os/windows.zig
+++ b/lib/std/os/windows.zig
@@ -2101,39 +2101,41 @@ pub fn UnlockFile(
/// This is a workaround for the C backend until zig has the ability to put
/// C code in inline assembly.
+extern fn zig_thumb_windows_teb() callconv(.c) *anyopaque;
+extern fn zig_aarch64_windows_teb() callconv(.c) *anyopaque;
extern fn zig_x86_windows_teb() callconv(.c) *anyopaque;
extern fn zig_x86_64_windows_teb() callconv(.c) *anyopaque;
pub fn teb() *TEB {
return switch (native_arch) {
- .x86 => blk: {
- if (builtin.zig_backend == .stage2_c) {
- break :blk @ptrCast(@alignCast(zig_x86_windows_teb()));
- } else {
- break :blk asm (
- \\ movl %%fs:0x18, %[ptr]
- : [ptr] "=r" (-> *TEB),
- );
- }
- },
- .x86_64 => blk: {
- if (builtin.zig_backend == .stage2_c) {
- break :blk @ptrCast(@alignCast(zig_x86_64_windows_teb()));
- } else {
- break :blk asm (
- \\ movq %%gs:0x30, %[ptr]
- : [ptr] "=r" (-> *TEB),
- );
- }
- },
- .thumb => asm (
- \\ mrc p15, 0, %[ptr], c13, c0, 2
- : [ptr] "=r" (-> *TEB),
- ),
- .aarch64 => asm (
- \\ mov %[ptr], x18
- : [ptr] "=r" (-> *TEB),
- ),
+ .thumb => if (builtin.zig_backend == .stage2_c)
+ @ptrCast(@alignCast(zig_thumb_windows_teb()))
+ else
+ asm (
+ \\ mrc p15, 0, %[ptr], c13, c0, 2
+ : [ptr] "=r" (-> *TEB),
+ ),
+ .aarch64 => if (builtin.zig_backend == .stage2_c)
+ @ptrCast(@alignCast(zig_aarch64_windows_teb()))
+ else
+ asm (
+ \\ mov %[ptr], x18
+ : [ptr] "=r" (-> *TEB),
+ ),
+ .x86 => if (builtin.zig_backend == .stage2_c)
+ @ptrCast(@alignCast(zig_x86_windows_teb()))
+ else
+ asm (
+ \\ movl %%fs:0x18, %[ptr]
+ : [ptr] "=r" (-> *TEB),
+ ),
+ .x86_64 => if (builtin.zig_backend == .stage2_c)
+ @ptrCast(@alignCast(zig_x86_64_windows_teb()))
+ else
+ asm (
+ \\ movq %%gs:0x30, %[ptr]
+ : [ptr] "=r" (-> *TEB),
+ ),
else => @compileError("unsupported arch"),
};
}