diff options
Diffstat (limited to 'gc/mmtk/src/lib.rs')
| -rw-r--r-- | gc/mmtk/src/lib.rs | 36 |
1 files changed, 32 insertions, 4 deletions
diff --git a/gc/mmtk/src/lib.rs b/gc/mmtk/src/lib.rs index 01497e9c42..52dc782051 100644 --- a/gc/mmtk/src/lib.rs +++ b/gc/mmtk/src/lib.rs @@ -1,3 +1,7 @@ +// Warn about unsafe operations in functions that are already marked as unsafe. +// This will become default in Rust 2024 edition. +#![warn(unsafe_op_in_unsafe_fn)] + extern crate libc; extern crate mmtk; #[macro_use] @@ -10,8 +14,11 @@ use std::sync::Mutex; use std::thread::ThreadId; use abi::RubyUpcalls; -use binding::{RubyBinding, RubyBindingFast, RubyConfiguration}; -use mmtk::vm::slot::{SimpleSlot, UnimplementedMemorySlice}; +use binding::RubyBinding; +use binding::RubyBindingFast; +use binding::RubyConfiguration; +use mmtk::vm::slot::SimpleSlot; +use mmtk::vm::slot::UnimplementedMemorySlice; use mmtk::vm::VMBinding; use mmtk::MMTK; use once_cell::sync::OnceCell; @@ -21,7 +28,9 @@ pub mod active_plan; pub mod api; pub mod binding; pub mod collection; +pub mod heap; pub mod object_model; +pub mod pinning_registry; pub mod reference_glue; pub mod scanning; pub mod utils; @@ -51,6 +60,11 @@ impl VMBinding for Ruby { type VMMemorySlice = RubyMemorySlice; } +/// The callback for mutator thread panic handler (which calls rb_bug to output +/// debugging information such as the Ruby backtrace and memory maps). +/// This is set before BINDING is set because mmtk_init could panic. +pub static MUTATOR_THREAD_PANIC_HANDLER: OnceCell<extern "C" fn()> = OnceCell::new(); + /// The singleton object for the Ruby binding itself. pub static BINDING: OnceCell<RubyBinding> = OnceCell::new(); @@ -112,8 +126,6 @@ fn handle_gc_thread_panic(panic_info: &PanicHookInfo) { eprintln!("Unknown backtrace status: {s:?}"); } } - - std::process::abort(); } pub(crate) fn set_panic_hook() { @@ -126,8 +138,24 @@ pub(crate) fn set_panic_hook() { std::panic::set_hook(Box::new(move |panic_info| { if is_gc_thread(std::thread::current().id()) { handle_gc_thread_panic(panic_info); + + (crate::binding().upcalls().gc_thread_panic_handler)(); } else { old_hook(panic_info); + (crate::MUTATOR_THREAD_PANIC_HANDLER + .get() + .expect("MUTATOR_THREAD_PANIC_HANDLER is not set"))(); } })); } + +/// This kind of assertion is enabled if either building in debug mode or the +/// "extra_assert" feature is enabled. +#[macro_export] +macro_rules! extra_assert { + ($($arg:tt)*) => { + if std::cfg!(any(debug_assertions, feature = "extra_assert")) { + std::assert!($($arg)*); + } + }; +} |
