Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VmIo for smart pointers to VmIo #199

Closed
tatetian opened this issue May 1, 2023 · 1 comment
Closed

Implement VmIo for smart pointers to VmIo #199

tatetian opened this issue May 1, 2023 · 1 comment
Assignees

Comments

@tatetian
Copy link
Contributor

tatetian commented May 1, 2023

Pointers to VmIo, e.g., &Vmar, Box<Mmio>, and Arc<Vmo>, should also be considered as VmIo. This can be achieved by providing the following blanket implementations for Vmio trait.

// Need to import inherit_methods_macro crate from Occlum.
// https://github.com/occlum/occlum/tree/1.0.0-preview/src/libos/crates/inherit-methods-macro
use inherit_methods_macro::inherit_methods;

#[inherit_methods(from = "(**self)")]
impl<T: Vmio> Vmio for &T {
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T>;
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>;
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>;
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>;
}

// Need to add the following blanket implementations for Vmio
#[inherit_methods(from = "(**self)")]
impl<T: Vmio> Vmio for &mut T {
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T>;
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>;
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>;
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>;
}

// Need to add the following blanket implementations for Vmio
#[inherit_methods(from = "(**self)")]
impl<T: Vmio> Vmio for Box<T> {
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T>;
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>;
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>;
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>;
}

// Need to add the following blanket implementations for Vmio
#[inherit_methods(from = "(**self)")]
impl<T: Vmio> Vmio for Arc<T> {
    fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()>;
    fn read_val<T: Pod>(&self, offset: usize) -> Result<T>;
    fn read_slice<T: Pod>(&self, offset: usize, slice: &mut [T]) -> Result<()>;
    fn write_bytes(&self, offset: usize, buf: &[u8]) -> Result<()>;
    fn write_val<T: Pod>(&self, offset: usize, new_val: &T) -> Result<()>;
    fn write_slice<T: Pod>(&self, offset: usize, slice: &[T]) -> Result<()>;
}
@tatetian tatetian changed the title Implement Vmio for smart pointers to VmIo Implement VmIo for smart pointers to VmIo May 5, 2023
@sdww0 sdww0 self-assigned this May 11, 2023
@tatetian
Copy link
Contributor Author

tatetian commented Jun 1, 2023

Done

@tatetian tatetian closed this as completed Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants