Advertisement
Guest User

Untitled

a guest
May 10th, 2020
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.36 KB | None | 0 0
  1. use anyhow::Result;
  2. use wasmtime::*;
  3. use wasmtime_wasi::{Wasi, WasiCtx};
  4.  
  5. fn main() -> Result<()> {
  6.     println!("Initializing...");
  7.     let store = Store::default();
  8.     let wasi = Wasi::new(&store, WasiCtx::new(std::env::args())?);
  9.  
  10.     println!("Compiling module...");
  11.     let module = Module::from_file(&store, "/home/yolo/hello/target/wasm32-wasi/debug/hello.wasm")?;
  12.     let module2 = Module::from_file(&store, "/home/yolo/hello2/target/wasm32-wasi/debug/hello.wasm")?;
  13.  
  14.     println!("Instantiating module...");
  15.     let ty = MemoryType::new(Limits::new(322, None));
  16.     let mem = Memory::new(&store, ty);
  17.     let imports = [Extern::from(mem), Extern::from(wasi.get_export("fd_write").unwrap().clone())];
  18.  
  19.     let instance = Instance::new(&module, &imports)?;
  20.     let instance2 = Instance::new(&module2, &imports)?;
  21.  
  22.     println!("Extracting export...");
  23.     let run = instance
  24.         .get_func("kek")
  25.         .ok_or(anyhow::format_err!("failed to find `run` function export"))?
  26.         .get0::<i32>()?;
  27.  
  28.     let run2 = instance2
  29.         .get_func("top")
  30.         .ok_or(anyhow::format_err!("failed to find `run` function export"))?
  31.         .get1::<i32, i32>()?;
  32.  
  33.     // And last but not least we can call it!
  34.     println!("Calling export...");
  35.     let kek_ptr = run()?;
  36.     //let kek2 = run2(kek_ptr)?;
  37.  
  38.     //println!("lmao. {:?}", kek2);
  39.     Ok(())
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement