Skip to content

Commit

Permalink
Mem: Add check if an addr is within the kernel's address range
Browse files Browse the repository at this point in the history
  • Loading branch information
corigan01 committed Jan 24, 2025
1 parent 45c79b1 commit 8fadee2
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions crates/mem/src/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWA

use core::marker::PhantomData;

/// The kernel start Virtual address
#[cfg(target_pointer_width = "64")]
pub const KERNEL_ADDR_START: VirtAddr = VirtAddr::new(0xffffffff80000000);

/// A trait to enfore structs to be aligned
pub trait AlignmentTo: Clone + Copy {}

Expand Down Expand Up @@ -371,6 +375,13 @@ macro_rules! make_addr {
};
}

impl<Align: AlignmentTo> VirtAddr<Align> {
/// Check if this virtual address is within the kernel
pub const fn is_kernel_addr(&self) -> bool {
self.addr() >= KERNEL_ADDR_START.addr()

Check failure on line 381 in crates/mem/src/addr.rs

View workflow job for this annotation

GitHub Actions / Build OS

cannot find value `KERNEL_ADDR_START` in this scope

Check failure on line 381 in crates/mem/src/addr.rs

View workflow job for this annotation

GitHub Actions / Build OS

cannot find value `KERNEL_ADDR_START` in this scope

Check failure on line 381 in crates/mem/src/addr.rs

View workflow job for this annotation

GitHub Actions / Build OS

cannot find value `KERNEL_ADDR_START` in this scope
}
}

make_addr! {
/// A structure safely repr a ptr to physical memory.
///
Expand Down

0 comments on commit 8fadee2

Please sign in to comment.