Skip to content

Commit

Permalink
docs: design merge
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwfang committed Feb 7, 2025
1 parent 23f461b commit 0703d41
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,4 @@ pub use syntax::{
FuncType, GlobalType, ImportDesc, Limits, Mut, RefType, ResultType, TableType, ValType,
};
pub use valid::prepare;
pub use valid::merge;
9 changes: 9 additions & 0 deletions crates/interpreter/src/valid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ use crate::syntax::*;
use crate::toctou::*;
use crate::util::*;
use crate::*;
use crate::Error::Invalid;

pub fn merge(binary: &[u8], side_table: Vec<MetadataEntry>) -> Result<Vec<u8>, Error> {
// Convert Vec<MetadataEntry> to Vec<u8>.
// Create a custom section at the beginning of the binary,
// and put the serialized `side_table` in it.
// Return the new module.
Err(Invalid)
}

/// Checks whether a WASM module in binary format is valid, and returns the side table.
pub fn prepare(binary: &[u8]) -> Result<Vec<MetadataEntry>, Error> {
Expand Down
6 changes: 4 additions & 2 deletions crates/interpreter/tests/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ impl<'m> Env<'m> {
}

fn maybe_instantiate(&mut self, name: &str, wasm: &[u8]) -> Result<InstId, Error> {
let module = self.alloc(wasm.len());
module.copy_from_slice(wasm);
let side_table = prepare(wasm)?;
let wasm_with_side_table = merge(wasm, side_table)?.as_slice();
let module = self.alloc(wasm_with_side_table.len());
module.copy_from_slice(wasm_with_side_table);
let module = Module::new(module)?;
let memory = self.alloc(mem_size(name));
self.store.instantiate(module, memory)
Expand Down

0 comments on commit 0703d41

Please sign in to comment.