mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
Implement VmIo for smart pointers to VmIo
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
6f321ad7b7
commit
358f44b3c0
@ -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"] }
|
||||||
|
@ -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)");
|
||||||
|
Reference in New Issue
Block a user