authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-09 09:55:40+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-10 04:43:18+02:00
log36dbe66cf4499e4a8f656bdf4629ec1623b345c1
tree64fbea0f74576eba0cbd3acda3f8ab6bcdb43aae
parentf33d3a516631be2566116b16fa2f9d5774fa62cc
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std: stop exposing anything having to do with ucontext_t

This type is useful for two things: * Doing non-local control flow with ucontext.h functions. * Inspecting machine state in a signal handler. The first use case is not one we support; we no longer expose bindings to those functions in the standard library. They're also deprecated in POSIX and, as a result, not available in musl. The second use case is valid, but is very poorly served by the standard library. As evidenced by my changes to std.debug.cpu_context.signal_context_t, users will be better served rolling their own ucontext_t and especially mcontext_t types which fit their specific situation. Further, these types tend to evolve frequently as architectures evolve, and the standard library has not done a good job keeping up, or even providing them for all supported targets.

21 files changed, 2 insertions(+), 870 deletions(-)

lib/std/c.zig+1-106
...@@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) {...@@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) {
1841 else => void,1841 else => void,
1842};1842};
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};
1948pub const RLIM = switch (native_os) {1844pub const RLIM = switch (native_os) {
1949 .linux => linux.RLIM,1845 .linux => linux.RLIM,
1950 .emscripten => emscripten.RLIM,1846 .emscripten => emscripten.RLIM,
...@@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) {...@@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) {
4553pub const siginfo_t = switch (native_os) {4449pub const siginfo_t = switch (native_os) {
4554 .linux => linux.siginfo_t,4450 .linux => linux.siginfo_t,
4555 .emscripten => emscripten.siginfo_t,4451 .emscripten => emscripten.siginfo_t,
4556 .macos, .ios, .tvos, .watchos, .visionos => extern struct {4452 .driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
4557 signo: c_int,4453 signo: c_int,
4558 errno: c_int,4454 errno: c_int,
4559 code: c_int,4455 code: c_int,
...@@ -11084,7 +10980,6 @@ pub const SETUSTACK = solaris.GETUSTACK;...@@ -11084,7 +10980,6 @@ pub const SETUSTACK = solaris.GETUSTACK;
11084pub const SFD = solaris.SFD;10980pub const SFD = solaris.SFD;
11085pub const ctid_t = solaris.ctid_t;10981pub const ctid_t = solaris.ctid_t;
11086pub const file_obj = solaris.file_obj;10982pub const file_obj = solaris.file_obj;
11087pub const fpregset_t = solaris.fpregset_t;
11088pub const id_t = solaris.id_t;10983pub const id_t = solaris.id_t;
11089pub const lif_ifinfo_req = solaris.lif_ifinfo_req;10984pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
11090pub const lif_nd_req = solaris.lif_nd_req;10985pub const lif_nd_req = solaris.lif_nd_req;
lib/std/c/solaris.zig-23
...@@ -31,29 +31,6 @@ pub const poolid_t = id_t;...@@ -31,29 +31,6 @@ pub const poolid_t = id_t;
31pub const zoneid_t = id_t;31pub const zoneid_t = id_t;
32pub const ctid_t = id_t;32pub 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
57pub const GETCONTEXT = 0;34pub const GETCONTEXT = 0;
58pub const SETCONTEXT = 1;35pub const SETCONTEXT = 1;
59pub const GETUSTACK = 2;36pub const GETUSTACK = 2;
lib/std/os/emscripten.zig-38
...@@ -400,28 +400,6 @@ pub const timeval = extern struct {...@@ -400,28 +400,6 @@ pub const timeval = extern struct {
400 usec: i32,400 usec: i32,
401};401};
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
425pub const S = struct {403pub const S = struct {
426 pub const IFMT = 0o170000;404 pub const IFMT = 0o170000;
427405
...@@ -813,13 +791,6 @@ pub const dl_phdr_info = extern struct {...@@ -813,13 +791,6 @@ pub const dl_phdr_info = extern struct {
813 phnum: u16,791 phnum: u16,
814};792};
815793
816pub const mcontext_t = extern struct {
817 gregs: [19]usize,
818 fpregs: [*]u8,
819 oldmask: usize,
820 cr2: usize,
821};
822
823pub const msghdr = std.c.msghdr;794pub const msghdr = std.c.msghdr;
824pub const msghdr_const = std.c.msghdr;795pub const msghdr_const = std.c.msghdr;
825796
...@@ -846,15 +817,6 @@ pub const timezone = extern struct {...@@ -846,15 +817,6 @@ pub const timezone = extern struct {
846 dsttime: i32,817 dsttime: i32,
847};818};
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
858pub const utsname = extern struct {820pub const utsname = extern struct {
859 sysname: [64:0]u8,821 sysname: [64:0]u8,
860 nodename: [64:0]u8,822 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,...@@ -48,75 +48,3 @@ pub fn copy_file_range(fd_in: fd_t, off_in: ?*i64, fd_out: fd_t, off_out: ?*i64,
48 else => |err| return unexpectedErrno(err),48 else => |err| return unexpectedErrno(err),
49 }49 }
50}50}
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+1-6
...@@ -47,9 +47,7 @@ const arch_bits = switch (native_arch) {...@@ -47,9 +47,7 @@ const arch_bits = switch (native_arch) {
47 .powerpc, .powerpcle => @import("linux/powerpc.zig"),47 .powerpc, .powerpcle => @import("linux/powerpc.zig"),
48 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),48 .powerpc64, .powerpc64le => @import("linux/powerpc64.zig"),
49 .s390x => @import("linux/s390x.zig"),49 .s390x => @import("linux/s390x.zig"),
50 else => struct {50 else => struct {},
51 pub const ucontext_t = void;
52 },
53};51};
5452
55const syscall_bits = if (native_arch.isThumb()) @import("linux/thumb.zig") else arch_bits;53const 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;...@@ -94,7 +92,6 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx;
94pub const F = arch_bits.F;92pub const F = arch_bits.F;
95pub const Flock = arch_bits.Flock;93pub const Flock = arch_bits.Flock;
96pub const HWCAP = arch_bits.HWCAP;94pub const HWCAP = arch_bits.HWCAP;
97pub const REG = arch_bits.REG;
98pub const SC = arch_bits.SC;95pub const SC = arch_bits.SC;
99pub const Stat = arch_bits.Stat;96pub const Stat = arch_bits.Stat;
100pub const VDSO = arch_bits.VDSO;97pub const VDSO = arch_bits.VDSO;
...@@ -102,14 +99,12 @@ pub const blkcnt_t = arch_bits.blkcnt_t;...@@ -102,14 +99,12 @@ pub const blkcnt_t = arch_bits.blkcnt_t;
102pub const blksize_t = arch_bits.blksize_t;99pub const blksize_t = arch_bits.blksize_t;
103pub const dev_t = arch_bits.dev_t;100pub const dev_t = arch_bits.dev_t;
104pub const ino_t = arch_bits.ino_t;101pub const ino_t = arch_bits.ino_t;
105pub const mcontext_t = arch_bits.mcontext_t;
106pub const mode_t = arch_bits.mode_t;102pub const mode_t = arch_bits.mode_t;
107pub const nlink_t = arch_bits.nlink_t;103pub const nlink_t = arch_bits.nlink_t;
108pub const off_t = arch_bits.off_t;104pub const off_t = arch_bits.off_t;
109pub const time_t = arch_bits.time_t;105pub const time_t = arch_bits.time_t;
110pub const timeval = arch_bits.timeval;106pub const timeval = arch_bits.timeval;
111pub const timezone = arch_bits.timezone;107pub const timezone = arch_bits.timezone;
112pub const ucontext_t = arch_bits.ucontext_t;
113pub const user_desc = arch_bits.user_desc;108pub const user_desc = arch_bits.user_desc;
114109
115pub const tls = @import("linux/tls.zig");110pub const tls = @import("linux/tls.zig");
lib/std/os/linux/aarch64.zig-19
...@@ -241,23 +241,4 @@ pub const timezone = extern struct {...@@ -241,23 +241,4 @@ pub const timezone = extern struct {
241 dsttime: i32,241 dsttime: i32,
242};242};
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
263pub const Elf_Symndx = u32;244pub const Elf_Symndx = u32;
lib/std/os/linux/arm.zig-33
...@@ -277,37 +277,4 @@ pub const timezone = extern struct {...@@ -277,37 +277,4 @@ pub const timezone = extern struct {
277 dsttime: i32,277 dsttime: i32,
278};278};
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
313pub const Elf_Symndx = u32;280pub const Elf_Symndx = u32;
lib/std/os/linux/hexagon.zig-28
...@@ -212,31 +212,3 @@ pub const Stat = extern struct {...@@ -212,31 +212,3 @@ pub const Stat = extern struct {
212pub const Elf_Symndx = u32;212pub const Elf_Symndx = u32;
213213
214pub const VDSO = void;214pub const VDSO = void;
215
216pub const mcontext_t = extern struct {
217 gregs: [32]u32 align(8),
218 sa0: u32,
219 lc0: u32,
220 sa1: u32,
221 lc1: u32,
222 m0: u32,
223 m1: u32,
224 usr: u32,
225 p3_0: u32,
226 gp: u32,
227 ugp: u32,
228 pc: u32,
229 cause: u32,
230 badva: u32,
231 cs0: u32,
232 cs1: u32,
233 _pad1: u32,
234};
235
236pub const ucontext_t = extern struct {
237 flags: u32,
238 link: ?*ucontext_t,
239 stack: stack_t,
240 mcontext: mcontext_t,
241 sigmask: sigset_t,
242};
lib/std/os/linux/loongarch64.zig-15
...@@ -210,19 +210,4 @@ pub const VDSO = struct {...@@ -210,19 +210,4 @@ pub const VDSO = struct {
210 pub const CGT_VER = "LINUX_5.10";210 pub const CGT_VER = "LINUX_5.10";
211};211};
212212
213pub const mcontext_t = extern struct {
214 pc: u64,
215 regs: [32]u64,
216 flags: u32,
217 extcontext: [0]u64 align(16),
218};
219
220pub const ucontext_t = extern struct {
221 flags: c_ulong,
222 link: ?*ucontext_t,
223 stack: stack_t,
224 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
225 mcontext: mcontext_t,
226};
227
228pub const Elf_Symndx = u32;213pub const Elf_Symndx = u32;
lib/std/os/linux/m68k.zig-3
...@@ -234,6 +234,3 @@ pub const Elf_Symndx = u32;...@@ -234,6 +234,3 @@ pub const Elf_Symndx = u32;
234234
235// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.235// No VDSO used as of glibc 112a0ae18b831bf31f44d81b82666980312511d6.
236pub const VDSO = void;236pub const VDSO = void;
237
238/// TODO
239pub const ucontext_t = void;
lib/std/os/linux/mips.zig-29
...@@ -348,32 +348,3 @@ pub const timezone = extern struct {...@@ -348,32 +348,3 @@ pub const timezone = extern struct {
348};348};
349349
350pub const Elf_Symndx = u32;350pub 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 {...@@ -327,29 +327,3 @@ pub const timezone = extern struct {
327};327};
328328
329pub const Elf_Symndx = u32;329pub 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 {...@@ -351,33 +351,4 @@ pub const timezone = extern struct {
351 dsttime: i32,351 dsttime: i32,
352};352};
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
383pub const Elf_Symndx = u32;354pub const Elf_Symndx = u32;
lib/std/os/linux/powerpc64.zig-39
...@@ -336,43 +336,4 @@ pub const timezone = extern struct {...@@ -336,43 +336,4 @@ pub const timezone = extern struct {
336 dsttime: i32,336 dsttime: i32,
337};337};
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
378pub const Elf_Symndx = u32;339pub const Elf_Symndx = u32;
lib/std/os/linux/riscv32.zig-35
...@@ -220,38 +220,3 @@ pub const VDSO = struct {...@@ -220,38 +220,3 @@ pub const VDSO = struct {
220 pub const CGT_SYM = "__vdso_clock_gettime";220 pub const CGT_SYM = "__vdso_clock_gettime";
221 pub const CGT_VER = "LINUX_4.15";221 pub const CGT_VER = "LINUX_4.15";
222};222};
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 {...@@ -220,38 +220,3 @@ pub const VDSO = struct {
220 pub const CGT_SYM = "__vdso_clock_gettime";220 pub const CGT_SYM = "__vdso_clock_gettime";
221 pub const CGT_VER = "LINUX_4.15";221 pub const CGT_VER = "LINUX_4.15";
222};222};
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-19
...@@ -235,22 +235,3 @@ pub const VDSO = struct {...@@ -235,22 +235,3 @@ pub const VDSO = struct {
235 pub const CGT_SYM = "__kernel_clock_gettime";235 pub const CGT_SYM = "__kernel_clock_gettime";
236 pub const CGT_VER = "LINUX_2.6.29";236 pub const CGT_VER = "LINUX_2.6.29";
237};237};
238
239pub const ucontext_t = extern struct {
240 flags: u64,
241 link: ?*ucontext_t,
242 stack: stack_t,
243 mcontext: mcontext_t,
244 sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
245};
246
247pub const mcontext_t = extern struct {
248 psw: extern struct {
249 mask: u64,
250 addr: u64,
251 },
252 gregs: [16]u64,
253 aregs: [16]u32,
254 fpc: u32,
255 fregs: [16]f64,
256};
lib/std/os/linux/sparc64.zig-100
...@@ -325,104 +325,4 @@ pub const timezone = extern struct {...@@ -325,104 +325,4 @@ pub const timezone = extern struct {
325 dsttime: i32,325 dsttime: i32,
326};326};
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
331pub const Elf_Symndx = u32;328pub 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 {...@@ -288,44 +288,6 @@ pub const timezone = extern struct {
288 dsttime: i32,288 dsttime: i32,
289};289};
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
329pub const Elf_Symndx = u32;291pub const Elf_Symndx = u32;
330292
331pub const user_desc = extern struct {293pub const user_desc = extern struct {
...@@ -366,73 +328,3 @@ pub const SC = struct {...@@ -366,73 +328,3 @@ pub const SC = struct {
366 pub const recvmmsg = 19;328 pub const recvmmsg = 19;
367 pub const sendmmsg = 20;329 pub const sendmmsg = 20;
368};330};
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 {...@@ -190,32 +190,6 @@ pub const ARCH = struct {
190 pub const GET_GS = 0x1004;190 pub const GET_GS = 0x1004;
191};191};
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
219pub const Flock = extern struct {193pub const Flock = extern struct {
220 type: i16,194 type: i16,
221 whence: i16,195 whence: i16,
...@@ -272,83 +246,3 @@ pub const timezone = extern struct {...@@ -272,83 +246,3 @@ pub const timezone = extern struct {
272};246};
273247
274pub const Elf_Symndx = u32;248pub 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;...@@ -97,7 +97,6 @@ pub const POLL = system.POLL;
97pub const POSIX_FADV = system.POSIX_FADV;97pub const POSIX_FADV = system.POSIX_FADV;
98pub const PR = system.PR;98pub const PR = system.PR;
99pub const PROT = system.PROT;99pub const PROT = system.PROT;
100pub const REG = system.REG;
101pub const RLIM = system.RLIM;100pub const RLIM = system.RLIM;
102pub const RR = system.RR;101pub const RR = system.RR;
103pub const S = system.S;102pub const S = system.S;