use core::fmt;
use crate::{lwpid_t, pid_t, sigset_t, size_t, uid_t, __MINSIGSTKSZ};
pub const SIGHUP: i32 = 1;
pub const SIGINT: i32 = 2;
pub const SIGQUIT: i32 = 3;
pub const SIGILL: i32 = 4;
pub const SIGTRAP: i32 = 5;
pub const SIGABRT: i32 = 6;
pub const SIGIOT: i32 = SIGABRT;
pub const SIGEMT: i32 = 7;
pub const SIGFPE: i32 = 8;
pub const SIGKILL: i32 = 9;
pub const SIGBUS: i32 = 10;
pub const SIGSEGV: i32 = 11;
pub const SIGSYS: i32 = 12;
pub const SIGPIPE: i32 = 13;
pub const SIGALRM: i32 = 14;
pub const SIGTERM: i32 = 15;
pub const SIGURG: i32 = 16;
pub const SIGSTOP: i32 = 17;
pub const SIGTSTP: i32 = 18;
pub const SIGCONT: i32 = 19;
pub const SIGCHLD: i32 = 20;
pub const SIGTTIN: i32 = 21;
pub const SIGTTOU: i32 = 22;
pub const SIGIO: i32 = 23;
pub const SIGXCPU: i32 = 24;
pub const SIGXFSZ: i32 = 25;
pub const SIGVTALRM: i32 = 26;
pub const SIGPROF: i32 = 27;
pub const SIGWINCH: i32 = 28;
pub const SIGINFO: i32 = 29;
pub const SIGUSR1: i32 = 30;
pub const SIGUSR2: i32 = 31;
pub const SIGTHR: i32 = 32;
pub const SIGLWP: i32 = SIGTHR;
pub const SIGLIBRT: i32 = 33;
pub const SIGRTMIN: i32 = 65;
pub const SIGRTMAX: i32 = 126;
pub const SIG_DFL: sighandler_t = 0;
pub const SIG_IGN: sighandler_t = 1;
#[allow(clippy::cast_sign_loss)]
pub const SIG_ERR: sighandler_t = -1_isize as sighandler_t;
pub const SIG_HOLD: sighandler_t = 3;
pub type sighandler_t = usize;
#[repr(C)]
#[derive(Clone, Copy)]
pub union sigval_u_t {
pub sival_int: i32,
pub sival_ptr: usize,
pub sigval_int: i32,
pub sigval_ptr: usize,
}
impl Default for sigval_u_t {
fn default() -> Self {
Self { sigval_ptr: 0 }
}
}
impl fmt::Debug for sigval_u_t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ptr = unsafe { self.sigval_ptr };
write!(f, "sigval_ptr: {}", ptr)
}
}
#[cfg(target_pointer_width = "64")]
#[repr(C)]
#[derive(Clone, Copy)]
pub union sigval32_t {
pub sival_int: i32,
pub sival_ptr: u32,
pub sigval_int: i32,
pub sigval_ptr: u32,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct sigev_thread_t {
pub function: usize,
pub attribute: usize,
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union sigev_un_t {
pub threadid: lwpid_t,
pub sigev_thread: sigev_thread_t,
pub kevent_flags: u16,
pub __spare__: [isize; 8],
}
impl Default for sigev_un_t {
fn default() -> Self {
Self { kevent_flags: 0 }
}
}
impl fmt::Debug for sigev_un_t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let flags = unsafe { self.kevent_flags };
write!(f, "_kevent_flags: {}", flags)
}
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct sigevent_t {
pub sigev_notify: i32,
pub sigev_signo: i32,
pub sigev_value: sigval_u_t,
pub sigev_un: sigev_un_t,
}
pub const SIGEV_NONE: i32 = 0;
pub const SIGEV_SIGNAL: i32 = 1;
pub const SIGEV_THREAD: i32 = 2;
pub const SIGEV_KEVENT: i32 = 3;
pub const SIGEV_THREAD_ID: i32 = 4;
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct siginfo_reason_fault_t {
pub trapno: i32,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct siginfo_reason_timer_t {
pub timerid: i32,
pub overrun: i32,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct siginfo_reason_mesgq_t {
pub mqd: i32,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct siginfo_reason_poll_t {
pub band: isize,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
pub struct siginfo_reason_capsicum_t {
pub syscall: i32,
}
#[repr(C)]
#[derive(Debug, Default, Clone, Copy)]
struct siginfo_reason_spare_t {
__spare1__: isize,
__spare2__: [i32; 7],
}
#[repr(C)]
#[derive(Clone, Copy)]
pub union siginfo_reason_u_t {
pub fault: siginfo_reason_fault_t,
pub timer: siginfo_reason_timer_t,
pub poll: siginfo_reason_poll_t,
pub mesgq: siginfo_reason_mesgq_t,
pub capsicum: siginfo_reason_capsicum_t,
__spare__: siginfo_reason_spare_t,
}
impl Default for siginfo_reason_u_t {
fn default() -> Self {
Self {
__spare__: siginfo_reason_spare_t::default(),
}
}
}
impl fmt::Debug for siginfo_reason_u_t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let poll = unsafe { self.poll };
write!(f, "poll: {:?}", poll)
}
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct siginfo_t {
pub si_signo: i32,
pub si_errno: i32,
pub si_code: i32,
pub si_pid: pid_t,
pub si_uid: uid_t,
pub si_status: i32,
pub si_addr: usize,
pub si_value: sigval_u_t,
pub reason: siginfo_reason_u_t,
}
pub const ILL_ILLOPC: i32 = 1;
pub const ILL_ILLOPN: i32 = 2;
pub const ILL_ILLADR: i32 = 3;
pub const ILL_ILLTRP: i32 = 4;
pub const ILL_PRVOPC: i32 = 5;
pub const ILL_PRVREG: i32 = 6;
pub const ILL_COPROC: i32 = 7;
pub const ILL_BADSTK: i32 = 8;
pub const BUS_ADRALN: i32 = 1;
pub const BUS_ADRERR: i32 = 2;
pub const BUS_OBJERR: i32 = 3;
pub const BUS_OOMERR: i32 = 100;
pub const SEGV_MAPERR: i32 = 1;
pub const SEGV_ACCERR: i32 = 2;
pub const SEGV_PKUERR: i32 = 100;
pub const FPE_INTOVF: i32 = 1;
pub const FPE_INTDIV: i32 = 2;
pub const FPE_FLTDIV: i32 = 3;
pub const FPE_FLTOVF: i32 = 4;
pub const FPE_FLTUND: i32 = 5;
pub const FPE_FLTRES: i32 = 6;
pub const FPE_FLTINV: i32 = 7;
pub const FPE_FLTSUB: i32 = 8;
pub const TRAP_BRKPT: i32 = 1;
pub const TRAP_TRACE: i32 = 2;
pub const TRAP_DTRACE: i32 = 3;
pub const TRAP_CAP: i32 = 4;
pub const CLD_EXITED: i32 = 1;
pub const CLD_KILLED: i32 = 2;
pub const CLD_DUMPED: i32 = 3;
pub const CLD_TRAPPED: i32 = 4;
pub const CLD_STOPPED: i32 = 5;
pub const CLD_CONTINUED: i32 = 6;
pub const POLL_IN: i32 = 1;
pub const POLL_OUT: i32 = 2;
pub const POLL_MSG: i32 = 3;
pub const POLL_ERR: i32 = 4;
pub const POLL_PRI: i32 = 5;
pub const POLL_HUP: i32 = 6;
#[repr(C)]
pub union sigaction_u_t {
pub sa_handler: sighandler_t,
pub sa_sigaction: siginfohandler_t,
}
impl Default for sigaction_u_t {
fn default() -> Self {
Self {
sa_handler: SIG_DFL,
}
}
}
impl fmt::Debug for sigaction_u_t {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let ptr = unsafe { self.sa_handler };
write!(f, "sigaction_u_t: {}", ptr)
}
}
#[repr(C)]
#[derive(Debug, Default)]
pub struct sigaction_t {
pub u: sigaction_u_t,
pub sa_flags: i32,
pub sa_mask: sigset_t,
}
pub const SA_NOCLDSTOP: i32 = 0x0008;
pub const SA_ONSTACK: i32 = 0x0001;
pub const SA_RESTART: i32 = 0x0002;
pub const SA_RESETHAND: i32 = 0x0004;
pub const SA_NODEFER: i32 = 0x0010;
pub const SA_NOCLDWAIT: i32 = 0x0020;
pub const SA_SIGINFO: i32 = 0x0040;
pub const NSIG: i32 = 32;
pub const SI_NOINFO: i32 = 0;
pub const SI_USER: i32 = 0x10001;
pub const SI_QUEUE: i32 = 0x10002;
pub const SI_TIMER: i32 = 0x10003;
pub const SI_ASYNCIO: i32 = 0x10004;
pub const SI_MESGQ: i32 = 0x10005;
pub const SI_KERNEL: i32 = 0x10006;
pub const SI_LWP: i32 = 0x10007;
pub const SI_UNDEFINED: i32 = 0;
pub type sig_t = usize;
pub type siginfohandler_t = usize;
pub type sigaltstack_t = stack_t;
pub const SS_ONSTACK: i32 = 0x0001;
pub const SS_DISABLE: i32 = 0x0004;
pub const MINSIGSTKSZ: usize = __MINSIGSTKSZ;
pub const SIGSTKSZ: usize = MINSIGSTKSZ + 32768;
pub struct stack_t {
pub ss_sp: usize,
pub ss_size: size_t,
pub ss_flags: i32,
}
pub const SV_ONSTACK: i32 = SA_ONSTACK;
pub const SV_INTERRUPT: i32 = SA_RESTART;
pub const SV_RESETHAND: i32 = SA_RESETHAND;
pub const SV_NODEFER: i32 = SA_NODEFER;
pub const SV_NOCLDSTOP: i32 = SA_NOCLDSTOP;
pub const SV_SIGINFO: i32 = SA_SIGINFO;
#[repr(C)]
#[derive(Debug, Default)]
pub struct sigstack_t {
pub ss_sp: usize,
pub ss_onstack: i32,
}
#[must_use]
pub const fn sigmask(m: i32) -> i32 {
1 << (m - 1)
}
pub const BADSIG: sighandler_t = SIG_ERR;
pub const SIG_BLOCK: i32 = 1;
pub const SIG_UNBLOCK: i32 = 2;
pub const SIG_SETMASK: i32 = 3;