authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-10 14:04:02+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-10-10 14:04:02+02:00
logf010a3131976b2e85aadccaaeda5c03d2288849f
tree81a24e3f4113356f994dc8a214b2f6fe379d2662
parent07b6dbf8cae53d1e7a0c43cf514bb9286c3fd09e
parent36dbe66cf4499e4a8f656bdf4629ec1623b345c1
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #25516 from alexrp/std-debug

`std.debug`: greatly expand target support for segfault handling/unwinding, and remove public `ucontext_t` completely

24 files changed, 931 insertions(+), 1649 deletions(-)

lib/std/c.zig+1-106
......@@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) {
18411841 else => void,
18421842};
18431843
1844pub const REG = switch (native_os) {
1845 .linux => linux.REG,
1846 .emscripten => emscripten.REG,
1847 .freebsd => switch (builtin.cpu.arch) {
1848 .aarch64 => struct {
1849 pub const FP = 29;
1850 pub const SP = 31;
1851 pub const PC = 32;
1852 },
1853 .arm => struct {
1854 pub const FP = 11;
1855 pub const SP = 13;
1856 pub const PC = 15;
1857 },
1858 .x86_64 => struct {
1859 pub const RBP = 12;
1860 pub const RIP = 21;
1861 pub const RSP = 24;
1862 },
1863 else => struct {},
1864 },
1865 .solaris, .illumos => struct {
1866 pub const R15 = 0;
1867 pub const R14 = 1;
1868 pub const R13 = 2;
1869 pub const R12 = 3;
1870 pub const R11 = 4;
1871 pub const R10 = 5;
1872 pub const R9 = 6;
1873 pub const R8 = 7;
1874 pub const RDI = 8;
1875 pub const RSI = 9;
1876 pub const RBP = 10;
1877 pub const RBX = 11;
1878 pub const RDX = 12;
1879 pub const RCX = 13;
1880 pub const RAX = 14;
1881 pub const RIP = 17;
1882 pub const RSP = 20;
1883 },
1884 .netbsd => switch (builtin.cpu.arch) {
1885 .aarch64, .aarch64_be => struct {
1886 pub const FP = 29;
1887 pub const SP = 31;
1888 pub const PC = 32;
1889 },
1890 .arm, .armeb => struct {
1891 pub const FP = 11;
1892 pub const SP = 13;
1893 pub const PC = 15;
1894 },
1895 .x86 => struct {
1896 pub const GS = 0;
1897 pub const FS = 1;
1898 pub const ES = 2;
1899 pub const DS = 3;
1900 pub const EDI = 4;
1901 pub const ESI = 5;
1902 pub const EBP = 6;
1903 pub const ESP = 7;
1904 pub const EBX = 8;
1905 pub const EDX = 9;
1906 pub const ECX = 10;
1907 pub const EAX = 11;
1908 pub const TRAPNO = 12;
1909 pub const ERR = 13;
1910 pub const EIP = 14;
1911 pub const CS = 15;
1912 pub const EFL = 16;
1913 pub const UESP = 17;
1914 pub const SS = 18;
1915 },
1916 .x86_64 => struct {
1917 pub const RDI = 0;
1918 pub const RSI = 1;
1919 pub const RDX = 2;
1920 pub const RCX = 3;
1921 pub const R8 = 4;
1922 pub const R9 = 5;
1923 pub const R10 = 6;
1924 pub const R11 = 7;
1925 pub const R12 = 8;
1926 pub const R13 = 9;
1927 pub const R14 = 10;
1928 pub const R15 = 11;
1929 pub const RBP = 12;
1930 pub const RBX = 13;
1931 pub const RAX = 14;
1932 pub const GS = 15;
1933 pub const FS = 16;
1934 pub const ES = 17;
1935 pub const DS = 18;
1936 pub const TRAPNO = 19;
1937 pub const ERR = 20;
1938 pub const RIP = 21;
1939 pub const CS = 22;
1940 pub const RFLAGS = 23;
1941 pub const RSP = 24;
1942 pub const SS = 25;
1943 },
1944 else => struct {},
1945 },
1946 else => struct {},
1947};
19481844pub const RLIM = switch (native_os) {
19491845 .linux => linux.RLIM,
19501846 .emscripten => emscripten.RLIM,
......@@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) {
45534449pub const siginfo_t = switch (native_os) {
45544450 .linux => linux.siginfo_t,
45554451 .emscripten => emscripten.siginfo_t,
4556 .macos, .ios, .tvos, .watchos, .visionos => extern struct {
4452 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
45574453 signo: c_int,
45584454 errno: c_int,
45594455 code: c_int,
......@@ -11084,7 +10980,6 @@ pub const SETUSTACK = solaris.GETUSTACK;
1108410980pub const SFD = solaris.SFD;
1108510981pub const ctid_t = solaris.ctid_t;
1108610982pub const file_obj = solaris.file_obj;
11087pub const fpregset_t = solaris.fpregset_t;
1108810983pub const id_t = solaris.id_t;
1108910984pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
1109010985pub const lif_nd_req = solaris.lif_nd_req;
lib/std/c/solaris.zig-23
......@@ -31,29 +31,6 @@ pub const poolid_t = id_t;
3131pub const zoneid_t = id_t;
3232pub const ctid_t = id_t;
3333
34pub const fpregset_t = extern union {
35 regs: [130]u32,
36 chip_state: extern struct {
37 cw: u16,
38 sw: u16,
39 fctw: u8,
40 __fx_rsvd: u8,
41 fop: u16,
42 rip: u64,
43 rdp: u64,
44 mxcsr: u32,
45 mxcsr_mask: u32,
46 st: [8]extern union {
47 fpr_16: [5]u16,
48 __fpr_pad: u128,
49 },
50 xmm: [16]u128,
51 __fx_ign2: [6]u128,
52 status: u32,
53 xstatus: u32,
54 },
55};
56
5734pub const GETCONTEXT = 0;
5835pub const SETCONTEXT = 1;
5936pub const GETUSTACK = 2;
lib/std/debug.zig+42-13
......@@ -63,7 +63,10 @@ pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfI
6363 root.debug.SelfInfo
6464else switch (std.Target.ObjectFormat.default(native_os, native_arch)) {
6565 .coff => if (native_os == .windows) @import("debug/SelfInfo/Windows.zig") else void,
66 .elf => @import("debug/SelfInfo/Elf.zig"),
66 .elf => switch (native_os) {
67 .freestanding, .other => void,
68 else => @import("debug/SelfInfo/Elf.zig"),
69 },
6770 .macho => @import("debug/SelfInfo/MachO.zig"),
6871 .goff, .plan9, .spirv, .wasm, .xcoff => void,
6972 .c, .hex, .raw => unreachable,
......@@ -985,7 +988,7 @@ const StackIterator = union(enum) {
985988 // On RISC-V the frame pointer points to the top of the saved register
986989 // area, on pretty much every other architecture it points to the stack
987990 // slot where the previous frame pointer is saved.
988 if (native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
991 if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
989992 // On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
990993 if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);
991994 break :off 0;
......@@ -993,7 +996,7 @@ const StackIterator = union(enum) {
993996
994997 /// Offset of the saved return address wrt the frame pointer.
995998 const ra_offset = off: {
996 if (native_arch.isRISCV()) break :off -1 * @sizeOf(usize);
999 if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -1 * @sizeOf(usize);
9971000 if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);
9981001 if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);
9991002 // 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 {
13121315
13131316/// Whether or not the current target can print useful debug information when a segfault occurs.
13141317pub const have_segfault_handling_support = switch (native_os) {
1318 .haiku,
13151319 .linux,
1316 .macos,
1320 .serenity,
1321
1322 .dragonfly,
1323 .freebsd,
13171324 .netbsd,
1318 .solaris,
1325 .openbsd,
1326
1327 .driverkit,
1328 .ios,
1329 .macos,
1330 .tvos,
1331 .visionos,
1332 .watchos,
1333
13191334 .illumos,
1335 .solaris,
1336
13201337 .windows,
1321 .freebsd,
1322 .openbsd,
1323 .serenity,
13241338 => true,
13251339
13261340 else => false,
......@@ -1403,11 +1417,26 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
14031417 }
14041418 }
14051419 const addr: usize = switch (native_os) {
1406 .linux => @intFromPtr(info.fields.sigfault.addr),
1407 .freebsd, .macos, .serenity => @intFromPtr(info.addr),
1408 .netbsd => @intFromPtr(info.info.reason.fault.addr),
1409 .openbsd => @intFromPtr(info.data.fault.addr),
1410 .solaris, .illumos => @intFromPtr(info.reason.fault.addr),
1420 .serenity,
1421 .dragonfly,
1422 .freebsd,
1423 .driverkit,
1424 .ios,
1425 .macos,
1426 .tvos,
1427 .visionos,
1428 .watchos,
1429 => @intFromPtr(info.addr),
1430 .linux,
1431 => @intFromPtr(info.fields.sigfault.addr),
1432 .netbsd,
1433 => @intFromPtr(info.info.reason.fault.addr),
1434 .haiku,
1435 .openbsd,
1436 => @intFromPtr(info.data.fault.addr),
1437 .illumos,
1438 .solaris,
1439 => @intFromPtr(info.reason.fault.addr),
14111440 else => comptime unreachable,
14121441 };
14131442 const name = switch (sig) {
lib/std/debug/SelfInfo/Elf.zig+41-9
......@@ -94,6 +94,15 @@ pub const can_unwind: bool = s: {
9494 // Notably, we are yet to support unwinding on ARM. There, unwinding is not done through
9595 // `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format.
9696 const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) {
97 // Not supported yet: arm, m68k, sparc64
98 .haiku => &.{
99 .aarch64,
100 .powerpc,
101 .riscv64,
102 .x86,
103 .x86_64,
104 },
105 // Not supported yet: arc, arm/armeb/thumb/thumbeb, csky, m68k, or1k, sparc/sparc64, xtensa
97106 .linux => &.{
98107 .aarch64,
99108 .aarch64_be,
......@@ -113,31 +122,54 @@ pub const can_unwind: bool = s: {
113122 .x86,
114123 .x86_64,
115124 },
116 .netbsd => &.{
125 .serenity => &.{
117126 .aarch64,
118 .aarch64_be,
119 .x86,
120127 .x86_64,
128 .riscv64,
121129 },
122 .freebsd => &.{
130
131 .dragonfly => &.{
123132 .x86_64,
133 },
134 // Not supported yet: arm
135 .freebsd => &.{
124136 .aarch64,
137 .powerpc64,
138 .powerpc64le,
139 .riscv64,
140 .x86_64,
125141 },
126 .openbsd => &.{
142 // Not supported yet: arm/armeb, m68k, mips64/mips64el, sparc/sparc64
143 .netbsd => &.{
144 .aarch64,
145 .aarch64_be,
146 .mips,
147 .mipsel,
148 .powerpc,
149 .x86,
127150 .x86_64,
128151 },
129 .solaris => &.{
152 // Not supported yet: arm, sparc64
153 .openbsd => &.{
154 .aarch64,
155 .mips64,
156 .mips64el,
157 .powerpc,
158 .powerpc64,
159 .riscv64,
160 .x86,
130161 .x86_64,
131162 },
163
132164 .illumos => &.{
133165 .x86,
134166 .x86_64,
135167 },
136 .serenity => &.{
168 // Not supported yet: sparc64
169 .solaris => &.{
137170 .x86_64,
138 .aarch64,
139 .riscv64,
140171 },
172
141173 else => unreachable,
142174 };
143175 for (archs) |a| {
lib/std/debug/cpu_context.zig+845-662
......@@ -24,229 +24,92 @@ pub const DwarfRegisterError = error{
2424
2525pub fn fromPosixSignalContext(ctx_ptr: ?*const anyopaque) ?Native {
2626 if (signal_ucontext_t == void) return null;
27
28 // In general, we include the hardwired zero register in the context if applicable.
2729 const uc: *const signal_ucontext_t = @ptrCast(@alignCast(ctx_ptr));
30
31 // Deal with some special cases first.
32 if (native_arch.isMIPS32() and native_os == .linux) {
33 // The O32 kABI uses 64-bit fields for some reason.
34 return .{
35 .r = s: {
36 var regs: [32]Mips.Gpr = undefined;
37 for (uc.mcontext.r, 0..) |r, i| regs[i] = @truncate(r);
38 break :s regs;
39 },
40 .pc = @truncate(uc.mcontext.pc),
41 };
42 }
43
44 // Only unified conversions from here.
2845 return switch (native_arch) {
29 .x86 => switch (native_os) {
30 .linux, .netbsd, .illumos => .{ .gprs = .init(.{
31 .eax = uc.mcontext.gregs[std.posix.REG.EAX],
32 .ecx = uc.mcontext.gregs[std.posix.REG.ECX],
33 .edx = uc.mcontext.gregs[std.posix.REG.EDX],
34 .ebx = uc.mcontext.gregs[std.posix.REG.EBX],
35 .esp = uc.mcontext.gregs[std.posix.REG.ESP],
36 .ebp = uc.mcontext.gregs[std.posix.REG.EBP],
37 .esi = uc.mcontext.gregs[std.posix.REG.ESI],
38 .edi = uc.mcontext.gregs[std.posix.REG.EDI],
39 .eip = uc.mcontext.gregs[std.posix.REG.EIP],
40 }) },
41 else => null,
46 .arm, .armeb, .thumb, .thumbeb => .{
47 .r = uc.mcontext.r ++ [_]u32{uc.mcontext.pc},
4248 },
43 .x86_64 => switch (native_os) {
44 .linux, .solaris, .illumos => .{ .gprs = .init(.{
45 .rax = uc.mcontext.gregs[std.posix.REG.RAX],
46 .rdx = uc.mcontext.gregs[std.posix.REG.RDX],
47 .rcx = uc.mcontext.gregs[std.posix.REG.RCX],
48 .rbx = uc.mcontext.gregs[std.posix.REG.RBX],
49 .rsi = uc.mcontext.gregs[std.posix.REG.RSI],
50 .rdi = uc.mcontext.gregs[std.posix.REG.RDI],
51 .rbp = uc.mcontext.gregs[std.posix.REG.RBP],
52 .rsp = uc.mcontext.gregs[std.posix.REG.RSP],
53 .r8 = uc.mcontext.gregs[std.posix.REG.R8],
54 .r9 = uc.mcontext.gregs[std.posix.REG.R9],
55 .r10 = uc.mcontext.gregs[std.posix.REG.R10],
56 .r11 = uc.mcontext.gregs[std.posix.REG.R11],
57 .r12 = uc.mcontext.gregs[std.posix.REG.R12],
58 .r13 = uc.mcontext.gregs[std.posix.REG.R13],
59 .r14 = uc.mcontext.gregs[std.posix.REG.R14],
60 .r15 = uc.mcontext.gregs[std.posix.REG.R15],
61 .rip = uc.mcontext.gregs[std.posix.REG.RIP],
62 }) },
63 .freebsd, .serenity => .{ .gprs = .init(.{
64 .rax = uc.mcontext.rax,
65 .rdx = uc.mcontext.rdx,
66 .rcx = uc.mcontext.rcx,
67 .rbx = uc.mcontext.rbx,
68 .rsi = uc.mcontext.rsi,
69 .rdi = uc.mcontext.rdi,
70 .rbp = uc.mcontext.rbp,
71 .rsp = uc.mcontext.rsp,
72 .r8 = uc.mcontext.r8,
73 .r9 = uc.mcontext.r9,
74 .r10 = uc.mcontext.r10,
75 .r11 = uc.mcontext.r11,
76 .r12 = uc.mcontext.r12,
77 .r13 = uc.mcontext.r13,
78 .r14 = uc.mcontext.r14,
79 .r15 = uc.mcontext.r15,
80 .rip = uc.mcontext.rip,
81 }) },
82 .openbsd => .{ .gprs = .init(.{
83 .rax = @bitCast(uc.sc_rax),
84 .rdx = @bitCast(uc.sc_rdx),
85 .rcx = @bitCast(uc.sc_rcx),
86 .rbx = @bitCast(uc.sc_rbx),
87 .rsi = @bitCast(uc.sc_rsi),
88 .rdi = @bitCast(uc.sc_rdi),
89 .rbp = @bitCast(uc.sc_rbp),
90 .rsp = @bitCast(uc.sc_rsp),
91 .r8 = @bitCast(uc.sc_r8),
92 .r9 = @bitCast(uc.sc_r9),
93 .r10 = @bitCast(uc.sc_r10),
94 .r11 = @bitCast(uc.sc_r11),
95 .r12 = @bitCast(uc.sc_r12),
96 .r13 = @bitCast(uc.sc_r13),
97 .r14 = @bitCast(uc.sc_r14),
98 .r15 = @bitCast(uc.sc_r15),
99 .rip = @bitCast(uc.sc_rip),
100 }) },
101 .driverkit, .macos, .ios => .{ .gprs = .init(.{
102 .rax = uc.mcontext.ss.rax,
103 .rdx = uc.mcontext.ss.rdx,
104 .rcx = uc.mcontext.ss.rcx,
105 .rbx = uc.mcontext.ss.rbx,
106 .rsi = uc.mcontext.ss.rsi,
107 .rdi = uc.mcontext.ss.rdi,
108 .rbp = uc.mcontext.ss.rbp,
109 .rsp = uc.mcontext.ss.rsp,
110 .r8 = uc.mcontext.ss.r8,
111 .r9 = uc.mcontext.ss.r9,
112 .r10 = uc.mcontext.ss.r10,
113 .r11 = uc.mcontext.ss.r11,
114 .r12 = uc.mcontext.ss.r12,
115 .r13 = uc.mcontext.ss.r13,
116 .r14 = uc.mcontext.ss.r14,
117 .r15 = uc.mcontext.ss.r15,
118 .rip = uc.mcontext.ss.rip,
119 }) },
120 else => null,
49 .aarch64, .aarch64_be => .{
50 .x = uc.mcontext.x ++ [_]u64{uc.mcontext.lr},
51 .sp = uc.mcontext.sp,
52 .pc = uc.mcontext.pc,
12153 },
122 .arm, .armeb, .thumb, .thumbeb => switch (builtin.os.tag) {
123 .linux => .{
124 .r = .{
125 uc.mcontext.arm_r0,
126 uc.mcontext.arm_r1,
127 uc.mcontext.arm_r2,
128 uc.mcontext.arm_r3,
129 uc.mcontext.arm_r4,
130 uc.mcontext.arm_r5,
131 uc.mcontext.arm_r6,
132 uc.mcontext.arm_r7,
133 uc.mcontext.arm_r8,
134 uc.mcontext.arm_r9,
135 uc.mcontext.arm_r10,
136 uc.mcontext.arm_fp, // r11 = fp
137 uc.mcontext.arm_ip, // r12 = ip
138 uc.mcontext.arm_sp, // r13 = sp
139 uc.mcontext.arm_lr, // r14 = lr
140 uc.mcontext.arm_pc, // r15 = pc
141 },
142 },
143 else => null,
54 .hexagon, .loongarch32, .loongarch64, .mips, .mipsel, .mips64, .mips64el, .or1k => .{
55 .r = uc.mcontext.r,
56 .pc = uc.mcontext.pc,
14457 },
145 .aarch64, .aarch64_be => switch (builtin.os.tag) {
146 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => .{
147 .x = uc.mcontext.ss.regs ++ @as([2]u64, .{
148 uc.mcontext.ss.fp, // x29 = fp
149 uc.mcontext.ss.lr, // x30 = lr
150 }),
151 .sp = uc.mcontext.ss.sp,
152 .pc = uc.mcontext.ss.pc,
153 },
154 .netbsd => .{
155 .x = uc.mcontext.gregs[0..31].*,
156 .sp = uc.mcontext.gregs[31],
157 .pc = uc.mcontext.gregs[32],
158 },
159 .freebsd => .{
160 .x = uc.mcontext.gpregs.x ++ @as([1]u64, .{
161 uc.mcontext.gpregs.lr, // x30 = lr
162 }),
163 .sp = uc.mcontext.gpregs.sp,
164 // On aarch64, the register ELR_LR1 defines the address to return to after handling
165 // a CPU exception (ELR is "Exception Link Register"). FreeBSD's ucontext_t uses
166 // this as the field name, but it's the same thing as the context's PC.
167 .pc = uc.mcontext.gpregs.elr,
168 },
169 .openbsd => .{
170 .x = uc.sc_x ++ .{uc.sc_lr},
171 .sp = uc.sc_sp,
172 // Not a bug; see freebsd above for explanation.
173 .pc = uc.sc_elr,
174 },
175 .linux => .{
176 .x = uc.mcontext.regs,
177 .sp = uc.mcontext.sp,
178 .pc = uc.mcontext.pc,
179 },
180 .serenity => .{
181 .x = uc.mcontext.x,
182 .sp = uc.mcontext.sp,
183 .pc = uc.mcontext.pc,
184 },
185 else => null,
186 },
187 .hexagon => switch (builtin.os.tag) {
188 .linux => .{
189 .r = uc.mcontext.gregs,
190 .pc = uc.mcontext.pc,
191 },
192 else => null,
58 .powerpc, .powerpcle, .powerpc64, .powerpc64le => .{
59 .r = uc.mcontext.r,
60 .pc = uc.mcontext.pc,
61 .lr = uc.mcontext.lr,
19362 },
194 .loongarch64 => switch (builtin.os.tag) {
195 .linux => .{
196 .r = uc.mcontext.regs, // includes r0 (hardwired zero)
197 .pc = uc.mcontext.pc,
198 },
199 else => null,
63 .riscv32, .riscv32be, .riscv64, .riscv64be => .{
64 // You can thank FreeBSD and OpenBSD for this silliness; they decided to be cute and
65 // group the registers by ABI mnemonic rather than register number.
66 .x = [_]Riscv.Gpr{0} ++
67 uc.mcontext.ra_sp_gp_tp ++
68 uc.mcontext.t0_2 ++
69 uc.mcontext.s0_1 ++
70 uc.mcontext.a ++
71 uc.mcontext.s2_11 ++
72 uc.mcontext.t3_6,
73 .pc = uc.mcontext.pc,
20074 },
201 .mips, .mipsel => switch (builtin.os.tag) {
202 // The O32 kABI uses 64-bit fields for some reason...
203 .linux => .{
204 .r = s: {
205 var regs: [32]Mips.Gpr = undefined;
206 for (uc.mcontext.regs, 0..) |r, i| regs[i] = @truncate(r); // includes r0 (hardwired zero)
207 break :s regs;
208 },
209 .pc = @truncate(uc.mcontext.pc),
75 .s390x => .{
76 .r = uc.mcontext.r,
77 .psw = .{
78 .mask = uc.mcontext.psw.mask,
79 .addr = uc.mcontext.psw.addr,
21080 },
211 else => null,
21281 },
213 .mips64, .mips64el => switch (builtin.os.tag) {
214 .linux => .{
215 .r = uc.mcontext.regs, // includes r0 (hardwired zero)
216 .pc = uc.mcontext.pc,
217 },
218 else => null,
219 },
220 .powerpc, .powerpcle, .powerpc64, .powerpc64le => switch (builtin.os.tag) {
221 .linux => .{
222 .r = uc.mcontext.gp_regs[0..32].*,
223 .pc = uc.mcontext.gp_regs[32],
224 .lr = uc.mcontext.gp_regs[36],
225 },
226 else => null,
227 },
228 .riscv32, .riscv64 => switch (builtin.os.tag) {
229 .linux => .{
230 .r = [1]usize{0} ++ uc.mcontext.gregs[1..].*, // r0 position is used for pc; replace with zero
231 .pc = uc.mcontext.gregs[0],
232 },
233 .serenity => if (native_arch == .riscv32) null else .{
234 .r = [1]u64{0} ++ uc.mcontext.x,
235 .pc = uc.mcontext.pc,
236 },
237 else => null,
238 },
239 .s390x => switch (builtin.os.tag) {
240 .linux => .{
241 .r = uc.mcontext.gregs,
242 .psw = .{
243 .mask = uc.mcontext.psw.mask,
244 .addr = uc.mcontext.psw.addr,
245 },
246 },
247 else => null,
248 },
249 else => null,
82 .x86 => .{ .gprs = .init(.{
83 .eax = uc.mcontext.eax,
84 .ecx = uc.mcontext.ecx,
85 .edx = uc.mcontext.edx,
86 .ebx = uc.mcontext.ebx,
87 .esp = uc.mcontext.esp,
88 .ebp = uc.mcontext.ebp,
89 .esi = uc.mcontext.esi,
90 .edi = uc.mcontext.edi,
91 .eip = uc.mcontext.eip,
92 }) },
93 .x86_64 => .{ .gprs = .init(.{
94 .rax = uc.mcontext.rax,
95 .rdx = uc.mcontext.rdx,
96 .rcx = uc.mcontext.rcx,
97 .rbx = uc.mcontext.rbx,
98 .rsi = uc.mcontext.rsi,
99 .rdi = uc.mcontext.rdi,
100 .rbp = uc.mcontext.rbp,
101 .rsp = uc.mcontext.rsp,
102 .r8 = uc.mcontext.r8,
103 .r9 = uc.mcontext.r9,
104 .r10 = uc.mcontext.r10,
105 .r11 = uc.mcontext.r11,
106 .r12 = uc.mcontext.r12,
107 .r13 = uc.mcontext.r13,
108 .r14 = uc.mcontext.r14,
109 .r15 = uc.mcontext.r15,
110 .rip = uc.mcontext.rip,
111 }) },
112 else => comptime unreachable,
250113 };
251114}
252115
......@@ -615,7 +478,7 @@ const LoongArch = extern struct {
615478 r: [32]Gpr,
616479 pc: Gpr,
617480
618 pub const Gpr = if (builtin.target.cpu.arch == .loongarch64) u64 else u32;
481 pub const Gpr = if (native_arch == .loongarch64) u64 else u32;
619482
620483 pub inline fn current() LoongArch {
621484 var ctx: LoongArch = undefined;
......@@ -717,7 +580,7 @@ const Mips = extern struct {
717580 r: [32]Gpr,
718581 pc: Gpr,
719582
720 pub const Gpr = if (builtin.target.cpu.arch.isMIPS64()) u64 else u32;
583 pub const Gpr = if (native_arch.isMIPS64()) u64 else u32;
721584
722585 pub inline fn current() Mips {
723586 var ctx: Mips = undefined;
......@@ -840,7 +703,7 @@ const Powerpc = extern struct {
840703 pc: Gpr,
841704 lr: Gpr,
842705
843 pub const Gpr = if (builtin.target.cpu.arch.isPowerPC64()) u64 else u32;
706 pub const Gpr = if (native_arch.isPowerPC64()) u64 else u32;
844707
845708 pub inline fn current() Powerpc {
846709 var ctx: Powerpc = undefined;
......@@ -992,10 +855,10 @@ const Powerpc = extern struct {
992855/// This is an `extern struct` so that inline assembly in `current` can use field offsets.
993856const Riscv = extern struct {
994857 /// The numbered general-purpose registers r0 - r31. r0 must be zero.
995 r: [32]Gpr,
858 x: [32]Gpr,
996859 pc: Gpr,
997860
998 pub const Gpr = if (builtin.target.cpu.arch.isRiscv64()) u64 else u32;
861 pub const Gpr = if (native_arch.isRiscv64()) u64 else u32;
999862
1000863 pub inline fn current() Riscv {
1001864 var ctx: Riscv = undefined;
......@@ -1081,7 +944,7 @@ const Riscv = extern struct {
1081944
1082945 pub fn dwarfRegisterBytes(ctx: *Riscv, register_num: u16) DwarfRegisterError![]u8 {
1083946 switch (register_num) {
1084 0...31 => return @ptrCast(&ctx.r[register_num]),
947 0...31 => return @ptrCast(&ctx.x[register_num]),
1085948 65 => return @ptrCast(&ctx.pc),
1086949
1087950 32...63 => return error.UnsupportedRegister, // f0 - f31
......@@ -1138,61 +1001,199 @@ const S390x = extern struct {
11381001 }
11391002};
11401003
1004/// The native operating system's `ucontext_t` as seen in the third argument to signal handlers.
1005///
1006/// These are dramatically simplified since we only need general-purpose registers and don't care
1007/// about all the complicated extension state (floating point, vector, etc). This means that these
1008/// structures are almost all shorter than the real ones, which is safe because we only access them
1009/// through a pointer.
1010///
1011/// Some effort is made to have structures for the same architecture use the same access pattern,
1012/// e.g. `uc.mcontext.x` for `aarch64-linux` and `aarch64-freebsd` even though that's not quite how
1013/// they're declared and spelled in the C headers for both targets. Similarly, registers are typed
1014/// as unsigned everywhere even if that's not how they're declared in the C headers.
11411015const signal_ucontext_t = switch (native_os) {
1142 .linux => std.os.linux.ucontext_t,
1143 .emscripten => std.os.emscripten.ucontext_t,
1144 .freebsd => std.os.freebsd.ucontext_t,
1145 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
1146 onstack: c_int,
1147 sigmask: std.c.sigset_t,
1148 stack: std.c.stack_t,
1149 link: ?*signal_ucontext_t,
1150 mcsize: u64,
1151 mcontext: *mcontext_t,
1152 const mcontext_t = switch (native_arch) {
1153 .aarch64 => extern struct {
1154 es: extern struct {
1155 far: u64, // Virtual Fault Address
1156 esr: u32, // Exception syndrome
1157 exception: u32, // Number of arm exception taken
1158 },
1159 ss: extern struct {
1160 /// General purpose registers
1161 regs: [29]u64,
1162 /// Frame pointer x29
1163 fp: u64,
1164 /// Link register x30
1016 .linux => switch (native_arch) {
1017 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm64/include/uapi/asm/ucontext.h
1018 .aarch64,
1019 .aarch64_be,
1020 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/loongarch/include/uapi/asm/ucontext.h
1021 .loongarch64,
1022 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/ucontext.h
1023 .powerpc64,
1024 .powerpc64le,
1025 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/riscv/include/uapi/asm/ucontext.h
1026 .riscv32,
1027 .riscv64,
1028 => extern struct {
1029 _flags: usize,
1030 _link: ?*signal_ucontext_t,
1031 _stack: std.os.linux.stack_t,
1032 _sigmask: std.os.linux.sigset_t,
1033 _unused: [120]u8,
1034 mcontext: switch (native_arch) {
1035 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm64/include/uapi/asm/sigcontext.h
1036 .aarch64, .aarch64_be => extern struct {
1037 _fault_address: u64 align(16),
1038 x: [30]u64,
11651039 lr: u64,
1166 /// Stack pointer x31
11671040 sp: u64,
1168 /// Program counter
11691041 pc: u64,
1170 /// Current program status register
1171 cpsr: u32,
1172 __pad: u32,
11731042 },
1174 ns: extern struct {
1175 q: [32]u128,
1176 fpsr: u32,
1177 fpcr: u32,
1043 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/loongarch/include/uapi/asm/sigcontext.h
1044 .loongarch64 => extern struct {
1045 pc: u64 align(16),
1046 r: [32]u64,
1047 },
1048 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/sigcontext.h
1049 .powerpc64, .powerpc64le => extern struct {
1050 _unused: [4]u64,
1051 _signal: i32,
1052 _pad: i32,
1053 _handler: u64,
1054 _oldmask: u64,
1055 _regs: ?*anyopaque,
1056 r: [32]u64,
1057 pc: u64,
1058 _msr: u64,
1059 _orig_r3: u64,
1060 _ctr: u64,
1061 lr: u64,
1062 },
1063 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/riscv/include/uapi/asm/sigcontext.h
1064 .riscv32, .riscv64 => extern struct {
1065 pc: usize align(16),
1066 ra_sp_gp_tp: [4]usize,
1067 t0_2: [3]usize,
1068 s0_1: [2]usize,
1069 a: [8]usize,
1070 s2_11: [10]usize,
1071 t3_6: [4]usize,
11781072 },
1073 else => unreachable,
11791074 },
1180 .x86_64 => extern struct {
1181 es: extern struct {
1182 trapno: u16,
1183 cpu: u16,
1184 err: u32,
1185 faultvaddr: u64,
1075 },
1076 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/include/uapi/asm-generic/ucontext.h
1077 .arc,
1078 .csky,
1079 .hexagon,
1080 .m68k,
1081 .mips,
1082 .mipsel,
1083 .mips64,
1084 .mips64el,
1085 .or1k,
1086 .s390x,
1087 .x86,
1088 .x86_64,
1089 .xtensa,
1090 => extern struct {
1091 _flags: usize,
1092 _link: ?*signal_ucontext_t,
1093 _stack: std.os.linux.stack_t,
1094 mcontext: switch (native_arch) {
1095 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arc/include/uapi/asm/sigcontext.h
1096 .arc => extern struct {
1097 _pad1: u32,
1098 _bta: u32,
1099 _lp: extern struct {
1100 _start: u32,
1101 _end: u32,
1102 _count: u32,
1103 },
1104 _status32: u32,
1105 pc: u32,
1106 r31: u32,
1107 r27_26: [2]u32,
1108 r12_0: [13]u32,
1109 r28: u32,
1110 _pad2: u32,
1111 r25_13: [13]u32,
1112 _efa: u32,
1113 _stop_pc: u32,
1114 r30: u32,
11861115 },
1187 ss: extern struct {
1188 rax: u64,
1189 rbx: u64,
1190 rcx: u64,
1191 rdx: u64,
1192 rdi: u64,
1193 rsi: u64,
1194 rbp: u64,
1195 rsp: u64,
1116 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/csky/include/uapi/asm/sigcontext.h
1117 .csky => extern struct {
1118 r31: u32,
1119 r15: u32,
1120 pc: u32,
1121 _sr: u32,
1122 r14: u32,
1123 _orig_a0: u32,
1124 r0_13: [14]u32,
1125 r16_30: [15]u32,
1126 },
1127 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/hexagon/include/uapi/asm/sigcontext.h
1128 .hexagon => extern struct {
1129 r: [32]u32 align(8),
1130 _salc: [2]extern struct {
1131 _sa: u32,
1132 _lc: u32,
1133 },
1134 _m: [2]u32,
1135 _usr: u32,
1136 _p: u32,
1137 _gp: u32,
1138 _ugp: u32,
1139 pc: u32,
1140 },
1141 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/m68k/include/asm/ucontext.h
1142 .m68k => extern struct {
1143 _version: i32,
1144 d: [8]u32,
1145 a: [8]u32,
1146 pc: u32,
1147 },
1148 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/mips/include/uapi/asm/sigcontext.h
1149 .mips, .mipsel => extern struct {
1150 _regmask: u32,
1151 _status: u32,
1152 // ??? A spectacularly failed attempt to be future-proof?
1153 pc: u64,
1154 r: [32]u64,
1155 },
1156 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/mips/include/uapi/asm/sigcontext.h
1157 .mips64, .mips64el => extern struct {
1158 r: [32]u64,
1159 _fpregs: [32]u64,
1160 _hi: [4]u64,
1161 _lo: [4]u64,
1162 pc: u64,
1163 },
1164 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/openrisc/include/uapi/asm/sigcontext.h
1165 .or1k => extern struct {
1166 r: [32]u32,
1167 pc: u32,
1168 },
1169 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/s390/include/uapi/asm/sigcontext.h
1170 .s390x => extern struct {
1171 psw: extern struct {
1172 mask: u64,
1173 addr: u64,
1174 },
1175 r: [16]u64,
1176 },
1177 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/x86/include/uapi/asm/sigcontext.h
1178 .x86 => extern struct {
1179 _gs: u32,
1180 _fs: u32,
1181 _es: u32,
1182 _ds: u32,
1183 edi: u32,
1184 esi: u32,
1185 ebp: u32,
1186 esp: u32,
1187 ebx: u32,
1188 edx: u32,
1189 ecx: u32,
1190 eax: u32,
1191 _trapno: u32,
1192 _err: u32,
1193 eip: u32,
1194 },
1195 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/x86/include/uapi/asm/sigcontext.h
1196 .x86_64 => extern struct {
11961197 r8: u64,
11971198 r9: u64,
11981199 r10: u64,
......@@ -1201,197 +1202,540 @@ const signal_ucontext_t = switch (native_os) {
12011202 r13: u64,
12021203 r14: u64,
12031204 r15: u64,
1205 rdi: u64,
1206 rsi: u64,
1207 rbp: u64,
1208 rbx: u64,
1209 rdx: u64,
1210 rax: u64,
1211 rcx: u64,
1212 rsp: u64,
12041213 rip: u64,
1205 rflags: u64,
1206 cs: u64,
1207 fs: u64,
1208 gs: u64,
12091214 },
1210 fs: extern struct {
1211 reserved: [2]c_int,
1212 fcw: u16,
1213 fsw: u16,
1214 ftw: u8,
1215 rsrv1: u8,
1216 fop: u16,
1217 ip: u32,
1218 cs: u16,
1219 rsrv2: u16,
1220 dp: u32,
1221 ds: u16,
1222 rsrv3: u16,
1223 mxcsr: u32,
1224 mxcsrmask: u32,
1225 stmm: [8]stmm_reg,
1226 xmm: [16]xmm_reg,
1227 rsrv4: [96]u8,
1228 reserved1: c_int,
1229
1230 const stmm_reg = [16]u8;
1231 const xmm_reg = [16]u8;
1215 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/xtensa/include/uapi/asm/sigcontext.h
1216 .xtensa => extern struct {
1217 pc: u32,
1218 _ps: u32,
1219 _l: extern struct {
1220 _beg: u32,
1221 _end: u32,
1222 _count: u32,
1223 },
1224 _sar: u32,
1225 _acc: extern struct {
1226 _lo: u32,
1227 _hi: u32,
1228 },
1229 a: [16]u32,
12321230 },
1231 else => unreachable,
12331232 },
1234 else => void,
1235 };
1233 },
1234 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm/include/asm/ucontext.h
1235 .arm, .armeb, .thumb, .thumbeb => extern struct {
1236 _flags: u32,
1237 _link: ?*signal_ucontext_t,
1238 _stack: std.os.linux.stack_t,
1239 _unused: [31]i32,
1240 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/arm/include/uapi/asm/sigcontext.h
1241 mcontext: extern struct {
1242 _trap_no: u32,
1243 _error_code: u32,
1244 _oldmask: u32,
1245 r: [15]u32,
1246 pc: u32,
1247 },
1248 },
1249 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/powerpc/include/uapi/asm/ucontext.h
1250 .powerpc, .powerpcle => extern struct {
1251 _flags: u32,
1252 _link: ?*signal_ucontext_t,
1253 _stack: std.os.linux.stack_t,
1254 _pad1: [7]i32,
1255 _regs: ?*anyopaque,
1256 _sigmask: std.os.linux.sigset_t,
1257 _unused: [120]u8,
1258 _pad2: [3]i32,
1259 mcontext: extern struct {
1260 r: [32]u32 align(16),
1261 pc: u32,
1262 _msr: u32,
1263 _orig_r3: u32,
1264 _ctr: u32,
1265 lr: u32,
1266 },
1267 },
1268 // https://github.com/torvalds/linux/blob/cd5a0afbdf8033dc83786315d63f8b325bdba2fd/arch/sparc/include/uapi/asm/uctx.h
1269 .sparc => @compileError("sparc-linux ucontext_t missing"),
1270 .sparc64 => @compileError("sparc64-linux ucontext_t missing"),
1271 else => unreachable,
12361272 },
1237 .solaris, .illumos => extern struct {
1238 flags: u64,
1239 link: ?*signal_ucontext_t,
1240 sigmask: std.c.sigset_t,
1241 stack: std.c.stack_t,
1242 mcontext: mcontext_t,
1243 brand_data: [3]?*anyopaque,
1244 filler: [2]i64,
1245 const mcontext_t = extern struct {
1246 gregs: [28]u64,
1247 fpregs: std.c.fpregset_t,
1248 };
1273 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/sys/_ucontext.h
1274 .freebsd => extern struct {
1275 _sigmask: std.c.sigset_t,
1276 mcontext: switch (native_arch) {
1277 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/arm64/include/ucontext.h
1278 .aarch64 => extern struct {
1279 x: [30]u64 align(16),
1280 lr: u64,
1281 sp: u64,
1282 pc: u64,
1283 },
1284 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/arm/include/ucontext.h
1285 .arm => extern struct {
1286 r: [15]u32,
1287 pc: u32,
1288 },
1289 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/powerpc/include/ucontext.h
1290 .powerpc64, .powerpc64le => extern struct {
1291 _vers: i32 align(16),
1292 _flags: i32,
1293 _onstack: i32,
1294 _len: i32,
1295 _avec: [32 * 2]u64,
1296 _av: [2]u32,
1297 r: [32]u64,
1298 lr: u64,
1299 _cr: u64,
1300 _xer: u64,
1301 _ctr: u64,
1302 pc: u64,
1303 },
1304 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/riscv/include/ucontext.h
1305 .riscv64 => extern struct {
1306 ra_sp_gp_tp: [4]u64,
1307 t0_2: [3]u64,
1308 t3_6: [4]u64,
1309 s0_1: [2]u64,
1310 s2_11: [10]u64,
1311 a: [8]u64,
1312 pc: u64,
1313 },
1314 // https://github.com/freebsd/freebsd-src/blob/55c28005f544282b984ae0e15dacd0c108d8ab12/sys/x86/include/ucontext.h
1315 .x86_64 => extern struct {
1316 _onstack: i64,
1317 rdi: u64,
1318 rsi: u64,
1319 rdx: u64,
1320 rcx: u64,
1321 r8: u64,
1322 r9: u64,
1323 rax: u64,
1324 rbx: u64,
1325 rbp: u64,
1326 r10: u64,
1327 r11: u64,
1328 r12: u64,
1329 r13: u64,
1330 r14: u64,
1331 r15: u64,
1332 _trapno: i32,
1333 _fs: i16,
1334 _gs: i16,
1335 _addr: i64,
1336 _flags: i32,
1337 _es: i16,
1338 _ds: i16,
1339 _err: i64,
1340 rip: u64,
1341 _cs: i64,
1342 _rflags: i64,
1343 rsp: u64,
1344 },
1345 else => unreachable,
1346 },
12491347 },
1250 .openbsd => switch (builtin.cpu.arch) {
1251 .x86_64 => extern struct {
1252 sc_rdi: c_long,
1253 sc_rsi: c_long,
1254 sc_rdx: c_long,
1255 sc_rcx: c_long,
1256 sc_r8: c_long,
1257 sc_r9: c_long,
1258 sc_r10: c_long,
1259 sc_r11: c_long,
1260 sc_r12: c_long,
1261 sc_r13: c_long,
1262 sc_r14: c_long,
1263 sc_r15: c_long,
1264 sc_rbp: c_long,
1265 sc_rbx: c_long,
1266 sc_rax: c_long,
1267 sc_gs: c_long,
1268 sc_fs: c_long,
1269 sc_es: c_long,
1270 sc_ds: c_long,
1271 sc_trapno: c_long,
1272 sc_err: c_long,
1273 sc_rip: c_long,
1274 sc_cs: c_long,
1275 sc_rflags: c_long,
1276 sc_rsp: c_long,
1277 sc_ss: c_long,
1278
1279 sc_fpstate: *anyopaque, // struct fxsave64 *
1280 __sc_unused: c_int,
1281 sc_mask: c_int,
1282 sc_cookie: c_long,
1348 // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/sys/_types/_ucontext.h
1349 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
1350 _onstack: i32,
1351 _sigmask: std.c.sigset_t,
1352 _stack: std.c.stack_t,
1353 _link: ?*signal_ucontext_t,
1354 _mcsize: u64,
1355 mcontext: *switch (native_arch) {
1356 // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/arm/_mcontext.h
1357 // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/mach/arm/_structs.h
1358 .aarch64 => extern struct {
1359 _far: u64 align(16),
1360 _esr: u64,
1361 x: [30]u64,
1362 lr: u64,
1363 sp: u64,
1364 pc: u64,
1365 },
1366 // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/i386/_mcontext.h
1367 // https://github.com/ziglang/zig/blob/60be67d3c0ba6ae15fa7115596734ab1e74fbcd3/lib/libc/include/any-macos-any/mach/i386/_structs.h
1368 .x86_64 => extern struct {
1369 _trapno: u16,
1370 _cpu: u16,
1371 _err: u32,
1372 _faultvaddr: u64,
1373 rax: u64,
1374 rbx: u64,
1375 rcx: u64,
1376 rdx: u64,
1377 rdi: u64,
1378 rsi: u64,
1379 rbp: u64,
1380 rsp: u64,
1381 r8: u64,
1382 r9: u64,
1383 r10: u64,
1384 r11: u64,
1385 r12: u64,
1386 r13: u64,
1387 r14: u64,
1388 r15: u64,
1389 rip: u64,
1390 },
1391 else => unreachable,
12831392 },
1393 },
1394 // This needs to be audited by someone with access to the Solaris headers.
1395 .solaris => extern struct {
1396 _flags: u64,
1397 _link: ?*signal_ucontext_t,
1398 _sigmask: std.c.sigset_t,
1399 _stack: std.c.stack_t,
1400 mcontext: switch (native_arch) {
1401 .sparc64 => @compileError("sparc64-solaris mcontext_t missing"),
1402 .x86_64 => extern struct {
1403 r15: u64,
1404 r14: u64,
1405 r13: u64,
1406 r12: u64,
1407 r11: u64,
1408 r10: u64,
1409 r9: u64,
1410 r8: u64,
1411 rdi: u64,
1412 rsi: u64,
1413 rbp: u64,
1414 rbx: u64,
1415 rdx: u64,
1416 rcx: u64,
1417 rax: u64,
1418 _trapno: i64,
1419 _err: i64,
1420 rip: u64,
1421 },
1422 else => unreachable,
1423 },
1424 },
1425 // https://github.com/illumos/illumos-gate/blob/d4ce137bba3bd16823db6374d9e9a643264ce245/usr/src/uts/intel/sys/ucontext.h
1426 .illumos => extern struct {
1427 _flags: usize,
1428 _link: ?*signal_ucontext_t,
1429 _sigmask: std.c.sigset_t,
1430 _stack: std.c.stack_t,
1431 mcontext: switch (native_arch) {
1432 // https://github.com/illumos/illumos-gate/blob/d4ce137bba3bd16823db6374d9e9a643264ce245/usr/src/uts/intel/sys/mcontext.h
1433 .x86 => extern struct {
1434 _gs: u32,
1435 _fs: u32,
1436 _es: u32,
1437 _ds: u32,
1438 edi: u32,
1439 esi: u32,
1440 ebp: u32,
1441 esp: u32,
1442 ebx: u32,
1443 edx: u32,
1444 ecx: u32,
1445 eax: u32,
1446 _trapno: i32,
1447 _err: i32,
1448 eip: u32,
1449 },
1450 .x86_64 => extern struct {
1451 r15: u64,
1452 r14: u64,
1453 r13: u64,
1454 r12: u64,
1455 r11: u64,
1456 r10: u64,
1457 r9: u64,
1458 r8: u64,
1459 rdi: u64,
1460 rsi: u64,
1461 rbp: u64,
1462 rbx: u64,
1463 rdx: u64,
1464 rcx: u64,
1465 rax: u64,
1466 _trapno: i64,
1467 _err: i64,
1468 rip: u64,
1469 },
1470 else => unreachable,
1471 },
1472 },
1473 .openbsd => switch (native_arch) {
1474 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/arm64/include/signal.h
12841475 .aarch64 => extern struct {
1285 __sc_unused: c_int,
1286 sc_mask: c_int,
1287 sc_sp: c_ulong,
1288 sc_lr: c_ulong,
1289 sc_elr: c_ulong,
1290 sc_spsr: c_ulong,
1291 sc_x: [30]c_ulong,
1292 sc_cookie: c_long,
1476 _unused: i32,
1477 _mask: i32,
1478 mcontext: extern struct {
1479 sp: u64,
1480 lr: u64,
1481 pc: u64,
1482 _spsr: u64,
1483 x: [30]u64,
1484 },
1485 },
1486 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/arm/include/signal.h
1487 .arm => extern struct {
1488 _cookie: i32,
1489 _mask: i32,
1490 mcontext: extern struct {
1491 _spsr: u32 align(8),
1492 r: [15]u32,
1493 _svc_lr: u32,
1494 pc: u32,
1495 },
12931496 },
1294 else => void,
1497 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/mips64/include/signal.h
1498 .mips64, .mips64el => extern struct {
1499 _cookie: i64,
1500 _mask: i64,
1501 mcontext: extern struct {
1502 pc: u64,
1503 r: [32]u64,
1504 },
1505 },
1506 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/powerpc/include/signal.h
1507 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/powerpc64/include/signal.h
1508 .powerpc, .powerpc64 => extern struct {
1509 _cookie: isize,
1510 _mask: i32,
1511 mcontext: extern struct {
1512 r: [32]usize,
1513 lr: usize,
1514 _cr: usize,
1515 _xer: usize,
1516 _ctr: usize,
1517 pc: usize,
1518 },
1519 },
1520 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/riscv64/include/signal.h
1521 .riscv64 => extern struct {
1522 _unused: i32,
1523 _mask: i32,
1524 mcontext: extern struct {
1525 ra_sp_gp_tp: [4]u64,
1526 t0_2: [3]u64,
1527 t3_6: [4]u64,
1528 s0_1: [2]u64,
1529 s2_11: [10]u64,
1530 a: [8]u64,
1531 pc: u64,
1532 },
1533 },
1534 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/sparc64/include/signal.h
1535 .sparc64 => @compileError("sparc64-openbsd mcontext_t missing"),
1536 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/i386/include/signal.h
1537 .x86 => extern struct {
1538 mcontext: extern struct {
1539 _gs: i32,
1540 _fs: i32,
1541 _es: i32,
1542 _ds: i32,
1543 edi: u32,
1544 esi: u32,
1545 ebp: u32,
1546 ebx: u32,
1547 edx: u32,
1548 ecx: u32,
1549 eax: u32,
1550 eip: u32,
1551 _cs: i32,
1552 _eflags: i32,
1553 esp: u32,
1554 },
1555 },
1556 // https://github.com/openbsd/src/blob/42468faed8369d07ae49ae02dd71ec34f59b66cd/sys/arch/amd64/include/signal.h
1557 .x86_64 => extern struct {
1558 mcontext: extern struct {
1559 rdi: u64,
1560 rsi: u64,
1561 rdx: u64,
1562 rcx: u64,
1563 r8: u64,
1564 r9: u64,
1565 r10: u64,
1566 r11: u64,
1567 r12: u64,
1568 r13: u64,
1569 r14: u64,
1570 r15: u64,
1571 rbp: u64,
1572 rbx: u64,
1573 rax: u64,
1574 _gs: i64,
1575 _fs: i64,
1576 _es: i64,
1577 _ds: i64,
1578 _trapno: i64,
1579 _err: i64,
1580 rip: u64,
1581 _cs: i64,
1582 _rflags: i64,
1583 rsp: u64,
1584 },
1585 },
1586 else => unreachable,
12951587 },
1588 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/sys/ucontext.h
12961589 .netbsd => extern struct {
1297 flags: u32,
1298 link: ?*signal_ucontext_t,
1299 sigmask: std.c.sigset_t,
1300 stack: std.c.stack_t,
1301 mcontext: mcontext_t,
1302 __pad: [
1303 switch (builtin.cpu.arch) {
1304 .x86 => 4,
1305 .mips, .mipsel, .mips64, .mips64el => 14,
1306 .arm, .armeb, .thumb, .thumbeb => 1,
1307 .sparc, .sparc64 => if (@sizeOf(usize) == 4) 43 else 8,
1308 else => 0,
1309 }
1310 ]u32,
1311 const mcontext_t = switch (builtin.cpu.arch) {
1590 _flags: u32,
1591 _link: ?*signal_ucontext_t,
1592 _sigmask: std.c.sigset_t,
1593 _stack: std.c.stack_t,
1594 mcontext: switch (native_arch) {
1595 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/arm/include/mcontext.h
13121596 .aarch64, .aarch64_be => extern struct {
1313 gregs: [35]u64,
1314 fregs: [528]u8 align(16),
1315 spare: [8]u64,
1597 x: [30]u64 align(16),
1598 lr: u64,
1599 sp: u64,
1600 pc: u64,
1601 },
1602 .arm, .armeb => extern struct {
1603 r: [15]u32 align(8),
1604 pc: u32,
13161605 },
1606 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/m68k/include/mcontext.h
1607 .m68k => extern struct {
1608 d: [8]u32,
1609 a: [8]u32,
1610 pc: u32,
1611 },
1612 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/mips/include/mcontext.h
1613 .mips, .mipsel => extern struct {
1614 r: [32]u32 align(8),
1615 _lo: i32,
1616 _hi: i32,
1617 _cause: i32,
1618 pc: u32,
1619 },
1620 .mips64, .mips64el => @compileError("https://github.com/ziglang/zig/issues/23765#issuecomment-2880386178"),
1621 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/powerpc/include/mcontext.h
1622 .powerpc => extern struct {
1623 r: [32]u32 align(16),
1624 _cr: i32,
1625 lr: u32,
1626 pc: u32,
1627 },
1628 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/sparc/include/mcontext.h
1629 .sparc => @compileError("sparc-netbsd mcontext_t missing"),
1630 .sparc64 => @compileError("sparc64-netbsd mcontext_t missing"),
1631 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/i386/include/mcontext.h
13171632 .x86 => extern struct {
1318 gregs: [19]u32,
1319 fpregs: [161]u32,
1320 mc_tlsbase: u32,
1633 _gs: i32,
1634 _fs: i32,
1635 _es: i32,
1636 _ds: i32,
1637 edi: u32,
1638 esi: u32,
1639 ebp: u32,
1640 esp: u32,
1641 ebx: u32,
1642 edx: u32,
1643 ecx: u32,
1644 eax: u32,
1645 _trapno: i32,
1646 _err: i32,
1647 eip: u32,
13211648 },
1649 // https://github.com/NetBSD/src/blob/861008c62187bf7bc0aac4d81e52ed6eee4d0c74/sys/arch/amd64/include/mcontext.h
13221650 .x86_64 => extern struct {
1323 gregs: [26]u64,
1324 mc_tlsbase: u64,
1325 fpregs: [512]u8 align(8),
1651 rdi: u64,
1652 rsi: u64,
1653 rdx: u64,
1654 rcx: u64,
1655 r8: u64,
1656 r9: u64,
1657 r10: u64,
1658 r11: u64,
1659 r12: u64,
1660 r13: u64,
1661 r14: u64,
1662 r15: u64,
1663 rbp: u64,
1664 rbx: u64,
1665 rax: u64,
1666 _gs: i64,
1667 _fs: i64,
1668 _es: i64,
1669 _ds: i64,
1670 _trapno: i64,
1671 _err: i64,
1672 rip: u64,
1673 _cs: i64,
1674 _rflags: i64,
1675 rsp: u64,
13261676 },
1327 else => void,
1328 };
1677 else => unreachable,
1678 },
13291679 },
1680 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/3de1e9d36269616d22237f19d60a737a41271ab5/sys/sys/_ucontext.h
13301681 .dragonfly => extern struct {
1331 sigmask: std.c.sigset_t,
1332 mcontext: mcontext_t,
1333 link: ?*signal_ucontext_t,
1334 stack: std.c.stack_t,
1335 cofunc: ?*fn (?*signal_ucontext_t, ?*anyopaque) void,
1336 arg: ?*void,
1337 _spare: [4]c_int,
1338 const mcontext_t = extern struct {
1339 const register_t = isize;
1340 onstack: register_t, // XXX - sigcontext compat.
1341 rdi: register_t,
1342 rsi: register_t,
1343 rdx: register_t,
1344 rcx: register_t,
1345 r8: register_t,
1346 r9: register_t,
1347 rax: register_t,
1348 rbx: register_t,
1349 rbp: register_t,
1350 r10: register_t,
1351 r11: register_t,
1352 r12: register_t,
1353 r13: register_t,
1354 r14: register_t,
1355 r15: register_t,
1356 xflags: register_t,
1357 trapno: register_t,
1358 addr: register_t,
1359 flags: register_t,
1360 err: register_t,
1361 rip: register_t,
1362 cs: register_t,
1363 rflags: register_t,
1364 rsp: register_t, // machine state
1365 ss: register_t,
1366
1367 len: c_uint, // sizeof(mcontext_t)
1368 fpformat: c_uint,
1369 ownedfp: c_uint,
1370 reserved: c_uint,
1371 unused: [8]c_uint,
1372
1373 // NOTE! 64-byte aligned as of here. Also must match savefpu structure.
1374 fpregs: [256]c_int align(64),
1375 };
1682 _sigmask: std.c.sigset_t,
1683 mcontext: switch (native_arch) {
1684 // https://github.com/DragonFlyBSD/DragonFlyBSD/blob/3de1e9d36269616d22237f19d60a737a41271ab5/sys/cpu/x86_64/include/ucontext.h
1685 .x86_64 => extern struct {
1686 _onstack: i64 align(64),
1687 rdi: u64,
1688 rsi: u64,
1689 rdx: u64,
1690 rcx: u64,
1691 r8: u64,
1692 r9: u64,
1693 rax: u64,
1694 rbx: u64,
1695 rbp: u64,
1696 r10: u64,
1697 r11: u64,
1698 r12: u64,
1699 r13: u64,
1700 r14: u64,
1701 r15: u64,
1702 _xflags: i64,
1703 _trapno: i64,
1704 _addr: i64,
1705 _flags: i64,
1706 _err: i64,
1707 rip: u64,
1708 _cs: i64,
1709 _rflags: i64,
1710 rsp: u64,
1711 },
1712 else => unreachable,
1713 },
13761714 },
1715 // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/API/POSIX/ucontext.h
13771716 .serenity => extern struct {
1378 link: ?*signal_ucontext_t,
1379 sigmask: std.c.sigset_t,
1380 stack: std.c.stack_t,
1381 mcontext: mcontext_t,
1382 const mcontext_t = switch (builtin.cpu.arch) {
1383 // https://github.com/SerenityOS/serenity/blob/200e91cd7f1ec5453799a2720d4dc114a59cc289/Kernel/Arch/aarch64/mcontext.h#L15-L19
1717 _link: ?*signal_ucontext_t,
1718 _sigmask: std.c.sigset_t,
1719 _stack: std.c.stack_t,
1720 mcontext: switch (native_arch) {
1721 // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/aarch64/mcontext.h
13841722 .aarch64 => extern struct {
1385 x: [31]u64,
1723 x: [30]u64,
1724 lr: u64,
13861725 sp: u64,
13871726 pc: u64,
13881727 },
1389 // https://github.com/SerenityOS/serenity/blob/66f8d0f031ef25c409dbb4fecaa454800fecae0f/Kernel/Arch/riscv64/mcontext.h#L15-L18
1728 // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/riscv64/mcontext.h
13901729 .riscv64 => extern struct {
1391 x: [31]u64,
1730 ra_sp_gp_tp: [4]u64,
1731 t0_2: [3]u64,
1732 s0_1: [2]u64,
1733 a: [8]u64,
1734 s2_11: [10]u64,
1735 t3_6: [4]u64,
13921736 pc: u64,
13931737 },
1394 // https://github.com/SerenityOS/serenity/blob/7b9ea3efdec9f86a1042893e8107d0b23aad8727/Kernel/Arch/x86_64/mcontext.h#L15-L40
1738 // https://github.com/SerenityOS/serenity/blob/103d6a07de9e28f3c94dfa2351b9af76a49ba6e6/Kernel/Arch/x86_64/mcontext.h
13951739 .x86_64 => extern struct {
13961740 rax: u64,
13971741 rcx: u64,
......@@ -1410,262 +1754,103 @@ const signal_ucontext_t = switch (native_os) {
14101754 r13: u64,
14111755 r14: u64,
14121756 r15: u64,
1413 rflags: u64,
1414 cs: u32,
1415 ss: u32,
1416 ds: u32,
1417 es: u32,
1418 fs: u32,
1419 gs: u32,
14201757 },
1421 else => void,
1422 };
1758 else => unreachable,
1759 },
14231760 },
1761 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/signal.h#L356
14241762 .haiku => extern struct {
1425 link: ?*signal_ucontext_t,
1426 sigmask: std.c.sigset_t,
1427 stack: std.c.stack_t,
1428 mcontext: mcontext_t,
1429 const mcontext_t = switch (builtin.cpu.arch) {
1430 .arm, .thumb => extern struct {
1431 r0: u32,
1432 r1: u32,
1433 r2: u32,
1434 r3: u32,
1435 r4: u32,
1436 r5: u32,
1437 r6: u32,
1438 r7: u32,
1439 r8: u32,
1440 r9: u32,
1441 r10: u32,
1442 r11: u32,
1443 r12: u32,
1444 r13: u32,
1445 r14: u32,
1446 r15: u32,
1447 cpsr: u32,
1763 _link: ?*signal_ucontext_t,
1764 _sigmask: std.c.sigset_t,
1765 _stack: std.c.stack_t,
1766 mcontext: switch (native_arch) {
1767 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/arm/signal.h
1768 .arm => extern struct {
1769 r: [15]u32 align(8),
1770 pc: u32,
14481771 },
1772 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/arm64/signal.h
14491773 .aarch64 => extern struct {
1450 x: [10]u64,
1774 x: [30]u64 align(16),
14511775 lr: u64,
14521776 sp: u64,
1453 elr: u64,
1454 spsr: u64,
1455 fp_q: [32]u128,
1456 fpsr: u32,
1457 fpcr: u32,
1777 pc: u64,
14581778 },
1779 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/m68k/signal.h
14591780 .m68k => extern struct {
1460 pc: u32,
1461 d0: u32,
1462 d1: u32,
1463 d2: u32,
1464 d3: u32,
1465 d4: u32,
1466 d5: u32,
1467 d6: u32,
1468 d7: u32,
1469 a0: u32,
1470 a1: u32,
1471 a2: u32,
1472 a3: u32,
1473 a4: u32,
1474 a5: u32,
1475 a6: u32,
1476 a7: u32,
1477 ccr: u8,
1478 f0: f64,
1479 f1: f64,
1480 f2: f64,
1481 f3: f64,
1482 f4: f64,
1483 f5: f64,
1484 f6: f64,
1485 f7: f64,
1486 f8: f64,
1487 f9: f64,
1488 f10: f64,
1489 f11: f64,
1490 f12: f64,
1491 f13: f64,
1492 },
1493 .mipsel => extern struct {
1494 r0: u32,
1781 pc: u32 align(8),
1782 d: [8]u32,
1783 a: [8]u32,
14951784 },
1785 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/ppc/signal.h
14961786 .powerpc => extern struct {
1497 pc: u32,
1498 r0: u32,
1499 r1: u32,
1500 r2: u32,
1501 r3: u32,
1502 r4: u32,
1503 r5: u32,
1504 r6: u32,
1505 r7: u32,
1506 r8: u32,
1507 r9: u32,
1508 r10: u32,
1509 r11: u32,
1510 r12: u32,
1511 f0: f64,
1512 f1: f64,
1513 f2: f64,
1514 f3: f64,
1515 f4: f64,
1516 f5: f64,
1517 f6: f64,
1518 f7: f64,
1519 f8: f64,
1520 f9: f64,
1521 f10: f64,
1522 f11: f64,
1523 f12: f64,
1524 f13: f64,
1525 reserved: u32,
1526 fpscr: u32,
1527 ctr: u32,
1528 xer: u32,
1529 cr: u32,
1530 msr: u32,
1787 pc: u32 align(8),
1788 r: [13]u32, // Um, are you okay, Haiku?
1789 _f: [14]f64,
1790 _reserved: u32,
1791 _fpscr: u32,
1792 _ctr: u32,
1793 _xer: u32,
1794 _cr: u32,
1795 _msr: u32,
15311796 lr: u32,
15321797 },
1798 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/riscv64/signal.h
15331799 .riscv64 => extern struct {
1534 x: [31]u64,
1800 ra_sp_gp_tp: [4]u64,
1801 t0_2: [3]u64,
1802 s0_1: [2]u64,
1803 a: [8]u64,
1804 s2_11: [10]u64,
1805 t3_6: [4]u64,
15351806 pc: u64,
1536 f: [32]f64,
1537 fcsr: u64,
1538 },
1539 .sparc64 => extern struct {
1540 g1: u64,
1541 g2: u64,
1542 g3: u64,
1543 g4: u64,
1544 g5: u64,
1545 g6: u64,
1546 g7: u64,
1547 o0: u64,
1548 o1: u64,
1549 o2: u64,
1550 o3: u64,
1551 o4: u64,
1552 o5: u64,
1553 sp: u64,
1554 o7: u64,
1555 l0: u64,
1556 l1: u64,
1557 l2: u64,
1558 l3: u64,
1559 l4: u64,
1560 l5: u64,
1561 l6: u64,
1562 l7: u64,
1563 i0: u64,
1564 i1: u64,
1565 i2: u64,
1566 i3: u64,
1567 i4: u64,
1568 i5: u64,
1569 fp: u64,
1570 i7: u64,
15711807 },
1808 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/sparc64/signal.h
1809 .sparc64 => @compileError("sparc64-haiku mcontext_t missing"),
1810 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/x86/signal.h
15721811 .x86 => extern struct {
1573 pub const old_extended_regs = extern struct {
1574 control: u16,
1575 reserved1: u16,
1576 status: u16,
1577 reserved2: u16,
1578 tag: u16,
1579 reserved3: u16,
1580 eip: u32,
1581 cs: u16,
1582 opcode: u16,
1583 datap: u32,
1584 ds: u16,
1585 reserved4: u16,
1586 fp_mmx: [8][10]u8,
1587 };
1588
1589 pub const fp_register = extern struct { value: [10]u8, reserved: [6]u8 };
1590
1591 pub const xmm_register = extern struct { value: [16]u8 };
1592
1593 pub const new_extended_regs = extern struct {
1594 control: u16,
1595 status: u16,
1596 tag: u16,
1597 opcode: u16,
1598 eip: u32,
1599 cs: u16,
1600 reserved1: u16,
1601 datap: u32,
1602 ds: u16,
1603 reserved2: u16,
1604 mxcsr: u32,
1605 reserved3: u32,
1606 fp_mmx: [8]fp_register,
1607 xmmx: [8]xmm_register,
1608 reserved4: [224]u8,
1609 };
1610
1611 pub const extended_regs = extern struct {
1612 state: extern union {
1613 old_format: old_extended_regs,
1614 new_format: new_extended_regs,
1615 },
1616 format: u32,
1617 };
1618
16191812 eip: u32,
1620 eflags: u32,
1813 _eflags: u32,
16211814 eax: u32,
16221815 ecx: u32,
16231816 edx: u32,
16241817 esp: u32,
16251818 ebp: u32,
1626 reserved: u32,
1627 xregs: extended_regs,
1819 _reserved: u32,
1820 _xregs: extern struct {
1821 _fp_control: u16,
1822 _fp_status: u16,
1823 _fp_tag: u16,
1824 _fp_opcode: u16,
1825 _fp_eip: u32,
1826 _fp_cs: u16,
1827 _reserved1: u16,
1828 _fp_datap: u32,
1829 _fp_ds: u16,
1830 _reserved2: u16,
1831 _mxcsr: u32,
1832 _mxcsr_mask: u32,
1833 _mmx: [8][16]u8,
1834 _xmmx: [8][16]u8,
1835 _reserved3: [176]u8,
1836 _fault_address: u32,
1837 _error_code: u32,
1838 _cs: u16,
1839 _ds: u16,
1840 _es: u16,
1841 _fs: u16,
1842 _gs: u16,
1843 _ss: u16,
1844 _trap_number: u8,
1845 _reserved4: [27]u8,
1846 _format: u32,
1847 },
16281848 edi: u32,
16291849 esi: u32,
16301850 ebx: u32,
16311851 },
1852 // https://github.com/haiku/haiku/blob/47538c534fe0aadc626c09d121773fee8ea10d71/headers/posix/arch/x86_64/signal.h
16321853 .x86_64 => extern struct {
1633 pub const fp_register = extern struct {
1634 value: [10]u8,
1635 reserved: [6]u8,
1636 };
1637
1638 pub const xmm_register = extern struct {
1639 value: [16]u8,
1640 };
1641
1642 pub const fpu_state = extern struct {
1643 control: u16,
1644 status: u16,
1645 tag: u16,
1646 opcode: u16,
1647 rip: u64,
1648 rdp: u64,
1649 mxcsr: u32,
1650 mscsr_mask: u32,
1651
1652 fp_mmx: [8]fp_register,
1653 xmm: [16]xmm_register,
1654 reserved: [96]u8,
1655 };
1656
1657 pub const xstate_hdr = extern struct {
1658 bv: u64,
1659 xcomp_bv: u64,
1660 reserved: [48]u8,
1661 };
1662
1663 pub const savefpu = extern struct {
1664 fxsave: fpu_state,
1665 xstate: xstate_hdr,
1666 ymm: [16]xmm_register,
1667 };
1668
16691854 rax: u64,
16701855 rbx: u64,
16711856 rcx: u64,
......@@ -1683,11 +1868,9 @@ const signal_ucontext_t = switch (native_os) {
16831868 r15: u64,
16841869 rsp: u64,
16851870 rip: u64,
1686 rflags: u64,
1687 fpu: savefpu,
16881871 },
1689 else => void,
1690 };
1872 else => unreachable,
1873 },
16911874 },
16921875 else => void,
16931876};
lib/std/os/emscripten.zig-38
......@@ -400,28 +400,6 @@ pub const timeval = extern struct {
400400 usec: i32,
401401};
402402
403pub const REG = struct {
404 pub const GS = 0;
405 pub const FS = 1;
406 pub const ES = 2;
407 pub const DS = 3;
408 pub const EDI = 4;
409 pub const ESI = 5;
410 pub const EBP = 6;
411 pub const ESP = 7;
412 pub const EBX = 8;
413 pub const EDX = 9;
414 pub const ECX = 10;
415 pub const EAX = 11;
416 pub const TRAPNO = 12;
417 pub const ERR = 13;
418 pub const EIP = 14;
419 pub const CS = 15;
420 pub const EFL = 16;
421 pub const UESP = 17;
422 pub const SS = 18;
423};
424
425403pub const S = struct {
426404 pub const IFMT = 0o170000;
427405
......@@ -813,13 +791,6 @@ pub const dl_phdr_info = extern struct {
813791 phnum: u16,
814792};
815793
816pub const mcontext_t = extern struct {
817 gregs: [19]usize,
818 fpregs: [*]u8,
819 oldmask: usize,
820 cr2: usize,
821};
822
823794pub const msghdr = std.c.msghdr;
824795pub const msghdr_const = std.c.msghdr;
825796
......@@ -846,15 +817,6 @@ pub const timezone = extern struct {
846817 dsttime: i32,
847818};
848819
849pub const ucontext_t = extern struct {
850 flags: usize,
851 link: ?*ucontext_t,
852 stack: stack_t,
853 mcontext: mcontext_t,
854 sigmask: sigset_t,
855 regspace: [28]usize,
856};
857
858820pub const utsname = extern struct {
859821 sysname: [64:0]u8,
860822 nodename: [64:0]u8,
lib/std/os/freebsd.zig-72
......@@ -48,75 +48,3 @@ pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64,
4848 else => |err| return unexpectedErrno(err),
4949 }
5050}
51
52pub const ucontext_t = extern struct {
53 sigmask: std.c.sigset_t,
54 mcontext: mcontext_t,
55 link: ?*ucontext_t,
56 stack: std.c.stack_t,
57 flags: c_int,
58 __spare__: [4]c_int,
59 const mcontext_t = switch (builtin.cpu.arch) {
60 .x86_64 => extern struct {
61 onstack: u64,
62 rdi: u64,
63 rsi: u64,
64 rdx: u64,
65 rcx: u64,
66 r8: u64,
67 r9: u64,
68 rax: u64,
69 rbx: u64,
70 rbp: u64,
71 r10: u64,
72 r11: u64,
73 r12: u64,
74 r13: u64,
75 r14: u64,
76 r15: u64,
77 trapno: u32,
78 fs: u16,
79 gs: u16,
80 addr: u64,
81 flags: u32,
82 es: u16,
83 ds: u16,
84 err: u64,
85 rip: u64,
86 cs: u64,
87 rflags: u64,
88 rsp: u64,
89 ss: u64,
90 len: u64,
91 fpformat: u64,
92 ownedfp: u64,
93 fpstate: [64]u64 align(16),
94 fsbase: u64,
95 gsbase: u64,
96 xfpustate: u64,
97 xfpustate_len: u64,
98 spare: [4]u64,
99 },
100 .aarch64 => extern struct {
101 gpregs: extern struct {
102 x: [30]u64,
103 lr: u64,
104 sp: u64,
105 elr: u64,
106 spsr: u32,
107 _pad: u32,
108 },
109 fpregs: extern struct {
110 q: [32]u128,
111 sr: u32,
112 cr: u32,
113 flags: u32,
114 _pad: u32,
115 },
116 flags: u32,
117 _pad: u32,
118 _spare: [8]u64,
119 },
120 else => void,
121 };
122};
lib/std/os/linux.zig+2-8
......@@ -47,9 +47,7 @@ const arch_bits = switch (native_arch) {
4747 .powerpc, .powerpcle => @import("linux/powerpc.zig"),
4848 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
4949 .s390x => @import("linux/s390x.zig"),
50 else => struct {
51 pub const ucontext_t = void;
52 },
50 else => struct {},
5351};
5452
5553const 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;
9492pub const F = arch_bits.F;
9593pub const Flock = arch_bits.Flock;
9694pub const HWCAP = arch_bits.HWCAP;
97pub const REG = arch_bits.REG;
9895pub const SC = arch_bits.SC;
9996pub const Stat = arch_bits.Stat;
10097pub const VDSO = arch_bits.VDSO;
......@@ -102,14 +99,12 @@ pub const blkcnt_t = arch_bits.blkcnt_t;
10299pub const blksize_t = arch_bits.blksize_t;
103100pub const dev_t = arch_bits.dev_t;
104101pub const ino_t = arch_bits.ino_t;
105pub const mcontext_t = arch_bits.mcontext_t;
106102pub const mode_t = arch_bits.mode_t;
107103pub const nlink_t = arch_bits.nlink_t;
108104pub const off_t = arch_bits.off_t;
109105pub const time_t = arch_bits.time_t;
110106pub const timeval = arch_bits.timeval;
111107pub const timezone = arch_bits.timezone;
112pub const ucontext_t = arch_bits.ucontext_t;
113108pub const user_desc = arch_bits.user_desc;
114109
115110pub const tls = @import("linux/tls.zig");
......@@ -3614,8 +3609,7 @@ pub const PROT = struct {
36143609 pub const EXEC = 0x4;
36153610 /// page may be used for atomic ops
36163611 pub const SEM = switch (native_arch) {
3617 // TODO: also xtensa
3618 .mips, .mipsel, .mips64, .mips64el => 0x10,
3612 .mips, .mipsel, .mips64, .mips64el, .xtensa => 0x10,
36193613 else => 0x8,
36203614 };
36213615 /// mprotect flag: extend change to start of growsdown vma
lib/std/os/linux/aarch64.zig-19
......@@ -241,23 +241,4 @@ pub const timezone = extern struct {
241241 dsttime: i32,
242242};
243243
244pub const mcontext_t = extern struct {
245 fault_address: usize,
246 regs: [31]usize,
247 sp: usize,
248 pc: usize,
249 pstate: usize,
250 // Make sure the field is correctly aligned since this area
251 // holds various FP/vector registers
252 reserved1: [256 * 16]u8 align(16),
253};
254
255pub const ucontext_t = extern struct {
256 flags: usize,
257 link: ?*ucontext_t,
258 stack: stack_t,
259 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
260 mcontext: mcontext_t,
261};
262
263244pub const Elf_Symndx = u32;
lib/std/os/linux/arm.zig-33
......@@ -277,37 +277,4 @@ pub const timezone = extern struct {
277277 dsttime: i32,
278278};
279279
280pub const mcontext_t = extern struct {
281 trap_no: usize,
282 error_code: usize,
283 oldmask: usize,
284 arm_r0: usize,
285 arm_r1: usize,
286 arm_r2: usize,
287 arm_r3: usize,
288 arm_r4: usize,
289 arm_r5: usize,
290 arm_r6: usize,
291 arm_r7: usize,
292 arm_r8: usize,
293 arm_r9: usize,
294 arm_r10: usize,
295 arm_fp: usize,
296 arm_ip: usize,
297 arm_sp: usize,
298 arm_lr: usize,
299 arm_pc: usize,
300 arm_cpsr: usize,
301 fault_address: usize,
302};
303
304pub const ucontext_t = extern struct {
305 flags: usize,
306 link: ?*ucontext_t,
307 stack: stack_t,
308 mcontext: mcontext_t,
309 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
310 regspace: [64]u64,
311};
312
313280pub const Elf_Symndx = u32;
lib/std/os/linux/hexagon.zig-52
......@@ -168,30 +168,6 @@ pub const Flock = extern struct {
168168 __unused: [4]u8,
169169};
170170
171pub const msghdr = extern struct {
172 name: ?*sockaddr,
173 namelen: socklen_t,
174 iov: [*]iovec,
175 iovlen: i32,
176 __pad1: i32 = 0,
177 control: ?*anyopaque,
178 controllen: socklen_t,
179 __pad2: socklen_t = 0,
180 flags: i32,
181};
182
183pub const msghdr_const = extern struct {
184 name: ?*const sockaddr,
185 namelen: socklen_t,
186 iov: [*]const iovec_const,
187 iovlen: i32,
188 __pad1: i32 = 0,
189 control: ?*const anyopaque,
190 controllen: socklen_t,
191 __pad2: socklen_t = 0,
192 flags: i32,
193};
194
195171pub const blksize_t = i32;
196172pub const nlink_t = u32;
197173pub const time_t = i32;
......@@ -236,31 +212,3 @@ pub const Stat = extern struct {
236212pub const Elf_Symndx = u32;
237213
238214pub const VDSO = void;
239
240pub const mcontext_t = extern struct {
241 gregs: [32]u32 align(8),
242 sa0: u32,
243 lc0: u32,
244 sa1: u32,
245 lc1: u32,
246 m0: u32,
247 m1: u32,
248 usr: u32,
249 p3_0: u32,
250 gp: u32,
251 ugp: u32,
252 pc: u32,
253 cause: u32,
254 badva: u32,
255 cs0: u32,
256 cs1: u32,
257 _pad1: u32,
258};
259
260pub const ucontext_t = extern struct {
261 flags: u32,
262 link: ?*ucontext_t,
263 stack: stack_t,
264 mcontext: mcontext_t,
265 sigmask: sigset_t,
266};
lib/std/os/linux/loongarch64.zig-39
......@@ -135,30 +135,6 @@ pub fn clone() callconv(.naked) usize {
135135 );
136136}
137137
138pub const msghdr = extern struct {
139 name: ?*sockaddr,
140 namelen: socklen_t,
141 iov: [*]iovec,
142 iovlen: i32,
143 __pad1: i32 = 0,
144 control: ?*anyopaque,
145 controllen: socklen_t,
146 __pad2: socklen_t = 0,
147 flags: i32,
148};
149
150pub const msghdr_const = extern struct {
151 name: ?*const sockaddr,
152 namelen: socklen_t,
153 iov: [*]const iovec_const,
154 iovlen: i32,
155 __pad1: i32 = 0,
156 control: ?*const anyopaque,
157 controllen: socklen_t,
158 __pad2: socklen_t = 0,
159 flags: i32,
160};
161
162138pub const blksize_t = i32;
163139pub const nlink_t = u32;
164140pub const time_t = i64;
......@@ -234,19 +210,4 @@ pub const VDSO = struct {
234210 pub const CGT_VER = "LINUX_5.10";
235211};
236212
237pub const mcontext_t = extern struct {
238 pc: u64,
239 regs: [32]u64,
240 flags: u32,
241 extcontext: [0]u64 align(16),
242};
243
244pub const ucontext_t = extern struct {
245 flags: c_ulong,
246 link: ?*ucontext_t,
247 stack: stack_t,
248 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
249 mcontext: mcontext_t,
250};
251
252213pub const Elf_Symndx = u32;
lib/std/os/linux/m68k.zig-24
......@@ -199,27 +199,6 @@ pub const Flock = extern struct {
199199 pid: pid_t,
200200};
201201
202// TODO: not 100% sure of padding for msghdr
203pub const msghdr = extern struct {
204 name: ?*sockaddr,
205 namelen: socklen_t,
206 iov: [*]iovec,
207 iovlen: i32,
208 control: ?*anyopaque,
209 controllen: socklen_t,
210 flags: i32,
211};
212
213pub const msghdr_const = extern struct {
214 name: ?*const sockaddr,
215 namelen: socklen_t,
216 iov: [*]const iovec_const,
217 iovlen: i32,
218 control: ?*const anyopaque,
219 controllen: socklen_t,
220 flags: i32,
221};
222
223202pub const Stat = extern struct {
224203 dev: dev_t,
225204 __pad: i16,
......@@ -255,6 +234,3 @@ pub const Elf_Symndx = u32;
255234
256235// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.
257236pub const VDSO = void;
258
259/// TODO
260pub const ucontext_t = void;
lib/std/os/linux/mips.zig-29
......@@ -348,32 +348,3 @@ pub const timezone = extern struct {
348348};
349349
350350pub const Elf_Symndx = u32;
351
352pub const mcontext_t = extern struct {
353 _regmask: u32,
354 _status: u32,
355 pc: u64,
356 regs: [32]u64,
357 fpregs: [32]f64,
358 acx: u32,
359 fpc_csr: u32,
360 _fpc_eir: u32,
361 used_math: u32,
362 dsp: u32,
363 mdhi: u64,
364 mdlo: u64,
365 hi1: u32,
366 lo1: u32,
367 hi2: u32,
368 lo2: u32,
369 hi3: u32,
370 lo3: u32,
371};
372
373pub const ucontext_t = extern struct {
374 flags: u32,
375 link: ?*ucontext_t,
376 stack: stack_t,
377 mcontext: mcontext_t,
378 sigmask: sigset_t,
379};
lib/std/os/linux/mips64.zig-26
......@@ -327,29 +327,3 @@ pub const timezone = extern struct {
327327};
328328
329329pub const Elf_Symndx = u32;
330
331pub const mcontext_t = extern struct {
332 regs: [32]u64,
333 fpregs: [32]f64,
334 mdhi: u64,
335 hi1: u64,
336 hi2: u64,
337 hi3: u64,
338 mdlo: u64,
339 lo1: u64,
340 lo2: u64,
341 lo3: u64,
342 pc: u64,
343 fpc_csr: u32,
344 used_math: u32,
345 dsp: u32,
346 _reserved: u32,
347};
348
349pub const ucontext_t = extern struct {
350 flags: u32,
351 link: ?*ucontext_t,
352 stack: stack_t,
353 mcontext: mcontext_t,
354 sigmask: sigset_t,
355};
lib/std/os/linux/powerpc.zig-29
......@@ -351,33 +351,4 @@ pub const timezone = extern struct {
351351 dsttime: i32,
352352};
353353
354pub const greg_t = u32;
355pub const gregset_t = [48]greg_t;
356pub const fpregset_t = [33]f64;
357
358pub const vrregset = extern struct {
359 vrregs: [32][4]u32,
360 vrsave: u32,
361 _pad: [2]u32,
362 vscr: u32,
363};
364pub const vrregset_t = vrregset;
365
366pub const mcontext_t = extern struct {
367 gp_regs: gregset_t,
368 fp_regs: fpregset_t,
369 v_regs: vrregset_t align(16),
370};
371
372pub const ucontext_t = extern struct {
373 flags: u32,
374 link: ?*ucontext_t,
375 stack: stack_t,
376 pad: [7]i32,
377 regs: *mcontext_t,
378 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
379 pad2: [3]i32,
380 mcontext: mcontext_t,
381};
382
383354pub const Elf_Symndx = u32;
lib/std/os/linux/powerpc64.zig-39
......@@ -336,43 +336,4 @@ pub const timezone = extern struct {
336336 dsttime: i32,
337337};
338338
339pub const greg_t = u64;
340pub const gregset_t = [48]greg_t;
341pub const fpregset_t = [33]f64;
342
343/// The position of the vscr register depends on endianness.
344/// On C, macros are used to change vscr_word's offset to
345/// account for this. Here we'll just define vscr_word_le
346/// and vscr_word_be. Code must take care to use the correct one.
347pub const vrregset = extern struct {
348 vrregs: [32][4]u32 align(16),
349 vscr_word_le: u32,
350 _pad1: [2]u32,
351 vscr_word_be: u32,
352 vrsave: u32,
353 _pad2: [3]u32,
354};
355pub const vrregset_t = vrregset;
356
357pub const mcontext_t = extern struct {
358 __unused: [4]u64,
359 signal: i32,
360 _pad0: i32,
361 handler: u64,
362 oldmask: u64,
363 regs: ?*anyopaque,
364 gp_regs: gregset_t,
365 fp_regs: fpregset_t,
366 v_regs: *vrregset_t,
367 vmx_reserve: [34 + 34 + 32 + 1]i64,
368};
369
370pub const ucontext_t = extern struct {
371 flags: u32,
372 link: ?*ucontext_t,
373 stack: stack_t,
374 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
375 mcontext: mcontext_t,
376};
377
378339pub const Elf_Symndx = u32;
lib/std/os/linux/riscv32.zig-35
......@@ -220,38 +220,3 @@ pub const VDSO = struct {
220220 pub const CGT_SYM = "__vdso_clock_gettime";
221221 pub const CGT_VER = "LINUX_4.15";
222222};
223
224pub const f_ext_state = extern struct {
225 f: [32]f32,
226 fcsr: u32,
227};
228
229pub const d_ext_state = extern struct {
230 f: [32]f64,
231 fcsr: u32,
232};
233
234pub const q_ext_state = extern struct {
235 f: [32]f128,
236 fcsr: u32,
237 _reserved: [3]u32,
238};
239
240pub const fpstate = extern union {
241 f: f_ext_state,
242 d: d_ext_state,
243 q: q_ext_state,
244};
245
246pub const mcontext_t = extern struct {
247 gregs: [32]u32,
248 fpregs: fpstate,
249};
250
251pub const ucontext_t = extern struct {
252 flags: c_ulong,
253 link: ?*ucontext_t,
254 stack: stack_t,
255 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
256 mcontext: mcontext_t,
257};
lib/std/os/linux/riscv64.zig-35
......@@ -220,38 +220,3 @@ pub const VDSO = struct {
220220 pub const CGT_SYM = "__vdso_clock_gettime";
221221 pub const CGT_VER = "LINUX_4.15";
222222};
223
224pub const f_ext_state = extern struct {
225 f: [32]f32,
226 fcsr: u32,
227};
228
229pub const d_ext_state = extern struct {
230 f: [32]f64,
231 fcsr: u32,
232};
233
234pub const q_ext_state = extern struct {
235 f: [32]f128,
236 fcsr: u32,
237 _reserved: [3]u32,
238};
239
240pub const fpstate = extern union {
241 f: f_ext_state,
242 d: d_ext_state,
243 q: q_ext_state,
244};
245
246pub const mcontext_t = extern struct {
247 gregs: [32]u64,
248 fpregs: fpstate,
249};
250
251pub const ucontext_t = extern struct {
252 flags: c_ulong,
253 link: ?*ucontext_t,
254 stack: stack_t,
255 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
256 mcontext: mcontext_t,
257};
lib/std/os/linux/s390x.zig-43
......@@ -199,30 +199,6 @@ pub const Flock = extern struct {
199199 pid: pid_t,
200200};
201201
202pub const msghdr = extern struct {
203 name: ?*sockaddr,
204 namelen: socklen_t,
205 iov: [*]iovec,
206 __pad1: i32 = 0,
207 iovlen: i32,
208 control: ?*anyopaque,
209 __pad2: i32 = 0,
210 controllen: socklen_t,
211 flags: i32,
212};
213
214pub const msghdr_const = extern struct {
215 name: ?*const sockaddr,
216 namelen: socklen_t,
217 iov: [*]const iovec_const,
218 __pad1: i32 = 0,
219 iovlen: i32,
220 control: ?*const anyopaque,
221 __pad2: i32 = 0,
222 controllen: socklen_t,
223 flags: i32,
224};
225
226202// The `stat` definition used by the Linux kernel.
227203pub const Stat = extern struct {
228204 dev: dev_t,
......@@ -259,22 +235,3 @@ pub const VDSO = struct {
259235 pub const CGT_SYM = "__kernel_clock_gettime";
260236 pub const CGT_VER = "LINUX_2.6.29";
261237};
262
263pub const ucontext_t = extern struct {
264 flags: u64,
265 link: ?*ucontext_t,
266 stack: stack_t,
267 mcontext: mcontext_t,
268 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
269};
270
271pub const mcontext_t = extern struct {
272 psw: extern struct {
273 mask: u64,
274 addr: u64,
275 },
276 gregs: [16]u64,
277 aregs: [16]u32,
278 fpc: u32,
279 fregs: [16]f64,
280};
lib/std/os/linux/sparc64.zig-100
......@@ -325,104 +325,4 @@ pub const timezone = extern struct {
325325 dsttime: i32,
326326};
327327
328// TODO I'm not sure if the code below is correct, need someone with more
329// knowledge about sparc64 linux internals to look into.
330
331328pub const Elf_Symndx = u32;
332
333pub const fpstate = extern struct {
334 regs: [32]u64,
335 fsr: u64,
336 gsr: u64,
337 fprs: u64,
338};
339
340pub const __fpq = extern struct {
341 fpq_addr: *u32,
342 fpq_instr: u32,
343};
344
345pub const __fq = extern struct {
346 FQu: extern union {
347 whole: f64,
348 fpq: __fpq,
349 },
350};
351
352pub const fpregset_t = extern struct {
353 fpu_fr: extern union {
354 fpu_regs: [32]u32,
355 fpu_dregs: [32]f64,
356 fpu_qregs: [16]c_longdouble,
357 },
358 fpu_q: *__fq,
359 fpu_fsr: u64,
360 fpu_qcnt: u8,
361 fpu_q_entrysize: u8,
362 fpu_en: u8,
363};
364
365pub const siginfo_fpu_t = extern struct {
366 float_regs: [64]u32,
367 fsr: u64,
368 gsr: u64,
369 fprs: u64,
370};
371
372pub const sigcontext = extern struct {
373 info: [128]i8,
374 regs: extern struct {
375 u_regs: [16]u64,
376 tstate: u64,
377 tpc: u64,
378 tnpc: u64,
379 y: u64,
380 fprs: u64,
381 },
382 fpu_save: *siginfo_fpu_t,
383 stack: extern struct {
384 sp: usize,
385 flags: i32,
386 size: u64,
387 },
388 mask: u64,
389};
390
391pub const greg_t = u64;
392pub const gregset_t = [19]greg_t;
393
394pub const fq = extern struct {
395 addr: *u64,
396 insn: u32,
397};
398
399pub const fpu_t = extern struct {
400 fregs: extern union {
401 sregs: [32]u32,
402 dregs: [32]u64,
403 qregs: [16]c_longdouble,
404 },
405 fsr: u64,
406 fprs: u64,
407 gsr: u64,
408 fq: *fq,
409 qcnt: u8,
410 qentsz: u8,
411 enab: u8,
412};
413
414pub const mcontext_t = extern struct {
415 gregs: gregset_t,
416 fp: greg_t,
417 i7: greg_t,
418 fpregs: fpu_t,
419};
420
421pub const ucontext_t = extern struct {
422 link: ?*ucontext_t,
423 flags: u64,
424 sigmask: u64,
425 mcontext: mcontext_t,
426 stack: stack_t,
427 sigset: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
428};
lib/std/os/linux/x86.zig-108
......@@ -288,44 +288,6 @@ pub const timezone = extern struct {
288288 dsttime: i32,
289289};
290290
291pub const mcontext_t = extern struct {
292 gregs: [19]usize,
293 fpregs: [*]u8,
294 oldmask: usize,
295 cr2: usize,
296};
297
298pub const REG = struct {
299 pub const GS = 0;
300 pub const FS = 1;
301 pub const ES = 2;
302 pub const DS = 3;
303 pub const EDI = 4;
304 pub const ESI = 5;
305 pub const EBP = 6;
306 pub const ESP = 7;
307 pub const EBX = 8;
308 pub const EDX = 9;
309 pub const ECX = 10;
310 pub const EAX = 11;
311 pub const TRAPNO = 12;
312 pub const ERR = 13;
313 pub const EIP = 14;
314 pub const CS = 15;
315 pub const EFL = 16;
316 pub const UESP = 17;
317 pub const SS = 18;
318};
319
320pub const ucontext_t = extern struct {
321 flags: usize,
322 link: ?*ucontext_t,
323 stack: stack_t,
324 mcontext: mcontext_t,
325 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
326 regspace: [64]u64,
327};
328
329291pub const Elf_Symndx = u32;
330292
331293pub const user_desc = extern struct {
......@@ -366,73 +328,3 @@ pub const SC = struct {
366328 pub const recvmmsg = 19;
367329 pub const sendmmsg = 20;
368330};
369
370fn gpRegisterOffset(comptime reg_index: comptime_int) usize {
371 return @offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "gregs") + @sizeOf(usize) * reg_index;
372}
373
374noinline fn getContextReturnAddress() usize {
375 return @returnAddress();
376}
377
378pub fn getContextInternal() callconv(.naked) usize {
379 asm volatile (
380 \\ movl $0, %[flags_offset:c](%%edx)
381 \\ movl $0, %[link_offset:c](%%edx)
382 \\ movl %%edi, %[edi_offset:c](%%edx)
383 \\ movl %%esi, %[esi_offset:c](%%edx)
384 \\ movl %%ebp, %[ebp_offset:c](%%edx)
385 \\ movl %%ebx, %[ebx_offset:c](%%edx)
386 \\ movl %%edx, %[edx_offset:c](%%edx)
387 \\ movl %%ecx, %[ecx_offset:c](%%edx)
388 \\ movl %%eax, %[eax_offset:c](%%edx)
389 \\ movl (%%esp), %%ecx
390 \\ movl %%ecx, %[eip_offset:c](%%edx)
391 \\ leal 4(%%esp), %%ecx
392 \\ movl %%ecx, %[esp_offset:c](%%edx)
393 \\ xorl %%ecx, %%ecx
394 \\ movw %%fs, %%cx
395 \\ movl %%ecx, %[fs_offset:c](%%edx)
396 \\ leal %[regspace_offset:c](%%edx), %%ecx
397 \\ movl %%ecx, %[fpregs_offset:c](%%edx)
398 \\ fnstenv (%%ecx)
399 \\ fldenv (%%ecx)
400 \\ pushl %%ebx
401 \\ pushl %%esi
402 \\ xorl %%ebx, %%ebx
403 \\ movl %[sigaltstack], %%eax
404 \\ leal %[stack_offset:c](%%edx), %%ecx
405 \\ int $0x80
406 \\ testl %%eax, %%eax
407 \\ jnz 0f
408 \\ movl %[sigprocmask], %%eax
409 \\ xorl %%ecx, %%ecx
410 \\ leal %[sigmask_offset:c](%%edx), %%edx
411 \\ movl %[sigset_size], %%esi
412 \\ int $0x80
413 \\0:
414 \\ popl %%esi
415 \\ popl %%ebx
416 \\ retl
417 :
418 : [flags_offset] "i" (@offsetOf(ucontext_t, "flags")),
419 [link_offset] "i" (@offsetOf(ucontext_t, "link")),
420 [edi_offset] "i" (comptime gpRegisterOffset(REG.EDI)),
421 [esi_offset] "i" (comptime gpRegisterOffset(REG.ESI)),
422 [ebp_offset] "i" (comptime gpRegisterOffset(REG.EBP)),
423 [esp_offset] "i" (comptime gpRegisterOffset(REG.ESP)),
424 [ebx_offset] "i" (comptime gpRegisterOffset(REG.EBX)),
425 [edx_offset] "i" (comptime gpRegisterOffset(REG.EDX)),
426 [ecx_offset] "i" (comptime gpRegisterOffset(REG.ECX)),
427 [eax_offset] "i" (comptime gpRegisterOffset(REG.EAX)),
428 [eip_offset] "i" (comptime gpRegisterOffset(REG.EIP)),
429 [fs_offset] "i" (comptime gpRegisterOffset(REG.FS)),
430 [fpregs_offset] "i" (@offsetOf(ucontext_t, "mcontext") + @offsetOf(mcontext_t, "fpregs")),
431 [regspace_offset] "i" (@offsetOf(ucontext_t, "regspace")),
432 [sigaltstack] "i" (@intFromEnum(linux.SYS.sigaltstack)),
433 [stack_offset] "i" (@offsetOf(ucontext_t, "stack")),
434 [sigprocmask] "i" (@intFromEnum(linux.SYS.rt_sigprocmask)),
435 [sigmask_offset] "i" (@offsetOf(ucontext_t, "sigmask")),
436 [sigset_size] "i" (linux.NSIG / 8),
437 : .{ .cc = true, .memory = true, .eax = true, .ecx = true, .edx = true });
438}
lib/std/os/linux/x86_64.zig-106
......@@ -190,32 +190,6 @@ pub const ARCH = struct {
190190 pub const GET_GS = 0x1004;
191191};
192192
193pub const REG = struct {
194 pub const R8 = 0;
195 pub const R9 = 1;
196 pub const R10 = 2;
197 pub const R11 = 3;
198 pub const R12 = 4;
199 pub const R13 = 5;
200 pub const R14 = 6;
201 pub const R15 = 7;
202 pub const RDI = 8;
203 pub const RSI = 9;
204 pub const RBP = 10;
205 pub const RBX = 11;
206 pub const RDX = 12;
207 pub const RAX = 13;
208 pub const RCX = 14;
209 pub const RSP = 15;
210 pub const RIP = 16;
211 pub const EFL = 17;
212 pub const CSGSFS = 18;
213 pub const ERR = 19;
214 pub const TRAPNO = 20;
215 pub const OLDMASK = 21;
216 pub const CR2 = 22;
217};
218
219193pub const Flock = extern struct {
220194 type: i16,
221195 whence: i16,
......@@ -272,83 +246,3 @@ pub const timezone = extern struct {
272246};
273247
274248pub const Elf_Symndx = u32;
275
276pub const greg_t = usize;
277pub const gregset_t = [23]greg_t;
278pub const fpstate = extern struct {
279 cwd: u16,
280 swd: u16,
281 ftw: u16,
282 fop: u16,
283 rip: usize,
284 rdp: usize,
285 mxcsr: u32,
286 mxcr_mask: u32,
287 st: [8]extern struct {
288 significand: [4]u16,
289 exponent: u16,
290 padding: [3]u16 = undefined,
291 },
292 xmm: [16]extern struct {
293 element: [4]u32,
294 },
295 padding: [24]u32 = undefined,
296};
297pub const fpregset_t = *fpstate;
298pub const sigcontext = extern struct {
299 r8: usize,
300 r9: usize,
301 r10: usize,
302 r11: usize,
303 r12: usize,
304 r13: usize,
305 r14: usize,
306 r15: usize,
307
308 rdi: usize,
309 rsi: usize,
310 rbp: usize,
311 rbx: usize,
312 rdx: usize,
313 rax: usize,
314 rcx: usize,
315 rsp: usize,
316 rip: usize,
317 eflags: usize,
318
319 cs: u16,
320 gs: u16,
321 fs: u16,
322 pad0: u16 = undefined,
323
324 err: usize,
325 trapno: usize,
326 oldmask: usize,
327 cr2: usize,
328
329 fpstate: *fpstate,
330 reserved1: [8]usize = undefined,
331};
332
333pub const mcontext_t = extern struct {
334 gregs: gregset_t,
335 fpregs: fpregset_t,
336 reserved1: [8]usize = undefined,
337};
338
339/// ucontext_t is part of the state pushed on the stack by the kernel for
340/// a signal handler. And also a subset of the state returned from the
341/// makecontext/getcontext/swapcontext POSIX APIs.
342///
343/// Currently this structure matches the glibc/musl layout. It contains a
344/// 1024-bit signal mask, and `fpregs_mem`. This structure should be
345/// split into one for the kernel ABI and c.zig should define a glibc/musl
346/// compatible structure.
347pub const ucontext_t = extern struct {
348 flags: usize,
349 link: ?*ucontext_t,
350 stack: stack_t,
351 mcontext: mcontext_t,
352 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a glibc-compatible (1024-bit) sigmask.
353 fpregs_mem: [64]usize, // Not part of kernel ABI, only part of glibc ucontext_t
354};
lib/std/posix.zig-1
......@@ -97,7 +97,6 @@ pub const POLL = system.POLL;
9797pub const POSIX_FADV = system.POSIX_FADV;
9898pub const PR = system.PR;
9999pub const PROT = system.PROT;
100pub const REG = system.REG;
101100pub const RLIM = system.RLIM;
102101pub const RR = system.RR;
103102pub const S = system.S;