Skip to main content

faces_pfm/
flags.rs

1bitflags::bitflags! {
2    /// Page frame status flags.
3    ///
4    /// These flags track the state of a physical page frame, such as whether it is
5    /// locked, dirty, up-to-date, part of the LRU list, etc. They are used by the
6    /// page frame manager and compatible with the `faces::AbsFlags` trait.
7    #[derive(Debug, Copy, Default, Eq, PartialEq)]
8    pub struct PageFlags: u16 {
9        /// Page is locked and cannot be evicted or moved.
10        const LOCKED   = 1 << 0;
11        /// Page has been written to (needs flushing to backing store).
12        const DIRTY    = 1 << 1;
13        /// Page content is up-to-date with its backing store.
14        const UPTODATE = 1 << 2;
15        /// Page is on the LRU (least recently used) list.
16        const LRU      = 1 << 3;
17        /// Page is a small (order‑0) allocation.
18        const SMALL    = 1 << 4;
19        /// Page is part of a compound page (e.g., huge page).
20        const COMPOUND = 1 << 5;
21        /// Page is in the swap cache.
22        const SWAPCACHE= 1 << 6;
23        /// Page is currently being written back to disk.
24        const WRITEBACK= 1 << 7;
25        /// Page is used as a page table.
26        const PAGETABLE= 1 << 8;
27        /// Page belongs to a file mapping.
28        const FILE     = 1 << 9;
29        /// Page is reserved (e.g., used by kernel or unavailable).
30        const RESERVED = 1 << 10;
31        /// Page is head of linked list
32        const HEAD = 1 << 11;
33    }
34}
35
36impl const Clone for PageFlags {
37    /// Clones the page flags by copying the underlying integer.
38    fn clone(&self) -> Self {
39        Self(self.0)
40    }
41}
42
43impl From<usize> for PageFlags {
44    /// Converts a `usize` value into a `PageFlags` instance.
45    ///
46    /// # Safety
47    /// This transmutes the integer representation directly. The caller must
48    /// ensure that the `usize` contains a valid bit pattern for `PageFlags`.
49    fn from(value: usize) -> Self {
50        * unsafe {
51            core::mem::transmute::<&usize, &Self>(&value)
52        }
53    }
54}
55
56impl faces::AbsFlags for PageFlags {}