twizzler_abi/syscall/
kaction.rs1use twizzler_rt_abi::Result;
2
3use super::{convert_codes_to_result, twzerr, Syscall};
4use crate::{
5 arch::syscall::raw_syscall,
6 kso::{KactionCmd, KactionFlags, KactionGenericCmd, KactionValue},
7 object::ObjID,
8};
9
10pub fn sys_kaction(
12 cmd: KactionCmd,
13 id: Option<ObjID>,
14 arg: u64,
15 arg2: u64,
16 flags: KactionFlags,
17) -> Result<KactionValue> {
18 let [hi, lo] = id.map_or([0, 0], |id| id.parts());
19 let (code, val) = unsafe {
20 raw_syscall(
21 Syscall::Kaction,
22 &[cmd.into(), hi, lo, arg, flags.bits(), arg2],
23 )
24 };
25 convert_codes_to_result(
26 code,
27 val,
28 |c, _| c == 0,
29 |c, v| KactionValue::from((c, v)),
30 twzerr,
31 )
32}
33
34#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd, Ord, Eq)]
35#[repr(C)]
36pub struct PinnedPage {
37 phys: u64,
38}
39
40impl PinnedPage {
41 pub fn new(phys: u64) -> Self {
42 Self { phys }
43 }
44
45 pub fn physical_address(&self) -> u64 {
46 self.phys
47 }
48}
49
50pub fn map_pages(
51 id: Option<ObjID>,
52 obj_start: u64,
53 phys_start: u64,
54 len: u32,
55 uc: bool,
56) -> Result<()> {
57 let mut arg = phys_start;
58 if uc {
59 arg |= 1 << 63;
60 }
61 let arg2 = (len as u64) | (obj_start & 0xFFFFFFFF) << 32;
62 let obj_start_hi = (obj_start >> 32) & 0xFFFF;
63 sys_kaction(
64 KactionCmd::Generic(KactionGenericCmd::MapPhys(obj_start_hi as u16)),
65 id,
66 arg,
67 arg2,
68 KactionFlags::empty(),
69 )
70 .map(|_| ())
71}