Skip to content

Commit

Permalink
ruxhal calling signal functions in ruxruntime using crate_interface
Browse files Browse the repository at this point in the history
  • Loading branch information
thesayol committed Jul 8, 2024
1 parent d200ab1 commit 8a20a58
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion api/ruxos_posix_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ multitask = ["ruxfeat/multitask", "ruxtask/multitask", "dep:ruxfutex"]
fd = ["alloc"]
fs = ["dep:ruxfs", "ruxfeat/fs", "fd"]
net = ["dep:ruxnet", "ruxfeat/net", "fd"]
signal = ["ruxruntime/signal"]
signal = ["ruxruntime/signal", "ruxhal/signal"]
pipe = ["fd"]
select = ["fd"]
epoll = ["fd"]
Expand Down
1 change: 1 addition & 0 deletions modules/ruxhal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ rtc = []
tls = ["alloc"]
default = []
musl = []
signal = []

[dependencies]
log = "0.4"
Expand Down
4 changes: 4 additions & 0 deletions modules/ruxhal/src/arch/aarch64/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ fn handle_sync_exception(tf: &mut TrapFrame) {
);
}
}
#[cfg(feature = "signal")]
{
crate::trap::handle_signal();
}
}

#[no_mangle]
Expand Down
10 changes: 10 additions & 0 deletions modules/ruxhal/src/trap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ pub trait TrapHandler {
fn handle_page_fault(_vaddr: usize, _caus: PageFaultCause) -> bool {
panic!("No handle_page_fault implement");
}
#[cfg(feature = "signal")]
fn handle_signal() {
panic!("No handle_page_fault implement");
}
}

/// Call the external IRQ handler.
Expand All @@ -65,3 +69,9 @@ pub(crate) fn handle_syscall(syscall_id: usize, args: [usize; 6]) -> isize {
pub(crate) fn handle_page_fault(vaddr: usize, cause: PageFaultCause) -> bool {
call_interface!(TrapHandler::handle_page_fault, vaddr, cause)
}

#[allow(dead_code)]
#[cfg(feature = "signal")]
pub(crate) fn handle_signal() {
call_interface!(TrapHandler::handle_signal)
}
2 changes: 1 addition & 1 deletion modules/ruxruntime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ fn init_interrupt() {
if signal & (1 << signum) != 0
/* TODO: && support mask */
{
Signal::sigaction(signum as u8, None, None);
Signal::signal(signum as i8, false);
Signal::sigaction(signum as u8, None, None);
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions modules/ruxruntime/src/signal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ use core::{
time::Duration,
};

use crate_interface::impl_interface;
use ruxhal::trap::TrapHandler;

/// sigaction in kernel
#[allow(non_camel_case_types)]
#[allow(dead_code)]
Expand Down Expand Up @@ -62,6 +65,23 @@ static mut SIGNAL_IF: Signal = Signal {
timer_interval: [Duration::from_nanos(0); 3],
};

struct SignalHandler;

#[impl_interface]
impl TrapHandler for SignalHandler {
fn handle_signal() {
let signal = Signal::signal(-1, true).unwrap();
for signum in 0..32 {
if signal & (1 << signum) != 0
/* TODO: && support mask */
{
Signal::signal(signum as i8, false);
Signal::sigaction(signum as u8, None, None);
}
}
}
}

impl Signal {
/// Set signal
/// signum: signal number, if signum < 0, just return current signal
Expand Down

0 comments on commit 8a20a58

Please sign in to comment.