Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the SIGINT handler conditional on --features "managed". #1552

Merged
merged 3 commits into from
Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## **[Unreleased]**

- [#1554](https://github.com/wasmerio/wasmer/pull/1554) Update supported stable Rust version to 1.45.2.
- [#1552](https://github.com/wasmerio/wasmer/pull/1552) Disable `sigint` handler by default.

## 0.17.1 - 2020-06-24

Expand Down
29 changes: 21 additions & 8 deletions lib/runtime-core/src/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ use crate::state::x64::{build_instance_image, read_stack, X64Register, GPR};
use crate::state::{CodeVersion, ExecutionStateImage};
use crate::vm;
use libc::{mmap, mprotect, siginfo_t, MAP_ANON, MAP_PRIVATE, PROT_NONE, PROT_READ, PROT_WRITE};
#[cfg(feature = "managed")]
use nix::sys::signal::SIGINT;
use nix::sys::signal::{
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGINT,
SIGSEGV, SIGTRAP,
sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal, SIGBUS, SIGFPE, SIGILL, SIGSEGV,
SIGTRAP,
};
use std::cell::{Cell, RefCell, UnsafeCell};
use std::ffi::c_void;
#[cfg(feature = "managed")]
use std::process;
#[cfg(feature = "managed")]
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Once;

Expand Down Expand Up @@ -84,6 +88,7 @@ thread_local! {
static UNWIND: UnsafeCell<Option<UnwindInfo>> = UnsafeCell::new(None);
static CURRENT_CTX: UnsafeCell<*mut vm::Ctx> = UnsafeCell::new(::std::ptr::null_mut());
static CURRENT_CODE_VERSIONS: RefCell<Vec<CodeVersion>> = RefCell::new(vec![]);
#[cfg(feature = "managed")]
static WAS_SIGINT_TRIGGERED: Cell<bool> = Cell::new(false);
static BOUNDARY_REGISTER_PRESERVATION: UnsafeCell<BoundaryRegisterPreservation> = UnsafeCell::new(BoundaryRegisterPreservation::default());
}
Expand Down Expand Up @@ -118,9 +123,11 @@ lazy_static! {
InterruptSignalMem(ptr as _)
};
}
#[cfg(feature = "managed")]
static INTERRUPT_SIGNAL_DELIVERED: AtomicBool = AtomicBool::new(false);

/// Returns a boolean indicating if SIGINT triggered the fault.
#[cfg(feature = "managed")]
pub fn was_sigint_triggered_fault() -> bool {
WAS_SIGINT_TRIGGERED.with(|x| x.get())
}
Expand Down Expand Up @@ -341,6 +348,7 @@ extern "C" fn signal_trap_handler(
should_unwind = allocate_and_run(TRAP_STACK_SIZE, || {
let mut is_suspend_signal = false;

#[cfg(feature = "managed")]
WAS_SIGINT_TRIGGERED.with(|x| x.set(false));

match Signal::from_c_int(signum) {
Expand Down Expand Up @@ -371,6 +379,7 @@ extern "C" fn signal_trap_handler(
if fault.faulting_addr as usize == get_wasm_interrupt_signal_mem() as usize {
is_suspend_signal = true;
clear_wasm_interrupt();
#[cfg(feature = "managed")]
if INTERRUPT_SIGNAL_DELIVERED.swap(false, Ordering::SeqCst) {
WAS_SIGINT_TRIGGERED.with(|x| x.set(true));
}
Expand Down Expand Up @@ -439,6 +448,7 @@ extern "C" fn signal_trap_handler(
}
}

#[cfg(feature = "managed")]
extern "C" fn sigint_handler(
_signum: ::nix::libc::c_int,
_siginfo: *mut siginfo_t,
Expand Down Expand Up @@ -474,12 +484,15 @@ unsafe fn install_sighandler() {
sigaction(SIGBUS, &sa_trap).unwrap();
sigaction(SIGTRAP, &sa_trap).unwrap();

let sa_interrupt = SigAction::new(
SigHandler::SigAction(sigint_handler),
SaFlags::SA_ONSTACK,
SigSet::empty(),
);
sigaction(SIGINT, &sa_interrupt).unwrap();
#[cfg(feature = "managed")]
{
let sa_interrupt = SigAction::new(
SigHandler::SigAction(sigint_handler),
SaFlags::SA_ONSTACK,
SigSet::empty(),
);
sigaction(SIGINT, &sa_interrupt).unwrap();
}
}

#[derive(Debug, Clone)]
Expand Down