From 482a054c7580c294d7dfcb57e75d8372c266eb0b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 3 Jan 2019 09:44:21 -0800 Subject: [PATCH] Move the signature_ids field first. --- lib/environ/src/func_environ.rs | 8 ++++---- lib/environ/src/vmoffsets.rs | 22 ++++++++++----------- lib/runtime/src/vmcontext.rs | 34 ++++++++++++++++++++++++--------- 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/lib/environ/src/func_environ.rs b/lib/environ/src/func_environ.rs index 515d1ee3ac..7d76e84997 100644 --- a/lib/environ/src/func_environ.rs +++ b/lib/environ/src/func_environ.rs @@ -59,6 +59,9 @@ pub struct FuncEnvironment<'module_environment> { /// The Cranelift global holding the vmctx address. vmctx: Option, + /// The Cranelift global holding the base address of the signature IDs vector. + signature_ids_base: Option, + /// The Cranelift global holding the base address of the imported functions table. imported_functions_base: Option, @@ -80,9 +83,6 @@ pub struct FuncEnvironment<'module_environment> { /// The Cranelift global holding the base address of the globals vector. globals_base: Option, - /// The Cranelift global holding the base address of the signature IDs vector. - signature_ids_base: Option, - /// The external function declaration for implementing wasm's `memory.size` /// for locally-defined 32-bit memories. memory32_size_extfunc: Option, @@ -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, diff --git a/lib/environ/src/vmoffsets.rs b/lib/environ/src/vmoffsets.rs index e0fc8abbde..3fc1974de4 100644 --- a/lib/environ/src/vmoffsets.rs +++ b/lib/environ/src/vmoffsets.rs @@ -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 } diff --git a/lib/runtime/src/vmcontext.rs b/lib/runtime/src/vmcontext.rs index c78baf9786..4b94f8cff2 100644 --- a/lib/runtime/src/vmcontext.rs +++ b/lib/runtime/src/vmcontext.rs @@ -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::(), 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()) ); } }