Implement VmIo for smart pointers to VmIo

This commit is contained in:
Yuke Peng
2023-05-22 07:08:08 -07:00
committed by Tate, Hongliang Tian
parent 6f321ad7b7
commit 358f44b3c0
2 changed files with 22 additions and 0 deletions

View File

@ -17,6 +17,7 @@ intrusive-collections = "0.9.5"
log = "0.4" log = "0.4"
lazy_static = { version = "1.0", features = ["spin_no_std"] } lazy_static = { version = "1.0", features = ["spin_no_std"] }
trapframe = { git = "https://github.com/sdww0/trapframe-rs", rev = "4234db5" } 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] [target.x86_64-custom.dependencies]
limine = { version = "0.1.10", features = ["into-uuid"] } limine = { version = "0.1.10", features = ["into-uuid"] }

View File

@ -1,6 +1,8 @@
use crate::prelude::*; use crate::prelude::*;
use pod::Pod; use pod::Pod;
use inherit_methods_macro::inherit_methods;
/// A trait that enables reading/writing data from/to a VM object, /// A trait that enables reading/writing data from/to a VM object,
/// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`. /// e.g., `VmSpace`, `VmFrameVec`, and `VmFrame`.
/// ///
@ -62,3 +64,22 @@ pub trait VmIo: Send + Sync {
self.write_bytes(offset, buf) self.write_bytes(offset, buf)
} }
} }
macro_rules! impl_vmio_pointer {
($typ:ty,$from:tt) => {
#[inherit_methods(from = $from)]
impl<T: VmIo> VmIo for $typ {
fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
fn read_val<F: Pod>(&self, offset: usize) -> Result<F>;
fn read_slice<F: Pod>(&self, offset: usize, slice: &mut [F]) -> Result<()>;
fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;
fn write_val<F: Pod>(&self, offset: usize, new_val: &F) -> Result<()>;
fn write_slice<F: Pod>(&self, offset: usize, slice: &[F]) -> Result<()>;
}
};
}
impl_vmio_pointer!(&T, "(**self)");
impl_vmio_pointer!(&mut T, "(**self)");
impl_vmio_pointer!(Box<T>, "(**self)");
impl_vmio_pointer!(Arc<T>, "(**self)");