|
1 | 1 | // All functions here are extern function. There is no point for marking them as unsafe. |
2 | 2 | #![allow(clippy::not_unsafe_ptr_arg_deref)] |
3 | 3 |
|
| 4 | +use std::ffi::CStr; |
| 5 | + |
4 | 6 | use crate::abi; |
5 | 7 | use crate::Ruby; |
6 | 8 | use crate::mmtk; |
7 | 9 | use crate::binding::RubyBinding; |
8 | 10 | use mmtk::MMTKBuilder; |
9 | 11 | use mmtk::memory_manager; |
| 12 | +use mmtk::memory_manager::mmtk_init; |
10 | 13 | use mmtk::scheduler::{GCController, GCWorker}; |
11 | 14 | use mmtk::util::constants::MIN_OBJECT_SIZE; |
| 15 | +use mmtk::util::options::PlanSelector; |
12 | 16 | use mmtk::util::{Address, ObjectReference}; |
13 | 17 | use mmtk::util::{VMMutatorThread, VMThread, VMWorkerThread}; |
14 | 18 | use mmtk::AllocationSemantics; |
15 | 19 | use mmtk::Mutator; |
| 20 | +use mmtk::util::options::Options; |
| 21 | + |
| 22 | +#[no_mangle] |
| 23 | +pub extern "C" fn mmtk_options_default() -> *mut Options { |
| 24 | + Box::into_raw(Box::new(Options::default())) |
| 25 | +} |
16 | 26 |
|
17 | 27 | #[no_mangle] |
18 | | -pub extern "C" fn mmtk_init_binding(heap_size: usize, upcalls: *const abi::RubyUpcalls) { |
19 | | - let mut builder = MMTKBuilder::default(); |
20 | | - builder.options.heap_size.set(heap_size); |
21 | | - let mmtk = builder.build(); |
22 | | - let mmtk_static = Box::leak(Box::new(mmtk)); |
| 28 | +pub extern "C" fn mmtk_options_set_heap_size(options: *mut Options, heap_size: usize) { |
| 29 | + let options = unsafe { &mut *options }; |
| 30 | + options.heap_size.set(heap_size); |
| 31 | +} |
| 32 | + |
| 33 | +#[no_mangle] |
| 34 | +pub extern "C" fn mmtk_options_set_plan(options: *mut Options, plan_name: *const libc::c_char) { |
| 35 | + let options = unsafe { &mut *options }; |
| 36 | + let plan_name_cstr = unsafe { CStr::from_ptr(plan_name) }; |
| 37 | + let plan_name_str = plan_name_cstr.to_str().unwrap(); |
| 38 | + let plan_selector = plan_name_str.parse::<PlanSelector>().unwrap(); |
| 39 | + options.plan.set(plan_selector); |
| 40 | +} |
| 41 | + |
| 42 | +#[no_mangle] |
| 43 | +pub extern "C" fn mmtk_init_binding(options: *mut Options, upcalls: *const abi::RubyUpcalls) { |
| 44 | + let options = unsafe { Box::from_raw(options) }; |
| 45 | + let builder = MMTKBuilder { options: *options }; |
| 46 | + let mmtk_boxed = mmtk_init(&builder); |
| 47 | + let mmtk_static = Box::leak(Box::new(mmtk_boxed)); |
| 48 | + |
23 | 49 | let binding = RubyBinding::new(mmtk_static, upcalls); |
24 | 50 |
|
25 | 51 | crate::BINDING.set(binding).unwrap_or_else(|_| { |
|
0 commit comments