From fd2d4507c86057bf43ae2198edeb3ebddfa6caca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 30 Jun 2025 06:54:45 +0200 Subject: [PATCH] std.os.linux: Define ucontext_t and mcontext_t for RISC-V Closes #24239. --- lib/std/os/linux/riscv32.zig | 38 ++++++++++++++++++++++++++++++++++-- lib/std/os/linux/riscv64.zig | 38 ++++++++++++++++++++++++++++++++++-- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux/riscv32.zig b/lib/std/os/linux/riscv32.zig index c37b0ee76c..7c03b3259e 100644 --- a/lib/std/os/linux/riscv32.zig +++ b/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 = {}; diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index b803e5b581..3d3c8a5afa 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/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 = {};