Skip to content

Commit

Permalink
feat(c-api) Implement wasm_module_validate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan committed Oct 5, 2020
1 parent 1de0606 commit ff4cb6d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/c-api/src/wasm_c_api/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::types::{
wasm_byte_vec_t, wasm_exporttype_t, wasm_exporttype_vec_t, wasm_importtype_t,
wasm_importtype_vec_t,
};
use crate::error::update_last_error;
use std::ptr::NonNull;
use std::slice;
use std::sync::Arc;
Expand Down Expand Up @@ -32,6 +33,30 @@ pub unsafe extern "C" fn wasm_module_new(
#[no_mangle]
pub unsafe extern "C" fn wasm_module_delete(_module: Option<Box<wasm_module_t>>) {}

#[no_mangle]
pub unsafe extern "C" fn wasm_module_validate(
store_ptr: Option<NonNull<wasm_store_t>>,
bytes: &wasm_byte_vec_t,
) -> bool {
// TODO: review lifetime of byte slice.
let wasm_byte_slice: &[u8] = slice::from_raw_parts(bytes.data, bytes.size);

if store_ptr.is_none() {
return false;
}

let store_ptr = store_ptr.unwrap().cast::<Store>();
let store = store_ptr.as_ref();

if let Err(error) = Module::validate(store, wasm_byte_slice) {
update_last_error(error);

false
} else {
true
}
}

#[no_mangle]
pub unsafe extern "C" fn wasm_module_exports(
module: &wasm_module_t,
Expand Down

0 comments on commit ff4cb6d

Please sign in to comment.