From c8efebcf53b2b5a93020686940fa2051feb59830 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 04:23:39 +0200 Subject: [PATCH 1/6] std.os.linux: remove dead/wrong msghdr definitions in some arch bits --- lib/std/os/linux/hexagon.zig | 24 ------------------------ lib/std/os/linux/loongarch64.zig | 24 ------------------------ lib/std/os/linux/m68k.zig | 21 --------------------- lib/std/os/linux/s390x.zig | 24 ------------------------ 4 files changed, 93 deletions(-) diff --git a/lib/std/os/linux/hexagon.zig b/lib/std/os/linux/hexagon.zig index bf6c6cb162..72e094da43 100644 --- a/lib/std/os/linux/hexagon.zig +++ b/lib/std/os/linux/hexagon.zig @@ -168,30 +168,6 @@ pub const Flock = extern struct { __unused: [4]u8, }; -pub const msghdr = extern struct { - name: ?*sockaddr, - namelen: socklen_t, - iov: [*]iovec, - iovlen: i32, - __pad1: i32 = 0, - control: ?*anyopaque, - controllen: socklen_t, - __pad2: socklen_t = 0, - flags: i32, -}; - -pub const msghdr_const = extern struct { - name: ?*const sockaddr, - namelen: socklen_t, - iov: [*]const iovec_const, - iovlen: i32, - __pad1: i32 = 0, - control: ?*const anyopaque, - controllen: socklen_t, - __pad2: socklen_t = 0, - flags: i32, -}; - pub const blksize_t = i32; pub const nlink_t = u32; pub const time_t = i32; diff --git a/lib/std/os/linux/loongarch64.zig b/lib/std/os/linux/loongarch64.zig index f57050ddb7..79d0612608 100644 --- a/lib/std/os/linux/loongarch64.zig +++ b/lib/std/os/linux/loongarch64.zig @@ -135,30 +135,6 @@ pub fn clone() callconv(.naked) usize { ); } -pub const msghdr = extern struct { - name: ?*sockaddr, - namelen: socklen_t, - iov: [*]iovec, - iovlen: i32, - __pad1: i32 = 0, - control: ?*anyopaque, - controllen: socklen_t, - __pad2: socklen_t = 0, - flags: i32, -}; - -pub const msghdr_const = extern struct { - name: ?*const sockaddr, - namelen: socklen_t, - iov: [*]const iovec_const, - iovlen: i32, - __pad1: i32 = 0, - control: ?*const anyopaque, - controllen: socklen_t, - __pad2: socklen_t = 0, - flags: i32, -}; - pub const blksize_t = i32; pub const nlink_t = u32; pub const time_t = i64; diff --git a/lib/std/os/linux/m68k.zig b/lib/std/os/linux/m68k.zig index 82d854e498..cff68f2383 100644 --- a/lib/std/os/linux/m68k.zig +++ b/lib/std/os/linux/m68k.zig @@ -199,27 +199,6 @@ pub const Flock = extern struct { pid: pid_t, }; -// TODO: not 100% sure of padding for msghdr -pub const msghdr = extern struct { - name: ?*sockaddr, - namelen: socklen_t, - iov: [*]iovec, - iovlen: i32, - control: ?*anyopaque, - controllen: socklen_t, - flags: i32, -}; - -pub const msghdr_const = extern struct { - name: ?*const sockaddr, - namelen: socklen_t, - iov: [*]const iovec_const, - iovlen: i32, - control: ?*const anyopaque, - controllen: socklen_t, - flags: i32, -}; - pub const Stat = extern struct { dev: dev_t, __pad: i16, diff --git a/lib/std/os/linux/s390x.zig b/lib/std/os/linux/s390x.zig index 86495f6f79..e76b6b57b1 100644 --- a/lib/std/os/linux/s390x.zig +++ b/lib/std/os/linux/s390x.zig @@ -199,30 +199,6 @@ pub const Flock = extern struct { pid: pid_t, }; -pub const msghdr = extern struct { - name: ?*sockaddr, - namelen: socklen_t, - iov: [*]iovec, - __pad1: i32 = 0, - iovlen: i32, - control: ?*anyopaque, - __pad2: i32 = 0, - controllen: socklen_t, - flags: i32, -}; - -pub const msghdr_const = extern struct { - name: ?*const sockaddr, - namelen: socklen_t, - iov: [*]const iovec_const, - __pad1: i32 = 0, - iovlen: i32, - control: ?*const anyopaque, - __pad2: i32 = 0, - controllen: socklen_t, - flags: i32, -}; - // The `stat` definition used by the Linux kernel. pub const Stat = extern struct { dev: dev_t, From 6c760d76b93680dc6eb4e2afc22b7d6bc286e3ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 07:47:19 +0200 Subject: [PATCH 2/6] std.os.linux: define PROT.SEM for xtensa --- lib/std/os/linux.zig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 45cf597c76..55a8297464 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -3614,8 +3614,7 @@ pub const PROT = struct { pub const EXEC = 0x4; /// page may be used for atomic ops pub const SEM = switch (native_arch) { - // TODO: also xtensa - .mips, .mipsel, .mips64, .mips64el => 0x10, + .mips, .mipsel, .mips64, .mips64el, .xtensa => 0x10, else => 0x8, }; /// mprotect flag: extend change to start of growsdown vma From 98f0bf9b67abc0fc2f787df95c26c75dc6db3c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 19:03:08 +0200 Subject: [PATCH 3/6] std.debug: fix SelfInfo default for freestanding ELF targets --- lib/std/debug.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 2ae9a23f85..51303b68dd 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -63,7 +63,10 @@ pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfI root.debug.SelfInfo else switch (std.Target.ObjectFormat.default(native_os, native_arch)) { .coff => if (native_os == .windows) @import("debug/SelfInfo/Windows.zig") else void, - .elf => @import("debug/SelfInfo/Elf.zig"), + .elf => switch (native_os) { + .freestanding, .other => void, + else => @import("debug/SelfInfo/Elf.zig"), + }, .macho => @import("debug/SelfInfo/MachO.zig"), .goff, .plan9, .spirv, .wasm, .xcoff => void, .c, .hex, .raw => unreachable, From 3f5e782357bbd89e604ff8ba214eb41fe56c8ff7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 20:42:54 +0200 Subject: [PATCH 4/6] std.debug: fix FP unwinding for LoongArch --- lib/std/debug.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 51303b68dd..5048d9c656 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -988,7 +988,7 @@ const StackIterator = union(enum) { // On RISC-V the frame pointer points to the top of the saved register // area, on pretty much every other architecture it points to the stack // slot where the previous frame pointer is saved. - if (native_arch.isRISCV()) break :off -2 * @sizeOf(usize); + if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize); // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS. if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize); break :off 0; @@ -996,7 +996,7 @@ const StackIterator = union(enum) { /// Offset of the saved return address wrt the frame pointer. const ra_offset = off: { - if (native_arch.isRISCV()) break :off -1 * @sizeOf(usize); + if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -1 * @sizeOf(usize); if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize); if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize); // On s390x, r14 is the link register and we need to grab it from its customary slot in the From f33d3a516631be2566116b16fa2f9d5774fa62cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 09:49:27 +0200 Subject: [PATCH 5/6] std.debug: greatly expand target support for segfault handling/unwinding I made a couple of decisions for this based on the fact that we don't expose the signal_ucontext_t type outside of the file: * Adding all the floating point and vector state to every ucontext_t and mcontext_t variant was way, way too much work, especially when we don't even use the stuff. So I deleted all that and kept only the bare minimum needed to reach into general-purpose registers. * There is no particularly compelling reason to stick to the naming and struct nesting used in the system headers. So we can actually unify the access patterns for almost all of these variants by taking some liberties here; as a result, fromPosixSignalContext() is now much nicer to read and extend. --- lib/std/debug.zig | 50 +- lib/std/debug/SelfInfo/Elf.zig | 52 +- lib/std/debug/cpu_context.zig | 1535 ++++++++++++++++++-------------- 3 files changed, 939 insertions(+), 698 deletions(-) diff --git a/lib/std/debug.zig b/lib/std/debug.zig index 5048d9c656..a1753f1e77 100644 --- a/lib/std/debug.zig +++ b/lib/std/debug.zig @@ -1315,15 +1315,26 @@ fn getDebugInfoAllocator() Allocator { /// Whether or not the current target can print useful debug information when a segfault occurs. pub const have_segfault_handling_support = switch (native_os) { + .haiku, .linux, - .macos, - .netbsd, - .solaris, - .illumos, - .windows, - .freebsd, - .openbsd, .serenity, + + .dragonfly, + .freebsd, + .netbsd, + .openbsd, + + .driverkit, + .ios, + .macos, + .tvos, + .visionos, + .watchos, + + .illumos, + .solaris, + + .windows, => true, else => false, @@ -1406,11 +1417,26 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa } } const addr: usize = switch (native_os) { - .linux => @intFromPtr(info.fields.sigfault.addr), - .freebsd, .macos, .serenity => @intFromPtr(info.addr), - .netbsd => @intFromPtr(info.info.reason.fault.addr), - .openbsd => @intFromPtr(info.data.fault.addr), - .solaris, .illumos => @intFromPtr(info.reason.fault.addr), + .serenity, + .dragonfly, + .freebsd, + .driverkit, + .ios, + .macos, + .tvos, + .visionos, + .watchos, + => @intFromPtr(info.addr), + .linux, + => @intFromPtr(info.fields.sigfault.addr), + .netbsd, + => @intFromPtr(info.info.reason.fault.addr), + .haiku, + .openbsd, + => @intFromPtr(info.data.fault.addr), + .illumos, + .solaris, + => @intFromPtr(info.reason.fault.addr), else => comptime unreachable, }; const name = switch (sig) { diff --git a/lib/std/debug/SelfInfo/Elf.zig b/lib/std/debug/SelfInfo/Elf.zig index 146f41278d..f10dc3cd63 100644 --- a/lib/std/debug/SelfInfo/Elf.zig +++ b/lib/std/debug/SelfInfo/Elf.zig @@ -94,6 +94,15 @@ pub const can_unwind: bool = s: { // Notably, we are yet to support unwinding on ARM. There, unwinding is not done through // `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format. const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) { + // Not supported yet: arm, m68k, sparc64 + .haiku => &.{ + .aarch64, + .powerpc, + .riscv64, + .x86, + .x86_64, + }, + // Not supported yet: arc, arm/armeb/thumb/thumbeb, csky, m68k, or1k, sparc/sparc64, xtensa .linux => &.{ .aarch64, .aarch64_be, @@ -113,31 +122,54 @@ pub const can_unwind: bool = s: { .x86, .x86_64, }, + .serenity => &.{ + .aarch64, + .x86_64, + .riscv64, + }, + + .dragonfly => &.{ + .x86_64, + }, + // Not supported yet: arm + .freebsd => &.{ + .aarch64, + .powerpc64, + .powerpc64le, + .riscv64, + .x86_64, + }, + // Not supported yet: arm/armeb, m68k, mips64/mips64el, sparc/sparc64 .netbsd => &.{ .aarch64, .aarch64_be, + .mips, + .mipsel, + .powerpc, .x86, .x86_64, }, - .freebsd => &.{ - .x86_64, - .aarch64, - }, + // Not supported yet: arm, sparc64 .openbsd => &.{ + .aarch64, + .mips64, + .mips64el, + .powerpc, + .powerpc64, + .riscv64, + .x86, .x86_64, }, - .solaris => &.{ - .x86_64, - }, + .illumos => &.{ .x86, .x86_64, }, - .serenity => &.{ + // Not supported yet: sparc64 + .solaris => &.{ .x86_64, - .aarch64, - .riscv64, }, + else => unreachable, }; for (archs) |a| { diff --git a/lib/std/debug/cpu_context.zig b/lib/std/debug/cpu_context.zig index b09f36d8ba..febe94cae6 100644 --- a/lib/std/debug/cpu_context.zig +++ b/lib/std/debug/cpu_context.zig @@ -24,229 +24,92 @@ pub const DwarfRegisterError = error{ pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native { if (signal_ucontext_t == void) return null; + + // In general, we include the hardwired zero register in the context if applicable. const uc: *const signal_ucontext_t = @ptrCast(@alignCast(ctx_ptr)); + + // Deal with some special cases first. + if (native_arch.isMIPS32() and native_os == .linux) { + // The O32 kABI uses 64-bit fields for some reason. + return .{ + .r = s: { + var regs: [32]Mips.Gpr = undefined; + for (uc.mcontext.r, 0..) |r, i| regs[i] = @truncate(r); + break :s regs; + }, + .pc = @truncate(uc.mcontext.pc), + }; + } + + // Only unified conversions from here. return switch (native_arch) { - .x86 => switch (native_os) { - .linux, .netbsd, .illumos => .{ .gprs = .init(.{ - .eax = uc.mcontext.gregs[std.posix.REG.EAX], - .ecx = uc.mcontext.gregs[std.posix.REG.ECX], - .edx = uc.mcontext.gregs[std.posix.REG.EDX], - .ebx = uc.mcontext.gregs[std.posix.REG.EBX], - .esp = uc.mcontext.gregs[std.posix.REG.ESP], - .ebp = uc.mcontext.gregs[std.posix.REG.EBP], - .esi = uc.mcontext.gregs[std.posix.REG.ESI], - .edi = uc.mcontext.gregs[std.posix.REG.EDI], - .eip = uc.mcontext.gregs[std.posix.REG.EIP], - }) }, - else => null, + .arm, .armeb, .thumb, .thumbeb => .{ + .r = uc.mcontext.r ++ [_]u32{uc.mcontext.pc}, }, - .x86_64 => switch (native_os) { - .linux, .solaris, .illumos => .{ .gprs = .init(.{ - .rax = uc.mcontext.gregs[std.posix.REG.RAX], - .rdx = uc.mcontext.gregs[std.posix.REG.RDX], - .rcx = uc.mcontext.gregs[std.posix.REG.RCX], - .rbx = uc.mcontext.gregs[std.posix.REG.RBX], - .rsi = uc.mcontext.gregs[std.posix.REG.RSI], - .rdi = uc.mcontext.gregs[std.posix.REG.RDI], - .rbp = uc.mcontext.gregs[std.posix.REG.RBP], - .rsp = uc.mcontext.gregs[std.posix.REG.RSP], - .r8 = uc.mcontext.gregs[std.posix.REG.R8], - .r9 = uc.mcontext.gregs[std.posix.REG.R9], - .r10 = uc.mcontext.gregs[std.posix.REG.R10], - .r11 = uc.mcontext.gregs[std.posix.REG.R11], - .r12 = uc.mcontext.gregs[std.posix.REG.R12], - .r13 = uc.mcontext.gregs[std.posix.REG.R13], - .r14 = uc.mcontext.gregs[std.posix.REG.R14], - .r15 = uc.mcontext.gregs[std.posix.REG.R15], - .rip = uc.mcontext.gregs[std.posix.REG.RIP], - }) }, - .freebsd, .serenity => .{ .gprs = .init(.{ - .rax = uc.mcontext.rax, - .rdx = uc.mcontext.rdx, - .rcx = uc.mcontext.rcx, - .rbx = uc.mcontext.rbx, - .rsi = uc.mcontext.rsi, - .rdi = uc.mcontext.rdi, - .rbp = uc.mcontext.rbp, - .rsp = uc.mcontext.rsp, - .r8 = uc.mcontext.r8, - .r9 = uc.mcontext.r9, - .r10 = uc.mcontext.r10, - .r11 = uc.mcontext.r11, - .r12 = uc.mcontext.r12, - .r13 = uc.mcontext.r13, - .r14 = uc.mcontext.r14, - .r15 = uc.mcontext.r15, - .rip = uc.mcontext.rip, - }) }, - .openbsd => .{ .gprs = .init(.{ - .rax = @bitCast(uc.sc_rax), - .rdx = @bitCast(uc.sc_rdx), - .rcx = @bitCast(uc.sc_rcx), - .rbx = @bitCast(uc.sc_rbx), - .rsi = @bitCast(uc.sc_rsi), - .rdi = @bitCast(uc.sc_rdi), - .rbp = @bitCast(uc.sc_rbp), - .rsp = @bitCast(uc.sc_rsp), - .r8 = @bitCast(uc.sc_r8), - .r9 = @bitCast(uc.sc_r9), - .r10 = @bitCast(uc.sc_r10), - .r11 = @bitCast(uc.sc_r11), - .r12 = @bitCast(uc.sc_r12), - .r13 = @bitCast(uc.sc_r13), - .r14 = @bitCast(uc.sc_r14), - .r15 = @bitCast(uc.sc_r15), - .rip = @bitCast(uc.sc_rip), - }) }, - .driverkit, .macos, .ios => .{ .gprs = .init(.{ - .rax = uc.mcontext.ss.rax, - .rdx = uc.mcontext.ss.rdx, - .rcx = uc.mcontext.ss.rcx, - .rbx = uc.mcontext.ss.rbx, - .rsi = uc.mcontext.ss.rsi, - .rdi = uc.mcontext.ss.rdi, - .rbp = uc.mcontext.ss.rbp, - .rsp = uc.mcontext.ss.rsp, - .r8 = uc.mcontext.ss.r8, - .r9 = uc.mcontext.ss.r9, - .r10 = uc.mcontext.ss.r10, - .r11 = uc.mcontext.ss.r11, - .r12 = uc.mcontext.ss.r12, - .r13 = uc.mcontext.ss.r13, - .r14 = uc.mcontext.ss.r14, - .r15 = uc.mcontext.ss.r15, - .rip = uc.mcontext.ss.rip, - }) }, - else => null, + .aarch64, .aarch64_be => .{ + .x = uc.mcontext.x ++ [_]u64{uc.mcontext.lr}, + .sp = uc.mcontext.sp, + .pc = uc.mcontext.pc, }, - .arm, .armeb, .thumb, .thumbeb => switch (builtin.os.tag) { - .linux => .{ - .r = .{ - uc.mcontext.arm_r0, - uc.mcontext.arm_r1, - uc.mcontext.arm_r2, - uc.mcontext.arm_r3, - uc.mcontext.arm_r4, - uc.mcontext.arm_r5, - uc.mcontext.arm_r6, - uc.mcontext.arm_r7, - uc.mcontext.arm_r8, - uc.mcontext.arm_r9, - uc.mcontext.arm_r10, - uc.mcontext.arm_fp, // r11 = fp - uc.mcontext.arm_ip, // r12 = ip - uc.mcontext.arm_sp, // r13 = sp - uc.mcontext.arm_lr, // r14 = lr - uc.mcontext.arm_pc, // r15 = pc - }, - }, - else => null, + .hexagon, .loongarch32, .loongarch64, .mips, .mipsel, .mips64, .mips64el, .or1k => .{ + .r = uc.mcontext.r, + .pc = uc.mcontext.pc, }, - .aarch64, .aarch64_be => switch (builtin.os.tag) { - .driverkit, .macos, .ios, .tvos, .watchos, .visionos => .{ - .x = uc.mcontext.ss.regs ++ @as([2]u64, .{ - uc.mcontext.ss.fp, // x29 = fp - uc.mcontext.ss.lr, // x30 = lr - }), - .sp = uc.mcontext.ss.sp, - .pc = uc.mcontext.ss.pc, - }, - .netbsd => .{ - .x = uc.mcontext.gregs[0..31].*, - .sp = uc.mcontext.gregs[31], - .pc = uc.mcontext.gregs[32], - }, - .freebsd => .{ - .x = uc.mcontext.gpregs.x ++ @as([1]u64, .{ - uc.mcontext.gpregs.lr, // x30 = lr - }), - .sp = uc.mcontext.gpregs.sp, - // On aarch64, the register ELR_LR1 defines the address to return to after handling - // a CPU exception (ELR is "Exception Link Register"). FreeBSD's ucontext_t uses - // this as the field name, but it's the same thing as the context's PC. - .pc = uc.mcontext.gpregs.elr, - }, - .openbsd => .{ - .x = uc.sc_x ++ .{uc.sc_lr}, - .sp = uc.sc_sp, - // Not a bug; see freebsd above for explanation. - .pc = uc.sc_elr, - }, - .linux => .{ - .x = uc.mcontext.regs, - .sp = uc.mcontext.sp, - .pc = uc.mcontext.pc, - }, - .serenity => .{ - .x = uc.mcontext.x, - .sp = uc.mcontext.sp, - .pc = uc.mcontext.pc, - }, - else => null, + .powerpc, .powerpcle, .powerpc64, .powerpc64le => .{ + .r = uc.mcontext.r, + .pc = uc.mcontext.pc, + .lr = uc.mcontext.lr, }, - .hexagon => switch (builtin.os.tag) { - .linux => .{ - .r = uc.mcontext.gregs, - .pc = uc.mcontext.pc, - }, - else => null, + .riscv32, .riscv32be, .riscv64, .riscv64be => .{ + // You can thank FreeBSD and OpenBSD for this silliness; they decided to be cute and + // group the registers by ABI mnemonic rather than register number. + .x = [_]Riscv.Gpr{0} ++ + uc.mcontext.ra_sp_gp_tp ++ + uc.mcontext.t0_2 ++ + uc.mcontext.s0_1 ++ + uc.mcontext.a ++ + uc.mcontext.s2_11 ++ + uc.mcontext.t3_6, + .pc = uc.mcontext.pc, }, - .loongarch64 => switch (builtin.os.tag) { - .linux => .{ - .r = uc.mcontext.regs, // includes r0 (hardwired zero) - .pc = uc.mcontext.pc, + .s390x => .{ + .r = uc.mcontext.r, + .psw = .{ + .mask = uc.mcontext.psw.mask, + .addr = uc.mcontext.psw.addr, }, - else => null, }, - .mips, .mipsel => switch (builtin.os.tag) { - // The O32 kABI uses 64-bit fields for some reason... - .linux => .{ - .r = s: { - var regs: [32]Mips.Gpr = undefined; - for (uc.mcontext.regs, 0..) |r, i| regs[i] = @truncate(r); // includes r0 (hardwired zero) - break :s regs; - }, - .pc = @truncate(uc.mcontext.pc), - }, - else => null, - }, - .mips64, .mips64el => switch (builtin.os.tag) { - .linux => .{ - .r = uc.mcontext.regs, // includes r0 (hardwired zero) - .pc = uc.mcontext.pc, - }, - else => null, - }, - .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (builtin.os.tag) { - .linux => .{ - .r = uc.mcontext.gp_regs[0..32].*, - .pc = uc.mcontext.gp_regs[32], - .lr = uc.mcontext.gp_regs[36], - }, - else => null, - }, - .riscv32, .riscv64 => switch (builtin.os.tag) { - .linux => .{ - .r = [1]usize{0} ++ uc.mcontext.gregs[1..].*, // r0 position is used for pc; replace with zero - .pc = uc.mcontext.gregs[0], - }, - .serenity => if (native_arch == .riscv32) null else .{ - .r = [1]u64{0} ++ uc.mcontext.x, - .pc = uc.mcontext.pc, - }, - else => null, - }, - .s390x => switch (builtin.os.tag) { - .linux => .{ - .r = uc.mcontext.gregs, - .psw = .{ - .mask = uc.mcontext.psw.mask, - .addr = uc.mcontext.psw.addr, - }, - }, - else => null, - }, - else => null, + .x86 => .{ .gprs = .init(.{ + .eax = uc.mcontext.eax, + .ecx = uc.mcontext.ecx, + .edx = uc.mcontext.edx, + .ebx = uc.mcontext.ebx, + .esp = uc.mcontext.esp, + .ebp = uc.mcontext.ebp, + .esi = uc.mcontext.esi, + .edi = uc.mcontext.edi, + .eip = uc.mcontext.eip, + }) }, + .x86_64 => .{ .gprs = .init(.{ + .rax = uc.mcontext.rax, + .rdx = uc.mcontext.rdx, + .rcx = uc.mcontext.rcx, + .rbx = uc.mcontext.rbx, + .rsi = uc.mcontext.rsi, + .rdi = uc.mcontext.rdi, + .rbp = uc.mcontext.rbp, + .rsp = uc.mcontext.rsp, + .r8 = uc.mcontext.r8, + .r9 = uc.mcontext.r9, + .r10 = uc.mcontext.r10, + .r11 = uc.mcontext.r11, + .r12 = uc.mcontext.r12, + .r13 = uc.mcontext.r13, + .r14 = uc.mcontext.r14, + .r15 = uc.mcontext.r15, + .rip = uc.mcontext.rip, + }) }, + else => comptime unreachable, }; } @@ -615,7 +478,7 @@ const LoongArch = extern struct { r: [32]Gpr, pc: Gpr, - pub const Gpr = if (builtin.target.cpu.arch == .loongarch64) u64 else u32; + pub const Gpr = if (native_arch == .loongarch64) u64 else u32; pub inline fn current() LoongArch { var ctx: LoongArch = undefined; @@ -717,7 +580,7 @@ const Mips = extern struct { r: [32]Gpr, pc: Gpr, - pub const Gpr = if (builtin.target.cpu.arch.isMIPS64()) u64 else u32; + pub const Gpr = if (native_arch.isMIPS64()) u64 else u32; pub inline fn current() Mips { var ctx: Mips = undefined; @@ -840,7 +703,7 @@ const Powerpc = extern struct { pc: Gpr, lr: Gpr, - pub const Gpr = if (builtin.target.cpu.arch.isPowerPC64()) u64 else u32; + pub const Gpr = if (native_arch.isPowerPC64()) u64 else u32; pub inline fn current() Powerpc { var ctx: Powerpc = undefined; @@ -992,10 +855,10 @@ const Powerpc = extern struct { /// This is an `extern struct` so that inline assembly in `current` can use field offsets. const Riscv = extern struct { /// The numbered general-purpose registers r0 - r31. r0 must be zero. - r: [32]Gpr, + x: [32]Gpr, pc: Gpr, - pub const Gpr = if (builtin.target.cpu.arch.isRiscv64()) u64 else u32; + pub const Gpr = if (native_arch.isRiscv64()) u64 else u32; pub inline fn current() Riscv { var ctx: Riscv = undefined; @@ -1081,7 +944,7 @@ const Riscv = extern struct { pub fn dwarfRegisterBytes(ctx: *Riscv, register_num: u16) DwarfRegisterError![]u8 { switch (register_num) { - 0...31 => return @ptrCast(&ctx.r[register_num]), + 0...31 => return @ptrCast(&ctx.x[register_num]), 65 => return @ptrCast(&ctx.pc), 32...63 => return error.UnsupportedRegister, // f0 - f31 @@ -1138,61 +1001,199 @@ const S390x = extern struct { } }; +/// The native operating system's `ucontext_t` as seen in the third argument to signal handlers. +/// +/// These are dramatically simplified since we only need general-purpose registers and don't care +/// about all the complicated extension state (floating point, vector, etc). This means that these +/// structures are almost all shorter than the real ones, which is safe because we only access them +/// through a pointer. +/// +/// Some effort is made to have structures for the same architecture use the same access pattern, +/// e.g. `uc.mcontext.x` for `aarch64-linux` and `aarch64-freebsd` even though that's not quite how +/// they're declared and spelled in the C headers for both targets. Similarly, registers are typed +/// as unsigned everywhere even if that's not how they're declared in the C headers. const signal_ucontext_t = switch (native_os) { - .linux => std.os.linux.ucontext_t, - .emscripten => std.os.emscripten.ucontext_t, - .freebsd => std.os.freebsd.ucontext_t, - .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct { - onstack: c_int, - sigmask: std.c.sigset_t, - stack: std.c.stack_t, - link: ?*signal_ucontext_t, - mcsize: u64, - mcontext: *mcontext_t, - const mcontext_t = switch (native_arch) { - .aarch64 => extern struct { - es: extern struct { - far: u64, // Virtual Fault Address - esr: u32, // Exception syndrome - exception: u32, // Number of arm exception taken - }, - ss: extern struct { - /// General purpose registers - regs: [29]u64, - /// Frame pointer x29 - fp: u64, - /// Link register x30 + .linux => switch (native_arch) { + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm64/include/uapi/asm/ucontext.h + .aarch64, + .aarch64_be, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/loongarch/include/uapi/asm/ucontext.h + .loongarch64, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/ucontext.h + .powerpc64, + .powerpc64le, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/riscv/include/uapi/asm/ucontext.h + .riscv32, + .riscv64, + => extern struct { + _flags: usize, + _link: ?*signal_ucontext_t, + _stack: std.os.linux.stack_t, + _sigmask: std.os.linux.sigset_t, + _unused: [120]u8, + mcontext: switch (native_arch) { + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm64/include/uapi/asm/sigcontext.h + .aarch64, .aarch64_be => extern struct { + _fault_address: u64 align(16), + x: [30]u64, lr: u64, - /// Stack pointer x31 sp: u64, - /// Program counter pc: u64, - /// Current program status register - cpsr: u32, - __pad: u32, }, - ns: extern struct { - q: [32]u128, - fpsr: u32, - fpcr: u32, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/loongarch/include/uapi/asm/sigcontext.h + .loongarch64 => extern struct { + pc: u64 align(16), + r: [32]u64, }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/sigcontext.h + .powerpc64, .powerpc64le => extern struct { + _unused: [4]u64, + _signal: i32, + _pad: i32, + _handler: u64, + _oldmask: u64, + _regs: ?*anyopaque, + r: [32]u64, + pc: u64, + _msr: u64, + _orig_r3: u64, + _ctr: u64, + lr: u64, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/riscv/include/uapi/asm/sigcontext.h + .riscv32, .riscv64 => extern struct { + pc: usize align(16), + ra_sp_gp_tp: [4]usize, + t0_2: [3]usize, + s0_1: [2]usize, + a: [8]usize, + s2_11: [10]usize, + t3_6: [4]usize, + }, + else => unreachable, }, - .x86_64 => extern struct { - es: extern struct { - trapno: u16, - cpu: u16, - err: u32, - faultvaddr: u64, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/include/uapi/asm-generic/ucontext.h + .arc, + .csky, + .hexagon, + .m68k, + .mips, + .mipsel, + .mips64, + .mips64el, + .or1k, + .s390x, + .x86, + .x86_64, + .xtensa, + => extern struct { + _flags: usize, + _link: ?*signal_ucontext_t, + _stack: std.os.linux.stack_t, + mcontext: switch (native_arch) { + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arc/include/uapi/asm/sigcontext.h + .arc => extern struct { + _pad1: u32, + _bta: u32, + _lp: extern struct { + _start: u32, + _end: u32, + _count: u32, + }, + _status32: u32, + pc: u32, + r31: u32, + r27_26: [2]u32, + r12_0: [13]u32, + r28: u32, + _pad2: u32, + r25_13: [13]u32, + _efa: u32, + _stop_pc: u32, + r30: u32, }, - ss: extern struct { - rax: u64, - rbx: u64, - rcx: u64, - rdx: u64, - rdi: u64, - rsi: u64, - rbp: u64, - rsp: u64, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/csky/include/uapi/asm/sigcontext.h + .csky => extern struct { + r31: u32, + r15: u32, + pc: u32, + _sr: u32, + r14: u32, + _orig_a0: u32, + r0_13: [14]u32, + r16_30: [15]u32, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/hexagon/include/uapi/asm/sigcontext.h + .hexagon => extern struct { + r: [32]u32 align(8), + _salc: [2]extern struct { + _sa: u32, + _lc: u32, + }, + _m: [2]u32, + _usr: u32, + _p: u32, + _gp: u32, + _ugp: u32, + pc: u32, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/m68k/include/asm/ucontext.h + .m68k => extern struct { + _version: i32, + d: [8]u32, + a: [8]u32, + pc: u32, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/mips/include/uapi/asm/sigcontext.h + .mips, .mipsel => extern struct { + _regmask: u32, + _status: u32, + // ??? A spectacularly failed attempt to be future-proof? + pc: u64, + r: [32]u64, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/mips/include/uapi/asm/sigcontext.h + .mips64, .mips64el => extern struct { + r: [32]u64, + _fpregs: [32]u64, + _hi: [4]u64, + _lo: [4]u64, + pc: u64, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/openrisc/include/uapi/asm/sigcontext.h + .or1k => extern struct { + r: [32]u32, + pc: u32, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/s390/include/uapi/asm/sigcontext.h + .s390x => extern struct { + psw: extern struct { + mask: u64, + addr: u64, + }, + r: [16]u64, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/x86/include/uapi/asm/sigcontext.h + .x86 => extern struct { + _gs: u32, + _fs: u32, + _es: u32, + _ds: u32, + edi: u32, + esi: u32, + ebp: u32, + esp: u32, + ebx: u32, + edx: u32, + ecx: u32, + eax: u32, + _trapno: u32, + _err: u32, + eip: u32, + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/x86/include/uapi/asm/sigcontext.h + .x86_64 => extern struct { r8: u64, r9: u64, r10: u64, @@ -1201,197 +1202,540 @@ const signal_ucontext_t = switch (native_os) { r13: u64, r14: u64, r15: u64, + rdi: u64, + rsi: u64, + rbp: u64, + rbx: u64, + rdx: u64, + rax: u64, + rcx: u64, + rsp: u64, rip: u64, - rflags: u64, - cs: u64, - fs: u64, - gs: u64, }, - fs: extern struct { - reserved: [2]c_int, - fcw: u16, - fsw: u16, - ftw: u8, - rsrv1: u8, - fop: u16, - ip: u32, - cs: u16, - rsrv2: u16, - dp: u32, - ds: u16, - rsrv3: u16, - mxcsr: u32, - mxcsrmask: u32, - stmm: [8]stmm_reg, - xmm: [16]xmm_reg, - rsrv4: [96]u8, - reserved1: c_int, - - const stmm_reg = [16]u8; - const xmm_reg = [16]u8; + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/xtensa/include/uapi/asm/sigcontext.h + .xtensa => extern struct { + pc: u32, + _ps: u32, + _l: extern struct { + _beg: u32, + _end: u32, + _count: u32, + }, + _sar: u32, + _acc: extern struct { + _lo: u32, + _hi: u32, + }, + a: [16]u32, }, + else => unreachable, }, - else => void, - }; - }, - .solaris, .illumos => extern struct { - flags: u64, - link: ?*signal_ucontext_t, - sigmask: std.c.sigset_t, - stack: std.c.stack_t, - mcontext: mcontext_t, - brand_data: [3]?*anyopaque, - filler: [2]i64, - const mcontext_t = extern struct { - gregs: [28]u64, - fpregs: std.c.fpregset_t, - }; - }, - .openbsd => switch (builtin.cpu.arch) { - .x86_64 => extern struct { - sc_rdi: c_long, - sc_rsi: c_long, - sc_rdx: c_long, - sc_rcx: c_long, - sc_r8: c_long, - sc_r9: c_long, - sc_r10: c_long, - sc_r11: c_long, - sc_r12: c_long, - sc_r13: c_long, - sc_r14: c_long, - sc_r15: c_long, - sc_rbp: c_long, - sc_rbx: c_long, - sc_rax: c_long, - sc_gs: c_long, - sc_fs: c_long, - sc_es: c_long, - sc_ds: c_long, - sc_trapno: c_long, - sc_err: c_long, - sc_rip: c_long, - sc_cs: c_long, - sc_rflags: c_long, - sc_rsp: c_long, - sc_ss: c_long, - - sc_fpstate: *anyopaque, // struct fxsave64 * - __sc_unused: c_int, - sc_mask: c_int, - sc_cookie: c_long, }, - .aarch64 => extern struct { - __sc_unused: c_int, - sc_mask: c_int, - sc_sp: c_ulong, - sc_lr: c_ulong, - sc_elr: c_ulong, - sc_spsr: c_ulong, - sc_x: [30]c_ulong, - sc_cookie: c_long, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm/include/asm/ucontext.h + .arm, .armeb, .thumb, .thumbeb => extern struct { + _flags: u32, + _link: ?*signal_ucontext_t, + _stack: std.os.linux.stack_t, + _unused: [31]i32, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm/include/uapi/asm/sigcontext.h + mcontext: extern struct { + _trap_no: u32, + _error_code: u32, + _oldmask: u32, + r: [15]u32, + pc: u32, + }, }, - else => void, - }, - .netbsd => extern struct { - flags: u32, - link: ?*signal_ucontext_t, - sigmask: std.c.sigset_t, - stack: std.c.stack_t, - mcontext: mcontext_t, - __pad: [ - switch (builtin.cpu.arch) { - .x86 => 4, - .mips, .mipsel, .mips64, .mips64el => 14, - .arm, .armeb, .thumb, .thumbeb => 1, - .sparc, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8, - else => 0, - } - ]u32, - const mcontext_t = switch (builtin.cpu.arch) { - .aarch64, .aarch64_be => extern struct { - gregs: [35]u64, - fregs: [528]u8 align(16), - spare: [8]u64, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/ucontext.h + .powerpc, .powerpcle => extern struct { + _flags: u32, + _link: ?*signal_ucontext_t, + _stack: std.os.linux.stack_t, + _pad1: [7]i32, + _regs: ?*anyopaque, + _sigmask: std.os.linux.sigset_t, + _unused: [120]u8, + _pad2: [3]i32, + mcontext: extern struct { + r: [32]u32 align(16), + pc: u32, + _msr: u32, + _orig_r3: u32, + _ctr: u32, + lr: u32, }, - .x86 => extern struct { - gregs: [19]u32, - fpregs: [161]u32, - mc_tlsbase: u32, - }, - .x86_64 => extern struct { - gregs: [26]u64, - mc_tlsbase: u64, - fpregs: [512]u8 align(8), - }, - else => void, - }; + }, + // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/sparc/include/uapi/asm/uctx.h + .sparc => @compileError("sparc-linux ucontext_t missing"), + .sparc64 => @compileError("sparc64-linux ucontext_t missing"), + else => unreachable, }, - .dragonfly => extern struct { - sigmask: std.c.sigset_t, - mcontext: mcontext_t, - link: ?*signal_ucontext_t, - stack: std.c.stack_t, - cofunc: ?*fn (?*signal_ucontext_t, ?*anyopaque) void, - arg: ?*void, - _spare: [4]c_int, - const mcontext_t = extern struct { - const register_t = isize; - onstack: register_t, // XXX - sigcontext compat. - rdi: register_t, - rsi: register_t, - rdx: register_t, - rcx: register_t, - r8: register_t, - r9: register_t, - rax: register_t, - rbx: register_t, - rbp: register_t, - r10: register_t, - r11: register_t, - r12: register_t, - r13: register_t, - r14: register_t, - r15: register_t, - xflags: register_t, - trapno: register_t, - addr: register_t, - flags: register_t, - err: register_t, - rip: register_t, - cs: register_t, - rflags: register_t, - rsp: register_t, // machine state - ss: register_t, - - len: c_uint, // sizeof(mcontext_t) - fpformat: c_uint, - ownedfp: c_uint, - reserved: c_uint, - unused: [8]c_uint, - - // NOTE! 64-byte aligned as of here. Also must match savefpu structure. - fpregs: [256]c_int align(64), - }; - }, - .serenity => extern struct { - link: ?*signal_ucontext_t, - sigmask: std.c.sigset_t, - stack: std.c.stack_t, - mcontext: mcontext_t, - const mcontext_t = switch (builtin.cpu.arch) { - // https://github.com/SerenityOS/serenity/blob/200e91cd7f1ec5453799a2720d4dc114a59cc289/Kernel/Arch/aarch64/mcontext.h#L15-L19 + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/sys/_ucontext.h + .freebsd => extern struct { + _sigmask: std.c.sigset_t, + mcontext: switch (native_arch) { + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/arm64/include/ucontext.h .aarch64 => extern struct { - x: [31]u64, + x: [30]u64 align(16), + lr: u64, sp: u64, pc: u64, }, - // https://github.com/SerenityOS/serenity/blob/66f8d0f031ef25c409dbb4fecaa454800fecae0f/Kernel/Arch/riscv64/mcontext.h#L15-L18 - .riscv64 => extern struct { - x: [31]u64, + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/arm/include/ucontext.h + .arm => extern struct { + r: [15]u32, + pc: u32, + }, + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/powerpc/include/ucontext.h + .powerpc64, .powerpc64le => extern struct { + _vers: i32 align(16), + _flags: i32, + _onstack: i32, + _len: i32, + _avec: [32 * 2]u64, + _av: [2]u32, + r: [32]u64, + lr: u64, + _cr: u64, + _xer: u64, + _ctr: u64, pc: u64, }, - // https://github.com/SerenityOS/serenity/blob/7b9ea3efdec9f86a1042893e8107d0b23aad8727/Kernel/Arch/x86_64/mcontext.h#L15-L40 + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/riscv/include/ucontext.h + .riscv64 => extern struct { + ra_sp_gp_tp: [4]u64, + t0_2: [3]u64, + t3_6: [4]u64, + s0_1: [2]u64, + s2_11: [10]u64, + a: [8]u64, + pc: u64, + }, + // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/x86/include/ucontext.h + .x86_64 => extern struct { + _onstack: i64, + rdi: u64, + rsi: u64, + rdx: u64, + rcx: u64, + r8: u64, + r9: u64, + rax: u64, + rbx: u64, + rbp: u64, + r10: u64, + r11: u64, + r12: u64, + r13: u64, + r14: u64, + r15: u64, + _trapno: i32, + _fs: i16, + _gs: i16, + _addr: i64, + _flags: i32, + _es: i16, + _ds: i16, + _err: i64, + rip: u64, + _cs: i64, + _rflags: i64, + rsp: u64, + }, + else => unreachable, + }, + }, + // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/sys/_types/_ucontext.h + .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct { + _onstack: i32, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + _link: ?*signal_ucontext_t, + _mcsize: u64, + mcontext: *switch (native_arch) { + // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/arm/_mcontext.h + // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/mach/arm/_structs.h + .aarch64 => extern struct { + _far: u64 align(16), + _esr: u64, + x: [30]u64, + lr: u64, + sp: u64, + pc: u64, + }, + // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/i386/_mcontext.h + // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/mach/i386/_structs.h + .x86_64 => extern struct { + _trapno: u16, + _cpu: u16, + _err: u32, + _faultvaddr: u64, + rax: u64, + rbx: u64, + rcx: u64, + rdx: u64, + rdi: u64, + rsi: u64, + rbp: u64, + rsp: u64, + r8: u64, + r9: u64, + r10: u64, + r11: u64, + r12: u64, + r13: u64, + r14: u64, + r15: u64, + rip: u64, + }, + else => unreachable, + }, + }, + // This needs to be audited by someone with access to the Solaris headers. + .solaris => extern struct { + _flags: u64, + _link: ?*signal_ucontext_t, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + mcontext: switch (native_arch) { + .sparc64 => @compileError("sparc64-solaris mcontext_t missing"), + .x86_64 => extern struct { + r15: u64, + r14: u64, + r13: u64, + r12: u64, + r11: u64, + r10: u64, + r9: u64, + r8: u64, + rdi: u64, + rsi: u64, + rbp: u64, + rbx: u64, + rdx: u64, + rcx: u64, + rax: u64, + _trapno: i64, + _err: i64, + rip: u64, + }, + else => unreachable, + }, + }, + // https://github.com/illumos/illumos-gate/blob/d4ce137bba3bd16823db6374d9e9a643264ce245/usr/src/uts/intel/sys/ucontext.h + .illumos => extern struct { + _flags: usize, + _link: ?*signal_ucontext_t, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + mcontext: switch (native_arch) { + // https://github.com/illumos/illumos-gate/blob/d4ce137bba3bd16823db6374d9e9a643264ce245/usr/src/uts/intel/sys/mcontext.h + .x86 => extern struct { + _gs: u32, + _fs: u32, + _es: u32, + _ds: u32, + edi: u32, + esi: u32, + ebp: u32, + esp: u32, + ebx: u32, + edx: u32, + ecx: u32, + eax: u32, + _trapno: i32, + _err: i32, + eip: u32, + }, + .x86_64 => extern struct { + r15: u64, + r14: u64, + r13: u64, + r12: u64, + r11: u64, + r10: u64, + r9: u64, + r8: u64, + rdi: u64, + rsi: u64, + rbp: u64, + rbx: u64, + rdx: u64, + rcx: u64, + rax: u64, + _trapno: i64, + _err: i64, + rip: u64, + }, + else => unreachable, + }, + }, + .openbsd => switch (native_arch) { + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/arm64/include/signal.h + .aarch64 => extern struct { + _unused: i32, + _mask: i32, + mcontext: extern struct { + sp: u64, + lr: u64, + pc: u64, + _spsr: u64, + x: [30]u64, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/arm/include/signal.h + .arm => extern struct { + _cookie: i32, + _mask: i32, + mcontext: extern struct { + _spsr: u32 align(8), + r: [15]u32, + _svc_lr: u32, + pc: u32, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/mips64/include/signal.h + .mips64, .mips64el => extern struct { + _cookie: i64, + _mask: i64, + mcontext: extern struct { + pc: u64, + r: [32]u64, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/powerpc/include/signal.h + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/powerpc64/include/signal.h + .powerpc, .powerpc64 => extern struct { + _cookie: isize, + _mask: i32, + mcontext: extern struct { + r: [32]usize, + lr: usize, + _cr: usize, + _xer: usize, + _ctr: usize, + pc: usize, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/riscv64/include/signal.h + .riscv64 => extern struct { + _unused: i32, + _mask: i32, + mcontext: extern struct { + ra_sp_gp_tp: [4]u64, + t0_2: [3]u64, + t3_6: [4]u64, + s0_1: [2]u64, + s2_11: [10]u64, + a: [8]u64, + pc: u64, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sparc64/include/signal.h + .sparc64 => @compileError("sparc64-openbsd mcontext_t missing"), + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/i386/include/signal.h + .x86 => extern struct { + mcontext: extern struct { + _gs: i32, + _fs: i32, + _es: i32, + _ds: i32, + edi: u32, + esi: u32, + ebp: u32, + ebx: u32, + edx: u32, + ecx: u32, + eax: u32, + eip: u32, + _cs: i32, + _eflags: i32, + esp: u32, + }, + }, + // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/amd64/include/signal.h + .x86_64 => extern struct { + mcontext: extern struct { + rdi: u64, + rsi: u64, + rdx: u64, + rcx: u64, + r8: u64, + r9: u64, + r10: u64, + r11: u64, + r12: u64, + r13: u64, + r14: u64, + r15: u64, + rbp: u64, + rbx: u64, + rax: u64, + _gs: i64, + _fs: i64, + _es: i64, + _ds: i64, + _trapno: i64, + _err: i64, + rip: u64, + _cs: i64, + _rflags: i64, + rsp: u64, + }, + }, + else => unreachable, + }, + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/sys/ucontext.h + .netbsd => extern struct { + _flags: u32, + _link: ?*signal_ucontext_t, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + mcontext: switch (native_arch) { + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/arm/include/mcontext.h + .aarch64, .aarch64_be => extern struct { + x: [30]u64 align(16), + lr: u64, + sp: u64, + pc: u64, + }, + .arm, .armeb => extern struct { + r: [15]u32 align(8), + pc: u32, + }, + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/m68k/include/mcontext.h + .m68k => extern struct { + d: [8]u32, + a: [8]u32, + pc: u32, + }, + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/mips/include/mcontext.h + .mips, .mipsel => extern struct { + r: [32]u32 align(8), + _lo: i32, + _hi: i32, + _cause: i32, + pc: u32, + }, + .mips64, .mips64el => @compileError("https://github.com/ziglang/zig/issues/23765#issuecomment-2880386178"), + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/powerpc/include/mcontext.h + .powerpc => extern struct { + r: [32]u32 align(16), + _cr: i32, + lr: u32, + pc: u32, + }, + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sparc/include/mcontext.h + .sparc => @compileError("sparc-netbsd mcontext_t missing"), + .sparc64 => @compileError("sparc64-netbsd mcontext_t missing"), + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/i386/include/mcontext.h + .x86 => extern struct { + _gs: i32, + _fs: i32, + _es: i32, + _ds: i32, + edi: u32, + esi: u32, + ebp: u32, + esp: u32, + ebx: u32, + edx: u32, + ecx: u32, + eax: u32, + _trapno: i32, + _err: i32, + eip: u32, + }, + // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/amd64/include/mcontext.h + .x86_64 => extern struct { + rdi: u64, + rsi: u64, + rdx: u64, + rcx: u64, + r8: u64, + r9: u64, + r10: u64, + r11: u64, + r12: u64, + r13: u64, + r14: u64, + r15: u64, + rbp: u64, + rbx: u64, + rax: u64, + _gs: i64, + _fs: i64, + _es: i64, + _ds: i64, + _trapno: i64, + _err: i64, + rip: u64, + _cs: i64, + _rflags: i64, + rsp: u64, + }, + else => unreachable, + }, + }, + // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/3de1e9d36269616d22237f19d60a737a41271ab5/sys/sys/_ucontext.h + .dragonfly => extern struct { + _sigmask: std.c.sigset_t, + mcontext: switch (native_arch) { + // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/3de1e9d36269616d22237f19d60a737a41271ab5/sys/cpu/x86_64/include/ucontext.h + .x86_64 => extern struct { + _onstack: i64 align(64), + rdi: u64, + rsi: u64, + rdx: u64, + rcx: u64, + r8: u64, + r9: u64, + rax: u64, + rbx: u64, + rbp: u64, + r10: u64, + r11: u64, + r12: u64, + r13: u64, + r14: u64, + r15: u64, + _xflags: i64, + _trapno: i64, + _addr: i64, + _flags: i64, + _err: i64, + rip: u64, + _cs: i64, + _rflags: i64, + rsp: u64, + }, + else => unreachable, + }, + }, + // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/API/POSIX/ucontext.h + .serenity => extern struct { + _link: ?*signal_ucontext_t, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + mcontext: switch (native_arch) { + // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/aarch64/mcontext.h + .aarch64 => extern struct { + x: [30]u64, + lr: u64, + sp: u64, + pc: u64, + }, + // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/riscv64/mcontext.h + .riscv64 => extern struct { + ra_sp_gp_tp: [4]u64, + t0_2: [3]u64, + s0_1: [2]u64, + a: [8]u64, + s2_11: [10]u64, + t3_6: [4]u64, + pc: u64, + }, + // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/x86_64/mcontext.h .x86_64 => extern struct { rax: u64, rcx: u64, @@ -1410,262 +1754,103 @@ const signal_ucontext_t = switch (native_os) { r13: u64, r14: u64, r15: u64, - rflags: u64, - cs: u32, - ss: u32, - ds: u32, - es: u32, - fs: u32, - gs: u32, }, - else => void, - }; + else => unreachable, + }, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/signal.h#L356 .haiku => extern struct { - link: ?*signal_ucontext_t, - sigmask: std.c.sigset_t, - stack: std.c.stack_t, - mcontext: mcontext_t, - const mcontext_t = switch (builtin.cpu.arch) { - .arm, .thumb => extern struct { - r0: u32, - r1: u32, - r2: u32, - r3: u32, - r4: u32, - r5: u32, - r6: u32, - r7: u32, - r8: u32, - r9: u32, - r10: u32, - r11: u32, - r12: u32, - r13: u32, - r14: u32, - r15: u32, - cpsr: u32, + _link: ?*signal_ucontext_t, + _sigmask: std.c.sigset_t, + _stack: std.c.stack_t, + mcontext: switch (native_arch) { + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/arm/signal.h + .arm => extern struct { + r: [15]u32 align(8), + pc: u32, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/arm64/signal.h .aarch64 => extern struct { - x: [10]u64, + x: [30]u64 align(16), lr: u64, sp: u64, - elr: u64, - spsr: u64, - fp_q: [32]u128, - fpsr: u32, - fpcr: u32, + pc: u64, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/m68k/signal.h .m68k => extern struct { - pc: u32, - d0: u32, - d1: u32, - d2: u32, - d3: u32, - d4: u32, - d5: u32, - d6: u32, - d7: u32, - a0: u32, - a1: u32, - a2: u32, - a3: u32, - a4: u32, - a5: u32, - a6: u32, - a7: u32, - ccr: u8, - f0: f64, - f1: f64, - f2: f64, - f3: f64, - f4: f64, - f5: f64, - f6: f64, - f7: f64, - f8: f64, - f9: f64, - f10: f64, - f11: f64, - f12: f64, - f13: f64, - }, - .mipsel => extern struct { - r0: u32, + pc: u32 align(8), + d: [8]u32, + a: [8]u32, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/ppc/signal.h .powerpc => extern struct { - pc: u32, - r0: u32, - r1: u32, - r2: u32, - r3: u32, - r4: u32, - r5: u32, - r6: u32, - r7: u32, - r8: u32, - r9: u32, - r10: u32, - r11: u32, - r12: u32, - f0: f64, - f1: f64, - f2: f64, - f3: f64, - f4: f64, - f5: f64, - f6: f64, - f7: f64, - f8: f64, - f9: f64, - f10: f64, - f11: f64, - f12: f64, - f13: f64, - reserved: u32, - fpscr: u32, - ctr: u32, - xer: u32, - cr: u32, - msr: u32, + pc: u32 align(8), + r: [13]u32, // Um, are you okay, Haiku? + _f: [14]f64, + _reserved: u32, + _fpscr: u32, + _ctr: u32, + _xer: u32, + _cr: u32, + _msr: u32, lr: u32, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/riscv64/signal.h .riscv64 => extern struct { - x: [31]u64, + ra_sp_gp_tp: [4]u64, + t0_2: [3]u64, + s0_1: [2]u64, + a: [8]u64, + s2_11: [10]u64, + t3_6: [4]u64, pc: u64, - f: [32]f64, - fcsr: u64, - }, - .sparc64 => extern struct { - g1: u64, - g2: u64, - g3: u64, - g4: u64, - g5: u64, - g6: u64, - g7: u64, - o0: u64, - o1: u64, - o2: u64, - o3: u64, - o4: u64, - o5: u64, - sp: u64, - o7: u64, - l0: u64, - l1: u64, - l2: u64, - l3: u64, - l4: u64, - l5: u64, - l6: u64, - l7: u64, - i0: u64, - i1: u64, - i2: u64, - i3: u64, - i4: u64, - i5: u64, - fp: u64, - i7: u64, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/sparc64/signal.h + .sparc64 => @compileError("sparc64-haiku mcontext_t missing"), + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/x86/signal.h .x86 => extern struct { - pub const old_extended_regs = extern struct { - control: u16, - reserved1: u16, - status: u16, - reserved2: u16, - tag: u16, - reserved3: u16, - eip: u32, - cs: u16, - opcode: u16, - datap: u32, - ds: u16, - reserved4: u16, - fp_mmx: [8][10]u8, - }; - - pub const fp_register = extern struct { value: [10]u8, reserved: [6]u8 }; - - pub const xmm_register = extern struct { value: [16]u8 }; - - pub const new_extended_regs = extern struct { - control: u16, - status: u16, - tag: u16, - opcode: u16, - eip: u32, - cs: u16, - reserved1: u16, - datap: u32, - ds: u16, - reserved2: u16, - mxcsr: u32, - reserved3: u32, - fp_mmx: [8]fp_register, - xmmx: [8]xmm_register, - reserved4: [224]u8, - }; - - pub const extended_regs = extern struct { - state: extern union { - old_format: old_extended_regs, - new_format: new_extended_regs, - }, - format: u32, - }; - eip: u32, - eflags: u32, + _eflags: u32, eax: u32, ecx: u32, edx: u32, esp: u32, ebp: u32, - reserved: u32, - xregs: extended_regs, + _reserved: u32, + _xregs: extern struct { + _fp_control: u16, + _fp_status: u16, + _fp_tag: u16, + _fp_opcode: u16, + _fp_eip: u32, + _fp_cs: u16, + _reserved1: u16, + _fp_datap: u32, + _fp_ds: u16, + _reserved2: u16, + _mxcsr: u32, + _mxcsr_mask: u32, + _mmx: [8][16]u8, + _xmmx: [8][16]u8, + _reserved3: [176]u8, + _fault_address: u32, + _error_code: u32, + _cs: u16, + _ds: u16, + _es: u16, + _fs: u16, + _gs: u16, + _ss: u16, + _trap_number: u8, + _reserved4: [27]u8, + _format: u32, + }, edi: u32, esi: u32, ebx: u32, }, + // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/x86_64/signal.h .x86_64 => extern struct { - pub const fp_register = extern struct { - value: [10]u8, - reserved: [6]u8, - }; - - pub const xmm_register = extern struct { - value: [16]u8, - }; - - pub const fpu_state = extern struct { - control: u16, - status: u16, - tag: u16, - opcode: u16, - rip: u64, - rdp: u64, - mxcsr: u32, - mscsr_mask: u32, - - fp_mmx: [8]fp_register, - xmm: [16]xmm_register, - reserved: [96]u8, - }; - - pub const xstate_hdr = extern struct { - bv: u64, - xcomp_bv: u64, - reserved: [48]u8, - }; - - pub const savefpu = extern struct { - fxsave: fpu_state, - xstate: xstate_hdr, - ymm: [16]xmm_register, - }; - rax: u64, rbx: u64, rcx: u64, @@ -1683,11 +1868,9 @@ const signal_ucontext_t = switch (native_os) { r15: u64, rsp: u64, rip: u64, - rflags: u64, - fpu: savefpu, }, - else => void, - }; + else => unreachable, + }, }, else => void, }; From 36dbe66cf4499e4a8f656bdf4629ec1623b345c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Thu, 9 Oct 2025 09:55:40 +0200 Subject: [PATCH 6/6] std: stop exposing anything having to do with ucontext_t This type is useful for two things: * Doing non-local control flow with ucontext.h functions. * Inspecting machine state in a signal handler. The first use case is not one we support; we no longer expose bindings to those functions in the standard library. They're also deprecated in POSIX and, as a result, not available in musl. The second use case is valid, but is very poorly served by the standard library. As evidenced by my changes to std.debug.cpu_context.signal_context_t, users will be better served rolling their own ucontext_t and especially mcontext_t types which fit their specific situation. Further, these types tend to evolve frequently as architectures evolve, and the standard library has not done a good job keeping up, or even providing them for all supported targets. --- lib/std/c.zig | 107 +----------------------------- lib/std/c/solaris.zig | 23 ------- lib/std/os/emscripten.zig | 38 ----------- lib/std/os/freebsd.zig | 72 --------------------- lib/std/os/linux.zig | 7 +- lib/std/os/linux/aarch64.zig | 19 ------ lib/std/os/linux/arm.zig | 33 ---------- lib/std/os/linux/hexagon.zig | 28 -------- lib/std/os/linux/loongarch64.zig | 15 ----- lib/std/os/linux/m68k.zig | 3 - lib/std/os/linux/mips.zig | 29 --------- lib/std/os/linux/mips64.zig | 26 -------- lib/std/os/linux/powerpc.zig | 29 --------- lib/std/os/linux/powerpc64.zig | 39 ----------- lib/std/os/linux/riscv32.zig | 35 ---------- lib/std/os/linux/riscv64.zig | 35 ---------- lib/std/os/linux/s390x.zig | 19 ------ lib/std/os/linux/sparc64.zig | 100 ---------------------------- lib/std/os/linux/x86.zig | 108 ------------------------------- lib/std/os/linux/x86_64.zig | 106 ------------------------------ lib/std/posix.zig | 1 - 21 files changed, 2 insertions(+), 870 deletions(-) diff --git a/lib/std/c.zig b/lib/std/c.zig index 39ee688563..248dd2f92f 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) { else => void, }; -pub const REG = switch (native_os) { - .linux => linux.REG, - .emscripten => emscripten.REG, - .freebsd => switch (builtin.cpu.arch) { - .aarch64 => struct { - pub const FP = 29; - pub const SP = 31; - pub const PC = 32; - }, - .arm => struct { - pub const FP = 11; - pub const SP = 13; - pub const PC = 15; - }, - .x86_64 => struct { - pub const RBP = 12; - pub const RIP = 21; - pub const RSP = 24; - }, - else => struct {}, - }, - .solaris, .illumos => struct { - pub const R15 = 0; - pub const R14 = 1; - pub const R13 = 2; - pub const R12 = 3; - pub const R11 = 4; - pub const R10 = 5; - pub const R9 = 6; - pub const R8 = 7; - pub const RDI = 8; - pub const RSI = 9; - pub const RBP = 10; - pub const RBX = 11; - pub const RDX = 12; - pub const RCX = 13; - pub const RAX = 14; - pub const RIP = 17; - pub const RSP = 20; - }, - .netbsd => switch (builtin.cpu.arch) { - .aarch64, .aarch64_be => struct { - pub const FP = 29; - pub const SP = 31; - pub const PC = 32; - }, - .arm, .armeb => struct { - pub const FP = 11; - pub const SP = 13; - pub const PC = 15; - }, - .x86 => struct { - pub const GS = 0; - pub const FS = 1; - pub const ES = 2; - pub const DS = 3; - pub const EDI = 4; - pub const ESI = 5; - pub const EBP = 6; - pub const ESP = 7; - pub const EBX = 8; - pub const EDX = 9; - pub const ECX = 10; - pub const EAX = 11; - pub const TRAPNO = 12; - pub const ERR = 13; - pub const EIP = 14; - pub const CS = 15; - pub const EFL = 16; - pub const UESP = 17; - pub const SS = 18; - }, - .x86_64 => struct { - pub const RDI = 0; - pub const RSI = 1; - pub const RDX = 2; - pub const RCX = 3; - pub const R8 = 4; - pub const R9 = 5; - pub const R10 = 6; - pub const R11 = 7; - pub const R12 = 8; - pub const R13 = 9; - pub const R14 = 10; - pub const R15 = 11; - pub const RBP = 12; - pub const RBX = 13; - pub const RAX = 14; - pub const GS = 15; - pub const FS = 16; - pub const ES = 17; - pub const DS = 18; - pub const TRAPNO = 19; - pub const ERR = 20; - pub const RIP = 21; - pub const CS = 22; - pub const RFLAGS = 23; - pub const RSP = 24; - pub const SS = 25; - }, - else => struct {}, - }, - else => struct {}, -}; pub const RLIM = switch (native_os) { .linux => linux.RLIM, .emscripten => emscripten.RLIM, @@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) { pub const siginfo_t = switch (native_os) { .linux => linux.siginfo_t, .emscripten => emscripten.siginfo_t, - .macos, .ios, .tvos, .watchos, .visionos => extern struct { + .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct { signo: c_int, errno: c_int, code: c_int, @@ -11084,7 +10980,6 @@ pub const SETUSTACK = solaris.GETUSTACK; pub const SFD = solaris.SFD; pub const ctid_t = solaris.ctid_t; pub const file_obj = solaris.file_obj; -pub const fpregset_t = solaris.fpregset_t; pub const id_t = solaris.id_t; pub const lif_ifinfo_req = solaris.lif_ifinfo_req; pub const lif_nd_req = solaris.lif_nd_req; diff --git a/lib/std/c/solaris.zig b/lib/std/c/solaris.zig index 39df093c86..e69c77dac7 100644 --- a/lib/std/c/solaris.zig +++ b/lib/std/c/solaris.zig @@ -31,29 +31,6 @@ pub const poolid_t = id_t; pub const zoneid_t = id_t; pub const ctid_t = id_t; -pub const fpregset_t = extern union { - regs: [130]u32, - chip_state: extern struct { - cw: u16, - sw: u16, - fctw: u8, - __fx_rsvd: u8, - fop: u16, - rip: u64, - rdp: u64, - mxcsr: u32, - mxcsr_mask: u32, - st: [8]extern union { - fpr_16: [5]u16, - __fpr_pad: u128, - }, - xmm: [16]u128, - __fx_ign2: [6]u128, - status: u32, - xstatus: u32, - }, -}; - pub const GETCONTEXT = 0; pub const SETCONTEXT = 1; pub const GETUSTACK = 2; diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index 0e07a8afb7..1ecb4f6bb0 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -400,28 +400,6 @@ pub const timeval = extern struct { usec: i32, }; -pub const REG = struct { - pub const GS = 0; - pub const FS = 1; - pub const ES = 2; - pub const DS = 3; - pub const EDI = 4; - pub const ESI = 5; - pub const EBP = 6; - pub const ESP = 7; - pub const EBX = 8; - pub const EDX = 9; - pub const ECX = 10; - pub const EAX = 11; - pub const TRAPNO = 12; - pub const ERR = 13; - pub const EIP = 14; - pub const CS = 15; - pub const EFL = 16; - pub const UESP = 17; - pub const SS = 18; -}; - pub const S = struct { pub const IFMT = 0o170000; @@ -813,13 +791,6 @@ pub const dl_phdr_info = extern struct { phnum: u16, }; -pub const mcontext_t = extern struct { - gregs: [19]usize, - fpregs: [*]u8, - oldmask: usize, - cr2: usize, -}; - pub const msghdr = std.c.msghdr; pub const msghdr_const = std.c.msghdr; @@ -846,15 +817,6 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const ucontext_t = extern struct { - flags: usize, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: sigset_t, - regspace: [28]usize, -}; - pub const utsname = extern struct { sysname: [64:0]u8, nodename: [64:0]u8, diff --git a/lib/std/os/freebsd.zig b/lib/std/os/freebsd.zig index aedb2d8cce..2d082bf0cd 100644 --- a/lib/std/os/freebsd.zig +++ b/lib/std/os/freebsd.zig @@ -48,75 +48,3 @@ pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64, else => |err| return unexpectedErrno(err), } } - -pub const ucontext_t = extern struct { - sigmask: std.c.sigset_t, - mcontext: mcontext_t, - link: ?*ucontext_t, - stack: std.c.stack_t, - flags: c_int, - __spare__: [4]c_int, - const mcontext_t = switch (builtin.cpu.arch) { - .x86_64 => extern struct { - onstack: u64, - rdi: u64, - rsi: u64, - rdx: u64, - rcx: u64, - r8: u64, - r9: u64, - rax: u64, - rbx: u64, - rbp: u64, - r10: u64, - r11: u64, - r12: u64, - r13: u64, - r14: u64, - r15: u64, - trapno: u32, - fs: u16, - gs: u16, - addr: u64, - flags: u32, - es: u16, - ds: u16, - err: u64, - rip: u64, - cs: u64, - rflags: u64, - rsp: u64, - ss: u64, - len: u64, - fpformat: u64, - ownedfp: u64, - fpstate: [64]u64 align(16), - fsbase: u64, - gsbase: u64, - xfpustate: u64, - xfpustate_len: u64, - spare: [4]u64, - }, - .aarch64 => extern struct { - gpregs: extern struct { - x: [30]u64, - lr: u64, - sp: u64, - elr: u64, - spsr: u32, - _pad: u32, - }, - fpregs: extern struct { - q: [32]u128, - sr: u32, - cr: u32, - flags: u32, - _pad: u32, - }, - flags: u32, - _pad: u32, - _spare: [8]u64, - }, - else => void, - }; -}; diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 55a8297464..502b2defc2 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -47,9 +47,7 @@ const arch_bits = switch (native_arch) { .powerpc, .powerpcle => @import("linux/powerpc.zig"), .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"), .s390x => @import("linux/s390x.zig"), - else => struct { - pub const ucontext_t = void; - }, + else => struct {}, }; const syscall_bits = if (native_arch.isThumb()) @import("linux/thumb.zig") else arch_bits; @@ -94,7 +92,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx; pub const F = arch_bits.F; pub const Flock = arch_bits.Flock; pub const HWCAP = arch_bits.HWCAP; -pub const REG = arch_bits.REG; pub const SC = arch_bits.SC; pub const Stat = arch_bits.Stat; pub const VDSO = arch_bits.VDSO; @@ -102,14 +99,12 @@ pub const blkcnt_t = arch_bits.blkcnt_t; pub const blksize_t = arch_bits.blksize_t; pub const dev_t = arch_bits.dev_t; pub const ino_t = arch_bits.ino_t; -pub const mcontext_t = arch_bits.mcontext_t; pub const mode_t = arch_bits.mode_t; pub const nlink_t = arch_bits.nlink_t; pub const off_t = arch_bits.off_t; pub const time_t = arch_bits.time_t; pub const timeval = arch_bits.timeval; pub const timezone = arch_bits.timezone; -pub const ucontext_t = arch_bits.ucontext_t; pub const user_desc = arch_bits.user_desc; pub const tls = @import("linux/tls.zig"); diff --git a/lib/std/os/linux/aarch64.zig b/lib/std/os/linux/aarch64.zig index 6538e1f175..4888a9eda3 100644 --- a/lib/std/os/linux/aarch64.zig +++ b/lib/std/os/linux/aarch64.zig @@ -241,23 +241,4 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const mcontext_t = extern struct { - fault_address: usize, - regs: [31]usize, - sp: usize, - pc: usize, - pstate: usize, - // Make sure the field is correctly aligned since this area - // holds various FP/vector registers - reserved1: [256 * 16]u8 align(16), -}; - -pub const ucontext_t = extern struct { - flags: usize, - link: ?*ucontext_t, - stack: stack_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - mcontext: mcontext_t, -}; - pub const Elf_Symndx = u32; diff --git a/lib/std/os/linux/arm.zig b/lib/std/os/linux/arm.zig index 693fe5aafd..7995570654 100644 --- a/lib/std/os/linux/arm.zig +++ b/lib/std/os/linux/arm.zig @@ -277,37 +277,4 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const mcontext_t = extern struct { - trap_no: usize, - error_code: usize, - oldmask: usize, - arm_r0: usize, - arm_r1: usize, - arm_r2: usize, - arm_r3: usize, - arm_r4: usize, - arm_r5: usize, - arm_r6: usize, - arm_r7: usize, - arm_r8: usize, - arm_r9: usize, - arm_r10: usize, - arm_fp: usize, - arm_ip: usize, - arm_sp: usize, - arm_lr: usize, - arm_pc: usize, - arm_cpsr: usize, - fault_address: usize, -}; - -pub const ucontext_t = extern struct { - flags: usize, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - regspace: [64]u64, -}; - pub const Elf_Symndx = u32; diff --git a/lib/std/os/linux/hexagon.zig b/lib/std/os/linux/hexagon.zig index 72e094da43..e3bf7a8709 100644 --- a/lib/std/os/linux/hexagon.zig +++ b/lib/std/os/linux/hexagon.zig @@ -212,31 +212,3 @@ pub const Stat = extern struct { pub const Elf_Symndx = u32; pub const VDSO = void; - -pub const mcontext_t = extern struct { - gregs: [32]u32 align(8), - sa0: u32, - lc0: u32, - sa1: u32, - lc1: u32, - m0: u32, - m1: u32, - usr: u32, - p3_0: u32, - gp: u32, - ugp: u32, - pc: u32, - cause: u32, - badva: u32, - cs0: u32, - cs1: u32, - _pad1: u32, -}; - -pub const ucontext_t = extern struct { - flags: u32, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: sigset_t, -}; diff --git a/lib/std/os/linux/loongarch64.zig b/lib/std/os/linux/loongarch64.zig index 79d0612608..4ed817167d 100644 --- a/lib/std/os/linux/loongarch64.zig +++ b/lib/std/os/linux/loongarch64.zig @@ -210,19 +210,4 @@ pub const VDSO = struct { pub const CGT_VER = "LINUX_5.10"; }; -pub const mcontext_t = extern struct { - pc: u64, - regs: [32]u64, - flags: u32, - extcontext: [0]u64 align(16), -}; - -pub const ucontext_t = extern struct { - flags: c_ulong, - link: ?*ucontext_t, - stack: stack_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - mcontext: mcontext_t, -}; - pub const Elf_Symndx = u32; diff --git a/lib/std/os/linux/m68k.zig b/lib/std/os/linux/m68k.zig index cff68f2383..c3bd42b2ff 100644 --- a/lib/std/os/linux/m68k.zig +++ b/lib/std/os/linux/m68k.zig @@ -234,6 +234,3 @@ pub const Elf_Symndx = u32; // No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6. pub const VDSO = void; - -/// TODO -pub const ucontext_t = void; diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index f34eb0edfb..6412c847bd 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -348,32 +348,3 @@ pub const timezone = extern struct { }; pub const Elf_Symndx = u32; - -pub const mcontext_t = extern struct { - _regmask: u32, - _status: u32, - pc: u64, - regs: [32]u64, - fpregs: [32]f64, - acx: u32, - fpc_csr: u32, - _fpc_eir: u32, - used_math: u32, - dsp: u32, - mdhi: u64, - mdlo: u64, - hi1: u32, - lo1: u32, - hi2: u32, - lo2: u32, - hi3: u32, - lo3: u32, -}; - -pub const ucontext_t = extern struct { - flags: u32, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: sigset_t, -}; diff --git a/lib/std/os/linux/mips64.zig b/lib/std/os/linux/mips64.zig index 4cde9cf15e..4419190193 100644 --- a/lib/std/os/linux/mips64.zig +++ b/lib/std/os/linux/mips64.zig @@ -327,29 +327,3 @@ pub const timezone = extern struct { }; pub const Elf_Symndx = u32; - -pub const mcontext_t = extern struct { - regs: [32]u64, - fpregs: [32]f64, - mdhi: u64, - hi1: u64, - hi2: u64, - hi3: u64, - mdlo: u64, - lo1: u64, - lo2: u64, - lo3: u64, - pc: u64, - fpc_csr: u32, - used_math: u32, - dsp: u32, - _reserved: u32, -}; - -pub const ucontext_t = extern struct { - flags: u32, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: sigset_t, -}; diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 32e66d8c78..c96a8a0804 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -351,33 +351,4 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const greg_t = u32; -pub const gregset_t = [48]greg_t; -pub const fpregset_t = [33]f64; - -pub const vrregset = extern struct { - vrregs: [32][4]u32, - vrsave: u32, - _pad: [2]u32, - vscr: u32, -}; -pub const vrregset_t = vrregset; - -pub const mcontext_t = extern struct { - gp_regs: gregset_t, - fp_regs: fpregset_t, - v_regs: vrregset_t align(16), -}; - -pub const ucontext_t = extern struct { - flags: u32, - link: ?*ucontext_t, - stack: stack_t, - pad: [7]i32, - regs: *mcontext_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - pad2: [3]i32, - mcontext: mcontext_t, -}; - pub const Elf_Symndx = u32; diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index fb4686c7b2..5b1af7cc2b 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -336,43 +336,4 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const greg_t = u64; -pub const gregset_t = [48]greg_t; -pub const fpregset_t = [33]f64; - -/// The position of the vscr register depends on endianness. -/// On C, macros are used to change vscr_word's offset to -/// account for this. Here we'll just define vscr_word_le -/// and vscr_word_be. Code must take care to use the correct one. -pub const vrregset = extern struct { - vrregs: [32][4]u32 align(16), - vscr_word_le: u32, - _pad1: [2]u32, - vscr_word_be: u32, - vrsave: u32, - _pad2: [3]u32, -}; -pub const vrregset_t = vrregset; - -pub const mcontext_t = extern struct { - __unused: [4]u64, - signal: i32, - _pad0: i32, - handler: u64, - oldmask: u64, - regs: ?*anyopaque, - gp_regs: gregset_t, - fp_regs: fpregset_t, - v_regs: *vrregset_t, - vmx_reserve: [34 + 34 + 32 + 1]i64, -}; - -pub const ucontext_t = extern struct { - flags: u32, - link: ?*ucontext_t, - stack: stack_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - mcontext: mcontext_t, -}; - pub const Elf_Symndx = u32; diff --git a/lib/std/os/linux/riscv32.zig b/lib/std/os/linux/riscv32.zig index f70fcefd14..a0f73adeef 100644 --- a/lib/std/os/linux/riscv32.zig +++ b/lib/std/os/linux/riscv32.zig @@ -220,38 +220,3 @@ pub const VDSO = struct { pub const CGT_SYM = "__vdso_clock_gettime"; pub const CGT_VER = "LINUX_4.15"; }; - -pub const f_ext_state = extern struct { - f: [32]f32, - fcsr: u32, -}; - -pub const d_ext_state = extern struct { - f: [32]f64, - fcsr: u32, -}; - -pub const q_ext_state = extern struct { - f: [32]f128, - fcsr: u32, - _reserved: [3]u32, -}; - -pub const fpstate = extern union { - f: f_ext_state, - d: d_ext_state, - q: q_ext_state, -}; - -pub const mcontext_t = extern struct { - gregs: [32]u32, - fpregs: fpstate, -}; - -pub const ucontext_t = extern struct { - flags: c_ulong, - link: ?*ucontext_t, - stack: stack_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - mcontext: mcontext_t, -}; diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index d2eb4f9b4d..5331620451 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -220,38 +220,3 @@ pub const VDSO = struct { pub const CGT_SYM = "__vdso_clock_gettime"; pub const CGT_VER = "LINUX_4.15"; }; - -pub const f_ext_state = extern struct { - f: [32]f32, - fcsr: u32, -}; - -pub const d_ext_state = extern struct { - f: [32]f64, - fcsr: u32, -}; - -pub const q_ext_state = extern struct { - f: [32]f128, - fcsr: u32, - _reserved: [3]u32, -}; - -pub const fpstate = extern union { - f: f_ext_state, - d: d_ext_state, - q: q_ext_state, -}; - -pub const mcontext_t = extern struct { - gregs: [32]u64, - fpregs: fpstate, -}; - -pub const ucontext_t = extern struct { - flags: c_ulong, - link: ?*ucontext_t, - stack: stack_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - mcontext: mcontext_t, -}; diff --git a/lib/std/os/linux/s390x.zig b/lib/std/os/linux/s390x.zig index e76b6b57b1..00bc09c518 100644 --- a/lib/std/os/linux/s390x.zig +++ b/lib/std/os/linux/s390x.zig @@ -235,22 +235,3 @@ pub const VDSO = struct { pub const CGT_SYM = "__kernel_clock_gettime"; pub const CGT_VER = "LINUX_2.6.29"; }; - -pub const ucontext_t = extern struct { - flags: u64, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask -}; - -pub const mcontext_t = extern struct { - psw: extern struct { - mask: u64, - addr: u64, - }, - gregs: [16]u64, - aregs: [16]u32, - fpc: u32, - fregs: [16]f64, -}; diff --git a/lib/std/os/linux/sparc64.zig b/lib/std/os/linux/sparc64.zig index 1859ba5c05..f222e84e84 100644 --- a/lib/std/os/linux/sparc64.zig +++ b/lib/std/os/linux/sparc64.zig @@ -325,104 +325,4 @@ pub const timezone = extern struct { dsttime: i32, }; -// TODO I'm not sure if the code below is correct, need someone with more -// knowledge about sparc64 linux internals to look into. - pub const Elf_Symndx = u32; - -pub const fpstate = extern struct { - regs: [32]u64, - fsr: u64, - gsr: u64, - fprs: u64, -}; - -pub const __fpq = extern struct { - fpq_addr: *u32, - fpq_instr: u32, -}; - -pub const __fq = extern struct { - FQu: extern union { - whole: f64, - fpq: __fpq, - }, -}; - -pub const fpregset_t = extern struct { - fpu_fr: extern union { - fpu_regs: [32]u32, - fpu_dregs: [32]f64, - fpu_qregs: [16]c_longdouble, - }, - fpu_q: *__fq, - fpu_fsr: u64, - fpu_qcnt: u8, - fpu_q_entrysize: u8, - fpu_en: u8, -}; - -pub const siginfo_fpu_t = extern struct { - float_regs: [64]u32, - fsr: u64, - gsr: u64, - fprs: u64, -}; - -pub const sigcontext = extern struct { - info: [128]i8, - regs: extern struct { - u_regs: [16]u64, - tstate: u64, - tpc: u64, - tnpc: u64, - y: u64, - fprs: u64, - }, - fpu_save: *siginfo_fpu_t, - stack: extern struct { - sp: usize, - flags: i32, - size: u64, - }, - mask: u64, -}; - -pub const greg_t = u64; -pub const gregset_t = [19]greg_t; - -pub const fq = extern struct { - addr: *u64, - insn: u32, -}; - -pub const fpu_t = extern struct { - fregs: extern union { - sregs: [32]u32, - dregs: [32]u64, - qregs: [16]c_longdouble, - }, - fsr: u64, - fprs: u64, - gsr: u64, - fq: *fq, - qcnt: u8, - qentsz: u8, - enab: u8, -}; - -pub const mcontext_t = extern struct { - gregs: gregset_t, - fp: greg_t, - i7: greg_t, - fpregs: fpu_t, -}; - -pub const ucontext_t = extern struct { - link: ?*ucontext_t, - flags: u64, - sigmask: u64, - mcontext: mcontext_t, - stack: stack_t, - sigset: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask -}; diff --git a/lib/std/os/linux/x86.zig b/lib/std/os/linux/x86.zig index 41b11a35e3..c24ffcae6a 100644 --- a/lib/std/os/linux/x86.zig +++ b/lib/std/os/linux/x86.zig @@ -288,44 +288,6 @@ pub const timezone = extern struct { dsttime: i32, }; -pub const mcontext_t = extern struct { - gregs: [19]usize, - fpregs: [*]u8, - oldmask: usize, - cr2: usize, -}; - -pub const REG = struct { - pub const GS = 0; - pub const FS = 1; - pub const ES = 2; - pub const DS = 3; - pub const EDI = 4; - pub const ESI = 5; - pub const EBP = 6; - pub const ESP = 7; - pub const EBX = 8; - pub const EDX = 9; - pub const ECX = 10; - pub const EAX = 11; - pub const TRAPNO = 12; - pub const ERR = 13; - pub const EIP = 14; - pub const CS = 15; - pub const EFL = 16; - pub const UESP = 17; - pub const SS = 18; -}; - -pub const ucontext_t = extern struct { - flags: usize, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask - regspace: [64]u64, -}; - pub const Elf_Symndx = u32; pub const user_desc = extern struct { @@ -366,73 +328,3 @@ pub const SC = struct { pub const recvmmsg = 19; pub const sendmmsg = 20; }; - -fn gpRegisterOffset(comptime reg_index: comptime_int) usize { - return @offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "gregs") + @sizeOf(usize) * reg_index; -} - -noinline fn getContextReturnAddress() usize { - return @returnAddress(); -} - -pub fn getContextInternal() callconv(.naked) usize { - asm volatile ( - \\ movl $0, %[flags_offset:c](%%edx) - \\ movl $0, %[link_offset:c](%%edx) - \\ movl %%edi, %[edi_offset:c](%%edx) - \\ movl %%esi, %[esi_offset:c](%%edx) - \\ movl %%ebp, %[ebp_offset:c](%%edx) - \\ movl %%ebx, %[ebx_offset:c](%%edx) - \\ movl %%edx, %[edx_offset:c](%%edx) - \\ movl %%ecx, %[ecx_offset:c](%%edx) - \\ movl %%eax, %[eax_offset:c](%%edx) - \\ movl (%%esp), %%ecx - \\ movl %%ecx, %[eip_offset:c](%%edx) - \\ leal 4(%%esp), %%ecx - \\ movl %%ecx, %[esp_offset:c](%%edx) - \\ xorl %%ecx, %%ecx - \\ movw %%fs, %%cx - \\ movl %%ecx, %[fs_offset:c](%%edx) - \\ leal %[regspace_offset:c](%%edx), %%ecx - \\ movl %%ecx, %[fpregs_offset:c](%%edx) - \\ fnstenv (%%ecx) - \\ fldenv (%%ecx) - \\ pushl %%ebx - \\ pushl %%esi - \\ xorl %%ebx, %%ebx - \\ movl %[sigaltstack], %%eax - \\ leal %[stack_offset:c](%%edx), %%ecx - \\ int $0x80 - \\ testl %%eax, %%eax - \\ jnz 0f - \\ movl %[sigprocmask], %%eax - \\ xorl %%ecx, %%ecx - \\ leal %[sigmask_offset:c](%%edx), %%edx - \\ movl %[sigset_size], %%esi - \\ int $0x80 - \\0: - \\ popl %%esi - \\ popl %%ebx - \\ retl - : - : [flags_offset] "i" (@offsetOf(ucontext_t, "flags")), - [link_offset] "i" (@offsetOf(ucontext_t, "link")), - [edi_offset] "i" (comptime gpRegisterOffset(REG.EDI)), - [esi_offset] "i" (comptime gpRegisterOffset(REG.ESI)), - [ebp_offset] "i" (comptime gpRegisterOffset(REG.EBP)), - [esp_offset] "i" (comptime gpRegisterOffset(REG.ESP)), - [ebx_offset] "i" (comptime gpRegisterOffset(REG.EBX)), - [edx_offset] "i" (comptime gpRegisterOffset(REG.EDX)), - [ecx_offset] "i" (comptime gpRegisterOffset(REG.ECX)), - [eax_offset] "i" (comptime gpRegisterOffset(REG.EAX)), - [eip_offset] "i" (comptime gpRegisterOffset(REG.EIP)), - [fs_offset] "i" (comptime gpRegisterOffset(REG.FS)), - [fpregs_offset] "i" (@offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "fpregs")), - [regspace_offset] "i" (@offsetOf(ucontext_t, "regspace")), - [sigaltstack] "i" (@intFromEnum(linux.SYS.sigaltstack)), - [stack_offset] "i" (@offsetOf(ucontext_t, "stack")), - [sigprocmask] "i" (@intFromEnum(linux.SYS.rt_sigprocmask)), - [sigmask_offset] "i" (@offsetOf(ucontext_t, "sigmask")), - [sigset_size] "i" (linux.NSIG / 8), - : .{ .cc = true, .memory = true, .eax = true, .ecx = true, .edx = true }); -} diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index 72944c37ac..e3db9e99c4 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -190,32 +190,6 @@ pub const ARCH = struct { pub const GET_GS = 0x1004; }; -pub const REG = struct { - pub const R8 = 0; - pub const R9 = 1; - pub const R10 = 2; - pub const R11 = 3; - pub const R12 = 4; - pub const R13 = 5; - pub const R14 = 6; - pub const R15 = 7; - pub const RDI = 8; - pub const RSI = 9; - pub const RBP = 10; - pub const RBX = 11; - pub const RDX = 12; - pub const RAX = 13; - pub const RCX = 14; - pub const RSP = 15; - pub const RIP = 16; - pub const EFL = 17; - pub const CSGSFS = 18; - pub const ERR = 19; - pub const TRAPNO = 20; - pub const OLDMASK = 21; - pub const CR2 = 22; -}; - pub const Flock = extern struct { type: i16, whence: i16, @@ -272,83 +246,3 @@ pub const timezone = extern struct { }; pub const Elf_Symndx = u32; - -pub const greg_t = usize; -pub const gregset_t = [23]greg_t; -pub const fpstate = extern struct { - cwd: u16, - swd: u16, - ftw: u16, - fop: u16, - rip: usize, - rdp: usize, - mxcsr: u32, - mxcr_mask: u32, - st: [8]extern struct { - significand: [4]u16, - exponent: u16, - padding: [3]u16 = undefined, - }, - xmm: [16]extern struct { - element: [4]u32, - }, - padding: [24]u32 = undefined, -}; -pub const fpregset_t = *fpstate; -pub const sigcontext = extern struct { - r8: usize, - r9: usize, - r10: usize, - r11: usize, - r12: usize, - r13: usize, - r14: usize, - r15: usize, - - rdi: usize, - rsi: usize, - rbp: usize, - rbx: usize, - rdx: usize, - rax: usize, - rcx: usize, - rsp: usize, - rip: usize, - eflags: usize, - - cs: u16, - gs: u16, - fs: u16, - pad0: u16 = undefined, - - err: usize, - trapno: usize, - oldmask: usize, - cr2: usize, - - fpstate: *fpstate, - reserved1: [8]usize = undefined, -}; - -pub const mcontext_t = extern struct { - gregs: gregset_t, - fpregs: fpregset_t, - reserved1: [8]usize = undefined, -}; - -/// ucontext_t is part of the state pushed on the stack by the kernel for -/// a signal handler. And also a subset of the state returned from the -/// makecontext/getcontext/swapcontext POSIX APIs. -/// -/// Currently this structure matches the glibc/musl layout. It contains a -/// 1024-bit signal mask, and `fpregs_mem`. This structure should be -/// split into one for the kernel ABI and c.zig should define a glibc/musl -/// compatible structure. -pub const ucontext_t = extern struct { - flags: usize, - link: ?*ucontext_t, - stack: stack_t, - mcontext: mcontext_t, - sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a glibc-compatible (1024-bit) sigmask. - fpregs_mem: [64]usize, // Not part of kernel ABI, only part of glibc ucontext_t -}; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index 9ba8e010e8..ce480928bf 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -97,7 +97,6 @@ pub const POLL = system.POLL; pub const POSIX_FADV = system.POSIX_FADV; pub const PR = system.PR; pub const PROT = system.PROT; -pub const REG = system.REG; pub const RLIM = system.RLIM; pub const RR = system.RR; pub const S = system.S;