Add some better docs

This commit is contained in:
Lachlan Sneff
2019-03-13 14:58:44 -07:00
parent 20d1023abe
commit 3eaf5525d1
3 changed files with 52 additions and 10 deletions

View File

@ -9,7 +9,16 @@ use std::{ffi::c_void, mem, ptr};
/// The context of the currently running WebAssembly instance.
///
/// This is implicitly passed to every webassembly function.
/// Since this is per-module, each field has a statically
/// (as in after compiling the wasm) known size, so no
/// runtime checks are necessary.
///
/// While the runtime currently just passes this around
/// as the first, implicit parameter of every function,
/// it may someday be pinned to a register (especially
/// on arm, which has a ton of registers) to reduce
/// register shuffling.
#[derive(Debug)]
#[repr(C)]
pub struct Ctx {
@ -42,11 +51,25 @@ pub struct Ctx {
pub(crate) local_functions: *const *const Func,
/// These are pointers to things that are known to be owned
/// by the owning `Instance`.
local_backing: *mut LocalBacking,
import_backing: *mut ImportBacking,
module: *const ModuleInner,
//// This is intended to be user-supplied, per-instance
/// contextual data. There are currently some issue with it,
/// notably that it cannot be set before running the `start`
/// function in a webassembly module.
///
/// [#219](https://github.com/wasmerio/wasmer/pull/219) fixes that
/// issue, as well as allowing the user to have *per-function*
/// context, instead of just per-instance.
pub data: *mut c_void,
/// If there's a function set in this field, it gets called
/// when the context is destructed, e.g. when an `Instance`
/// is dropped.
pub data_finalizer: Option<extern "C" fn(data: *mut c_void)>,
}