Move the signature_ids field first.

This commit is contained in:
Dan Gohman
2019-01-03 09:44:21 -08:00
parent e8e8f453a4
commit 482a054c75
3 changed files with 40 additions and 24 deletions

View File

@@ -59,6 +59,9 @@ pub struct FuncEnvironment<'module_environment> {
/// The Cranelift global holding the vmctx address.
vmctx: Option<ir::GlobalValue>,
/// The Cranelift global holding the base address of the signature IDs vector.
signature_ids_base: Option<ir::GlobalValue>,
/// The Cranelift global holding the base address of the imported functions table.
imported_functions_base: Option<ir::GlobalValue>,
@@ -80,9 +83,6 @@ pub struct FuncEnvironment<'module_environment> {
/// The Cranelift global holding the base address of the globals vector.
globals_base: Option<ir::GlobalValue>,
/// The Cranelift global holding the base address of the signature IDs vector.
signature_ids_base: Option<ir::GlobalValue>,
/// The external function declaration for implementing wasm's `memory.size`
/// for locally-defined 32-bit memories.
memory32_size_extfunc: Option<FuncRef>,
@@ -109,6 +109,7 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
target_config,
module,
vmctx: None,
signature_ids_base: None,
imported_functions_base: None,
imported_tables_base: None,
imported_memories_base: None,
@@ -116,7 +117,6 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
tables_base: None,
memories_base: None,
globals_base: None,
signature_ids_base: None,
memory32_size_extfunc: None,
imported_memory32_size_extfunc: None,
memory_grow_extfunc: None,

View File

@@ -207,45 +207,45 @@ impl VMOffsets {
/// Offsets for `VMContext`.
impl VMOffsets {
/// The offset of the `signature_ids` field.
pub fn vmctx_signature_ids(&self) -> u8 {
0 * self.pointer_size
}
/// The offset of the `tables` field.
#[allow(clippy::erasing_op)]
pub fn vmctx_imported_functions(&self) -> u8 {
0 * self.pointer_size
1 * self.pointer_size
}
/// The offset of the `tables` field.
#[allow(clippy::identity_op)]
pub fn vmctx_imported_tables(&self) -> u8 {
1 * self.pointer_size
2 * self.pointer_size
}
/// The offset of the `memories` field.
pub fn vmctx_imported_memories(&self) -> u8 {
2 * self.pointer_size
3 * self.pointer_size
}
/// The offset of the `globals` field.
pub fn vmctx_imported_globals(&self) -> u8 {
3 * self.pointer_size
4 * self.pointer_size
}
/// The offset of the `tables` field.
pub fn vmctx_tables(&self) -> u8 {
4 * self.pointer_size
5 * self.pointer_size
}
/// The offset of the `memories` field.
pub fn vmctx_memories(&self) -> u8 {
5 * self.pointer_size
6 * self.pointer_size
}
/// The offset of the `globals` field.
pub fn vmctx_globals(&self) -> u8 {
6 * self.pointer_size
}
/// The offset of the `signature_ids` field.
pub fn vmctx_signature_ids(&self) -> u8 {
7 * self.pointer_size
}

View File

@@ -469,6 +469,9 @@ impl Default for VMCallerCheckedAnyfunc {
#[derive(Debug)]
#[repr(C)]
pub struct VMContext {
/// Signature identifiers for signature-checking indirect calls.
signature_ids: *mut VMSharedSignatureIndex,
/// A pointer to an array of `*const VMFunctionBody` instances, indexed by `FuncIndex`.
imported_functions: *const VMFunctionImport,
@@ -492,9 +495,6 @@ pub struct VMContext {
/// A pointer to an array of locally-defined `VMGlobalDefinition` instances,
/// indexed by `DefinedGlobalIndex`.
globals: *mut VMGlobalDefinition,
/// Signature identifiers for signature-checking indirect calls.
signature_ids: *mut VMSharedSignatureIndex,
// If more elements are added here, remember to add offset_of tests below!
}
@@ -509,20 +509,36 @@ mod test {
let offsets = VMOffsets::new(size_of::<*mut u8>() as u8);
assert_eq!(size_of::<VMContext>(), usize::from(offsets.size_of_vmctx()));
assert_eq!(
offset_of!(VMContext, memories),
usize::from(offsets.vmctx_memories())
offset_of!(VMContext, signature_ids),
usize::from(offsets.vmctx_signature_ids())
);
assert_eq!(
offset_of!(VMContext, globals),
usize::from(offsets.vmctx_globals())
offset_of!(VMContext, imported_functions),
usize::from(offsets.vmctx_imported_functions())
);
assert_eq!(
offset_of!(VMContext, imported_tables),
usize::from(offsets.vmctx_imported_tables())
);
assert_eq!(
offset_of!(VMContext, imported_memories),
usize::from(offsets.vmctx_imported_memories())
);
assert_eq!(
offset_of!(VMContext, imported_globals),
usize::from(offsets.vmctx_imported_globals())
);
assert_eq!(
offset_of!(VMContext, tables),
usize::from(offsets.vmctx_tables())
);
assert_eq!(
offset_of!(VMContext, signature_ids),
usize::from(offsets.vmctx_signature_ids())
offset_of!(VMContext, memories),
usize::from(offsets.vmctx_memories())
);
assert_eq!(
offset_of!(VMContext, globals),
usize::from(offsets.vmctx_globals())
);
}
}