obkrnl/uma/
x86_64.rs

1use super::Alloc;
2use crate::vm::{PageFlags, Vm};
3use core::sync::atomic::{AtomicUsize, Ordering};
4
5/// See `uma_small_alloc` on the Orbis for a reference.
6///
7/// # Reference offsets
8/// | Version | Offset |
9/// |---------|--------|
10/// |PS4 11.00|0x22FD70|
11pub fn small_alloc(vm: &Vm, flags: Alloc) {
12    // TODO: Figure out the name of this static variable. Also the Orbis does not use atomic
13    // operation here.
14    static UNK: AtomicUsize = AtomicUsize::new(0);
15
16    // TODO: Refactor this for readability.
17    let req = ((((u32::from(flags) & 0x100) >> 2) - (u32::from((u32::from(flags) & 0x401) == 1))
18        + 0x22)
19        | 0x100)
20        .into();
21    let page = loop {
22        match vm.alloc_page(None, UNK.fetch_add(1, Ordering::Relaxed), req) {
23            Some(v) => break v,
24            None => todo!(),
25        }
26    };
27
28    // TODO: The Orbis set unknown field on vm_page here.
29    let ps = page.state.lock();
30
31    if flags.has_any(Alloc::Zero) && !ps.flags.has_any(PageFlags::Zero) {
32        todo!()
33    }
34
35    todo!()
36}