Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(c-api) Implement wasm_module_validate #1636

Merged
merged 2 commits into from
Oct 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I commented elsewhere on this PR about the implied semantics of NonNull, store: &wasm_store_t is probably better, especially if we're calling unwrap on it

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