Last active
July 20, 2020 14:44
-
-
Save alexcrichton/ba66d506b48723a72574111ccbbfd0fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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