pub fn run(&mut self, func_ref: FuncRef) -> HypervisorResult<InstanceRunResult> {
        let _alt_sig_stack = unsafe { self.signal_stack.register() };

        let result = match &func_ref {
            FuncRef::Method(wasm_method) => self.invoke_export(&wasm_method.to_string(), &[]),
            FuncRef::QueryClosure(closure) | FuncRef::UpdateClosure(closure) => self
                .instance
                .get_export(&mut self.store, "table")
                .ok_or_else(|| HypervisorError::ContractViolation("table not found".to_string()))?
                .into_table()
                .ok_or_else(|| {
                    HypervisorError::ContractViolation("export 'table' is not a table".to_string())
                })?
                .get(&mut self.store, closure.func_idx)
                .ok_or(HypervisorError::FunctionNotFound(0, closure.func_idx))?
                .funcref()
                .ok_or_else(|| {
                    HypervisorError::ContractViolation("not a function reference".to_string())
                })?
                .ok_or_else(|| {
                    HypervisorError::ContractViolation(
                        "unexpected null function reference".to_string(),
                    )
                })?
                .call(&mut self.store, &[Val::I32(closure.env as i32)])
                .map_err(wasmtime_error_to_hypervisor_error)
                .map(|boxed_slice| boxed_slice.to_vec()),
        }
        .map_err(|e| {
            self.store
                .data_mut()
                .system_api
                .get_execution_error()
                .cloned()
                .unwrap_or(e)
        });

        let dirty_pages = self.dirty_pages();
        let num_accessed_pages = self
            .memory_tracker
            .as_ref()
            .map_or(0, |tracker| tracker.lock().unwrap().num_accessed_pages());
        self.instance_stats.accessed_pages += num_accessed_pages;
        self.instance_stats.dirty_pages += dirty_pages.len();

        let stable_memory_dirty_pages: Vec<_> = self
            .store
            .data()
            .system_api
            .stable_memory_dirty_pages()
            .into_iter()
            .map(|(i, p)| (i, *p))
            .collect();
        let stable_memory_size =
            NumWasmPages::from(self.store.data().system_api.stable_memory_size());
        self.instance_stats.dirty_pages += stable_memory_dirty_pages.len();

        match result {
            Ok(_) => Ok(InstanceRunResult {
                exported_globals: self.get_exported_globals(),
                dirty_pages,
                stable_memory_size,
                stable_memory_dirty_pages,
            }),
            Err(err) => Err(err),
        }
    }
/// Executes first exported method on an embedder instance, whose name
/// consists of one of the prefixes and method_name.
Executes first exported method on an embedder instance, whose name
consists of one of the prefixes and method_name.
Executes first exported method on an embedder instance whose name consists of one of the prefixes and method_name .
pub fn run(&mut self, func_ref: FuncRef) -> HypervisorResult<InstanceRunResult> {
        let _alt_sig_stack = unsafe { self.signal_stack.register() };
        let result = match &func_ref {
            FuncRef::Method(wasm_method) => self.invoke_export(&wasm_method.to_string(), &[]),
            FuncRef::QueryClosure(closure) | FuncRef::UpdateClosure(closure) => self
                .instance
                .get_export(&mut self.store, "table")
                .ok_or_else(|| HypervisorError::ContractViolation("table not found".to_string()))?
                .into_table()
                .ok_or_else(|| {
                    HypervisorError::ContractViolation("export 'table' is not a table".to_string())
                })?
                .get(&mut self.store, closure.func_idx)
                .ok_or(HypervisorError::FunctionNotFound(0, closure.func_idx))?
                .funcref()
                .ok_or_else(|| {
                    HypervisorError::ContractViolation("not a function reference".to_string())
                })?
                .ok_or_else(|| {
                    HypervisorError::ContractViolation(
                        "unexpected null function reference".to_string(),
                    )
                })?
                .call(&mut self.store, &[Val::I32(closure.env as i32)])
                .map_err(wasmtime_error_to_hypervisor_error)
                .map(|boxed_slice| boxed_slice.to_vec()),
        }
        .map_err(|e| {
            self.store
                .data_mut()
                .system_api
                .get_execution_error()
                .cloned()
                .unwrap_or(e)
        });
        let dirty_pages = self.dirty_pages();
        let num_accessed_pages = self
            .memory_tracker
            .as_ref()
            .map_or(0, |tracker| tracker.lock().unwrap().num_accessed_pages());
        self.instance_stats.accessed_pages += num_accessed_pages;
        self.instance_stats.dirty_pages += dirty_pages.len();
        let stable_memory_dirty_pages: Vec<_> = self
            .store
            .data()
            .system_api
            .stable_memory_dirty_pages()
            .into_iter()
            .map(|(i, p)| (i, *p))
            .collect();
        let stable_memory_size =
            NumWasmPages::from(self.store.data().system_api.stable_memory_size());
        self.instance_stats.dirty_pages += stable_memory_dirty_pages.len();
        match result {
            Ok(_) => Ok(InstanceRunResult {
                exported_globals: self.get_exported_globals(),
                dirty_pages,
                stable_memory_size,
                stable_memory_dirty_pages,
            }),
            Err(err) => Err(err),
        }
    }
pub fn run ( & mut self , func_ref : FuncRef ) -> HypervisorResult < InstanceRunResult > { let _alt_sig_stack = unsafe { self . signal_stack . register ( ) } ; let result = match & func_ref { FuncRef :: Method ( wasm_method ) => self . invoke_export ( & wasm_method . to_string ( ) , & [ ] ) , FuncRef :: QueryClosure ( closure ) | FuncRef :: UpdateClosure ( closure ) => self . instance . get_export ( & mut self . store , " " ) . ok_or_else ( | | HypervisorError :: ContractViolation ( " " . to_string ( ) ) ) ? . into_table ( ) . ok_or_else ( | | { HypervisorError :: ContractViolation ( " " . to_string ( ) ) } ) ? . get ( & mut self . store , closure . func_idx ) . ok_or ( HypervisorError :: FunctionNotFound ( 0 , closure . func_idx ) ) ? . funcref ( ) . ok_or_else ( | | { HypervisorError :: ContractViolation ( " " . to_string ( ) ) } ) ? . ok_or_else ( | | { HypervisorError :: ContractViolation ( " " . to_string ( ) , ) } ) ? . call ( & mut self . store , & [ Val :: I32 ( closure . env as i32 ) ] ) . map_err ( wasmtime_error_to_hypervisor_error ) . map ( | boxed_slice | boxed_slice . to_vec ( ) ) , } . map_err ( | e | { self . store . data_mut ( ) . system_api . get_execution_error ( ) . cloned ( ) . unwrap_or ( e ) } ) ; let dirty_pages = self . dirty_pages ( ) ; let num_accessed_pages = self . memory_tracker . as_ref ( ) . map_or ( 0 , | tracker | tracker . lock ( ) . unwrap ( ) . num_accessed_pages ( ) ) ; self . instance_stats . accessed_pages += num_accessed_pages ; self . instance_stats . dirty_pages += dirty_pages . len ( ) ; let stable_memory_dirty_pages : Vec < _ > = self . store . data ( ) . system_api . stable_memory_dirty_pages ( ) . into_iter ( ) . map ( | ( i , p ) | ( i , * p ) ) . collect ( ) ; let stable_memory_size = NumWasmPages :: from ( self . store . data ( ) . system_api . stable_memory_size ( ) ) ; self . instance_stats . dirty_pages += stable_memory_dirty_pages . len ( ) ; match result { Ok ( _ ) => Ok ( InstanceRunResult { exported_globals : self . get_exported_globals ( ) , dirty_pages , stable_memory_size , stable_memory_dirty_pages , } ) , Err ( err ) => Err ( err ) , } }
Executes first exported method on an embedder instance, whose name
consists of one of the prefixes and method_name.
Executes first exported method on an embedder instance whose name consists of one of the prefixes and method_name .
&mut self
func_ref
FuncRef
&mut self
func_ref
FuncRef