unsafe fn initialize_vmctx(&mut self, module: &Module, store: StorePtr, imports: Imports) {
        assert!(std::ptr::eq(module, self.module().as_ref()));

        if let Some(store) = store.as_raw() {
            *self.interrupts() = (*store).vminterrupts();
            *self.epoch_ptr() = (*store).epoch_ptr();
            *self.externref_activations_table() = (*store).externref_activations_table().0;
            self.set_store(store);
        }

        // Initialize shared signatures
        let signatures = self.runtime_info.signature_ids();
        *self.vmctx_plus_offset(self.offsets.vmctx_signature_ids_array()) = signatures.as_ptr();

        // Initialize the built-in functions
        *self.vmctx_plus_offset(self.offsets.vmctx_builtin_functions()) =
            &VMBuiltinFunctionsArray::INIT;

        // Initialize the imports
        debug_assert_eq!(imports.functions.len(), module.num_imported_funcs);
        ptr::copy_nonoverlapping(
            imports.functions.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_functions_begin()),
            imports.functions.len(),
        );
        debug_assert_eq!(imports.tables.len(), module.num_imported_tables);
        ptr::copy_nonoverlapping(
            imports.tables.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_tables_begin()),
            imports.tables.len(),
        );
        debug_assert_eq!(imports.memories.len(), module.num_imported_memories);
        ptr::copy_nonoverlapping(
            imports.memories.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_memories_begin()),
            imports.memories.len(),
        );
        debug_assert_eq!(imports.globals.len(), module.num_imported_globals);
        ptr::copy_nonoverlapping(
            imports.globals.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_globals_begin()),
            imports.globals.len(),
        );

        // N.B.: there is no need to initialize the anyfuncs array because
        // we eagerly construct each element in it whenever asked for a
        // reference to that element. In other words, there is no state
        // needed to track the lazy-init, so we don't need to initialize
        // any state now.

        // Initialize the defined tables
        let mut ptr = self.vmctx_plus_offset(self.offsets.vmctx_tables_begin());
        for i in 0..module.table_plans.len() - module.num_imported_tables {
            ptr::write(ptr, self.tables[DefinedTableIndex::new(i)].vmtable());
            ptr = ptr.add(1);
        }

        // Initialize the defined memories
        let mut ptr = self.vmctx_plus_offset(self.offsets.vmctx_memories_begin());
        for i in 0..module.memory_plans.len() - module.num_imported_memories {
            ptr::write(ptr, self.memories[DefinedMemoryIndex::new(i)].vmmemory());
            ptr = ptr.add(1);
        }

        // Initialize the defined globals
        self.initialize_vmctx_globals(module);
    }
/// Initialize the VMContext data associated with this Instance.
///
/// The `VMContext` memory is assumed to be uninitialized; any field
/// that we need in a certain state will be explicitly written by this
/// function.
Initialize the VMContext data associated with this Instance.
The `VMContext` memory is assumed to be uninitialized; any field
that we need in a certain state will be explicitly written by this
function.
Initialize the VMContext data associated with this Instance . The ` VMContext ` memory is assumed to be uninitialized ; any field that we need in a certain state will be explicitly written by this function .
unsafe fn initialize_vmctx(&mut self, module: &Module, store: StorePtr, imports: Imports) {
        assert!(std::ptr::eq(module, self.module().as_ref()));
        if let Some(store) = store.as_raw() {
            *self.interrupts() = (*store).vminterrupts();
            *self.epoch_ptr() = (*store).epoch_ptr();
            *self.externref_activations_table() = (*store).externref_activations_table().0;
            self.set_store(store);
        }
        // Initialize shared signatures
        let signatures = self.runtime_info.signature_ids();
        *self.vmctx_plus_offset(self.offsets.vmctx_signature_ids_array()) = signatures.as_ptr();
        // Initialize the built-in functions
        *self.vmctx_plus_offset(self.offsets.vmctx_builtin_functions()) =
            &VMBuiltinFunctionsArray::INIT;
        // Initialize the imports
        debug_assert_eq!(imports.functions.len(), module.num_imported_funcs);
        ptr::copy_nonoverlapping(
            imports.functions.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_functions_begin()),
            imports.functions.len(),
        );
        debug_assert_eq!(imports.tables.len(), module.num_imported_tables);
        ptr::copy_nonoverlapping(
            imports.tables.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_tables_begin()),
            imports.tables.len(),
        );
        debug_assert_eq!(imports.memories.len(), module.num_imported_memories);
        ptr::copy_nonoverlapping(
            imports.memories.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_memories_begin()),
            imports.memories.len(),
        );
        debug_assert_eq!(imports.globals.len(), module.num_imported_globals);
        ptr::copy_nonoverlapping(
            imports.globals.as_ptr(),
            self.vmctx_plus_offset(self.offsets.vmctx_imported_globals_begin()),
            imports.globals.len(),
        );
        // N.B.: there is no need to initialize the anyfuncs array because
        // we eagerly construct each element in it whenever asked for a
        // reference to that element. In other words, there is no state
        // needed to track the lazy-init, so we don't need to initialize
        // any state now.
        // Initialize the defined tables
        let mut ptr = self.vmctx_plus_offset(self.offsets.vmctx_tables_begin());
        for i in 0..module.table_plans.len() - module.num_imported_tables {
            ptr::write(ptr, self.tables[DefinedTableIndex::new(i)].vmtable());
            ptr = ptr.add(1);
        }
        // Initialize the defined memories
        let mut ptr = self.vmctx_plus_offset(self.offsets.vmctx_memories_begin());
        for i in 0..module.memory_plans.len() - module.num_imported_memories {
            ptr::write(ptr, self.memories[DefinedMemoryIndex::new(i)].vmmemory());
            ptr = ptr.add(1);
        }
        // Initialize the defined globals
        self.initialize_vmctx_globals(module);
    }
unsafe fn initialize_vmctx ( & mut self , module : & Module , store : StorePtr , imports : Imports ) { assert ! ( std ptr eq ( module self module ( ) as_ref ( ) ) ) ; if let Some ( store ) = store . as_raw ( ) { * self . interrupts ( ) = ( * store ) . vminterrupts ( ) ; * self . epoch_ptr ( ) = ( * store ) . epoch_ptr ( ) ; * self . externref_activations_table ( ) = ( * store ) . externref_activations_table ( ) . 0 ; self . set_store ( store ) ; } // Initialize shared signatures let signatures = self . runtime_info . signature_ids ( ) ; * self . vmctx_plus_offset ( self . offsets . vmctx_signature_ids_array ( ) ) = signatures . as_ptr ( ) ; // Initialize the built-in functions * self . vmctx_plus_offset ( self . offsets . vmctx_builtin_functions ( ) ) = & VMBuiltinFunctionsArray :: INIT ; // Initialize the imports debug_assert_eq ! ( imports functions len ( ) module num_imported_funcs ) ; ptr :: copy_nonoverlapping ( imports . functions . as_ptr ( ) , self . vmctx_plus_offset ( self . offsets . vmctx_imported_functions_begin ( ) ) , imports . functions . len ( ) , ) ; debug_assert_eq ! ( imports tables len ( ) module num_imported_tables ) ; ptr :: copy_nonoverlapping ( imports . tables . as_ptr ( ) , self . vmctx_plus_offset ( self . offsets . vmctx_imported_tables_begin ( ) ) , imports . tables . len ( ) , ) ; debug_assert_eq ! ( imports memories len ( ) module num_imported_memories ) ; ptr :: copy_nonoverlapping ( imports . memories . as_ptr ( ) , self . vmctx_plus_offset ( self . offsets . vmctx_imported_memories_begin ( ) ) , imports . memories . len ( ) , ) ; debug_assert_eq ! ( imports globals len ( ) module num_imported_globals ) ; ptr :: copy_nonoverlapping ( imports . globals . as_ptr ( ) , self . vmctx_plus_offset ( self . offsets . vmctx_imported_globals_begin ( ) ) , imports . globals . len ( ) , ) ; // N.B.: there is no need to initialize the anyfuncs array because // we eagerly construct each element in it whenever asked for a // reference to that element. In other words, there is no state // needed to track the lazy-init, so we don't need to initialize // any state now. // Initialize the defined tables let mut ptr = self . vmctx_plus_offset ( self . offsets . vmctx_tables_begin ( ) ) ; for i in 0 .. module . table_plans . len ( ) - module . num_imported_tables { ptr :: write ( ptr , self . tables [ DefinedTableIndex :: new ( i ) ] . vmtable ( ) ) ; ptr = ptr . add ( 1 ) ; } // Initialize the defined memories let mut ptr = self . vmctx_plus_offset ( self . offsets . vmctx_memories_begin ( ) ) ; for i in 0 .. module . memory_plans . len ( ) - module . num_imported_memories { ptr :: write ( ptr , self . memories [ DefinedMemoryIndex :: new ( i ) ] . vmmemory ( ) ) ; ptr = ptr . add ( 1 ) ; } // Initialize the defined globals self . initialize_vmctx_globals ( module ) ; }
Initialize the VMContext data associated with this Instance.
Initialize the VMContext data associated with this Instance .
&mut self
module
&Module
store
StorePtr
imports
Imports
&mut self
module
&Module
store
StorePtr
imports
Imports