Commit 59e0bcc2 authored by Nifou's avatar Nifou

Add a send_signal helper function

parent aff24cd4
Pipeline #173591552 passed with stages
in 9 minutes and 31 seconds
......@@ -20,8 +20,8 @@ Tested in (with `uname -a`):
Thanks to [Vagrant](https://www.vagrantup.com/).
##### Use the ISO
The ISO is builded with Gitlab CI pipelines. You can download the latest ISO [here](https://gitlab.com/obsidian-os/obsidianos/-/jobs/artifacts/master/download?job=iso).
After the download, you can see the result in a virtual machine (Qemu for now)
The ISO is built with Gitlab CI pipelines. You can download the latest ISO [here](https://gitlab.com/obsidian-os/obsidianos/-/jobs/artifacts/master/download?job=iso).
After the download, you can see the result in a virtual machine (QEMU for now)
by using the command (in the directory where there is the ISO):
```
qemu-system-x86_64 -enable-kvm -m 3G -device ahci,id=ahci0\
......
......@@ -480,7 +480,7 @@ pub extern "x86-interrupt" fn page_fault_handler(
}
if handled == false {
let mut processes = PROCESSES.write();
let processes = PROCESSES.read();
if processes.is_empty() {
// The page fault is generated by the kernel
//
......@@ -493,21 +493,19 @@ pub extern "x86-interrupt" fn page_fault_handler(
);
stop();
} else {
drop(processes);
// The page fault is generated by a userspace program, send the SIGSEGV signal
let thread = SCHEDULER.get().current().unwrap();
processes.get_mut(&thread.process).unwrap().signals.push_back(
(
Signal::SIGSEGV,
SigInfo {
si_signo: Signal::SIGSEGV as usize,
si_errno: 0, // FIXME ???
si_code: SEGV_MAPERR,
si_addr: stack_frame.instruction_pointer.as_u64() as usize,
}
)
);
send_signal(
Signal::SIGSEGV,
SigInfo {
si_signo: Signal::SIGSEGV as usize,
si_errno: 0, // FIXME ???
si_code: SEGV_MAPERR,
si_addr: stack_frame.instruction_pointer.as_u64() as usize,
}
).expect("Signal sending failed");
drop(processes);
SCHEDULER.get().switch();
unreachable!();
}
......
......@@ -25,7 +25,7 @@
/// sends a signal to it.
macro_rules! fault {
($signal: ident, $stack: ident, $kernel_panic_code: block) => {
let mut processes = PROCESSES.write();
let processes = PROCESSES.read();
if processes.is_empty() {
// The fault is caused by the kernel
//
......@@ -33,21 +33,19 @@ macro_rules! fault {
$kernel_panic_code
stop();
} else {
drop(processes);
// The page fault is generated by a userspace program, send the SIGSEGV signal
let thread = SCHEDULER.get().current().unwrap();
processes.get_mut(&thread.process).unwrap().signals.push_back(
(
Signal::$signal,
SigInfo {
si_signo: Signal::$signal as usize,
si_code: SI_USER,
si_errno: 0, // FIXME: ???
si_addr: $stack.instruction_pointer.as_u64() as usize,
}
)
);
send_signal(
Signal::$signal,
SigInfo {
si_signo: Signal::$signal as usize,
si_code: SI_USER,
si_errno: 0, // FIXME: ???
si_addr: $stack.instruction_pointer.as_u64() as usize,
}
).expect("Signal sending failed");
drop(processes);
SCHEDULER.get().switch();
unreachable!();
}
......
......@@ -25,6 +25,7 @@
#![feature(llvm_asm)]
#![feature(alloc_error_handler)]
#![feature(naked_functions)]
#![feature(try_trait)]
#![warn(deprecated_in_future)]
#![warn(missing_docs)]
......
......@@ -30,7 +30,7 @@ use crate::tasking::{
process::{Pid, NEXT_PID},
scheduler::{exit, PROCESSES, SCHEDULER},
thread::Thread,
signal::{Signal, SigAction, SI_TKILL, SigInfo},
signal::{Signal, SigAction, SI_TKILL, SigInfo, send_signal_to},
};
impl Syscall {
......@@ -69,25 +69,20 @@ impl Syscall {
let sig = Signal::from(sig);
println!("kill({:#x}, {:?})", pid, sig);
let mut processes = PROCESSES.write();
let process = processes.get_mut(&Pid(pid));
match process {
Some(process) => {
process.signals.push_back(
(
sig,
SigInfo {
si_signo: sig as usize,
si_code: SI_TKILL,
si_errno: 0, // FIXME: ???
si_addr: 0, // FIXME: What to do?
}
)
);
match send_signal_to(
Pid(pid),
sig,
SigInfo {
si_signo: sig as usize,
si_code: SI_TKILL,
si_errno: 0, // FIXME: ???
si_addr: 0, // FIXME: What to do?
})
{
Ok(_) => {
Ok(0)
},
None => Err(Error::EINVAL),
Err(_) => Err(Error::EINVAL),
}
}
......
......@@ -71,7 +71,6 @@ pub trait SchedulerAlgo {
let action = process.actions.get(&signal.0).expect("cannot find the requested signal");
println!("[ {} ] {:?} {}", process.pid.0, signal.0, process.name);
println!("{:#?}", action);
if action.sa_handler == SIGIGN {
// Ignore this signal, so nothing to do!
......
......@@ -23,9 +23,19 @@ use alloc::collections::{
};
use lazy_static::lazy_static;
use bitflags::bitflags;
use core::fmt;
use core::{
fmt,
option::NoneError,
};
use super::scheduler::exit;
use super::{
scheduler::{
SCHEDULER,
PROCESSES,
exit,
},
process::Pid,
};
/// A queue of signals
pub type SignalQueue = VecDeque<(Signal, SigInfo)>;
......@@ -398,3 +408,24 @@ impl Default for SigActions {
actions
}
}
/// Helper functions to send a signal to the current process
pub fn send_signal(sig: Signal, info: SigInfo) -> Result<(), NoneError> {
let mut processes = PROCESSES.write();
let thread = SCHEDULER.get().current()?;
processes.get_mut(&thread.process)?.signals.push_back(
(sig, info)
);
Ok(())
}
/// Helper functions to send a signal to a specific process
pub fn send_signal_to(pid: Pid, sig: Signal, info: SigInfo) -> Result<(), NoneError> {
let mut processes = PROCESSES.write();
processes.get_mut(&pid)?.signals.push_back(
(sig, info)
);
Ok(())
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment