Commit e5aa6694 authored by Isaac's avatar Isaac

rustfmt

parent ad91a280
......@@ -747,10 +747,12 @@ impl fmt::Display for MuType_ {
}
pub type StructTagMap = AtomicPtr<RwLock<HashMap<StructTag, StructType_>>>;
pub static mut STRUCT_TAG_MAP_LOC: StructTagMap = AtomicPtr::new(ptr::null_mut());
pub static mut STRUCT_TAG_MAP_LOC: StructTagMap =
AtomicPtr::new(ptr::null_mut());
pub type HybridTagMap = AtomicPtr<RwLock<HashMap<HybridTag, HybridType_>>>;
pub static mut HYBRID_TAG_MAP_LOC: HybridTagMap = AtomicPtr::new(ptr::null_mut());
pub static mut HYBRID_TAG_MAP_LOC: HybridTagMap =
AtomicPtr::new(ptr::null_mut());
lazy_static! {
/// storing a map from MuName to StructType_
......
......@@ -322,12 +322,16 @@ fn link_dylib_internal(
// allow dynamic lookup symbols
cc.arg("dynamic_lookup");
cc.arg(format!("-L{}",
cc.arg(format!(
"-L{}",
get_path_under_zebu(if cfg!(debug_assertions) {
"target/debug/deps/"
} else {
"target/release/deps/"
}).to_str().unwrap()));
})
.to_str()
.unwrap()
));
cc.arg("-lmu");
// all object files
......@@ -383,10 +387,18 @@ pub fn compile_fnc<'a>(
backend::emit_context(&vm);
let libname = &get_dylib_name(fnc_name);
let dylib = aot::link_dylib(vec![Mu(fnc_name)], libname, &vm);
// ll::Library dosn't load using the RTLD_GLOBAL flag, which we need for dlsym calls to work
// So I'm using this hack to fix this (the transmute is needed because ll::Library has a
// private constructor).
unsafe { std::mem::transmute(ll::os::unix::Library::open(Some(dylib.as_os_str()), libc::RTLD_NOW | libc::RTLD_GLOBAL).unwrap()) }
// ll::Library dosn't load using the RTLD_GLOBAL flag, which we need for
// dlsym calls to work So I'm using this hack to fix this (the transmute
// is needed because ll::Library has a private constructor).
unsafe {
std::mem::transmute(
ll::os::unix::Library::open(
Some(dylib.as_os_str()),
libc::RTLD_NOW | libc::RTLD_GLOBAL
)
.unwrap()
)
}
}
/// builds a bundle (that contains several functions), compiles them,
......
......@@ -13,9 +13,9 @@
// limitations under the License.
use crate::compiler::backend::RegGroup;
use crate::vm::VM;
use crate::vm::api::{to_CMuVM};
use crate::vm::api::api_c::CMuVM;
use crate::vm::api::to_CMuVM;
use crate::vm::VM;
use ast::ir::*;
use ast::types::*;
use utils;
......@@ -112,7 +112,7 @@ pub fn resolve_symbol(symbol: MuName) -> Address {
let error = unsafe { dlerror() };
if !error.is_null() {
return resolve_symbol_unmangled(symbol)
return resolve_symbol_unmangled(symbol);
}
Address::from_ptr(ret)
......@@ -294,23 +294,25 @@ pub static mut LAST_TIME: c_ulong = 0;
// RTMU mu_main needs changes
/// a function to resume a mu VM dumped as a shared library boot image, this function will be called
/// from C, and returns a MuVM* that works with the C API
/// a function to resume a mu VM dumped as a shared library boot image, this
/// function will be called from C, and returns a MuVM* that works with the C
/// API
#[no_mangle]
pub extern "C" fn mu_resume(
stm: StructTagMap, htm: HybridTagMap,
stm: StructTagMap,
htm: HybridTagMap,
edata: *const (),
dumped_vm: *mut Arc<VM>,
dumped_vm: *mut Arc<VM>
) -> *mut CMuVM {
// resume the VM and wrap it into a C API object
to_CMuVM(resume_runtime(stm, htm, edata, dumped_vm))
}
fn resume_runtime(
stm: StructTagMap, htm: HybridTagMap,
stm: StructTagMap,
htm: HybridTagMap,
edata: *const (),
dumped_vm: *mut Arc<VM>,
dumped_vm: *mut Arc<VM>
) -> Arc<VM> {
unsafe {
STRUCT_TAG_MAP_LOC = stm;
......@@ -336,13 +338,13 @@ fn resume_runtime(
// );
}
/// the main function for executable boot image, this function will be called
/// from C For RTMu, we start the primordial thread with the default system attr
/// The client can modify this afterwards
#[no_mangle]
pub extern "C" fn mu_main(
stm: StructTagMap, htm: HybridTagMap,
stm: StructTagMap,
htm: HybridTagMap,
edata: *const (),
dumped_vm: *mut Arc<VM>,
argc: c_int,
......
......@@ -661,12 +661,19 @@ impl MuThread {
let cur = muentry_get_thread_local();
if !cur.is_zero() {
if Arc::ptr_eq(&vm, &cur.to_ref::<MuThread>().vm) {
warn!("current thread has a thread local (has a muthread to it)");
warn!(
"current thread has a thread local (has a muthread to it)"
);
return false;
} else {
warn!("current thread is attached to a different mu VM, changing this now");
Box::from_raw(cur.to_ptr_mut::<MuThread>()); // destroy old thread structure as we will be making a new one
// TODO: destroy associated stack as well?
Box::from_raw(cur.to_ptr_mut::<MuThread>()); // destroy old
// thread structure
// as we will be
// making a new one
// TODO: destroy
// associated stack
// as well?
}
}
......
......@@ -38,7 +38,7 @@ impl MuVM {
/**
** Create a micro VM object for the given VM
**/
pub fn new(vm: Arc<VM>)->MuVM {
pub fn new(vm: Arc<VM>) -> MuVM {
MuVM {
vm: vm,
// Cache C strings. The C client expects `char*` from `name_of`. We
......@@ -189,7 +189,10 @@ pub extern "C" fn mu_fastimpl_new_with_opts(opts: *const c_char) -> *mut CMuVM {
let c_mvm = to_CMuVM(Arc::new(VM::new_with_opts(str_opts)));
debug!("The MuVM instance address: {:?}", from_MuVM_ptr(c_mvm));
debug!("The C-visible CMuVM struct address: {:?}", c_mvm as *mut c_void);
debug!(
"The C-visible CMuVM struct address: {:?}",
c_mvm as *mut c_void
);
c_mvm
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment