Add the internals field and necessary structures for metering.

This commit is contained in:
losfair
2019-05-17 01:10:21 +08:00
parent 4e5ac24517
commit 6aa87a0bbf
6 changed files with 46 additions and 4 deletions

View File

@ -1,4 +1,4 @@
pub use crate::backing::{ImportBacking, LocalBacking};
pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE};
use crate::{
memory::{Memory, MemoryType},
module::{ModuleInfo, ModuleInner},
@ -92,6 +92,8 @@ pub struct InternalCtx {
pub memory_base: *mut u8,
pub memory_bound: usize,
pub internals: *mut [u64; INTERNALS_SIZE], // TODO: Make this dynamic?
}
#[repr(C)]
@ -200,6 +202,8 @@ impl Ctx {
memory_base: mem_base,
memory_bound: mem_bound,
internals: &mut local_backing.internals.0,
},
local_functions: local_backing.local_functions.as_ptr(),
@ -249,6 +253,8 @@ impl Ctx {
memory_base: mem_base,
memory_bound: mem_bound,
internals: &mut local_backing.internals.0,
},
local_functions: local_backing.local_functions.as_ptr(),
@ -356,9 +362,13 @@ impl Ctx {
11 * (mem::size_of::<usize>() as u8)
}
pub fn offset_local_functions() -> u8 {
pub fn offset_internals() -> u8 {
12 * (mem::size_of::<usize>() as u8)
}
pub fn offset_local_functions() -> u8 {
13 * (mem::size_of::<usize>() as u8)
}
}
enum InnerFunc {}
@ -572,6 +582,11 @@ mod vm_offset_tests {
offset_of!(InternalCtx => memory_bound).get_byte_offset(),
);
assert_eq!(
Ctx::offset_internals() as usize,
offset_of!(InternalCtx => internals).get_byte_offset(),
);
assert_eq!(
Ctx::offset_local_functions() as usize,
offset_of!(Ctx => local_functions).get_byte_offset(),