Skip to content

Instantly share code, notes, and snippets.

@alexcrichton
Last active July 20, 2020 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexcrichton/ba66d506b48723a72574111ccbbfd0fc to your computer and use it in GitHub Desktop.
Save alexcrichton/ba66d506b48723a72574111ccbbfd0fc to your computer and use it in GitHub Desktop.
use wasmtime::*;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut config = Config::new();
config.profiler(ProfilingStrategy::JitDump)?;
let engine = Engine::new(&config);
let store = Store::new(&engine);
let module = Module::from_file(&engine, "./fib.wasm")?;
let instance = Instance::new(&store, &module, &[])?;
let start = instance.get_func("main").unwrap();
let start = start.get2::<i32, i32, i32>()?;
unsafe {
let n = 1 << 13; // 12 works
let a = libc::mmap(
0 as *mut _,
n,
libc::PROT_READ | libc::PROT_WRITE,
libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
-1,
0,
);
libc::mprotect(a, n, libc::PROT_READ | libc::PROT_EXEC);
}
start(0, 0)?;
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment