Nothing to see here, move along
1use crate::cap::pool::POOL;
2use crate::cap::table::Rights;
3use crate::proc::PROCESSES;
4use crate::proc::context::CpuContext;
5
6use lancer_core::object_tag::ObjectTag;
7
8use super::{SyscallResult, try_syscall};
9
10pub fn sys_untyped_retype(ctx: &mut CpuContext) {
11 let pid = crate::arch::syscall::current_pid();
12 let untyped_cap_addr = ctx.rdi;
13 let obj_type = ctx.rsi;
14 let size_bits = ctx.rdx;
15 let dest_slot_base = ctx.r10;
16 let count = ctx.r8;
17
18 let tag = try_syscall!(ctx, ObjectTag::try_from(obj_type));
19 let size_bits_u8 = try_syscall!(ctx, super::u8_from_reg(size_bits));
20 let count_u32 = try_syscall!(ctx, super::u32_from_reg(count));
21
22 let mut ptable = PROCESSES.lock();
23 let (cnode_id, cnode_gen, depth, gv, gb) =
24 try_syscall!(ctx, crate::cap::cnode::cnode_coords(pid, &ptable));
25
26 let mut pool = POOL.lock_after(&ptable);
27
28 let untyped_cap = try_syscall!(
29 ctx,
30 crate::cap::cnode::resolve_and_validate(
31 &pool,
32 cnode_id,
33 cnode_gen,
34 untyped_cap_addr,
35 depth,
36 gv,
37 gb,
38 ObjectTag::Untyped,
39 Rights::REVOKE,
40 )
41 );
42
43 let untyped_oid = untyped_cap.phys();
44 let untyped_gen = untyped_cap.generation();
45
46 let ptable_arg = match tag {
47 ObjectTag::Process => Some(&mut *ptable),
48 _ => None,
49 };
50
51 let result = crate::cap::retype::kernel_retype(
52 &mut pool,
53 ptable_arg,
54 untyped_oid,
55 untyped_gen,
56 tag,
57 size_bits_u8,
58 cnode_id,
59 cnode_gen,
60 dest_slot_base,
61 depth,
62 gv,
63 gb,
64 count_u32,
65 );
66
67 ctx.rax = match result {
68 Ok(()) => SyscallResult::ok().raw(),
69 Err(e) => SyscallResult::error(e).raw(),
70 };
71}