Merge pull request #25516 from alexrp/std-debug

`std.debug`: greatly expand target support for segfault handling/unwinding, and remove public `ucontext_t` completely
This commit is contained in:
Alex Rønne Petersen 2025-10-10 14:04:02 +02:00 committed by GitHub
commit f010a31319
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
24 changed files with 948 additions and 1666 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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,
@ -985,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;
@ -993,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
@ -1312,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,
@ -1403,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) {

View File

@ -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| {

File diff suppressed because it is too large Load Diff

View File

@ -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,

View File

@ -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,
};
};

View File

@ -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");
@ -3614,8 +3609,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

View File

@ -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;

View File

@ -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;

View File

@ -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;
@ -236,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,
};

View File

@ -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;
@ -234,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;

View File

@ -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,
@ -255,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;

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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;

View File

@ -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;

View File

@ -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,
};

View File

@ -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,
};

View File

@ -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,
@ -259,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,
};

View File

@ -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
};

View File

@ -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 });
}

View File

@ -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
};

View File

@ -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;