diff --git a/framework/jinux-frame/Cargo.toml b/framework/jinux-frame/Cargo.toml index 025c18833..5b517b1c1 100644 --- a/framework/jinux-frame/Cargo.toml +++ b/framework/jinux-frame/Cargo.toml @@ -17,6 +17,7 @@ intrusive-collections = "0.9.5" log = "0.4" lazy_static = { version = "1.0", features = ["spin_no_std"] } trapframe = { git = "https://github.com/sdww0/trapframe-rs", rev = "4234db5" } +inherit-methods-macro = { git = "https://github.com/occlum/occlum", branch = "1.0.0-preview" } [target.x86_64-custom.dependencies] limine = { version = "0.1.10", features = ["into-uuid"] } diff --git a/framework/jinux-frame/src/vm/io.rs b/framework/jinux-frame/src/vm/io.rs index 870d16de2..f252defb7 100644 --- a/framework/jinux-frame/src/vm/io.rs +++ b/framework/jinux-frame/src/vm/io.rs @@ -1,6 +1,8 @@ use crate::prelude::*; use pod::Pod; +use inherit_methods_macro::inherit_methods; + /// A trait that enables reading/writing data from/to a VM object, /// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`. /// @@ -62,3 +64,22 @@ pub trait VmIo: Send + Sync { self.write_bytes(offset, buf) } } + +macro_rules! impl_vmio_pointer { + ($typ:ty,$from:tt) => { + #[inherit_methods(from = $from)] + impl VmIo for $typ { + fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>; + fn read_val(&self, offset: usize) -> Result; + fn read_slice(&self, offset: usize, slice: &mut [F]) -> Result<()>; + fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>; + fn write_val(&self, offset: usize, new_val: &F) -> Result<()>; + fn write_slice(&self, offset: usize, slice: &[F]) -> Result<()>; + } + }; +} + +impl_vmio_pointer!(&T, "(**self)"); +impl_vmio_pointer!(&mut T, "(**self)"); +impl_vmio_pointer!(Box, "(**self)"); +impl_vmio_pointer!(Arc, "(**self)");