Add prototype ucontext_t support.

This commit is contained in:
4lDO2
2024-07-30 23:24:42 +02:00
parent b48da5622d
commit abc2ec7bb5
5 changed files with 138 additions and 23 deletions
+42
View File
@@ -14,6 +14,48 @@ use crate::{
},
};
// Mirrors the ucontext_t struct from the libc crate on Linux.
#[repr(C)]
pub struct ucontext_t {
pub uc_flags: c_ulong,
pub uc_link: *mut ucontext_t,
pub uc_stack: stack_t,
pub uc_mcontext: mcontext_t,
pub uc_sigmask: sigset_t,
__private: [u8; 512],
}
#[repr(C)]
pub struct _libc_fpstate {
pub cwd: u16,
pub swd: u16,
pub ftw: u16,
pub fop: u16,
pub rip: u64,
pub rdp: u64,
pub mxcsr: u32,
pub mxcr_mask: u32,
pub _st: [_libc_fpxreg; 8],
pub _xmm: [_libc_xmmreg; 16],
__private: [u64; 12],
}
#[repr(C)]
pub struct _libc_fpxreg {
pub significand: [u16; 4],
pub exponent: u16,
__private: [u16; 3],
}
#[repr(C)]
pub struct _libc_xmmreg {
pub element: [u32; 4],
}
#[repr(C)]
pub struct mcontext_t {
pub gregs: [i64; 23], // TODO: greg_t?
pub fpregs: *mut _libc_fpstate,
__private: [u64; 8],
}
impl PalSignal for Sys {
unsafe fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
e(syscall!(GETITIMER, which, out)) as c_int
+51 -2
View File
@@ -1,5 +1,7 @@
use core::mem;
use redox_rt::signal::{Sigaction, SigactionFlags, SigactionKind, Sigaltstack, SignalHandler};
use core::mem::{self, offset_of};
use redox_rt::signal::{
SigStack, Sigaction, SigactionFlags, SigactionKind, Sigaltstack, SignalHandler,
};
use syscall::{self, Result};
use super::{
@@ -20,6 +22,53 @@ use crate::{
platform::ERRNO,
};
#[repr(C)]
pub struct ucontext_t {
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
_pad: [usize; 1], // pad from 7*8 to 64
#[cfg(target_arch = "x86")]
_pad: [usize; 0], // don't pad from 8*4
pub uc_link: *mut ucontext_t,
pub uc_stack: stack_t,
pub uc_sigmask: sigset_t,
_sival: usize,
_signum: usize,
pub uc_mcontext: mcontext_t,
}
const _: () = {
const fn assert_eq(a: usize, b: usize) {
if a != b {
panic!("compile-time struct verification failed");
}
}
assert_eq(offset_of!(ucontext_t, uc_link), offset_of!(SigStack, link));
assert_eq(
offset_of!(ucontext_t, uc_stack),
offset_of!(SigStack, old_stack),
);
assert_eq(
offset_of!(ucontext_t, uc_sigmask),
offset_of!(SigStack, old_mask),
);
assert_eq(
offset_of!(ucontext_t, uc_mcontext),
offset_of!(SigStack, regs),
);
};
#[repr(C)]
pub struct mcontext_t {
#[cfg(target_arch = "x86")]
_opaque: [u8; 512],
#[cfg(target_arch = "x86-64")]
_opaque: [u8; 864],
#[cfg(target_arch = "aarch64")]
_opaque: [u8; 272],
}
impl PalSignal for Sys {
unsafe fn getitimer(which: c_int, out: *mut itimerval) -> c_int {
let path = match which {