Skip to content

Commit a5b9638

Browse files
auronandacetgross35
authored andcommitted
correct siginfo_t and other signal related items for redox
Corrected `siginfo_t` to match relibc: - [siginfo struct](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/mod.rs#L152) (siginfo_t struct in libc) - [siginfo_t pub type pointing to siginfo](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/mod.rs#L185) Added the following items: - [sigaltstack struct](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/mod.rs#L99) (stack_t struct in libc) - [stack_t pub type pointing to sigaltstack struct](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/mod.rs#L188) - [sigaltstack function](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/mod.rs#L346) - [SS_ONSTACK constant](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/constants.rs#L131) - [SS_DISABLE constant](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/signal/constants.rs#L133) - [pid_t type](https://gitlab.redox-os.org/redox-os/relibc/-/blob/f1772c4bb829e02742275e655d349dda02b27cec/src/header/bits_pid-t/mod.rs#L5) These changes, when released in a stable 0.2.x release, will allow us to use upstream libc for compiling wasmtime natively on Redox. Edited to add the following: - [ucontext struct](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L48) - [ucontext_t pub type pointing to ucontext](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L42) - [mcontext struct x86_64](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L82) - [mcontext struct x86](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L74) - [mcontext struct aarch64](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L107) - [mcontext struct riscv64](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L113) - [mcontext_t pub type pointing to mcontext struct](https://gitlab.redox-os.org/redox-os/relibc/-/blob/e596d08aeaf43f90b18b961c1155d1c1e3eea416/src/header/signal/redox.rs#L44)
1 parent 31e8e55 commit a5b9638

1 file changed

Lines changed: 113 additions & 3 deletions

File tree

src/unix/redox/mod.rs

Lines changed: 113 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,19 @@ pub type suseconds_t = c_int;
2828
pub type tcflag_t = u32;
2929
pub type time_t = c_longlong;
3030
pub type id_t = c_uint;
31+
pub type pid_t = c_int;
3132
pub type uid_t = c_int;
3233
pub type gid_t = c_int;
34+
pub type ucontext_t = ucontext;
35+
pub type stack_t = sigaltstack;
36+
pub type siginfo_t = siginfo;
37+
#[cfg(any(
38+
target_arch = "x86",
39+
target_arch = "x86_64",
40+
target_arch = "aarch64",
41+
target_arch = "riscv64"
42+
))]
43+
pub type mcontext_t = mcontext;
3344

3445
extern_ty! {
3546
pub type timezone;
@@ -157,12 +168,21 @@ s! {
157168
pub sa_mask: crate::sigset_t,
158169
}
159170

160-
pub struct siginfo_t {
171+
pub struct siginfo {
161172
pub si_signo: c_int,
162173
pub si_errno: c_int,
163174
pub si_code: c_int,
164-
_pad: Padding<[c_int; 29]>,
165-
_align: [usize; 0],
175+
pub si_pid: pid_t,
176+
pub si_uid: uid_t,
177+
pub si_addr: *mut c_void,
178+
pub si_status: c_int,
179+
pub si_value: crate::sigval,
180+
}
181+
182+
pub struct sigaltstack {
183+
pub ss_sp: *mut c_void,
184+
pub ss_flags: c_int,
185+
pub ss_size: size_t,
166186
}
167187

168188
pub struct sockaddr {
@@ -295,7 +315,93 @@ s! {
295315
pub struct pthread_spinlock_t {
296316
bytes: [u8; _PTHREAD_SPINLOCK_SIZE],
297317
}
318+
319+
pub struct ucontext {
320+
#[cfg(any(
321+
target_arch = "x86_64",
322+
target_arch = "aarch64",
323+
target_arch = "riscv64"
324+
))]
325+
_pad: [c_ulong; 1], // pad from 7*8 to 64
326+
327+
#[cfg(target_arch = "x86")]
328+
_pad: [c_ulong; 3], // pad from 9*4 to 12*4
329+
330+
pub uc_link: *mut ucontext_t,
331+
pub uc_stack: stack_t,
332+
pub uc_sigmask: sigset_t,
333+
_sival: c_ulong,
334+
_sigcode: c_uint,
335+
_signum: c_uint,
336+
pub uc_mcontext: mcontext_t,
337+
}
338+
#[cfg(target_arch = "x86")]
339+
pub struct mcontext {
340+
_opaque: [c_uchar; 512],
341+
}
342+
#[cfg(target_arch = "x86_64")]
343+
pub struct mcontext {
344+
pub ymm_upper: [[c_ulong; 2]; 16],
345+
pub fxsave: [[c_ulong; 2]; 29],
346+
pub r15: c_ulong, // fxsave "available" +0
347+
pub r14: c_ulong, // available +8
348+
pub r13: c_ulong, // available +16
349+
pub r12: c_ulong, // available +24
350+
pub rbp: c_ulong, // available +32
351+
pub rbx: c_ulong, // available +40
352+
pub r11: c_ulong, // outside fxsave, and so on
353+
pub r10: c_ulong,
354+
pub r9: c_ulong,
355+
pub r8: c_ulong,
356+
pub rax: c_ulong,
357+
pub rcx: c_ulong,
358+
pub rdx: c_ulong,
359+
pub rsi: c_ulong,
360+
pub rdi: c_ulong,
361+
pub rflags: c_ulong,
362+
pub rip: c_ulong,
363+
pub rsp: c_ulong,
364+
}
365+
#[cfg(target_arch = "aarch64")]
366+
pub struct mcontext {
367+
_opaque: [c_uchar; 272],
368+
}
369+
#[cfg(target_arch = "riscv64")]
370+
pub struct mcontext {
371+
_opaque: [c_uchar; 520],
372+
}
298373
}
374+
375+
impl siginfo_t {
376+
pub unsafe fn si_addr(&self) -> *mut c_void {
377+
self.si_addr
378+
}
379+
380+
pub unsafe fn si_code(&self) -> c_int {
381+
self.si_code
382+
}
383+
384+
pub unsafe fn si_errno(&self) -> c_int {
385+
self.si_errno
386+
}
387+
388+
pub unsafe fn si_pid(&self) -> crate::pid_t {
389+
self.si_pid
390+
}
391+
392+
pub unsafe fn si_uid(&self) -> uid_t {
393+
self.si_uid
394+
}
395+
396+
pub unsafe fn si_value(&self) -> crate::sigval {
397+
self.si_value
398+
}
399+
400+
pub unsafe fn si_status(&self) -> c_int {
401+
self.si_status
402+
}
403+
}
404+
299405
const _PTHREAD_ATTR_SIZE: usize = 32;
300406
const _PTHREAD_RWLOCKATTR_SIZE: usize = 1;
301407
const _PTHREAD_RWLOCK_SIZE: usize = 4;
@@ -673,6 +779,9 @@ pub const SA_NODEFER: c_int = 0x1000_0000;
673779
pub const SA_RESETHAND: c_int = 0x2000_0000;
674780
pub const SA_NOCLDSTOP: c_int = 0x4000_0000;
675781

782+
pub const SS_ONSTACK: c_int = 0x00000001;
783+
pub const SS_DISABLE: c_int = 0x00000002;
784+
676785
// sys/file.h
677786
pub const LOCK_SH: c_int = 1;
678787
pub const LOCK_EX: c_int = 2;
@@ -1334,6 +1443,7 @@ extern "C" {
13341443
timeout: *const crate::timespec,
13351444
) -> c_int;
13361445
pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
1446+
pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int;
13371447

13381448
// stdlib.h
13391449
pub fn getsubopt(

0 commit comments

Comments
 (0)