use std::sync::{Arc, RwLock};
use nix::{
errno::Errno,
sys::signal::{kill, Signal},
unistd::Pid,
};
use crate::{
kernel::ptrace::handle_ptrace_sysenter,
ptrace::{ptrace_cont, ptrace_get_syscall_info, ptrace_syscall},
sandbox::Sandbox,
workers::WorkerCache,
};
pub(crate) fn sysevent_scmp(pid: Pid, cache: &Arc<WorkerCache>, sandbox: &Arc<RwLock<Sandbox>>) {
let info = match ptrace_get_syscall_info(pid) {
Ok(info) if info.seccomp().is_none() => {
let _ = kill(pid, Some(Signal::SIGKILL));
return;
}
Ok(info) => info,
Err(Errno::ESRCH) => return,
Err(_) => {
let _ = kill(pid, Some(Signal::SIGKILL));
return;
}
};
let result = handle_ptrace_sysenter(pid, info, cache, sandbox);
match result {
Ok(_) => {
let _ = ptrace_syscall(pid, None);
}
Err(Errno::ECANCELED) => {
let _ = ptrace_cont(pid, None);
}
Err(Errno::ESRCH) => {}
Err(_) => {
let _ = kill(pid, Some(Signal::SIGKILL));
}
};
}