xen/foreignmemory/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
mod handle;
pub use self::handle::XenForeignMemoryHandle;

mod mapped;
use std::rc::Rc;

pub use self::mapped::XenForeignMemoryMapped;
use crate::{XenDomainId, XenError};

bitflags::bitflags! {
    #[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
    pub struct XenForeignMemoryProtection: i32 {
        const READ = libc::PROT_READ;
        const WRITE = libc::PROT_WRITE;
        const EXECUTE = libc::PROT_EXEC;
    }
}

#[derive(Debug, Clone)]
pub struct XenForeignMemory {
    pub(crate) handle: Rc<XenForeignMemoryHandle>,
}

impl XenForeignMemory {
    pub fn new() -> Result<Self, XenError> {
        Ok(Self {
            handle: Rc::new(XenForeignMemoryHandle::new()?),
        })
    }

    pub fn map(
        &self,
        domain_id: XenDomainId,
        protection: XenForeignMemoryProtection,
        arr: &[u64],
        err: Option<&mut [i32]>,
    ) -> Result<XenForeignMemoryMapped, XenError> {
        XenForeignMemoryMapped::new(self.clone(), domain_id, protection, arr, err)
    }
}