From 279e3719ff32b0674b32d05284188afc371fbd38 Mon Sep 17 00:00:00 2001 From: yanjuguang Date: Wed, 24 Apr 2024 16:47:16 +0800 Subject: [PATCH] fix CI warnings remove /dev/foo/bar change license import crates_interface,kernel_guard,handler_table,memory_addr from crates.io --- Cargo.lock | 8 + Cargo.toml | 8 - README.md | 4 + api/ruxos_posix_api/Cargo.toml | 6 +- api/ruxos_posix_api/src/lib.rs | 1 - apps/c/dl/features.txt | 2 +- apps/fs/shell/Cargo.toml | 2 +- crates/allocator/src/lib.rs | 1 - crates/crate_interface/Cargo.toml | 20 - crates/crate_interface/README.md | 38 -- crates/crate_interface/src/lib.rs | 196 --------- .../tests/test_crate_interface.rs | 43 -- crates/driver_9p/Cargo.toml | 2 +- crates/driver_display/Cargo.toml | 2 +- crates/dtb/Cargo.toml | 2 +- crates/flatten_objects/src/lib.rs | 1 - crates/handler_table/Cargo.toml | 14 - crates/handler_table/README.md | 23 - crates/handler_table/src/lib.rs | 58 --- crates/kernel_guard/Cargo.toml | 20 - crates/kernel_guard/README.md | 56 --- crates/kernel_guard/src/arch/aarch64.rs | 23 - crates/kernel_guard/src/arch/mod.rs | 23 - crates/kernel_guard/src/arch/riscv.rs | 27 -- crates/kernel_guard/src/arch/x86.rs | 29 -- crates/kernel_guard/src/lib.rs | 248 ----------- crates/memory_addr/Cargo.toml | 14 - crates/memory_addr/README.md | 20 - crates/memory_addr/src/lib.rs | 393 ------------------ crates/page_table/Cargo.toml | 2 +- crates/page_table/src/lib.rs | 1 - crates/page_table_entry/Cargo.toml | 2 +- crates/percpu/Cargo.toml | 2 +- crates/spinlock/Cargo.toml | 2 +- doc/README.md | 4 - modules/axalloc/Cargo.toml | 2 +- modules/axlog/Cargo.toml | 2 +- modules/rux9p/Cargo.toml | 2 +- modules/ruxdisplay/Cargo.toml | 2 +- modules/ruxfs/Cargo.toml | 4 +- modules/ruxfs/src/mounts.rs | 3 - modules/ruxfs/src/root.rs | 6 +- modules/ruxfs/tests/test_common/mod.rs | 9 - modules/ruxfutex/Cargo.toml | 6 +- modules/ruxhal/Cargo.toml | 8 +- modules/ruxhal/src/lib.rs | 1 - modules/ruxhal/src/platform/dummy/mod.rs | 4 +- modules/ruxruntime/Cargo.toml | 4 +- modules/ruxtask/Cargo.toml | 6 +- ulib/ruxmusl/Cargo.toml | 6 +- 50 files changed, 53 insertions(+), 1309 deletions(-) delete mode 100644 crates/crate_interface/Cargo.toml delete mode 100644 crates/crate_interface/README.md delete mode 100644 crates/crate_interface/src/lib.rs delete mode 100644 crates/crate_interface/tests/test_crate_interface.rs delete mode 100644 crates/handler_table/Cargo.toml delete mode 100644 crates/handler_table/README.md delete mode 100644 crates/handler_table/src/lib.rs delete mode 100644 crates/kernel_guard/Cargo.toml delete mode 100644 crates/kernel_guard/README.md delete mode 100644 crates/kernel_guard/src/arch/aarch64.rs delete mode 100644 crates/kernel_guard/src/arch/mod.rs delete mode 100644 crates/kernel_guard/src/arch/riscv.rs delete mode 100644 crates/kernel_guard/src/arch/x86.rs delete mode 100644 crates/kernel_guard/src/lib.rs delete mode 100644 crates/memory_addr/Cargo.toml delete mode 100644 crates/memory_addr/README.md delete mode 100644 crates/memory_addr/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b53869d52..c4fb205fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -493,6 +493,8 @@ checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" [[package]] name = "crate_interface" version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d54b79db793871881b52a1eb5dc6fd869743122e34795f12db8e183dcb6a4f28" dependencies = [ "proc-macro2", "quote", @@ -848,6 +850,8 @@ checksum = "eabb4a44450da02c90444cf74558da904edde8fb4e9035a9a6a4e15445af0bd7" [[package]] name = "handler_table" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "011878ffbfb4cbfcbd9fd799d1168a65897b0b0195fc55f9ec73d27f1685b1dd" [[package]] name = "hash32" @@ -966,6 +970,8 @@ dependencies = [ [[package]] name = "kernel_guard" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5638cc8298368ef284589ad372890c849b520cccd50567d86a77a9232e68afdc" dependencies = [ "cfg-if", "crate_interface", @@ -1065,6 +1071,8 @@ dependencies = [ [[package]] name = "memory_addr" version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91b53e2ffbb2aaf3b738bd38ddd7ca8c511e47e05cd03fc09eacb7c5fa1285e5" [[package]] name = "micromath" diff --git a/Cargo.toml b/Cargo.toml index 29f519fc3..ff52575d4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ members = [ "crates/axfs_vfs", "crates/axio", "crates/capability", - "crates/crate_interface", "crates/driver_9p", "crates/driver_block", "crates/driver_common", @@ -22,11 +21,8 @@ members = [ "crates/driver_virtio", "crates/dtb", "crates/flatten_objects", - "crates/handler_table", - "crates/kernel_guard", "crates/lazy_init", "crates/linked_list", - "crates/memory_addr", "crates/page_table", "crates/page_table_entry", "crates/percpu", @@ -71,7 +67,3 @@ lto = true [profile.reldebug] inherits = "release" debug = true - - -[patch.crates-io] -crate_interface = { path = "crates/crate_interface" } diff --git a/README.md b/README.md index 5747cf316..74f02b87a 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ RuxOS was inspired by [Unikraft](https://github.com/unikraft/unikraft) and [Arce * [x] SMP scheduling with single run queue * [x] File system * [x] Compatible with Linux apps +* [x] Dynamically loading apps * [ ] Interrupt driven device I/O * [ ] Async I/O @@ -63,6 +64,9 @@ The currently supported applications (Rust), as well as their dependent modules | [iperf](apps/c/iperf/) | alloc, paging, net, fs, blkfs, select, fp_simd | A network performance test tool | | [redis](apps/c/redis/) | alloc, paging, fp_simd, irq, multitask, fs, blkfs, net, pipe, epoll, poll, virtio-9p, rtc | A Redis server on Ruxos | | [sqlite3](apps/c/sqlite3/) | alloc, paging, fs, fp_simd, blkfs | A simple test for Sqlite3 API | +| [cpp](apps/c/cpp/) | alloc, paging, irq, multitask, fs, random-hw | C++ benchmark | +| [dl](apps/c/dl/) | paging, alloc, irq, musl, multitask, fs, pipe, poll, rtc, signal, virtio-9p | An example for dynamically loading apps | + ## Build & Run diff --git a/api/ruxos_posix_api/Cargo.toml b/api/ruxos_posix_api/Cargo.toml index b767b2d72..b62f65c7b 100644 --- a/api/ruxos_posix_api/Cargo.toml +++ b/api/ruxos_posix_api/Cargo.toml @@ -11,7 +11,7 @@ authors = [ "Shiping Yuan ", ] description = "POSIX-compatible APIs for Ruxos modules" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" repository = "https://github.com/syswonder/ruxos/tree/main/api/ruxos_posix_api" [features] @@ -52,14 +52,14 @@ axnet = { path = "../../modules/axnet", optional = true } # Other crates axio = { path = "../../crates/axio" } axerrno = { path = "../../crates/axerrno" } -memory_addr = { path = "../../crates/memory_addr" } +memory_addr = "0.1.0" static_assertions = "1.1.0" spin = { version = "0.9" } spinlock = { path = "../../crates/spinlock" } lazy_static = { version = "1.4", features = ["spin_no_std"] } flatten_objects = { path = "../../crates/flatten_objects" } page_table = { path = "../../crates/page_table" } -crate_interface = { path = "../../crates/crate_interface" } +crate_interface = "0.1.1" cfg-if = "1.0" elf = { version = "0.7", default-features = false } diff --git a/api/ruxos_posix_api/src/lib.rs b/api/ruxos_posix_api/src/lib.rs index 0a0a8debd..5bd396cee 100644 --- a/api/ruxos_posix_api/src/lib.rs +++ b/api/ruxos_posix_api/src/lib.rs @@ -13,7 +13,6 @@ #![cfg_attr(all(not(test), not(doc)), no_std)] #![feature(ip_in_core)] -#![feature(result_option_inspect)] #![feature(doc_cfg)] #![feature(doc_auto_cfg)] #![allow(clippy::missing_safety_doc)] diff --git a/apps/c/dl/features.txt b/apps/c/dl/features.txt index 0b7506227..ed120d4d3 100644 --- a/apps/c/dl/features.txt +++ b/apps/c/dl/features.txt @@ -8,4 +8,4 @@ pipe poll rtc signal -virtio-9p \ No newline at end of file +virtio-9p diff --git a/apps/fs/shell/Cargo.toml b/apps/fs/shell/Cargo.toml index 25d70a3af..069c77a3b 100644 --- a/apps/fs/shell/Cargo.toml +++ b/apps/fs/shell/Cargo.toml @@ -13,5 +13,5 @@ default = [] [dependencies] axfs_vfs = { path = "../../../crates/axfs_vfs", optional = true } axfs_ramfs = { path = "../../../crates/axfs_ramfs", optional = true } -crate_interface = { path = "../../../crates/crate_interface", optional = true } +crate_interface = { version = "0.1.1", optional = true } axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs","blkfs"], optional = true } diff --git a/crates/allocator/src/lib.rs b/crates/allocator/src/lib.rs index 8fd653b09..061c9f763 100644 --- a/crates/allocator/src/lib.rs +++ b/crates/allocator/src/lib.rs @@ -18,7 +18,6 @@ //! - [`IdAllocator`]: Used to allocate unique IDs. #![no_std] -#![feature(result_option_inspect)] #![cfg_attr(feature = "allocator_api", feature(allocator_api))] #[cfg(feature = "bitmap")] diff --git a/crates/crate_interface/Cargo.toml b/crates/crate_interface/Cargo.toml deleted file mode 100644 index 7608daea3..000000000 --- a/crates/crate_interface/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "crate_interface" -version = "0.1.1" -edition = "2021" -authors = ["Yuekai Jia "] -description = "Provides a way to define an interface (trait) in a crate, but can implement or use it in any crate." -license = "GPL-3.0-or-later OR Apache-2.0" -homepage = "https://github.com/rcore-os/arceos" -repository = "https://github.com/rcore-os/arceos/tree/main/crates/crate_interface" -documentation = "https://rcore-os.github.io/arceos/crate_interface/index.html" -keywords = ["arceos", "api", "macro"] -categories = ["development-tools::procedural-macro-helpers", "no-std"] - -[dependencies] -proc-macro2 = "1.0" -quote = "1.0" -syn = { version = "2.0", features = ["full"] } - -[lib] -proc-macro = true diff --git a/crates/crate_interface/README.md b/crates/crate_interface/README.md deleted file mode 100644 index ca910ca7c..000000000 --- a/crates/crate_interface/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# crate_interface - -[![Crates.io](https://img.shields.io/crates/v/crate_interface)](https://crates.io/crates/crate_interface) - -Provides a way to **define** an interface (trait) in a crate, but can -**implement** or **use** it in any crate. It 's usually used to solve -the problem of *circular dependencies* between crates. - -## Example - -```rust -// Define the interface -#[crate_interface::def_interface] -pub trait HelloIf { - fn hello(&self, name: &str, id: usize) -> String; -} - -// Implement the interface in any crate -struct HelloIfImpl; - -#[crate_interface::impl_interface] -impl HelloIf for HelloIfImpl { - fn hello(&self, name: &str, id: usize) -> String { - format!("Hello, {} {}!", name, id) - } -} - -// Call `HelloIfImpl::hello` in any crate -use crate_interface::call_interface; -assert_eq!( - call_interface!(HelloIf::hello("world", 123)), - "Hello, world 123!" -); -assert_eq!( - call_interface!(HelloIf::hello, "rust", 456), // another calling style - "Hello, rust 456!" -); -``` diff --git a/crates/crate_interface/src/lib.rs b/crates/crate_interface/src/lib.rs deleted file mode 100644 index 6ae5e40fd..000000000 --- a/crates/crate_interface/src/lib.rs +++ /dev/null @@ -1,196 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -#![doc = include_str!("../README.md")] -#![feature(iter_next_chunk)] - -use proc_macro::TokenStream; -use proc_macro2::Span; -use quote::{format_ident, quote}; -use syn::{Error, FnArg, ImplItem, ImplItemFn, ItemImpl, ItemTrait, TraitItem, Type}; - -fn compiler_error(err: Error) -> TokenStream { - err.to_compile_error().into() -} - -/// Define an interface. -/// -/// This attribute should be added above the definition of a trait. All traits -/// that use the attribute cannot have the same name. -/// -/// It is not necessary to define it in the same crate as the implementation, -/// but it is required that these crates are linked together. -/// -/// See the [crate-level documentation](crate) for more details. -#[proc_macro_attribute] -pub fn def_interface(attr: TokenStream, item: TokenStream) -> TokenStream { - if !attr.is_empty() { - return compiler_error(Error::new( - Span::call_site(), - "expect an empty attribute: `#[crate_interface_def]`", - )); - } - - let ast = syn::parse_macro_input!(item as ItemTrait); - let trait_name = &ast.ident; - - let mut extern_fn_list = vec![]; - for item in &ast.items { - if let TraitItem::Fn(method) = item { - let mut sig = method.sig.clone(); - let fn_name = &sig.ident; - sig.ident = format_ident!("__{}_{}", trait_name, fn_name); - sig.inputs = syn::punctuated::Punctuated::new(); - - for arg in &method.sig.inputs { - if let FnArg::Typed(_) = arg { - sig.inputs.push(arg.clone()); - } - } - - let extern_fn = quote! { - #sig; - }; - extern_fn_list.push(extern_fn); - } - } - - quote! { - #ast - extern "Rust" { - #(#extern_fn_list)* - } - } - .into() -} - -/// Implement the interface for a struct. -/// -/// This attribute should be added above the implementation of a trait for a -/// struct, and the trait must be defined with -/// [`#[def_interface]`](macro@crate::def_interface). -/// -/// It is not necessary to implement it in the same crate as the definition, but -/// it is required that these crates are linked together. -/// -/// See the [crate-level documentation](crate) for more details. -#[proc_macro_attribute] -pub fn impl_interface(attr: TokenStream, item: TokenStream) -> TokenStream { - if !attr.is_empty() { - return compiler_error(Error::new( - Span::call_site(), - "expect an empty attribute: `#[crate_interface_impl]`", - )); - } - - let mut ast = syn::parse_macro_input!(item as ItemImpl); - let trait_name = if let Some((_, path, _)) = &ast.trait_ { - &path.segments.last().unwrap().ident - } else { - return compiler_error(Error::new_spanned(ast, "expect a trait implementation")); - }; - let impl_name = if let Type::Path(path) = &ast.self_ty.as_ref() { - path.path.get_ident().unwrap() - } else { - return compiler_error(Error::new_spanned(ast, "expect a trait implementation")); - }; - - for item in &mut ast.items { - if let ImplItem::Fn(method) = item { - let (attrs, vis, sig, stmts) = - (&method.attrs, &method.vis, &method.sig, &method.block.stmts); - let fn_name = &sig.ident; - let extern_fn_name = format_ident!("__{}_{}", trait_name, fn_name).to_string(); - - let mut new_sig = sig.clone(); - new_sig.ident = format_ident!("{}", extern_fn_name); - new_sig.inputs = syn::punctuated::Punctuated::new(); - - let mut args = vec![]; - let mut has_self = false; - for arg in &sig.inputs { - match arg { - FnArg::Receiver(_) => has_self = true, - FnArg::Typed(ty) => { - args.push(ty.pat.clone()); - new_sig.inputs.push(arg.clone()); - } - } - } - - let call_impl = if has_self { - quote! { - let IMPL: #impl_name = #impl_name; - IMPL.#fn_name( #(#args),* ) - } - } else { - quote! { #impl_name::#fn_name( #(#args),* ) } - }; - - let item = quote! { - #(#attrs)* - #vis - #sig - { - { - #[export_name = #extern_fn_name] - extern "Rust" #new_sig { - #call_impl - } - } - #(#stmts)* - } - } - .into(); - *method = syn::parse_macro_input!(item as ImplItemFn); - } - } - - quote! { #ast }.into() -} - -/// Call a function in the interface. -/// -/// It is not necessary to call it in the same crate as the implementation, but -/// it is required that these crates are linked together. -/// -/// See the [crate-level documentation](crate) for more details. -#[proc_macro] -pub fn call_interface(item: TokenStream) -> TokenStream { - parse_call_interface(item) - .unwrap_or_else(|msg| compiler_error(Error::new(Span::call_site(), msg))) -} - -fn parse_call_interface(item: TokenStream) -> Result { - let mut iter = item.into_iter(); - let tt = iter - .next_chunk::<4>() - .or(Err("expect `Trait::func`"))? - .map(|t| t.to_string()); - - let trait_name = &tt[0]; - if tt[1] != ":" || tt[2] != ":" { - return Err("missing `::`".into()); - } - let fn_name = &tt[3]; - let extern_fn_name = format!("__{}_{}", trait_name, fn_name); - - let mut args = iter.map(|x| x.to_string()).collect::>().join(""); - if args.starts_with(',') { - args.remove(0); - } else if args.starts_with('(') && args.ends_with(')') { - args.remove(0); - args.pop(); - } - - let call = format!("unsafe {{ {}( {} ) }}", extern_fn_name, args); - Ok(call - .parse::() - .or(Err("expect a correct argument list"))?) -} diff --git a/crates/crate_interface/tests/test_crate_interface.rs b/crates/crate_interface/tests/test_crate_interface.rs deleted file mode 100644 index a90079e5b..000000000 --- a/crates/crate_interface/tests/test_crate_interface.rs +++ /dev/null @@ -1,43 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -use crate_interface::*; - -#[def_interface] -trait SimpleIf { - fn foo() -> u32 { - 123 - } - - /// Test comments - fn bar(&self, a: u16, b: &[u8], c: &str); -} - -struct SimpleIfImpl; - -#[impl_interface] -impl SimpleIf for SimpleIfImpl { - #[inline] - fn foo() -> u32 { - 456 - } - - /// Test comments2 - fn bar(&self, a: u16, b: &[u8], c: &str) { - println!("{} {:?} {}", a, b, c); - assert_eq!(b[1], 3); - } -} - -#[test] -fn test_crate_interface_call() { - call_interface!(SimpleIf::bar, 123, &[2, 3, 5, 7, 11], "test"); - call_interface!(SimpleIf::bar(123, &[2, 3, 5, 7, 11], "test")); - assert_eq!(call_interface!(SimpleIf::foo), 456); -} diff --git a/crates/driver_9p/Cargo.toml b/crates/driver_9p/Cargo.toml index 8c07a9808..dd56965c8 100644 --- a/crates/driver_9p/Cargo.toml +++ b/crates/driver_9p/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Zheng Wu "] description = "Common traits and types for 9p drivers" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/crates/driver_9p" diff --git a/crates/driver_display/Cargo.toml b/crates/driver_display/Cargo.toml index 5c8836802..a98048ec6 100644 --- a/crates/driver_display/Cargo.toml +++ b/crates/driver_display/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Shiping Yuan "] description = "Common traits and types for graphics device drivers" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/crates/driver_display" diff --git a/crates/dtb/Cargo.toml b/crates/dtb/Cargo.toml index 64f5e1cb7..2f65516dd 100644 --- a/crates/dtb/Cargo.toml +++ b/crates/dtb/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Leping Wang "] description = "Device tree basic operations" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/crates/dtb" diff --git a/crates/flatten_objects/src/lib.rs b/crates/flatten_objects/src/lib.rs index 25760028a..11387fb8b 100644 --- a/crates/flatten_objects/src/lib.rs +++ b/crates/flatten_objects/src/lib.rs @@ -39,7 +39,6 @@ //! ``` #![no_std] -#![feature(const_maybe_uninit_zeroed)] #![feature(maybe_uninit_uninit_array)] #![feature(const_maybe_uninit_uninit_array)] diff --git a/crates/handler_table/Cargo.toml b/crates/handler_table/Cargo.toml deleted file mode 100644 index e4ecacea9..000000000 --- a/crates/handler_table/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "handler_table" -version = "0.1.0" -edition = "2021" -authors = ["Yuekai Jia "] -description = "A lock-free table of event handlers" -license = "GPL-3.0-or-later OR Apache-2.0" -homepage = "https://github.com/rcore-os/arceos" -repository = "https://github.com/rcore-os/arceos/tree/main/crates/handler_table" -documentation = "https://rcore-os.github.io/arceos/handler_table/index.html" -keywords = ["arceos", "event", "lock-free"] -categories = ["no-std"] - -[dependencies] diff --git a/crates/handler_table/README.md b/crates/handler_table/README.md deleted file mode 100644 index 33878d1ad..000000000 --- a/crates/handler_table/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# handler_table - -[![Crates.io](https://img.shields.io/crates/v/handler_table)](https://crates.io/crates/handler_table) - -A lock-free table of event handlers. - -## Examples - -```rust -use handler_table::HandlerTable; - -static TABLE: HandlerTable<8> = HandlerTable::new(); - -TABLE.register_handler(0, || { - println!("Hello, event 0!"); -}); -TABLE.register_handler(1, || { - println!("Hello, event 1!"); -}); - -assert!(TABLE.handle(0)); // print "Hello, event 0!" -assert!(!TABLE.handle(2)); // unregistered -``` diff --git a/crates/handler_table/src/lib.rs b/crates/handler_table/src/lib.rs deleted file mode 100644 index efe992e53..000000000 --- a/crates/handler_table/src/lib.rs +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -#![no_std] -#![doc = include_str!("../README.md")] - -use core::sync::atomic::{AtomicUsize, Ordering}; - -/// The type of an event handler. -/// -/// Currently no arguments and return values are supported. -pub type Handler = fn(); - -/// A lock-free table of event handlers. -/// -/// It internally uses an array of `AtomicUsize` to store the handlers. -pub struct HandlerTable { - handlers: [AtomicUsize; N], -} - -impl HandlerTable { - /// Creates a new handler table with all entries empty. - #[allow(clippy::declare_interior_mutable_const)] - pub const fn new() -> Self { - const EMPTY: AtomicUsize = AtomicUsize::new(0); - Self { - handlers: [EMPTY; N], - } - } - - /// Registers a handler for the given index. - pub fn register_handler(&self, idx: usize, handler: Handler) -> bool { - self.handlers[idx] - .compare_exchange(0, handler as usize, Ordering::Acquire, Ordering::Relaxed) - .is_ok() - } - - /// Handles the event with the given index. - /// - /// Returns `true` if the event is handled, `false` if no handler is - /// registered for the given index. - pub fn handle(&self, idx: usize) -> bool { - let handler = self.handlers[idx].load(Ordering::Acquire); - if handler != 0 { - let handler: Handler = unsafe { core::mem::transmute(handler) }; - handler(); - true - } else { - false - } - } -} diff --git a/crates/kernel_guard/Cargo.toml b/crates/kernel_guard/Cargo.toml deleted file mode 100644 index 841470199..000000000 --- a/crates/kernel_guard/Cargo.toml +++ /dev/null @@ -1,20 +0,0 @@ -[package] -name = "kernel_guard" -version = "0.1.0" -edition = "2021" -authors = ["Yuekai Jia "] -description = "RAII wrappers to create a critical section with local IRQs or preemption disabled" -license = "GPL-3.0-or-later OR Apache-2.0" -homepage = "https://github.com/rcore-os/arceos" -repository = "https://github.com/rcore-os/arceos/tree/main/crates/kernel_guard" -documentation = "https://rcore-os.github.io/arceos/kernel_guard/index.html" -keywords = ["arceos", "synchronization", "preemption"] -categories = ["os", "no-std"] - -[features] -preempt = [] -default = [] - -[dependencies] -cfg-if = "1.0" -crate_interface = "0.1" diff --git a/crates/kernel_guard/README.md b/crates/kernel_guard/README.md deleted file mode 100644 index 4f137e084..000000000 --- a/crates/kernel_guard/README.md +++ /dev/null @@ -1,56 +0,0 @@ -# kernel_guard - -[![Crates.io](https://img.shields.io/crates/v/kernel_guard)](https://crates.io/crates/kernel_guard) - -RAII wrappers to create a critical section with local IRQs or preemption -disabled, used to implement spin locks in kernel. - -The critical section is created after the guard struct is created, and is -ended when the guard falls out of scope. - -The crate user must implement the `KernelGuardIf` trait using -[`crate_interface::impl_interface`](https://crates.io/crates/crate_interface) to provide the low-level implementantion -of how to enable/disable kernel preemption, if the feature `preempt` is -enabled. - -Available guards: - -- `NoOp`: Does nothing around the critical section. -- `IrqSave`: Disables/enables local IRQs around the critical section. -- `NoPreempt`: Disables/enables kernel preemption around the critical -section. -- `NoPreemptIrqSave`: Disables/enables both kernel preemption and local -IRQs around the critical section. - -## Crate features - -- `preempt`: Use in the preemptive system. If this feature is enabled, you -need to implement the `KernelGuardIf` trait in other crates. Otherwise -the preemption enable/disable operations will be no-ops. This feature is -disabled by default. - -## Examples - -```rust -use kernel_guard::{KernelGuardIf, NoPreempt}; - -struct KernelGuardIfImpl; - -#[crate_interface::impl_interface] -impl KernelGuardIf for KernelGuardIfImpl { - fn enable_preempt() { - // Your implementation here - } - fn disable_preempt() { - // Your implementation here - } -} - -let guard = NoPreempt::new(); -/* The critical section starts here - -Do something that requires preemption to be disabled - -The critical section ends here */ -drop(guard); -``` diff --git a/crates/kernel_guard/src/arch/aarch64.rs b/crates/kernel_guard/src/arch/aarch64.rs deleted file mode 100644 index d8fe72831..000000000 --- a/crates/kernel_guard/src/arch/aarch64.rs +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -use core::arch::asm; - -#[inline] -pub fn local_irq_save_and_disable() -> usize { - let flags: usize; - // save `DAIF` flags, mask `I` bit (disable IRQs) - unsafe { asm!("mrs {}, daif; msr daifset, #2", out(reg) flags) }; - flags -} - -#[inline] -pub fn local_irq_restore(flags: usize) { - unsafe { asm!("msr daif, {}", in(reg) flags) }; -} diff --git a/crates/kernel_guard/src/arch/mod.rs b/crates/kernel_guard/src/arch/mod.rs deleted file mode 100644 index c88782965..000000000 --- a/crates/kernel_guard/src/arch/mod.rs +++ /dev/null @@ -1,23 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -#![cfg_attr(not(target_os = "none"), allow(dead_code))] - -cfg_if::cfg_if! { - if #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] { - mod x86; - pub use self::x86::*; - } else if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { - mod riscv; - pub use self::riscv::*; - } else if #[cfg(target_arch = "aarch64")] { - mod aarch64; - pub use self::aarch64::*; - } -} diff --git a/crates/kernel_guard/src/arch/riscv.rs b/crates/kernel_guard/src/arch/riscv.rs deleted file mode 100644 index c11f7e180..000000000 --- a/crates/kernel_guard/src/arch/riscv.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -use core::arch::asm; - -/// Bit 1: Supervisor Interrupt Enable -const SIE_BIT: usize = 1 << 1; - -#[inline] -pub fn local_irq_save_and_disable() -> usize { - let flags: usize; - // clear the `SIE` bit, and return the old CSR - unsafe { asm!("csrrc {}, sstatus, {}", out(reg) flags, const SIE_BIT) }; - flags & SIE_BIT -} - -#[inline] -pub fn local_irq_restore(flags: usize) { - // restore the `SIE` bit - unsafe { asm!("csrrs x0, sstatus, {}", in(reg) flags) }; -} diff --git a/crates/kernel_guard/src/arch/x86.rs b/crates/kernel_guard/src/arch/x86.rs deleted file mode 100644 index 272b2659a..000000000 --- a/crates/kernel_guard/src/arch/x86.rs +++ /dev/null @@ -1,29 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -use core::arch::asm; - -/// Interrupt Enable Flag (IF) -const IF_BIT: usize = 1 << 9; - -#[inline] -pub fn local_irq_save_and_disable() -> usize { - let flags: usize; - unsafe { asm!("pushf; pop {}; cli", out(reg) flags) }; - flags & IF_BIT -} - -#[inline] -pub fn local_irq_restore(flags: usize) { - if flags != 0 { - unsafe { asm!("sti") }; - } else { - unsafe { asm!("cli") }; - } -} diff --git a/crates/kernel_guard/src/lib.rs b/crates/kernel_guard/src/lib.rs deleted file mode 100644 index ebe97c7ad..000000000 --- a/crates/kernel_guard/src/lib.rs +++ /dev/null @@ -1,248 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -//! RAII wrappers to create a critical section with local IRQs or preemption -//! disabled, used to implement spin locks in kernel. -//! -//! The critical section is created after the guard struct is created, and is -//! ended when the guard falls out of scope. -//! -//! The crate user must implement the [`KernelGuardIf`] trait using -//! [`crate_interface::impl_interface`] to provide the low-level implementantion -//! of how to enable/disable kernel preemption, if the feature `preempt` is -//! enabled. -//! -//! Available guards: -//! -//! - [`NoOp`]: Does nothing around the critical section. -//! - [`IrqSave`]: Disables/enables local IRQs around the critical section. -//! - [`NoPreempt`]: Disables/enables kernel preemption around the critical -//! section. -//! - [`NoPreemptIrqSave`]: Disables/enables both kernel preemption and local -//! IRQs around the critical section. -//! -//! # Crate features -//! -//! - `preempt`: Use in the preemptive system. If this feature is enabled, you -//! need to implement the [`KernelGuardIf`] trait in other crates. Otherwise -//! the preemption enable/disable operations will be no-ops. This feature is -//! disabled by default. -//! -//! # Examples -//! -//! ``` -//! use kernel_guard::{KernelGuardIf, NoPreempt}; -//! -//! struct KernelGuardIfImpl; -//! -//! #[crate_interface::impl_interface] -//! impl KernelGuardIf for KernelGuardIfImpl { -//! fn enable_preempt() { -//! // Your implementation here -//! } -//! fn disable_preempt() { -//! // Your implementation here -//! } -//! } -//! -//! let guard = NoPreempt::new(); -//! /* The critical section starts here -//! -//! Do something that requires preemption to be disabled -//! -//! The critical section ends here */ -//! drop(guard); -//! ``` - -#![no_std] -#![feature(asm_const)] - -mod arch; - -/// Low-level interfaces that must be implemented by the crate user. -#[crate_interface::def_interface] -pub trait KernelGuardIf { - /// How to enable kernel preemption. - fn enable_preempt(); - - /// How to disable kernel preemption. - fn disable_preempt(); -} - -/// A base trait that all guards implement. -pub trait BaseGuard { - /// The saved state when entering the critical section. - type State: Clone + Copy; - - /// Something that must be done before entering the critical section. - fn acquire() -> Self::State; - - /// Something that must be done after leaving the critical section. - fn release(state: Self::State); -} - -/// A no-op guard that does nothing around the critical section. -pub struct NoOp; - -cfg_if::cfg_if! { - // For user-mode std apps, we use the alias of [`NoOp`] for all guards, - // since we can not disable IRQs or preemption in user-mode. - if #[cfg(any(target_os = "none", doc))] { - /// A guard that disables/enables local IRQs around the critical section. - pub struct IrqSave(usize); - - /// A guard that disables/enables kernel preemption around the critical - /// section. - pub struct NoPreempt; - - /// A guard that disables/enables both kernel preemption and local IRQs - /// around the critical section. - /// - /// When entering the critical section, it disables kernel preemption - /// first, followed by local IRQs. When leaving the critical section, it - /// re-enables local IRQs first, followed by kernel preemption. - pub struct NoPreemptIrqSave(usize); - } else { - /// Alias of [`NoOp`]. - pub type IrqSave = NoOp; - - /// Alias of [`NoOp`]. - pub type NoPreempt = NoOp; - - /// Alias of [`NoOp`]. - pub type NoPreemptIrqSave = NoOp; - } -} - -impl BaseGuard for NoOp { - type State = (); - fn acquire() -> Self::State {} - fn release(_state: Self::State) {} -} - -impl NoOp { - /// Creates a new [`NoOp`] guard. - pub const fn new() -> Self { - Self - } -} - -impl Drop for NoOp { - fn drop(&mut self) {} -} - -#[cfg(any(target_os = "none", doc))] -mod imp { - use super::*; - - impl BaseGuard for IrqSave { - type State = usize; - - #[inline] - fn acquire() -> Self::State { - super::arch::local_irq_save_and_disable() - } - - #[inline] - fn release(state: Self::State) { - // restore IRQ states - super::arch::local_irq_restore(state); - } - } - - impl BaseGuard for NoPreempt { - type State = (); - fn acquire() -> Self::State { - // disable preempt - #[cfg(feature = "preempt")] - crate_interface::call_interface!(KernelGuardIf::disable_preempt); - } - fn release(_state: Self::State) { - // enable preempt - #[cfg(feature = "preempt")] - crate_interface::call_interface!(KernelGuardIf::enable_preempt); - } - } - - impl BaseGuard for NoPreemptIrqSave { - type State = usize; - fn acquire() -> Self::State { - // disable preempt - #[cfg(feature = "preempt")] - crate_interface::call_interface!(KernelGuardIf::disable_preempt); - // disable IRQs and save IRQ states - super::arch::local_irq_save_and_disable() - } - fn release(state: Self::State) { - // restore IRQ states - super::arch::local_irq_restore(state); - // enable preempt - #[cfg(feature = "preempt")] - crate_interface::call_interface!(KernelGuardIf::enable_preempt); - } - } - - impl IrqSave { - /// Creates a new [`IrqSave`] guard. - pub fn new() -> Self { - Self(Self::acquire()) - } - } - - impl Drop for IrqSave { - fn drop(&mut self) { - Self::release(self.0) - } - } - - impl Default for IrqSave { - fn default() -> Self { - Self::new() - } - } - - impl NoPreempt { - /// Creates a new [`NoPreempt`] guard. - pub fn new() -> Self { - Self::acquire(); - Self - } - } - - impl Drop for NoPreempt { - fn drop(&mut self) { - Self::release(()) - } - } - - impl Default for NoPreempt { - fn default() -> Self { - Self::new() - } - } - - impl NoPreemptIrqSave { - /// Creates a new [`NoPreemptIrqSave`] guard. - pub fn new() -> Self { - Self(Self::acquire()) - } - } - - impl Drop for NoPreemptIrqSave { - fn drop(&mut self) { - Self::release(self.0) - } - } - - impl Default for NoPreemptIrqSave { - fn default() -> Self { - Self::new() - } - } -} diff --git a/crates/memory_addr/Cargo.toml b/crates/memory_addr/Cargo.toml deleted file mode 100644 index 1b900359d..000000000 --- a/crates/memory_addr/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "memory_addr" -version = "0.1.0" -edition = "2021" -authors = ["Yuekai Jia "] -description = "Wrappers and helper functions for physical and virtual addresses" -license = "GPL-3.0-or-later OR Apache-2.0" -homepage = "https://github.com/rcore-os/arceos" -repository = "https://github.com/rcore-os/arceos/tree/main/crates/memory_addr" -documentation = "https://rcore-os.github.io/arceos/memory_addr/index.html" -keywords = ["arceos", "address", "virtual-memory"] -categories = ["os", "memory-management", "no-std"] - -[dependencies] diff --git a/crates/memory_addr/README.md b/crates/memory_addr/README.md deleted file mode 100644 index 2b1768b5f..000000000 --- a/crates/memory_addr/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# memory_addr - -[![Crates.io](https://img.shields.io/crates/v/memory_addr)](https://crates.io/crates/memory_addr) - -Wrappers and helper functions for physical and virtual memory addresses. - -## Examples - -```rust -use memory_addr::{PhysAddr, VirtAddr}; - -let phys_addr = PhysAddr::from(0x12345678); -let virt_addr = VirtAddr::from(0x87654321); - -assert_eq!(phys_addr.align_down(0x1000usize), PhysAddr::from(0x12345000)); -assert_eq!(phys_addr.align_offset_4k(), 0x678); -assert_eq!(virt_addr.align_up_4k(), VirtAddr::from(0x87655000)); -assert!(!virt_addr.is_aligned_4k()); -assert!(VirtAddr::from(0xabcedf0).is_aligned(16usize)); -``` diff --git a/crates/memory_addr/src/lib.rs b/crates/memory_addr/src/lib.rs deleted file mode 100644 index 55646faf0..000000000 --- a/crates/memory_addr/src/lib.rs +++ /dev/null @@ -1,393 +0,0 @@ -/* Copyright (c) [2023] [Syswonder Community] - * [Ruxos] is licensed under Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -#![no_std] -#![feature(const_mut_refs)] -#![doc = include_str!("../README.md")] - -use core::fmt; -use core::ops::{Add, AddAssign, Sub, SubAssign}; - -/// The size of a 4K page (4096 bytes). -pub const PAGE_SIZE_4K: usize = 0x1000; - -/// Align address downwards. -/// -/// Returns the greatest `x` with alignment `align` so that `x <= addr`. -/// -/// The alignment must be a power of two. -#[inline] -pub const fn align_down(addr: usize, align: usize) -> usize { - addr & !(align - 1) -} - -/// Align address upwards. -/// -/// Returns the smallest `x` with alignment `align` so that `x >= addr`. -/// -/// The alignment must be a power of two. -#[inline] -pub const fn align_up(addr: usize, align: usize) -> usize { - (addr + align - 1) & !(align - 1) -} - -/// Returns the offset of the address within the alignment. -/// -/// Equivalent to `addr % align`, but the alignment must be a power of two. -#[inline] -pub const fn align_offset(addr: usize, align: usize) -> usize { - addr & (align - 1) -} - -/// Checks whether the address has the demanded alignment. -/// -/// Equivalent to `addr % align == 0`, but the alignment must be a power of two. -#[inline] -pub const fn is_aligned(addr: usize, align: usize) -> bool { - align_offset(addr, align) == 0 -} - -/// Align address downwards to 4096 (bytes). -#[inline] -pub const fn align_down_4k(addr: usize) -> usize { - align_down(addr, PAGE_SIZE_4K) -} - -/// Align address upwards to 4096 (bytes). -#[inline] -pub const fn align_up_4k(addr: usize) -> usize { - align_up(addr, PAGE_SIZE_4K) -} - -/// Returns the offset of the address within a 4K-sized page. -#[inline] -pub const fn align_offset_4k(addr: usize) -> usize { - align_offset(addr, PAGE_SIZE_4K) -} - -/// Checks whether the address is 4K-aligned. -#[inline] -pub const fn is_aligned_4k(addr: usize) -> bool { - is_aligned(addr, PAGE_SIZE_4K) -} - -/// A physical memory address. -/// -/// It's a wrapper type around an `usize`. -#[repr(transparent)] -#[derive(Copy, Clone, Default, Ord, PartialOrd, Eq, PartialEq)] -pub struct PhysAddr(usize); - -/// A virtual memory address. -/// -/// It's a wrapper type around an `usize`. -#[repr(transparent)] -#[derive(Copy, Clone, Default, Ord, PartialOrd, Eq, PartialEq)] -pub struct VirtAddr(usize); - -impl PhysAddr { - /// Converts an `usize` to a physical address. - #[inline] - pub const fn from(addr: usize) -> Self { - Self(addr) - } - - /// Converts the address to an `usize`. - #[inline] - pub const fn as_usize(self) -> usize { - self.0 - } - - /// Aligns the address downwards to the given alignment. - /// - /// See the [`align_down`] function for more information. - #[inline] - pub fn align_down(self, align: U) -> Self - where - U: Into, - { - Self(align_down(self.0, align.into())) - } - - /// Aligns the address upwards to the given alignment. - /// - /// See the [`align_up`] function for more information. - #[inline] - pub fn align_up(self, align: U) -> Self - where - U: Into, - { - Self(align_up(self.0, align.into())) - } - - /// Returns the offset of the address within the given alignment. - /// - /// See the [`align_offset`] function for more information. - #[inline] - pub fn align_offset(self, align: U) -> usize - where - U: Into, - { - align_offset(self.0, align.into()) - } - - /// Checks whether the address has the demanded alignment. - /// - /// See the [`is_aligned`] function for more information. - #[inline] - pub fn is_aligned(self, align: U) -> bool - where - U: Into, - { - is_aligned(self.0, align.into()) - } - - /// Aligns the address downwards to 4096 (bytes). - #[inline] - pub fn align_down_4k(self) -> Self { - self.align_down(PAGE_SIZE_4K) - } - - /// Aligns the address upwards to 4096 (bytes). - #[inline] - pub fn align_up_4k(self) -> Self { - self.align_up(PAGE_SIZE_4K) - } - - /// Returns the offset of the address within a 4K-sized page. - #[inline] - pub fn align_offset_4k(self) -> usize { - self.align_offset(PAGE_SIZE_4K) - } - - /// Checks whether the address is 4K-aligned. - #[inline] - pub fn is_aligned_4k(self) -> bool { - self.is_aligned(PAGE_SIZE_4K) - } -} - -impl VirtAddr { - /// Converts an `usize` to a virtual address. - #[inline] - pub const fn from(addr: usize) -> Self { - Self(addr) - } - - /// Converts the address to an `usize`. - #[inline] - pub const fn as_usize(self) -> usize { - self.0 - } - - /// Converts the virtual address to a raw pointer. - #[inline] - pub const fn as_ptr(self) -> *const u8 { - self.0 as *const u8 - } - - /// Converts the virtual address to a mutable raw pointer. - #[inline] - pub const fn as_mut_ptr(self) -> *mut u8 { - self.0 as *mut u8 - } - - /// Aligns the address downwards to the given alignment. - /// - /// See the [`align_down`] function for more information. - #[inline] - pub fn align_down(self, align: U) -> Self - where - U: Into, - { - Self(align_down(self.0, align.into())) - } - - /// Aligns the address upwards to the given alignment. - /// - /// See the [`align_up`] function for more information. - #[inline] - pub fn align_up(self, align: U) -> Self - where - U: Into, - { - Self(align_up(self.0, align.into())) - } - - /// Returns the offset of the address within the given alignment. - /// - /// See the [`align_offset`] function for more information. - #[inline] - pub fn align_offset(self, align: U) -> usize - where - U: Into, - { - align_offset(self.0, align.into()) - } - - /// Checks whether the address has the demanded alignment. - /// - /// See the [`is_aligned`] function for more information. - #[inline] - pub fn is_aligned(self, align: U) -> bool - where - U: Into, - { - is_aligned(self.0, align.into()) - } - - /// Aligns the address downwards to 4096 (bytes). - #[inline] - pub fn align_down_4k(self) -> Self { - self.align_down(PAGE_SIZE_4K) - } - - /// Aligns the address upwards to 4096 (bytes). - #[inline] - pub fn align_up_4k(self) -> Self { - self.align_up(PAGE_SIZE_4K) - } - - /// Returns the offset of the address within a 4K-sized page. - #[inline] - pub fn align_offset_4k(self) -> usize { - self.align_offset(PAGE_SIZE_4K) - } - - /// Checks whether the address is 4K-aligned. - #[inline] - pub fn is_aligned_4k(self) -> bool { - self.is_aligned(PAGE_SIZE_4K) - } -} - -impl From for PhysAddr { - #[inline] - fn from(addr: usize) -> Self { - Self(addr) - } -} - -impl From for VirtAddr { - #[inline] - fn from(addr: usize) -> Self { - Self(addr) - } -} - -impl From for usize { - #[inline] - fn from(addr: PhysAddr) -> usize { - addr.0 - } -} - -impl From for usize { - #[inline] - fn from(addr: VirtAddr) -> usize { - addr.0 - } -} - -impl Add for PhysAddr { - type Output = Self; - #[inline] - fn add(self, rhs: usize) -> Self { - Self(self.0 + rhs) - } -} - -impl AddAssign for PhysAddr { - #[inline] - fn add_assign(&mut self, rhs: usize) { - *self = *self + rhs; - } -} - -impl Sub for PhysAddr { - type Output = Self; - #[inline] - fn sub(self, rhs: usize) -> Self { - Self(self.0 - rhs) - } -} - -impl SubAssign for PhysAddr { - #[inline] - fn sub_assign(&mut self, rhs: usize) { - *self = *self - rhs; - } -} - -impl Add for VirtAddr { - type Output = Self; - #[inline] - fn add(self, rhs: usize) -> Self { - Self(self.0 + rhs) - } -} - -impl AddAssign for VirtAddr { - #[inline] - fn add_assign(&mut self, rhs: usize) { - *self = *self + rhs; - } -} - -impl Sub for VirtAddr { - type Output = Self; - #[inline] - fn sub(self, rhs: usize) -> Self { - Self(self.0 - rhs) - } -} - -impl SubAssign for VirtAddr { - #[inline] - fn sub_assign(&mut self, rhs: usize) { - *self = *self - rhs; - } -} - -impl fmt::Debug for PhysAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("PA:{:#x}", self.0)) - } -} - -impl fmt::Debug for VirtAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("VA:{:#x}", self.0)) - } -} - -impl fmt::LowerHex for PhysAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("PA:{:#x}", self.0)) - } -} - -impl fmt::UpperHex for PhysAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("PA:{:#X}", self.0)) - } -} - -impl fmt::LowerHex for VirtAddr { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("VA:{:#x}", self.0)) - } -} - -impl fmt::UpperHex for VirtAddr { - #[inline] - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_fmt(format_args!("VA:{:#X}", self.0)) - } -} diff --git a/crates/page_table/Cargo.toml b/crates/page_table/Cargo.toml index 4178458b1..6cc0ff95c 100644 --- a/crates/page_table/Cargo.toml +++ b/crates/page_table/Cargo.toml @@ -11,5 +11,5 @@ documentation = "https://rcore-os.github.io/arceos/page_table/index.html" [dependencies] log = "0.4" -memory_addr = { path = "../memory_addr" } +memory_addr = "0.1.0" page_table_entry = { path = "../page_table_entry" } diff --git a/crates/page_table/src/lib.rs b/crates/page_table/src/lib.rs index 1ff711300..a86a95658 100644 --- a/crates/page_table/src/lib.rs +++ b/crates/page_table/src/lib.rs @@ -28,7 +28,6 @@ #![no_std] #![feature(const_trait_impl)] -#![feature(result_option_inspect)] #![feature(doc_auto_cfg)] #[macro_use] diff --git a/crates/page_table_entry/Cargo.toml b/crates/page_table_entry/Cargo.toml index 2a86e6b7a..c42558047 100644 --- a/crates/page_table_entry/Cargo.toml +++ b/crates/page_table_entry/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://rcore-os.github.io/arceos/page_table_entry/index.html" [dependencies] log = "0.4" bitflags = "2.2" -memory_addr = { path = "../memory_addr" } +memory_addr = "0.1.0" aarch64-cpu = "9.3" # TODO: put it in [target.'cfg(target_arch = "aarch64")'.dependencies] [target.'cfg(target_arch = "x86_64")'.dependencies] diff --git a/crates/percpu/Cargo.toml b/crates/percpu/Cargo.toml index 864169122..25f82144e 100644 --- a/crates/percpu/Cargo.toml +++ b/crates/percpu/Cargo.toml @@ -20,7 +20,7 @@ default = [] [dependencies] cfg-if = "1.0" -kernel_guard = { path = "../kernel_guard", optional = true } +kernel_guard = { version = "0.1.0", optional = true } percpu_macros = { path = "../percpu_macros" } [target.'cfg(target_arch = "x86_64")'.dependencies] diff --git a/crates/spinlock/Cargo.toml b/crates/spinlock/Cargo.toml index 1dd75e3d2..4cd97499d 100644 --- a/crates/spinlock/Cargo.toml +++ b/crates/spinlock/Cargo.toml @@ -16,4 +16,4 @@ default = [] [dependencies] cfg-if = "1.0" -kernel_guard = { path = "../kernel_guard" } +kernel_guard = "0.1.0" diff --git a/doc/README.md b/doc/README.md index 5d0a93ca5..43706d0b6 100644 --- a/doc/README.md +++ b/doc/README.md @@ -28,7 +28,6 @@ * [axfs_vfs](../crates/axfs_vfs): Virtual filesystem interfaces used by Ruxos. * [axio](../crates/axio): `std::io`-like I/O traits for `no_std` environment. * [capability](../crates/capability): Provide basic capability-based security. -* [crate_interface](../crates/crate_interface): Provides a way to define an interface (trait) in a crate, but can implement or use it in any crate. [![Crates.io](https://img.shields.io/crates/v/crate_interface)](https://crates.io/crates/crate_interface) * [driver_9p](../crates/driver_9p/): Basic 9pfs operation traits for 9p protocol drivers. * [driver_block](../crates/driver_block): Common traits and types for block storage drivers. * [driver_common](../crates/driver_common): Device driver interfaces used by Ruxos. @@ -37,11 +36,8 @@ * [driver_pci](../crates/driver_pci): Structures and functions for PCI bus operations. * [driver_virtio](../crates/driver_virtio): Wrappers of some devices in the `virtio-drivers` crate, that implement traits in the `driver_common` series crates. * [flatten_objects](../crates/flatten_objects): A container that stores numbered objects. Each object can be assigned with a unique ID. -* [handler_table](../crates/handler_table): A lock-free table of event handlers. [![Crates.io](https://img.shields.io/crates/v/handler_table)](https://crates.io/crates/handler_table) -* [kernel_guard](../crates/kernel_guard): RAII wrappers to create a critical section with local IRQs or preemption disabled. [![Crates.io](https://img.shields.io/crates/v/kernel_guard)](https://crates.io/crates/kernel_guard) * [lazy_init](../crates/lazy_init): A wrapper for lazy initialized values without concurrency safety but more efficient. * [linked_list](../crates/linked_list): Linked lists that supports arbitrary removal in constant time. -* [memory_addr](../crates/memory_addr): Wrappers and helper functions for physical and virtual addresses. [![Crates.io](https://img.shields.io/crates/v/memory_addr)](https://crates.io/crates/memory_addr) * [page_table](../crates/page_table): Generic page table structures for various hardware architectures. * [page_table_entry](../crates/page_table_entry): Page table entry definition for various hardware architectures. * [percpu](../crates/percpu): Define and access per-CPU data structures. diff --git a/modules/axalloc/Cargo.toml b/modules/axalloc/Cargo.toml index 40eedf404..311476037 100644 --- a/modules/axalloc/Cargo.toml +++ b/modules/axalloc/Cargo.toml @@ -19,6 +19,6 @@ buddy = ["allocator/buddy"] log = "0.4" cfg-if = "1.0" spinlock = { path = "../../crates/spinlock" } -memory_addr = { path = "../../crates/memory_addr" } +memory_addr = "0.1.0" allocator = { path = "../../crates/allocator", features = ["bitmap"] } axerrno = { path = "../../crates/axerrno" } diff --git a/modules/axlog/Cargo.toml b/modules/axlog/Cargo.toml index a679060a4..98ecdcf70 100644 --- a/modules/axlog/Cargo.toml +++ b/modules/axlog/Cargo.toml @@ -23,7 +23,7 @@ default = [] cfg-if = "1.0" log = "0.4" spinlock = { path = "../../crates/spinlock" } -crate_interface = { path = "../../crates/crate_interface" } +crate_interface = { version = "0.1.1" } chrono = { version = "0.4", optional = true } [dev-dependencies] diff --git a/modules/rux9p/Cargo.toml b/modules/rux9p/Cargo.toml index a792d24f1..e24320b2a 100644 --- a/modules/rux9p/Cargo.toml +++ b/modules/rux9p/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Zheng Wu "] description = "RuxOS Plan-9 filesystem module" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/modules/rux9p" diff --git a/modules/ruxdisplay/Cargo.toml b/modules/ruxdisplay/Cargo.toml index d4daaef87..33ab19f23 100644 --- a/modules/ruxdisplay/Cargo.toml +++ b/modules/ruxdisplay/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["Shiping Yuan "] description = "Ruxos graphics module" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/modules/ruxdisplay" diff --git a/modules/ruxfs/Cargo.toml b/modules/ruxfs/Cargo.toml index 91d3356c7..6b95596e9 100644 --- a/modules/ruxfs/Cargo.toml +++ b/modules/ruxfs/Cargo.toml @@ -38,9 +38,9 @@ axfs_devfs = { path = "../../crates/axfs_devfs", optional = true } axfs_ramfs = { path = "../../crates/axfs_ramfs", optional = true } ruxdriver = { path = "../ruxdriver", features = ["block"] } axsync = { path = "../axsync" } -crate_interface = { path = "../../crates/crate_interface", optional = true } +crate_interface = { version = "0.1.1", optional = true } axalloc = { path = "../axalloc", optional = true } -memory_addr = { path = "../../crates/memory_addr" } +memory_addr = "0.1.0" [dependencies.fatfs] git = "https://github.com/rafalh/rust-fatfs" diff --git a/modules/ruxfs/src/mounts.rs b/modules/ruxfs/src/mounts.rs index b6dbf224f..b5d74cae0 100644 --- a/modules/ruxfs/src/mounts.rs +++ b/modules/ruxfs/src/mounts.rs @@ -18,16 +18,13 @@ use crate::fs; pub(crate) fn devfs() -> Arc { let null = fs::devfs::NullDev; let zero = fs::devfs::ZeroDev; - let bar = fs::devfs::ZeroDev; let random = fs::devfs::RandomDev; let urandom = fs::devfs::RandomDev; let devfs = fs::devfs::DeviceFileSystem::new(); - let foo_dir = devfs.mkdir("foo"); devfs.add("null", Arc::new(null)); devfs.add("zero", Arc::new(zero)); devfs.add("random", Arc::new(random)); devfs.add("urandom", Arc::new(urandom)); - foo_dir.add("bar", Arc::new(bar)); Arc::new(devfs) } diff --git a/modules/ruxfs/src/root.rs b/modules/ruxfs/src/root.rs index 4d381cfdb..eb19f2c60 100644 --- a/modules/ruxfs/src/root.rs +++ b/modules/ruxfs/src/root.rs @@ -162,7 +162,11 @@ impl VfsNodeOps for RootDirectory { } pub(crate) fn init_rootfs(mount_points: Vec) { - let main_fs = mount_points.get(0).expect("No filesystem found").fs.clone(); + let main_fs = mount_points + .first() + .expect("No filesystem found") + .fs + .clone(); let mut root_dir = RootDirectory::new(main_fs); for mp in mount_points.iter().skip(1) { diff --git a/modules/ruxfs/tests/test_common/mod.rs b/modules/ruxfs/tests/test_common/mod.rs index 37a085f75..2eee93c9d 100644 --- a/modules/ruxfs/tests/test_common/mod.rs +++ b/modules/ruxfs/tests/test_common/mod.rs @@ -217,14 +217,6 @@ fn test_devfs_ramfs() -> Result<()> { assert!(!md.is_file()); assert!(md.is_dir()); - // stat /dev/foo/bar - let fname = ".//.///././/./dev///.///./foo//././bar"; - let file = File::open(fname)?; - let md = file.metadata()?; - println!("metadata of {:?}: {:?}", fname, md); - assert_eq!(md.file_type(), FileType::CharDevice); - assert!(!md.is_dir()); - // error cases assert_err!(fs::metadata("/dev/null/"), NotADirectory); assert_err!(fs::create_dir("dev"), AlreadyExists); @@ -242,7 +234,6 @@ fn test_devfs_ramfs() -> Result<()> { assert_eq!(fs::write(".///dev//..//233//.///test.txt", "test"), Ok(())); assert_err!(fs::remove_file("./dev//../..//233//.///test.txt"), NotFound); assert_eq!(fs::remove_file("./dev//..//233//../233/./test.txt"), Ok(())); - assert_eq!(fs::remove_dir("dev//foo/../foo/../.././/233"), Ok(())); assert_err!(fs::remove_dir("very/../dev//"), PermissionDenied); // tests in /tmp diff --git a/modules/ruxfutex/Cargo.toml b/modules/ruxfutex/Cargo.toml index a3c5e50ed..c4f2d8a10 100644 --- a/modules/ruxfutex/Cargo.toml +++ b/modules/ruxfutex/Cargo.toml @@ -5,7 +5,7 @@ version = "0.1.0" edition = "2021" authors = ["Zhi Zhou "] description = "Ruxos futex implementation" -license = "GPL-3.0-or-later OR Apache-2.0" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/modules/ruxfutex" @@ -15,7 +15,7 @@ default = [] irq = ["ruxtask/irq"] [dependencies] -# Ruxos modules +# RuxOS modules axerrno = { path = "../../crates/axerrno" } ruxconfig = { path = "../ruxconfig" } @@ -30,4 +30,4 @@ ahash = { version = "0.8.7", default-features = false, features = [ ] } [dev-dependencies] -memory_addr = { path = "../../crates/memory_addr" } +memory_addr = "0.1.0" diff --git a/modules/ruxhal/Cargo.toml b/modules/ruxhal/Cargo.toml index 0e5186f1b..d485d82a8 100644 --- a/modules/ruxhal/Cargo.toml +++ b/modules/ruxhal/Cargo.toml @@ -31,16 +31,16 @@ embedded-hal = "0.2.7" axlog = { path = "../axlog" } ruxconfig = { path = "../ruxconfig" } axalloc = { path = "../axalloc", optional = true } -kernel_guard = { path = "../../crates/kernel_guard" } +kernel_guard = "0.1.0" spinlock = { path = "../../crates/spinlock" } ratio = { path = "../../crates/ratio" } lazy_init = { path = "../../crates/lazy_init" } page_table = { path = "../../crates/page_table", optional = true } page_table_entry = { path = "../../crates/page_table_entry" } percpu = { path = "../../crates/percpu" } -memory_addr = { path = "../../crates/memory_addr" } -handler_table = { path = "../../crates/handler_table" } -crate_interface = { path = "../../crates/crate_interface" } +memory_addr = "0.1.0" +handler_table = "0.1.0" +crate_interface = "0.1.1" [target.'cfg(target_arch = "x86_64")'.dependencies] x86 = "0.52" diff --git a/modules/ruxhal/src/lib.rs b/modules/ruxhal/src/lib.rs index 3785e3498..fcb78a72d 100644 --- a/modules/ruxhal/src/lib.rs +++ b/modules/ruxhal/src/lib.rs @@ -36,7 +36,6 @@ #![no_std] #![feature(asm_const)] #![feature(naked_functions)] -#![feature(const_maybe_uninit_zeroed)] #![feature(const_option)] #![feature(doc_auto_cfg)] diff --git a/modules/ruxhal/src/platform/dummy/mod.rs b/modules/ruxhal/src/platform/dummy/mod.rs index 9e627cd7d..164f9b6a8 100644 --- a/modules/ruxhal/src/platform/dummy/mod.rs +++ b/modules/ruxhal/src/platform/dummy/mod.rs @@ -69,7 +69,9 @@ pub mod time { } #[cfg(feature = "rtc")] - pub fn rtc_write_time(seconds: u32) -> u64 {} + pub fn rtc_write_time(seconds: u32) -> u64 { + 0 + } } #[cfg(feature = "irq")] diff --git a/modules/ruxruntime/Cargo.toml b/modules/ruxruntime/Cargo.toml index f0615e5e1..849acd6d5 100644 --- a/modules/ruxruntime/Cargo.toml +++ b/modules/ruxruntime/Cargo.toml @@ -49,8 +49,8 @@ ruxtask = { path = "../ruxtask", optional = true } axsync = { path = "../axsync", optional = true } ruxfutex = { path = "../ruxfutex", optional = true } -crate_interface = { path = "../../crates/crate_interface" } +crate_interface = "0.1.1" percpu = { path = "../../crates/percpu", optional = true } -kernel_guard = { path = "../../crates/kernel_guard", optional = true } +kernel_guard = { version = "0.1.0", optional = true } lazy_init = { path = "../../crates/lazy_init", optional = true } dtb = { path = "../../crates/dtb", optional = true } diff --git a/modules/ruxtask/Cargo.toml b/modules/ruxtask/Cargo.toml index a2227c092..14618f1ed 100644 --- a/modules/ruxtask/Cargo.toml +++ b/modules/ruxtask/Cargo.toml @@ -37,11 +37,11 @@ ruxconfig = { path = "../ruxconfig", optional = true } percpu = { path = "../../crates/percpu", optional = true } spinlock = { path = "../../crates/spinlock", optional = true } lazy_init = { path = "../../crates/lazy_init", optional = true } -memory_addr = { path = "../../crates/memory_addr", optional = true } +memory_addr = { version = "0.1.0", optional = true } scheduler = { path = "../../crates/scheduler", optional = true } timer_list = { path = "../../crates/timer_list", optional = true } -kernel_guard = { path = "../../crates/kernel_guard", optional = true } -crate_interface = { path = "../../crates/crate_interface", optional = true } +kernel_guard = { version = "0.1.0", optional = true } +crate_interface = { version = "0.1.1", optional = true } [dev-dependencies] rand = "0.8" diff --git a/ulib/ruxmusl/Cargo.toml b/ulib/ruxmusl/Cargo.toml index 77b5855b4..cdbf28ba1 100644 --- a/ulib/ruxmusl/Cargo.toml +++ b/ulib/ruxmusl/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" authors = ["yanjuguang "] description = "Ruxos compatible layer for Musl libc" -license = "GPL-3.0-or-later OR Apache-2.0 OR MulanPSL2" +license = "Mulan PSL v2" homepage = "https://github.com/syswonder/ruxos" repository = "https://github.com/syswonder/ruxos/tree/main/ulib/ruxmusl" @@ -58,5 +58,5 @@ ruxos_posix_api = { path = "../../api/ruxos_posix_api" } num_enum = { version = "0.5.11", default-features = false } ruxhal = { path = "../../modules/ruxhal" } axlog = { path = "../../modules/axlog" } -kernel_guard = { path = "../../crates/kernel_guard" } -crate_interface = { path = "../../crates/crate_interface" } +kernel_guard = "0.1.0" +crate_interface = "0.1.1"