Moved memories, tables and globals to be Unchecked slices

This commit is contained in:
Syrus Akbary
2018-10-22 18:31:12 +02:00
parent 7e7d230441
commit 7444837d09

View File

@@ -86,20 +86,20 @@ impl VmCtx {
} }
} }
#[derive(Debug)] // #[derive(Debug)]
#[repr(C)] #[repr(C)]
pub struct VmCtxData<'phantom> { pub struct VmCtxData<'phantom> {
pub user_data: UserData, pub user_data: UserData,
// globals: UncheckedSlice<u8>, globals: UncheckedSlice<u8>,
// memories: UncheckedSlice<UncheckedSlice<u8>>, memories: UncheckedSlice<UncheckedSlice<u8>>,
// tables: UncheckedSlice<BoundedSlice<usize>>, tables: UncheckedSlice<BoundedSlice<usize>>,
globals: Vec<u8>, // globals: Vec<u8>,
memories: Vec<Vec<u8>>, // memories: Vec<Vec<u8>>,
tables: Vec<Vec<usize>>, // pub tables: UncheckedSlice<BoundedSlice<usize>>,
phantom: PhantomData<&'phantom ()>, phantom: PhantomData<&'phantom ()>,
} }
#[derive(Debug)] // #[derive(Debug)]
#[repr(C)] #[repr(C)]
pub struct UserData { pub struct UserData {
// pub process: Dispatch<Process>, // pub process: Dispatch<Process>,
@@ -519,11 +519,11 @@ impl Instance {
} }
pub fn generate_context(&mut self) -> &VmCtx { pub fn generate_context(&mut self) -> &VmCtx {
let mut memories: Vec<Vec<u8>> = self.memories.iter().map(|mem| mem[..].into()).collect(); let mut memories: Vec<UncheckedSlice<u8>> = self.memories.iter().map(|mem| mem[..].into()).collect();
let tables: Vec<Vec<usize>> = self.tables.iter().map(|table| table[..].into()).collect(); let tables: Vec<BoundedSlice<usize>> = self.tables.iter().map(|table| table[..].into()).collect();
let globals: Vec<u8> = self.globals[..].into(); let globals: UncheckedSlice<u8> = self.globals[..].into();
assert!(memories.len() >= 1, "modules must have at least one memory"); assert!(memories.len() >= 1, "modules must have at least one memory");
// the first memory has a space of `mem::size_of::<VmCtxData>()` rounded // the first memory has a space of `mem::size_of::<VmCtxData>()` rounded