/// Initializes a new execution state for a canister.
///
/// The wasm_binary is validated and instrumented to detect instrumentation
/// errors however just the validated binary is stored.  The expectation is
/// that the binary will be instrumented before compiling.  This is done
/// to support IC upgrades where the instrumentation changes.
Initializes a new execution state for a canister.
The wasm_binary is validated and instrumented to detect instrumentation
errors however just the validated binary is stored.  The expectation is
that the binary will be instrumented before compiling.  This is done
to support IC upgrades where the instrumentation changes.
Initializes a new execution state for a canister . The wasm_binary is validated and instrumented to detect instrumentation errors however just the validated binary is stored . The expectation is that the binary will be instrumented before compiling . This is done to support IC upgrades where the instrumentation changes .
pub fn new(
        wasm_binary: Vec<u8>,
        canister_root: PathBuf,
        wasm_validation_config: WasmValidationLimits,
    ) -> HypervisorResult<Self> {
        let wasm_binary = BinaryEncodedWasm::new(wasm_binary);
        ic_wasm_utils::validation::validate_wasm_binary(&wasm_binary, wasm_validation_config)?;
        let output = instrument(&wasm_binary, &InstructionCostTable::new())?;
        // Get all exported methods that are relevant to the IC.
        // Methods relevant to the IC are:
        //     - Queries (e.g. canister_query ___)
        //     - Updates (e.g. canister_update ___)
        //     - System methods (e.g. canister_init)
        // Other methods are assumed to be private to the module and are ignored.
        let exports = output
            .exports
            .iter()
            .filter_map(|export| WasmMethod::try_from(export.to_string()).ok())
            .collect();
        let mut page_map = PageMap::default();
        page_map.update(data_to_page_delta(output.data));
        let cow_mem_mgr = Arc::new(CowMemoryManagerImpl::open_readwrite(canister_root.clone()));
        if cow_state_feature::is_enabled(cow_state_feature::cow_state) {
            let mapped_state = cow_mem_mgr.get_map();
            let mut updated_pages = Vec::new();
            for i in page_map.host_pages_iter() {
                let page_idx = i.0;
                updated_pages.push(page_idx.get());
                mapped_state.update_heap_page(page_idx.get(), page_map.get_page(page_idx));
            }
            mapped_state.soft_commit(&updated_pages);
        }
        let session_nonce = None;
        let execution_state = ExecutionState {
            canister_root,
            session_nonce,
            wasm_binary,
            exports,
            page_map,
            embedder_cache: None,
            exported_globals: vec![],
            heap_size: NumWasmPages::from(0),
            last_executed_round: ExecutionRound::from(0),
            cow_mem_mgr,
            mapped_state: None,
        };
        Ok(execution_state)
    }
pub fn new ( wasm_binary : Vec < u8 > , canister_root : PathBuf , wasm_validation_config : WasmValidationLimits , ) -> HypervisorResult < Self > { let wasm_binary = BinaryEncodedWasm :: new ( wasm_binary ) ; ic_wasm_utils :: validation :: validate_wasm_binary ( & wasm_binary , wasm_validation_config ) ? ; let output = instrument ( & wasm_binary , & InstructionCostTable :: new ( ) ) ? ; // Get all exported methods that are relevant to the IC. // Methods relevant to the IC are: //     - Queries (e.g. canister_query ___) //     - Updates (e.g. canister_update ___) //     - System methods (e.g. canister_init) // Other methods are assumed to be private to the module and are ignored. let exports = output . exports . iter ( ) . filter_map ( | export | WasmMethod :: try_from ( export . to_string ( ) ) . ok ( ) ) . collect ( ) ; let mut page_map = PageMap :: default ( ) ; page_map . update ( data_to_page_delta ( output . data ) ) ; let cow_mem_mgr = Arc :: new ( CowMemoryManagerImpl :: open_readwrite ( canister_root . clone ( ) ) ) ; if cow_state_feature :: is_enabled ( cow_state_feature :: cow_state ) { let mapped_state = cow_mem_mgr . get_map ( ) ; let mut updated_pages = Vec :: new ( ) ; for i in page_map . host_pages_iter ( ) { let page_idx = i . 0 ; updated_pages . push ( page_idx . get ( ) ) ; mapped_state . update_heap_page ( page_idx . get ( ) , page_map . get_page ( page_idx ) ) ; } mapped_state . soft_commit ( & updated_pages ) ; } let session_nonce = None ; let execution_state = ExecutionState { canister_root , session_nonce , wasm_binary , exports , page_map , embedder_cache : None , exported_globals : vec ! [ ] , heap_size : NumWasmPages :: from ( 0 ) , last_executed_round : ExecutionRound :: from ( 0 ) , cow_mem_mgr , mapped_state : None , } ; Ok ( execution_state ) }
Initializes a new execution state for a canister.
Initializes a new execution state for a canister .
wasm_binary
Vec<u8>
canister_root
PathBuf
wasm_validation_config
WasmValidationLimits