From ff43be1be0823bb879e32d0e8d9447f8ee1bafcb Mon Sep 17 00:00:00 2001 From: Wildan M Date: Wed, 15 Apr 2026 10:05:35 +0700 Subject: [PATCH] Use native types for signal.h --- src/header/signal/cbindgen.toml | 2 +- src/header/signal/linux.rs | 34 +++++++++---------- src/header/signal/mod.rs | 9 ++--- src/header/signal/redox.rs | 60 ++++++++++++++++++--------------- 4 files changed, 55 insertions(+), 50 deletions(-) diff --git a/src/header/signal/cbindgen.toml b/src/header/signal/cbindgen.toml index bbbc6174eb..1b00793e87 100644 --- a/src/header/signal/cbindgen.toml +++ b/src/header/signal/cbindgen.toml @@ -6,7 +6,7 @@ # - "pid_t As described in ." # - "The header shall define the pthread_attr_t type as described in ." # - "Inclusion of the header may make visible all symbols from the header." -sys_includes = ["sys/types.h", "stdint.h"] +sys_includes = ["sys/types.h"] include_guard = "_RELIBC_SIGNAL_H" after_includes = """ #include // for timespec from time.h diff --git a/src/header/signal/linux.rs b/src/header/signal/linux.rs index 0f9d3e314e..e933e3054a 100644 --- a/src/header/signal/linux.rs +++ b/src/header/signal/linux.rs @@ -1,5 +1,5 @@ use super::{sigset_t, stack_t}; -use crate::platform::types::c_ulong; +use crate::platform::types::{c_longlong, c_uchar, c_uint, c_ulong, c_ulonglong, c_ushort}; use core::arch::global_asm; // Needs to be defined in assembly because it can't have a function prologue @@ -143,37 +143,37 @@ pub struct ucontext { pub uc_stack: stack_t, pub uc_mcontext: mcontext_t, pub uc_sigmask: sigset_t, - __private: [u8; 512], + __private: [c_uchar; 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 cwd: c_ushort, + pub swd: c_ushort, + pub ftw: c_ushort, + pub fop: c_ushort, + pub rip: c_ulonglong, + pub rdp: c_ulonglong, + pub mxcsr: c_uint, + pub mxcr_mask: c_uint, pub _st: [_libc_fpxreg; 8], pub _xmm: [_libc_xmmreg; 16], - __private: [u64; 12], + __private: [c_ulonglong; 12], } #[repr(C)] pub struct _libc_fpxreg { - pub significand: [u16; 4], - pub exponent: u16, - __private: [u16; 3], + pub significand: [c_ushort; 4], + pub exponent: c_ushort, + __private: [c_ushort; 3], } #[repr(C)] pub struct _libc_xmmreg { - pub element: [u32; 4], + pub element: [c_uint; 4], } #[repr(C)] pub struct mcontext { - pub gregs: [i64; 23], // TODO: greg_t? + pub gregs: [c_longlong; 23], // TODO: greg_t? pub fpregs: *mut _libc_fpstate, - __private: [u64; 8], + __private: [c_ulonglong; 8], } diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index d71999ef25..c8973c0635 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -12,7 +12,8 @@ use crate::{ platform::{ self, ERRNO, Pal, PalSignal, Sys, types::{ - c_char, c_int, c_ulonglong, c_void, pid_t, pthread_attr_t, pthread_t, size_t, uid_t, + c_char, c_int, c_ulong, c_ulonglong, c_void, pid_t, pthread_attr_t, pthread_t, size_t, + uid_t, }, }, }; @@ -112,13 +113,13 @@ pub type siginfo_t = siginfo; pub type stack_t = sigaltstack; unsafe extern "C" { - pub fn sigsetjmp(jb: *mut u64, savemask: i32) -> i32; + pub fn sigsetjmp(jb: *mut c_ulong, savemask: c_int) -> c_int; } //NOTE for the following two functions, to see why they're implemented slightly differently from their intended behavior, read // https://git.musl-libc.org/cgit/musl/commit/?id=583e55122e767b1586286a0d9c35e2a4027998ab #[unsafe(no_mangle)] -unsafe extern "C" fn __sigsetjmp_tail(jb: *mut u64, ret: i32) -> i32 { +unsafe extern "C" fn __sigsetjmp_tail(jb: *mut c_ulong, ret: c_int) -> c_int { let set = jb.wrapping_add(9); if ret > 0 { unsafe { sigprocmask(SIG_SETMASK, set, ptr::null_mut()) }; @@ -129,7 +130,7 @@ unsafe extern "C" fn __sigsetjmp_tail(jb: *mut u64, ret: i32) -> i32 { } #[unsafe(no_mangle)] -pub unsafe extern "C" fn siglongjmp(jb: *mut u64, ret: i32) { +pub unsafe extern "C" fn siglongjmp(jb: *mut c_ulong, ret: c_int) { unsafe { setjmp::longjmp(jb, ret) }; } diff --git a/src/header/signal/redox.rs b/src/header/signal/redox.rs index 781b0923e4..0159dbdc5a 100644 --- a/src/header/signal/redox.rs +++ b/src/header/signal/redox.rs @@ -1,5 +1,9 @@ use redox_rt::signal::SiginfoAbi; +#[cfg(any(target_arch = "x86", target_arch = "aarch64", target_arch = "riscv64"))] +use crate::platform::types::c_uchar; +use crate::platform::types::{c_uint, c_ulong}; + use super::{siginfo_t, sigset_t, stack_t}; pub const SIGHUP: usize = 1; @@ -120,24 +124,24 @@ pub struct ucontext { target_arch = "aarch64", target_arch = "riscv64" ))] - _pad: [usize; 1], // pad from 7*8 to 64 + _pad: [c_ulong; 1], // pad from 7*8 to 64 #[cfg(target_arch = "x86")] - _pad: [usize; 3], // pad from 9*4 to 12*4 + _pad: [c_ulong; 3], // pad from 9*4 to 12*4 pub uc_link: *mut ucontext_t, pub uc_stack: stack_t, pub uc_sigmask: sigset_t, - _sival: usize, - _sigcode: u32, - _signum: u32, + _sival: c_ulong, + _sigcode: c_uint, + _signum: c_uint, pub uc_mcontext: mcontext_t, } #[cfg(target_arch = "x86")] #[repr(C)] pub struct mcontext { - _opaque: [u8; 512], + _opaque: [c_uchar; 512], } //TODO: share definition with ArchIntRegs? @@ -145,38 +149,38 @@ pub struct mcontext { #[cfg(target_arch = "x86_64")] #[repr(C)] pub struct mcontext { - pub ymm_upper: [[u64; 2]; 16], - pub fxsave: [[u64; 2]; 29], - pub r15: usize, // fxsave "available" +0 - pub r14: usize, // available +8 - pub r13: usize, // available +16 - pub r12: usize, // available +24 - pub rbp: usize, // available +32 - pub rbx: usize, // available +40 - pub r11: usize, // outside fxsave, and so on - pub r10: usize, - pub r9: usize, - pub r8: usize, - pub rax: usize, - pub rcx: usize, - pub rdx: usize, - pub rsi: usize, - pub rdi: usize, - pub rflags: usize, - pub rip: usize, - pub rsp: usize, + pub ymm_upper: [[c_ulong; 2]; 16], + pub fxsave: [[c_ulong; 2]; 29], + pub r15: c_ulong, // fxsave "available" +0 + pub r14: c_ulong, // available +8 + pub r13: c_ulong, // available +16 + pub r12: c_ulong, // available +24 + pub rbp: c_ulong, // available +32 + pub rbx: c_ulong, // available +40 + pub r11: c_ulong, // outside fxsave, and so on + pub r10: c_ulong, + pub r9: c_ulong, + pub r8: c_ulong, + pub rax: c_ulong, + pub rcx: c_ulong, + pub rdx: c_ulong, + pub rsi: c_ulong, + pub rdi: c_ulong, + pub rflags: c_ulong, + pub rip: c_ulong, + pub rsp: c_ulong, } #[cfg(target_arch = "aarch64")] #[repr(C)] pub struct mcontext { - _opaque: [u8; 272], + _opaque: [c_uchar; 272], } #[cfg(target_arch = "riscv64")] #[repr(C)] pub struct mcontext { - _opaque: [u8; 520], + _opaque: [c_uchar; 520], } #[unsafe(no_mangle)]