Sync sig pages using proc and thread calls.

This commit is contained in:
4lDO2
2025-03-31 16:24:47 +02:00
parent 59090a83f4
commit 98c8beae3d
3 changed files with 37 additions and 9 deletions
+19
View File
@@ -30,6 +30,16 @@ pub enum ProcCall {
Setsid = 7,
Kill = 8,
Sigq = 9,
// TODO: replace with sendfd equivalent syscall for sending memory
SyncSigPctl = 10,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[repr(usize)]
pub enum ThreadCall {
// TODO: replace with sendfd equivalent syscall for sending memory, or force userspace to
// obtain its TCB memory from this server
SyncSigTctl = 0,
}
impl ProcCall {
@@ -45,6 +55,15 @@ impl ProcCall {
7 => Self::Setsid,
8 => Self::Kill,
9 => Self::Sigq,
10 => Self::SyncSigPctl,
_ => return None,
})
}
}
impl ThreadCall {
pub fn try_from_raw(raw: usize) -> Option<Self> {
Some(match raw {
0 => Self::SyncSigTctl,
_ => return None,
})
}
+9 -2
View File
@@ -1,12 +1,12 @@
use core::{ffi::c_int, mem::MaybeUninit, ptr::NonNull, sync::atomic::Ordering};
use syscall::{
data::AtomicU64, Error, RawAction, Result, RtSigInfo, SenderInfo, SetSighandlerData,
data::AtomicU64, CallFlags, Error, RawAction, Result, RtSigInfo, SenderInfo, SetSighandlerData,
SigProcControl, Sigcontrol, SigcontrolFlags, TimeSpec, EAGAIN, EINTR, EINVAL, ENOMEM, EPERM,
SIGCHLD, SIGKILL, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU, SIGURG, SIGWINCH,
};
use crate::{arch::*, proc::FdGuard, sync::Mutex, RtTcb, Tcb};
use crate::{arch::*, proc::FdGuard, protocol::{ProcCall, ThreadCall}, sync::Mutex, sys::{proc_call, thread_call}, RtTcb, Tcb};
#[cfg(target_arch = "x86_64")]
static CPUID_EAX1_ECX: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0);
@@ -576,6 +576,13 @@ pub fn setup_sighandler(tcb: &RtTcb) {
syscall::dup(**tcb.thread_fd(), b"sighandler").expect("failed to open sighandler fd"),
);
let _ = syscall::write(*fd, &data).expect("failed to write to sighandler fd");
thread_call(&mut [], CallFlags::empty(), &[
ThreadCall::SyncSigTctl as usize,
]);
// TODO: Only run for first thread
proc_call(&mut [], CallFlags::empty(), &[
ProcCall::SyncSigPctl as usize,
]);
// TODO: Inherited set of ignored signals
set_sigmask(Some(0), None);
+9 -7
View File
@@ -10,11 +10,7 @@ use syscall::{
};
use crate::{
arch::manually_enter_trampoline,
proc::FdGuard,
protocol::{ProcCall, ProcKillTarget, WaitFlags},
signal::tmp_disable_signals,
DynamicProcInfo, Tcb, DYNAMIC_PROC_INFO,
arch::manually_enter_trampoline, proc::FdGuard, protocol::{ProcCall, ProcKillTarget, WaitFlags}, signal::tmp_disable_signals, DynamicProcInfo, RtTcb, Tcb, DYNAMIC_PROC_INFO
};
#[inline]
@@ -116,11 +112,11 @@ pub unsafe fn sys_futex_wake(addr: *mut u32, num: u32) -> Result<u32> {
)
.map(|awoken| awoken as u32)
}
fn proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result<usize> {
pub fn sys_call(fd: usize, payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result<usize> {
unsafe {
syscall::syscall5(
syscall::SYS_CALL,
**crate::current_proc_fd(),
fd,
payload.as_mut_ptr() as usize,
payload.len(),
metadata.len() | flags.bits(),
@@ -128,6 +124,12 @@ fn proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result
)
}
}
pub fn proc_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result<usize> {
sys_call(**crate::current_proc_fd(), payload, flags, metadata)
}
pub fn thread_call(payload: &mut [u8], flags: CallFlags, metadata: &[usize]) -> Result<usize> {
sys_call(**RtTcb::current().thread_fd(), payload, flags, metadata)
}
#[derive(Clone, Copy, Debug)]
pub enum WaitpidTarget {