Commit fd2d4507c8

Alex Rønne Petersen <alex@alexrp.com>
2025-06-30 06:54:45
std.os.linux: Define ucontext_t and mcontext_t for RISC-V
Closes #24239.
1 parent 07114e6
Changed files (2)
lib
lib/std/os/linux/riscv32.zig
@@ -7,6 +7,8 @@ const SYS = linux.SYS;
 const uid_t = std.os.linux.uid_t;
 const gid_t = std.os.linux.gid_t;
 const pid_t = std.os.linux.pid_t;
+const stack_t = linux.stack_t;
+const sigset_t = linux.sigset_t;
 const sockaddr = linux.sockaddr;
 const socklen_t = linux.socklen_t;
 const timespec = std.os.linux.timespec;
@@ -261,8 +263,40 @@ pub const VDSO = struct {
     pub const CGT_VER = "LINUX_4.15";
 };
 
-/// TODO
-pub const ucontext_t = void;
+pub const f_ext_state = extern struct {
+    f: [32]f32,
+    fcsr: u32,
+};
+
+pub const d_ext_state = extern struct {
+    f: [32]f64,
+    fcsr: u32,
+};
+
+pub const q_ext_state = extern struct {
+    f: [32]f128,
+    fcsr: u32,
+    _reserved: [3]u32,
+};
+
+pub const fpstate = extern union {
+    f: f_ext_state,
+    d: d_ext_state,
+    q: q_ext_state,
+};
+
+pub const mcontext_t = extern struct {
+    gregs: [32]u32,
+    fpregs: fpstate,
+};
+
+pub const ucontext_t = extern struct {
+    flags: c_ulong,
+    link: ?*ucontext_t,
+    stack: stack_t,
+    sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
+    mcontext: mcontext_t,
+};
 
 /// TODO
 pub const getcontext = {};
lib/std/os/linux/riscv64.zig
@@ -7,6 +7,8 @@ const SYS = linux.SYS;
 const uid_t = std.os.linux.uid_t;
 const gid_t = std.os.linux.gid_t;
 const pid_t = std.os.linux.pid_t;
+const stack_t = linux.stack_t;
+const sigset_t = linux.sigset_t;
 const sockaddr = linux.sockaddr;
 const socklen_t = linux.socklen_t;
 const timespec = std.os.linux.timespec;
@@ -261,8 +263,40 @@ pub const VDSO = struct {
     pub const CGT_VER = "LINUX_4.15";
 };
 
-/// TODO
-pub const ucontext_t = void;
+pub const f_ext_state = extern struct {
+    f: [32]f32,
+    fcsr: u32,
+};
+
+pub const d_ext_state = extern struct {
+    f: [32]f64,
+    fcsr: u32,
+};
+
+pub const q_ext_state = extern struct {
+    f: [32]f128,
+    fcsr: u32,
+    _reserved: [3]u32,
+};
+
+pub const fpstate = extern union {
+    f: f_ext_state,
+    d: d_ext_state,
+    q: q_ext_state,
+};
+
+pub const mcontext_t = extern struct {
+    gregs: [32]u64,
+    fpregs: fpstate,
+};
+
+pub const ucontext_t = extern struct {
+    flags: c_ulong,
+    link: ?*ucontext_t,
+    stack: stack_t,
+    sigmask: [1024 / @bitSizeOf(c_ulong)]c_ulong, // Currently a libc-compatible (1024-bit) sigmask
+    mcontext: mcontext_t,
+};
 
 /// TODO
 pub const getcontext = {};