From b32e6794376a2213879eaf9d3858169de7df4460 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Sun, 28 Jul 2024 23:17:39 +0200 Subject: [PATCH] Add syscalls for an initial in-kernel rtsig impl. --- src/number.rs | 2 ++ src/sigabi.rs | 39 ++++++++++++++++++++++++++++----------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/src/number.rs b/src/number.rs index 741b3380c8..2a53a57b88 100644 --- a/src/number.rs +++ b/src/number.rs @@ -78,6 +78,8 @@ pub const SYS_GETUID: usize = 199; pub const SYS_IOPL: usize = 110; pub const SYS_KILL: usize = 37; pub const SYS_SIGQUEUE: usize = 101; +pub const SYS_SIGENQUEUE: usize = 101; +pub const SYS_SIGDEQUEUE: usize = 102; pub const SYS_MPROTECT: usize = 125; pub const SYS_MKNS: usize = 984; pub const SYS_NANOSLEEP: usize = 162; diff --git a/src/sigabi.rs b/src/sigabi.rs index 5bc3c898b9..8680819b47 100644 --- a/src/sigabi.rs +++ b/src/sigabi.rs @@ -5,18 +5,16 @@ use core::sync::atomic::{AtomicU8, AtomicUsize, Ordering}; #[repr(C, align(4096))] pub struct SigProcControl { pub pending: AtomicU64, - pub qhead: AtomicU8, - pub _rsvd: [u8; 7], pub actions: [RawAction; 64], - pub queue: [RealtimeSig; 32], - pub qtail: AtomicU8, + //pub queue: [RealtimeSig; 32], TODO + // qhead, qtail TODO } -#[derive(Debug)] +/*#[derive(Debug)] #[repr(transparent)] pub struct RealtimeSig { pub arg: NonatomicUsize, -} -#[derive(Debug)] +}*/ +#[derive(Debug, Default)] #[repr(C, align(16))] pub struct RawAction { /// Only two MSBs are interesting for the kernel. If bit 63 is set, signal is ignored. If bit @@ -229,7 +227,10 @@ mod atomic { #[cfg(test)] mod tests { - use std::sync::{atomic::Ordering, Arc}; + use std::sync::{ + atomic::{AtomicU64, Ordering}, + Arc, + }; #[cfg(not(loom))] use std::{sync::Mutex, thread}; @@ -241,13 +242,25 @@ mod tests { #[cfg(loom)] use loom::{model, sync::Mutex, thread}; - use crate::Sigcontrol; + use crate::{RawAction, SigProcControl, Sigcontrol}; - #[derive(Default)] struct FakeThread { ctl: Sigcontrol, + pctl: SigProcControl, ctxt: Mutex<()>, } + impl Default for FakeThread { + fn default() -> Self { + Self { + ctl: Sigcontrol::default(), + pctl: SigProcControl { + pending: AtomicU64::new(0), + actions: core::array::from_fn(|_| RawAction::default()), + }, + ctxt: Default::default(), + } + } + } #[test] fn singlethread_mask() { @@ -261,7 +274,11 @@ mod tests { fake_thread.ctl.set_allowset(!0); { let _g = fake_thread.ctxt.lock(); - if fake_thread.ctl.currently_pending_unblocked() == 0 { + if fake_thread + .ctl + .currently_pending_unblocked(&fake_thread.pctl) + == 0 + { drop(_g); thread::park(); }