Add clif-backend crate and runtime example

This commit is contained in:
Lachlan Sneff
2019-01-08 16:04:03 -05:00
parent 8a73ff71af
commit 7324c85749
14 changed files with 2378 additions and 10 deletions

View File

@ -102,14 +102,12 @@ impl Instance {
.chain(iter::once(libffi_arg(&vmctx_ptr)))
.collect();
let func_ptr = CodePtr::from_ptr(
self.module
let func_ptr = CodePtr::from_ptr(self.module
.func_resolver
.get(&self.module, func_index)
.expect("broken invariant, func resolver not synced with module.exports")
.cast()
.as_ptr(),
);
.as_ptr());
call_protected(|| {
self.module.sig_registry.lookup_func_sig(sig_index)

View File

@ -4,19 +4,19 @@ mod backend;
mod backing;
mod instance;
mod memory;
mod module;
mod sig_registry;
mod table;
mod recovery;
mod sighandler;
mod mmap;
pub mod mmap;
pub mod module;
pub mod types;
pub mod vm;
pub mod vmcalls;
pub use self::backend::{Compiler, FuncResolver};
pub use self::instance::{Import, ImportResolver, Imports, Instance};
pub use self::module::Module;
pub use self::module::{Module, ModuleInner};
pub use self::sig_registry::SigRegistry;
pub use self::memory::LinearMemory;

View File

@ -45,7 +45,8 @@ impl Mmap {
pub unsafe fn protect(&mut self, range: Range<usize>, protect: Protect) -> Result<(), String> {
let page_size = page_size::get();
let start = self.ptr.add(round_down_to_page_size(range.start, page_size));
let size = range.end - range.start;
let size = round_up_to_page_size(range.end - range.start, page_size);
assert!(size <= self.size);
let success = libc::mprotect(start as _, size, protect as i32);
if success == -1 {
@ -67,7 +68,7 @@ impl Mmap {
slice::from_raw_parts_mut(self.ptr, self.size)
}
pub fn as_ptr(&mut self) -> *mut u8 {
pub fn as_ptr(&self) -> *mut u8 {
self.ptr
}
}