Skip to content

Commit

Permalink
Make the internal field private from outside.
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Mar 21, 2019
1 parent a4ee873 commit 26e4278
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
28 changes: 14 additions & 14 deletions lib/dynasm-backend/src/codegen_x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,8 @@ impl ProtectedCaller for X64ExecutionContext {
});
}
unsafe {
(
(**(*_vmctx).internal.memories).base,
(**(*_vmctx).internal.memories).bound,
)
let vmctx = _vmctx as *mut vm::InternalCtx;
((**(*vmctx).memories).base, (**(*vmctx).memories).bound)
}
} else if _module.info.imported_memories.len() > 0 {
if _module.info.memories.len() != 0 || _module.info.imported_memories.len() != 1 {
Expand All @@ -418,9 +416,10 @@ impl ProtectedCaller for X64ExecutionContext {
});
}
unsafe {
let vmctx = _vmctx as *mut vm::InternalCtx;
(
(**(*_vmctx).internal.imported_memories).base,
(**(*_vmctx).internal.imported_memories).bound,
(**(*vmctx).imported_memories).base,
(**(*vmctx).imported_memories).bound,
)
}
} else {
Expand Down Expand Up @@ -5130,13 +5129,13 @@ unsafe extern "C" fn invoke_import(
import_id: usize,
stack_top: *mut u8,
stack_base: *mut u8,
vmctx: *mut vm::Ctx,
_vmctx: *mut vm::Ctx,
_memory_base: *mut u8,
) -> u64 {
let vmctx: &mut vm::Ctx = &mut *vmctx;
let import = (*vmctx.internal.imported_funcs.offset(import_id as isize)).func;
let vmctx: &mut vm::InternalCtx = &mut *(_vmctx as *mut vm::InternalCtx);
let import = (*vmctx.imported_funcs.offset(import_id as isize)).func;

CONSTRUCT_STACK_AND_CALL_NATIVE(stack_top, stack_base, vmctx, import)
CONSTRUCT_STACK_AND_CALL_NATIVE(stack_top, stack_base, _vmctx, import)
}

#[repr(u64)]
Expand All @@ -5160,16 +5159,17 @@ unsafe extern "C" fn call_indirect(
assert!(stack_top as usize <= stack_base as usize);

let table: &LocalTable = match local_or_import {
CallIndirectLocalOrImport::Local => &*(*(*vmctx).internal.tables),
CallIndirectLocalOrImport::Import => &*(*(*vmctx).internal.imported_tables),
CallIndirectLocalOrImport::Local => &*(*(*(vmctx as *mut vm::InternalCtx)).tables),
CallIndirectLocalOrImport::Import => {
&*(*(*(vmctx as *mut vm::InternalCtx)).imported_tables)
}
};
if elem_index >= table.count as usize {
eprintln!("element index out of bounds");
protect_unix::trigger_trap();
}
let anyfunc = &*(table.base as *mut vm::Anyfunc).offset(elem_index as isize);
let dynamic_sigindex = *(*vmctx)
.internal
let dynamic_sigindex = *(*(vmctx as *mut vm::InternalCtx))
.dynamic_sigindices
.offset(sig_index as isize);

Expand Down
3 changes: 2 additions & 1 deletion lib/runtime-core/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{ffi::c_void, mem, ptr};
#[repr(C)]
pub struct Ctx {
// `internal` must be the first field of `Ctx`.
pub internal: InternalCtx,
pub(crate) internal: InternalCtx,

pub(crate) local_functions: *const *const Func,

Expand All @@ -29,6 +29,7 @@ pub struct Ctx {
/// The internal context of the currently running WebAssembly instance.
///
///
#[doc(hidden)]
#[derive(Debug)]
#[repr(C)]
pub struct InternalCtx {
Expand Down

0 comments on commit 26e4278

Please sign in to comment.