Skip to content

Commit

Permalink
Merge pull request #17 from ElrondNetwork/signal-handling-as-dylib
Browse files Browse the repository at this point in the history
Create separate sighandler install function for dylib
  • Loading branch information
camilbancioiu authored Feb 21, 2022
2 parents 2549b5a + 8e99e50 commit 004a42c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/runtime-core/src/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,13 @@ extern "C" fn sigint_handler(
/// Ensure the signal handler is installed.
pub fn ensure_sighandler() {
INSTALL_SIGHANDLER.call_once(|| unsafe {
install_sighandler();
install_sighandler_as_dylib();
});
}

static INSTALL_SIGHANDLER: Once = Once::new();

#[allow(dead_code)]
unsafe fn install_sighandler() {
let sa_trap = SigAction::new(
SigHandler::SigAction(signal_trap_handler),
Expand All @@ -471,6 +472,18 @@ unsafe fn install_sighandler() {
sigaction(SIGINT, &sa_interrupt).unwrap();
}

unsafe fn install_sighandler_as_dylib() {
let sa_trap = SigAction::new(
SigHandler::SigAction(signal_trap_handler),
SaFlags::SA_ONSTACK,
SigSet::empty(),
);
sigaction(SIGFPE, &sa_trap).unwrap();
sigaction(SIGILL, &sa_trap).unwrap();
sigaction(SIGBUS, &sa_trap).unwrap();
sigaction(SIGTRAP, &sa_trap).unwrap();
}

#[derive(Debug, Clone)]
/// Info about the fault
pub struct FaultInfo {
Expand Down

0 comments on commit 004a42c

Please sign in to comment.