Skip to content

Commit 36dbe66

Browse files
committed
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.
1 parent f33d3a5 commit 36dbe66

21 files changed

+2
-870
lines changed

lib/std/c.zig

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) {
18411841
else => void,
18421842
};
18431843

1844-
pub 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-
};
19481844
pub const RLIM = switch (native_os) {
19491845
.linux => linux.RLIM,
19501846
.emscripten => emscripten.RLIM,
@@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) {
45534449
pub 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;
1108410980
pub const SFD = solaris.SFD;
1108510981
pub const ctid_t = solaris.ctid_t;
1108610982
pub const file_obj = solaris.file_obj;
11087-
pub const fpregset_t = solaris.fpregset_t;
1108810983
pub const id_t = solaris.id_t;
1108910984
pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
1109010985
pub const lif_nd_req = solaris.lif_nd_req;

lib/std/c/solaris.zig

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,6 @@ pub const poolid_t = id_t;
3131
pub const zoneid_t = id_t;
3232
pub const ctid_t = id_t;
3333

34-
pub 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-
5734
pub const GETCONTEXT = 0;
5835
pub const SETCONTEXT = 1;
5936
pub const GETUSTACK = 2;

lib/std/os/emscripten.zig

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -400,28 +400,6 @@ pub const timeval = extern struct {
400400
usec: i32,
401401
};
402402

403-
pub 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-
425403
pub 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

816-
pub const mcontext_t = extern struct {
817-
gregs: [19]usize,
818-
fpregs: [*]u8,
819-
oldmask: usize,
820-
cr2: usize,
821-
};
822-
823794
pub const msghdr = std.c.msghdr;
824795
pub const msghdr_const = std.c.msghdr;
825796

@@ -846,15 +817,6 @@ pub const timezone = extern struct {
846817
dsttime: i32,
847818
};
848819

849-
pub 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-
858820
pub const utsname = extern struct {
859821
sysname: [64:0]u8,
860822
nodename: [64:0]u8,

lib/std/os/freebsd.zig

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
52-
pub 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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5553
const syscall_bits = if (native_arch.isThumb()) @import("linux/thumb.zig") else arch_bits;
@@ -94,22 +92,19 @@ pub const Elf_Symndx = arch_bits.Elf_Symndx;
9492
pub const F = arch_bits.F;
9593
pub const Flock = arch_bits.Flock;
9694
pub const HWCAP = arch_bits.HWCAP;
97-
pub const REG = arch_bits.REG;
9895
pub const SC = arch_bits.SC;
9996
pub const Stat = arch_bits.Stat;
10097
pub const VDSO = arch_bits.VDSO;
10198
pub const blkcnt_t = arch_bits.blkcnt_t;
10299
pub const blksize_t = arch_bits.blksize_t;
103100
pub const dev_t = arch_bits.dev_t;
104101
pub const ino_t = arch_bits.ino_t;
105-
pub const mcontext_t = arch_bits.mcontext_t;
106102
pub const mode_t = arch_bits.mode_t;
107103
pub const nlink_t = arch_bits.nlink_t;
108104
pub const off_t = arch_bits.off_t;
109105
pub const time_t = arch_bits.time_t;
110106
pub const timeval = arch_bits.timeval;
111107
pub const timezone = arch_bits.timezone;
112-
pub const ucontext_t = arch_bits.ucontext_t;
113108
pub const user_desc = arch_bits.user_desc;
114109

115110
pub const tls = @import("linux/tls.zig");

lib/std/os/linux/aarch64.zig

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -241,23 +241,4 @@ pub const timezone = extern struct {
241241
dsttime: i32,
242242
};
243243

244-
pub 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-
255-
pub 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-
263244
pub const Elf_Symndx = u32;

lib/std/os/linux/arm.zig

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -277,37 +277,4 @@ pub const timezone = extern struct {
277277
dsttime: i32,
278278
};
279279

280-
pub 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-
304-
pub 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-
313280
pub const Elf_Symndx = u32;

0 commit comments

Comments
 (0)