Make the calls to wasm's memory.grow and memory.size indirect (#194)
* Make the calls to wasm's memory.grow and memory.size indirect
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
//! module.
|
||||
|
||||
use crate::module::Module;
|
||||
use crate::BuiltinFunctionIndex;
|
||||
use core::convert::TryFrom;
|
||||
use cranelift_codegen::ir;
|
||||
use cranelift_wasm::{
|
||||
@@ -332,9 +333,8 @@ impl VMOffsets {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Return the size of the `VMContext` allocation.
|
||||
#[allow(dead_code)]
|
||||
pub fn size_of_vmctx(&self) -> u32 {
|
||||
/// The offset of the builtin functions array.
|
||||
pub fn vmctx_builtin_functions_begin(&self) -> u32 {
|
||||
self.vmctx_globals_begin()
|
||||
.checked_add(
|
||||
self.num_defined_globals
|
||||
@@ -344,6 +344,17 @@ impl VMOffsets {
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Return the size of the `VMContext` allocation.
|
||||
pub fn size_of_vmctx(&self) -> u32 {
|
||||
self.vmctx_builtin_functions_begin()
|
||||
.checked_add(
|
||||
BuiltinFunctionIndex::builtin_functions_total_number()
|
||||
.checked_mul(u32::from(self.pointer_size))
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Return the offset to `VMSharedSignatureId` index `index`.
|
||||
pub fn vmctx_vmshared_signature_id(&self, index: SignatureIndex) -> u32 {
|
||||
assert!(index.as_u32() < self.num_signature_ids);
|
||||
@@ -517,6 +528,18 @@ impl VMOffsets {
|
||||
.checked_add(u32::from(self.vmglobal_import_from()))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// Return the offset to builtin function in `VMBuiltinFunctionsArray` index `index`.
|
||||
pub fn vmctx_builtin_function(&self, index: BuiltinFunctionIndex) -> u32 {
|
||||
self.vmctx_builtin_functions_begin()
|
||||
.checked_add(
|
||||
index
|
||||
.index()
|
||||
.checked_mul(u32::from(self.pointer_size))
|
||||
.unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
/// Target specific type for shared signature index.
|
||||
|
||||
Reference in New Issue
Block a user