Skip to main content

relibc/header/signal/
redox.rs

1use redox_rt::signal::SiginfoAbi;
2
3#[cfg(any(target_arch = "x86", target_arch = "aarch64", target_arch = "riscv64"))]
4use crate::platform::types::c_uchar;
5use crate::platform::types::{c_uint, c_ulong};
6
7use super::{siginfo_t, sigset_t, stack_t};
8
9// The below SA_* constants are different to Linux for implementation reasons.
10/// Non-POSIX, see <https://www.man7.org/linux/man-pages/man2/sigaction.2.html>.
11///
12/// Not intended for application use. Used by C libraries to indicate that the
13/// `sa_restorer` field contains the address of a "signal trampoline".
14pub const SA_RESTORER: usize = 0x0000_0004; // TODO: remove
15/// Causes extra information to be passed to signal handlers at the time of
16/// receipt of a signal.
17pub const SA_SIGINFO: usize = 0x0200_0000;
18/// Process is executing on an alternate signal stack.
19pub const SA_ONSTACK: usize = 0x0400_0000;
20/// Causes certain functions to become restartable.
21pub const SA_RESTART: usize = 0x0800_0000;
22/// Causes signal not to be automatically blocked on entry to signal handler.
23pub const SA_NODEFER: usize = 0x1000_0000;
24/// Causes signal dispositions to be set to `SIG_DFL` on entry to signal
25/// handlers.
26pub const SA_RESETHAND: usize = 0x2000_0000;
27/// Do not generate `SIGCHLD` when children stop or stopped children continue.
28pub const SA_NOCLDSTOP: usize = 0x4000_0000;
29
30const _: () = {
31    if super::constants::SS_ONSTACK != redox_rt::signal::SS_ONSTACK {
32        panic!();
33    }
34    if super::constants::SS_DISABLE != redox_rt::signal::SS_DISABLE {
35        panic!();
36    }
37    if super::constants::MINSIGSTKSZ != redox_rt::signal::MIN_SIGALTSTACK_SIZE {
38        panic!();
39    }
40};
41
42pub(crate) type ucontext_t = ucontext;
43/// A machine-specific representation of the saved context.
44pub(crate) type mcontext_t = mcontext;
45
46//TODO: share definition with SigStack?
47#[repr(C)]
48pub struct ucontext {
49    #[cfg(any(
50        target_arch = "x86_64",
51        target_arch = "aarch64",
52        target_arch = "riscv64"
53    ))]
54    _pad: [c_ulong; 1], // pad from 7*8 to 64
55
56    #[cfg(target_arch = "x86")]
57    _pad: [c_ulong; 3], // pad from 9*4 to 12*4
58
59    /// Pointer to the context that is resumed when this context returns.
60    pub uc_link: *mut ucontext_t,
61    /// The stack used by this context.
62    pub uc_stack: stack_t,
63    /// The set of signals that are blocked when this context is active.
64    pub uc_sigmask: sigset_t,
65    _sival: c_ulong,
66    _sigcode: c_uint,
67    _signum: c_uint,
68    /// A machine-specific representation of the saved context.
69    pub uc_mcontext: mcontext_t,
70}
71
72#[cfg(target_arch = "x86")]
73#[repr(C)]
74pub struct mcontext {
75    _opaque: [c_uchar; 512],
76}
77
78//TODO: share definition with ArchIntRegs?
79//TODO: repr(align(16))?
80#[cfg(target_arch = "x86_64")]
81#[repr(C)]
82pub struct mcontext {
83    pub ymm_upper: [[c_ulong; 2]; 16],
84    pub fxsave: [[c_ulong; 2]; 29],
85    pub r15: c_ulong, // fxsave "available" +0
86    pub r14: c_ulong, // available +8
87    pub r13: c_ulong, // available +16
88    pub r12: c_ulong, // available +24
89    pub rbp: c_ulong, // available +32
90    pub rbx: c_ulong, // available +40
91    pub r11: c_ulong, // outside fxsave, and so on
92    pub r10: c_ulong,
93    pub r9: c_ulong,
94    pub r8: c_ulong,
95    pub rax: c_ulong,
96    pub rcx: c_ulong,
97    pub rdx: c_ulong,
98    pub rsi: c_ulong,
99    pub rdi: c_ulong,
100    pub rflags: c_ulong,
101    pub rip: c_ulong,
102    pub rsp: c_ulong,
103}
104
105#[cfg(target_arch = "aarch64")]
106#[repr(C)]
107pub struct mcontext {
108    _opaque: [c_uchar; 272],
109}
110
111#[cfg(target_arch = "riscv64")]
112#[repr(C)]
113pub struct mcontext {
114    _opaque: [c_uchar; 520],
115}
116
117impl From<SiginfoAbi> for siginfo_t {
118    fn from(value: SiginfoAbi) -> Self {
119        unsafe { core::mem::transmute(value) }
120    }
121}