mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-25 06:31:32 +00:00
Merge branch 'master' into feature/wasi-fs
This commit is contained in:
@ -8,6 +8,7 @@ pub type LinkResult<T> = std::result::Result<T, Vec<LinkError>>;
|
||||
pub type RuntimeResult<T> = std::result::Result<T, RuntimeError>;
|
||||
pub type CallResult<T> = std::result::Result<T, CallError>;
|
||||
pub type ResolveResult<T> = std::result::Result<T, ResolveError>;
|
||||
pub type ParseResult<T> = std::result::Result<T, ParseError>;
|
||||
|
||||
/// This is returned when the chosen compiler is unable to
|
||||
/// successfully compile the provided webassembly module into
|
||||
@ -445,3 +446,14 @@ impl Into<GrowError> for MemoryProtectionError {
|
||||
GrowError::CouldNotProtectMemory(self)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum ParseError {
|
||||
BinaryReadError,
|
||||
}
|
||||
|
||||
impl From<wasmparser::BinaryReaderError> for ParseError {
|
||||
fn from(_: wasmparser::BinaryReaderError) -> Self {
|
||||
ParseError::BinaryReadError
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,11 @@ pub fn compile_with(
|
||||
let token = backend::Token::generate();
|
||||
compiler
|
||||
.compile(wasm, Default::default(), token)
|
||||
.map(|inner| module::Module::new(Arc::new(inner)))
|
||||
.map(|mut inner| {
|
||||
let inner_info: &mut crate::module::ModuleInfo = &mut inner.info;
|
||||
inner_info.import_custom_sections(wasm).unwrap();
|
||||
module::Module::new(Arc::new(inner))
|
||||
})
|
||||
}
|
||||
|
||||
/// The same as `compile_with` but changes the compiler behavior
|
||||
|
@ -59,6 +59,26 @@ pub struct ModuleInfo {
|
||||
|
||||
/// Symbol information from emscripten
|
||||
pub em_symbol_map: Option<HashMap<u32, String>>,
|
||||
|
||||
pub custom_sections: HashMap<String, Vec<u8>>,
|
||||
}
|
||||
|
||||
impl ModuleInfo {
|
||||
pub fn import_custom_sections(&mut self, wasm: &[u8]) -> crate::error::ParseResult<()> {
|
||||
let mut parser = wasmparser::ModuleReader::new(wasm)?;
|
||||
while !parser.eof() {
|
||||
let section = parser.read()?;
|
||||
if let wasmparser::SectionCode::Custom { name, kind: _ } = section.code {
|
||||
let mut reader = section.get_binary_reader();
|
||||
let len = reader.bytes_remaining();
|
||||
let bytes = reader.read_bytes(len)?;
|
||||
let data = bytes.to_vec();
|
||||
let name = String::from_utf8_lossy(name).to_string();
|
||||
self.custom_sections.insert(name, data);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
/// A compiled WebAssembly module.
|
||||
|
@ -547,7 +547,7 @@ mod vm_ctx_tests {
|
||||
use crate::backend::{
|
||||
sys::Memory, Backend, CacheGen, FuncResolver, ProtectedCaller, Token, UserTrapper,
|
||||
};
|
||||
use crate::cache::{Error as CacheError, WasmHash};
|
||||
use crate::cache::Error as CacheError;
|
||||
use crate::error::RuntimeResult;
|
||||
use crate::types::{FuncIndex, LocalFuncIndex, Value};
|
||||
use hashbrown::HashMap;
|
||||
@ -617,6 +617,8 @@ mod vm_ctx_tests {
|
||||
name_table: StringTable::new(),
|
||||
|
||||
em_symbol_map: None,
|
||||
|
||||
custom_sections: HashMap::new(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user