From 6267f8449d2c45f3f3097208d056a02238f2bbf3 Mon Sep 17 00:00:00 2001 From: Paul Pan Date: Mon, 8 Apr 2024 22:59:32 +0800 Subject: [PATCH] feat: move vspace into lib --- kernel/src/vspace/paging/mod.rs | 9 --- lib/vspace/Cargo.lock | 79 +++++++++++++++++++ lib/vspace/Cargo.toml | 13 +++ {kernel/src/vspace => lib/vspace/src}/addr.rs | 2 +- lib/vspace/src/lib.rs | 9 +++ .../vspace => lib/vspace/src}/paging/entry.rs | 2 +- lib/vspace/src/paging/mod.rs | 5 ++ .../vspace => lib/vspace/src}/paging/table.rs | 4 +- 8 files changed, 111 insertions(+), 12 deletions(-) delete mode 100644 kernel/src/vspace/paging/mod.rs create mode 100644 lib/vspace/Cargo.lock create mode 100644 lib/vspace/Cargo.toml rename {kernel/src/vspace => lib/vspace/src}/addr.rs (99%) create mode 100644 lib/vspace/src/lib.rs rename {kernel/src/vspace => lib/vspace/src}/paging/entry.rs (95%) create mode 100644 lib/vspace/src/paging/mod.rs rename {kernel/src/vspace => lib/vspace/src}/paging/table.rs (93%) diff --git a/kernel/src/vspace/paging/mod.rs b/kernel/src/vspace/paging/mod.rs deleted file mode 100644 index f06e8cb..0000000 --- a/kernel/src/vspace/paging/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -mod entry; -mod table; - -pub use crate::arch::vspace::{Entry, Table}; -pub use entry::*; -pub use table::*; - -assert_impl_all!(Entry: EntryOps); -assert_impl_all!(Table: TableOps); diff --git a/lib/vspace/Cargo.lock b/lib/vspace/Cargo.lock new file mode 100644 index 0000000..5233fc9 --- /dev/null +++ b/lib/vspace/Cargo.lock @@ -0,0 +1,79 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "autocfg" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" + +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "num-derive" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed3955f1a9c7c0c15e092f9c887db08b1fc683305fdf6eb6684f22555355e202" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "num-traits" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "proc-macro2" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "syn" +version = "2.0.58" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "vspace" +version = "0.1.0" +dependencies = [ + "bitflags", + "num-derive", + "num-traits", +] diff --git a/lib/vspace/Cargo.toml b/lib/vspace/Cargo.toml new file mode 100644 index 0000000..2000d3f --- /dev/null +++ b/lib/vspace/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "vspace" +version = "0.1.0" +edition = "2021" + +[features] +default = [] +legacy = [] + +[dependencies] +bitflags = "2.4" +num-derive = "0.4" +num-traits = { version = "0.2", default-features = false } diff --git a/kernel/src/vspace/addr.rs b/lib/vspace/src/addr.rs similarity index 99% rename from kernel/src/vspace/addr.rs rename to lib/vspace/src/addr.rs index 8cc129f..9e75c03 100644 --- a/kernel/src/vspace/addr.rs +++ b/lib/vspace/src/addr.rs @@ -1,6 +1,6 @@ use core::fmt::*; use core::hash::*; -use core::iter::Step; +use core::iter::*; use core::num::*; use core::ops::*; diff --git a/lib/vspace/src/lib.rs b/lib/vspace/src/lib.rs new file mode 100644 index 0000000..b9a2f96 --- /dev/null +++ b/lib/vspace/src/lib.rs @@ -0,0 +1,9 @@ +#![cfg_attr(not(test), no_std)] +#![feature(const_mut_refs)] +#![feature(step_trait)] + +#[macro_use] +extern crate num_derive; + +pub mod addr; +pub mod paging; diff --git a/kernel/src/vspace/paging/entry.rs b/lib/vspace/src/paging/entry.rs similarity index 95% rename from kernel/src/vspace/paging/entry.rs rename to lib/vspace/src/paging/entry.rs index b350cb6..ad49d5a 100644 --- a/kernel/src/vspace/paging/entry.rs +++ b/lib/vspace/src/paging/entry.rs @@ -1,4 +1,4 @@ -use crate::vspace::addr::PhysAddr; +use crate::addr::PhysAddr; use bitflags::bitflags; use core::fmt::Debug; diff --git a/lib/vspace/src/paging/mod.rs b/lib/vspace/src/paging/mod.rs new file mode 100644 index 0000000..7379868 --- /dev/null +++ b/lib/vspace/src/paging/mod.rs @@ -0,0 +1,5 @@ +mod entry; +mod table; + +pub use entry::*; +pub use table::*; diff --git a/kernel/src/vspace/paging/table.rs b/lib/vspace/src/paging/table.rs similarity index 93% rename from kernel/src/vspace/paging/table.rs rename to lib/vspace/src/paging/table.rs index 3d1993c..959425d 100644 --- a/kernel/src/vspace/paging/table.rs +++ b/lib/vspace/src/paging/table.rs @@ -1,5 +1,5 @@ use super::{EntryOps, MapAttr}; -use crate::vspace::addr::{PhysAddr, VirtAddr}; +use crate::addr::{PhysAddr, VirtAddr}; use core::fmt::Debug; #[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Eq, FromPrimitive, ToPrimitive)] @@ -51,6 +51,8 @@ pub trait TableOps: Debug { type Entry: EntryOps; const MAX_PAGE_SIZE: TableLevel; + /// # Safety + /// `location` must be a page-aligned virtual address and will not be dropped. unsafe fn new(location: VirtAddr) -> &'static mut Self; fn map(&mut self, from: VirtAddr, to: PhysAddr, attr: MapAttr, level: TableLevel)