Deny missing docs in runtime core and add missing docs

This commit is contained in:
Brandon Fish
2019-11-10 13:13:18 -06:00
parent 0d644a53db
commit aad390d09d
32 changed files with 674 additions and 15 deletions

View File

@ -1,3 +1,5 @@
//! The runtime vm module contains data structures and helper functions used during runtime to
//! execute wasm instance functions.
pub use crate::backing::{ImportBacking, LocalBacking, INTERNALS_SIZE};
use crate::{
error::CallResult,
@ -36,6 +38,7 @@ use std::collections::HashMap;
#[repr(C)]
pub struct Ctx {
// `internal` must be the first field of `Ctx`.
/// InternalCtx data field
pub internal: InternalCtx,
pub(crate) local_functions: *const *const Func,
@ -43,7 +46,9 @@ pub struct Ctx {
/// These are pointers to things that are known to be owned
/// by the owning `Instance`.
pub local_backing: *mut LocalBacking,
/// Mutable pointer to import data
pub import_backing: *mut ImportBacking,
/// Const pointer to module inner data
pub module: *const ModuleInner,
/// This is intended to be user-supplied, per-instance
@ -110,22 +115,31 @@ pub struct InternalCtx {
/// modules safely.
pub dynamic_sigindices: *const SigId,
/// Const pointer to Intrinsics.
pub intrinsics: *const Intrinsics,
/// Stack lower bound.
pub stack_lower_bound: *mut u8,
/// Mutable pointer to memory base.
pub memory_base: *mut u8,
/// Memory bound.
pub memory_bound: usize,
/// Mutable pointer to internal fields.
pub internals: *mut [u64; INTERNALS_SIZE], // TODO: Make this dynamic?
/// Interrupt signal mem.
pub interrupt_signal_mem: *mut u8,
}
static INTERNAL_FIELDS: AtomicUsize = AtomicUsize::new(0);
/// An internal field.
pub struct InternalField {
/// Init once field.
init: Once,
/// Inner field.
inner: UnsafeCell<usize>,
}
@ -133,6 +147,7 @@ unsafe impl Send for InternalField {}
unsafe impl Sync for InternalField {}
impl InternalField {
/// Allocate and return an `InternalField`.
pub const fn allocate() -> InternalField {
InternalField {
init: Once::new(),
@ -140,6 +155,7 @@ impl InternalField {
}
}
/// Get the index of this `InternalField`.
pub fn index(&self) -> usize {
let inner: *mut usize = self.inner.get();
self.init.call_once(|| {
@ -157,9 +173,12 @@ impl InternalField {
}
}
/// A container for VM instrinsic functions
#[repr(C)]
pub struct Intrinsics {
/// Const pointer to memory grow `Func`.
pub memory_grow: *const Func,
/// Const pointer to memory size `Func`.
pub memory_size: *const Func,
/*pub memory_grow: unsafe extern "C" fn(
ctx: &mut Ctx,
@ -176,27 +195,33 @@ unsafe impl Send for Intrinsics {}
unsafe impl Sync for Intrinsics {}
impl Intrinsics {
/// Memory grow offset
#[allow(clippy::erasing_op)]
pub fn offset_memory_grow() -> u8 {
(0 * ::std::mem::size_of::<usize>()) as u8
}
/// Memory size offset
pub fn offset_memory_size() -> u8 {
(1 * ::std::mem::size_of::<usize>()) as u8
}
}
/// Local static memory intrinsics
pub static INTRINSICS_LOCAL_STATIC_MEMORY: Intrinsics = Intrinsics {
memory_grow: vmcalls::local_static_memory_grow as _,
memory_size: vmcalls::local_static_memory_size as _,
};
/// Local dynamic memory intrinsics
pub static INTRINSICS_LOCAL_DYNAMIC_MEMORY: Intrinsics = Intrinsics {
memory_grow: vmcalls::local_dynamic_memory_grow as _,
memory_size: vmcalls::local_dynamic_memory_size as _,
};
/// Imported static memory intrinsics
pub static INTRINSICS_IMPORTED_STATIC_MEMORY: Intrinsics = Intrinsics {
memory_grow: vmcalls::imported_static_memory_grow as _,
memory_size: vmcalls::imported_static_memory_size as _,
};
/// Imported dynamic memory intrinsics
pub static INTRINSICS_IMPORTED_DYNAMIC_MEMORY: Intrinsics = Intrinsics {
memory_grow: vmcalls::imported_dynamic_memory_grow as _,
memory_size: vmcalls::imported_dynamic_memory_size as _,
@ -509,7 +534,9 @@ pub struct Func(InnerFunc);
#[derive(Debug, Clone)]
#[repr(C)]
pub struct ImportedFunc {
/// Const pointer to `Func`.
pub func: *const Func,
/// Mutable pointer to `Ctx`.
pub vmctx: *mut Ctx,
}
@ -517,15 +544,18 @@ pub struct ImportedFunc {
unsafe impl Send for ImportedFunc {}
impl ImportedFunc {
/// Offset to func.
#[allow(clippy::erasing_op)] // TODO
pub fn offset_func() -> u8 {
0 * (mem::size_of::<usize>() as u8)
}
/// Offset to vmctx.
pub fn offset_vmctx() -> u8 {
1 * (mem::size_of::<usize>() as u8)
}
/// Size of an `ImportedFunc`.
pub fn size() -> u8 {
mem::size_of::<Self>() as u8
}
@ -547,15 +577,18 @@ pub struct LocalTable {
unsafe impl Send for LocalTable {}
impl LocalTable {
/// Offset base.
#[allow(clippy::erasing_op)] // TODO
pub fn offset_base() -> u8 {
0 * (mem::size_of::<usize>() as u8)
}
/// Offset count.
pub fn offset_count() -> u8 {
1 * (mem::size_of::<usize>() as u8)
}
/// Size of a `LocalTable`.
pub fn size() -> u8 {
mem::size_of::<Self>() as u8
}
@ -579,15 +612,18 @@ pub struct LocalMemory {
unsafe impl Send for LocalMemory {}
impl LocalMemory {
/// Offset base.
#[allow(clippy::erasing_op)] // TODO
pub fn offset_base() -> u8 {
0 * (mem::size_of::<usize>() as u8)
}
/// Offset bound.
pub fn offset_bound() -> u8 {
1 * (mem::size_of::<usize>() as u8)
}
/// Size of a `LocalMemory`.
pub fn size() -> u8 {
mem::size_of::<Self>() as u8
}
@ -597,24 +633,29 @@ impl LocalMemory {
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct LocalGlobal {
/// Data.
pub data: u128,
}
impl LocalGlobal {
/// Offset data.
#[allow(clippy::erasing_op)] // TODO
pub fn offset_data() -> u8 {
0 * (mem::size_of::<usize>() as u8)
}
/// A null `LocalGlobal`.
pub fn null() -> Self {
Self { data: 0 }
}
/// Size of a `LocalGlobal`.
pub fn size() -> u8 {
mem::size_of::<Self>() as u8
}
}
/// Identifier for a function signature.
#[derive(Debug, Clone, Copy)]
#[repr(transparent)]
pub struct SigId(pub u32);
@ -623,8 +664,11 @@ pub struct SigId(pub u32);
#[derive(Debug, Clone, Copy)]
#[repr(C)]
pub struct Anyfunc {
/// Const pointer to `Func`.
pub func: *const Func,
/// Mutable pointer to `Ctx`.
pub ctx: *mut Ctx,
/// Sig id of this function
pub sig_id: SigId,
}
@ -632,6 +676,7 @@ pub struct Anyfunc {
unsafe impl Send for Anyfunc {}
impl Anyfunc {
/// A null `Anyfunc` value.
pub fn null() -> Self {
Self {
func: ptr::null(),
@ -640,19 +685,23 @@ impl Anyfunc {
}
}
/// The offset for this func.
#[allow(clippy::erasing_op)] // TODO
pub fn offset_func() -> u8 {
0 * (mem::size_of::<usize>() as u8)
}
/// The offset of the vmctx.
pub fn offset_vmctx() -> u8 {
1 * (mem::size_of::<usize>() as u8)
}
/// The offset of the sig id.
pub fn offset_sig_id() -> u8 {
2 * (mem::size_of::<usize>() as u8)
}
/// The size of `Anyfunc`.
pub fn size() -> u8 {
mem::size_of::<Self>() as u8
}