From fb99ec7e6de04373507b7c4ee68fd8fe548f5e1a Mon Sep 17 00:00:00 2001 From: ticki <ticki@users.noreply.github.com> Date: Sun, 14 Aug 2016 19:21:21 +0200 Subject: [PATCH] Strongly typed virtual/physical memory seperation. This minicommit introduces two newtpyes, `Physical` and `Virtual`, respectively. These serves as a way to segregate the different forms of addresses to avoid the issues we had in the old kernel. --- arch/x86_64/mod.rs | 2 ++ arch/x86_64/physical.rs | 11 +++++++++++ paging/mod.rs | 6 ++++++ 3 files changed, 19 insertions(+) create mode 100644 arch/x86_64/physical.rs create mode 100644 paging/mod.rs diff --git a/arch/x86_64/mod.rs b/arch/x86_64/mod.rs index f9239d23..d5180fc0 100644 --- a/arch/x86_64/mod.rs +++ b/arch/x86_64/mod.rs @@ -23,3 +23,5 @@ pub mod serial; /// Task state segment. pub mod tss; + +pub mod physical; diff --git a/arch/x86_64/physical.rs b/arch/x86_64/physical.rs new file mode 100644 index 00000000..8885cd1c --- /dev/null +++ b/arch/x86_64/physical.rs @@ -0,0 +1,11 @@ +//! Typestrong address segregation. + +/// A physical address in memory. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct Physical { + /// The position. + /// + /// Note that we do not use a pointer here to avoid simple mistakes where the programmer + /// confuse virtual and physical. + pub inner: u64, +} diff --git a/paging/mod.rs b/paging/mod.rs new file mode 100644 index 00000000..f0179621 --- /dev/null +++ b/paging/mod.rs @@ -0,0 +1,6 @@ +/// A newtype representing a virtual address. +#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] +pub struct Virtual { + /// The inner value. + pub inner: usize, +} -- GitLab