From 673910b7de5c979cfeab24481588d0ff230b8bca Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 18 Aug 2020 15:52:46 -0700 Subject: [PATCH 1/2] Make the SIGINT handler conditional on --features "managed". The SIGINT handler was used in the tier switching demo to switch between compiler tiers upon press of ^C in the terminal. --- lib/runtime-core/src/fault.rs | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/lib/runtime-core/src/fault.rs b/lib/runtime-core/src/fault.rs index 4d7d919acf8..7ce53d627cf 100644 --- a/lib/runtime-core/src/fault.rs +++ b/lib/runtime-core/src/fault.rs @@ -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; @@ -84,6 +88,7 @@ thread_local! { static UNWIND: UnsafeCell> = UnsafeCell::new(None); static CURRENT_CTX: UnsafeCell<*mut vm::Ctx> = UnsafeCell::new(::std::ptr::null_mut()); static CURRENT_CODE_VERSIONS: RefCell> = RefCell::new(vec![]); + #[cfg(feature = "managed")] static WAS_SIGINT_TRIGGERED: Cell = Cell::new(false); static BOUNDARY_REGISTER_PRESERVATION: UnsafeCell = UnsafeCell::new(BoundaryRegisterPreservation::default()); } @@ -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()) } @@ -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) { @@ -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)); } @@ -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, @@ -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)] From 2a73c5eba2ed4450eefd277926681a660dcb2008 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 18 Aug 2020 16:01:27 -0700 Subject: [PATCH 2/2] Add changelog entry. --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66001c3fa69..d9c27f501c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## **[Unreleased]** +- [#1552](https://github.com/wasmerio/wasmer/pull/1552) Disable `sigint` handler by default. + ## 0.17.1 - 2020-06-24 - [#1439](https://github.com/wasmerio/wasmer/pull/1439) Move `wasmer-interface-types` into its own repository