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
41
42
43
44
45
46
use super::{convert_codes_to_result, Syscall};
use crate::{
    arch::syscall::raw_syscall,
    kso::{KactionCmd, KactionError, KactionFlags, KactionValue},
    object::ObjID,
};

/// Execute a kaction on an object.
pub fn sys_kaction(
    cmd: KactionCmd,
    id: Option<ObjID>,
    arg: u64,
    arg2: u64,
    flags: KactionFlags,
) -> Result<KactionValue, KactionError> {
    let (hi, lo) = id.map_or((0, 0), |id| id.split());
    let (code, val) = unsafe {
        raw_syscall(
            Syscall::Kaction,
            &[cmd.into(), hi, lo, arg, flags.bits(), arg2],
        )
    };
    convert_codes_to_result(
        code,
        val,
        |c, _| c == 0,
        |c, v| KactionValue::from((c, v)),
        |_, v| KactionError::from(v),
    )
}

#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Ord, Eq)]
#[repr(C)]
pub struct PinnedPage {
    phys: u64,
}

impl PinnedPage {
    pub fn new(phys: u64) -> Self {
        Self { phys }
    }

    pub fn physical_address(&self) -> u64 {
        self.phys
    }
}