Next Generation WASM Microkernel Operating System
at trap_handler 33 lines 1.2 kB view raw
1// Copyright 2025 Jonas Kruckenberg 2// 3// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or 4// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or 5// http://opensource.org/licenses/MIT>, at your option. This file may not be 6// copied, modified, or distributed except according to those terms. 7 8use crate::wasm::store::{StoreOpaque, Stored}; 9use crate::wasm::types::MemoryType; 10use crate::wasm::vm::{ExportedMemory, VMMemoryImport, VmPtr}; 11 12#[derive(Clone, Copy, Debug)] 13pub struct Memory(Stored<ExportedMemory>); 14 15impl Memory { 16 pub fn ty(self, store: &StoreOpaque) -> MemoryType { 17 let export = &store[self.0]; 18 MemoryType::from_wasm_memory(&export.memory) 19 } 20 21 pub(super) fn from_exported_memory(store: &mut StoreOpaque, export: ExportedMemory) -> Self { 22 let stored = store.add_memory(export); 23 Self(stored) 24 } 25 pub(super) fn as_vmmemory_import(self, store: &mut StoreOpaque) -> VMMemoryImport { 26 let export = &store[self.0]; 27 VMMemoryImport { 28 from: VmPtr::from(export.definition), 29 vmctx: VmPtr::from(export.vmctx), 30 index: export.index, 31 } 32 } 33}