faces_pfm/frame.rs
1use crate::PageFlags;
2
3/// Metadata associated with a single physical page frame.
4///
5/// This structure stores per‑frame information required by the page frame
6/// manager, such as flags, allocation order, linked list pointers for free
7/// lists, reference count, and a pointer to the kernel virtual address of
8/// the freelist header (if any). It is guaranteed to be 32‑byte aligned.
9#[derive(Debug, Default)]
10#[repr(C)]
11pub struct PageFrame {
12 /// Page state flags (locked, dirty, reserved, etc.).
13 pub flags: PageFlags,
14 /// Allocation order (2^order pages). 0 means a single 4 KiB page.
15 pub order: u8,
16 /// Index of the next page frame in a linked list (e.g., free list).
17 pub next: u32,
18 /// Index of the previous page frame in a linked list.
19 pub prev: u32,
20 /// Size class index for slab allocators (if used).
21 pub size_class: u8,
22 /// Reference count: number of users of this page frame.
23 pub rc: u16,
24 /// Kernel virtual address of the freelist header (or 0 if none).
25 pub freelist_va: usize,
26}
27
28impl PageFrame {
29 /// Creates a new, zeroed (default) page frame metadata structure.
30 ///
31 /// All fields are initialised with their default values. The `flags`
32 /// field is cloned from a zeroed instance of `F`.
33 ///
34 /// # Panics
35 /// This function is `const` and will not panic.
36 pub const fn new() -> Self {
37 Self {
38 flags: (*unsafe { core::mem::transmute::<&usize, &PageFlags>(&0) }).clone(),
39 order: 0,
40 next: 0,
41 prev: 0,
42 size_class: 0,
43 rc: 0,
44 freelist_va: 0,
45 }
46 }
47
48 /// Resets the page frame metadata to its default state.
49 ///
50 /// This is equivalent to `*self = PageFrame::new()`. After calling this,
51 /// all flags are cleared, and counters are set to zero.
52 pub fn reset(&mut self) {
53 self.flags = (*unsafe { core::mem::transmute::<&usize, &PageFlags>(&0) }).clone();
54 self.order = 0;
55 self.next = 0;
56 self.prev = 0;
57 self.freelist_va = 0;
58 self.rc = 0;
59 self.size_class = 0;
60 }
61}