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    }
32}
33
34impl const Clone for PageFlags {
35    /// Clones the page flags by copying the underlying integer.
36    fn clone(&self) -> Self {
37        Self(self.0)
38    }
39}
40
41impl From<usize> for PageFlags {
42    /// Converts a `usize` value into a `PageFlags` instance.
43    ///
44    /// # Safety
45    /// This transmutes the integer representation directly. The caller must
46    /// ensure that the `usize` contains a valid bit pattern for `PageFlags`.
47    fn from(value: usize) -> Self {
48        * unsafe {
49            core::mem::transmute::<&usize, &Self>(&value)
50        }
51    }
52}
53
54impl faces::AbsFlags for PageFlags {}