diff --git a/Cargo.lock b/Cargo.lock index 64d45f3c7d..04a30d298a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,18 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ahash" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91429305e9f0a25f6205c5b8e0d2db09e0708a7a6df0f42212bb56c32c8ac97a" +dependencies = [ + "cfg-if", + "once_cell", + "version_check", + "zerocopy", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -70,9 +82,12 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +dependencies = [ + "ahash", +] [[package]] name = "indexmap" @@ -94,6 +109,7 @@ dependencies = [ "cc", "fdt", "goblin", + "hashbrown", "linked_list_allocator 0.9.1", "log", "paste", @@ -151,6 +167,12 @@ version = "2.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "paste" version = "1.0.9" @@ -343,6 +365,12 @@ version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "301abaae475aa91687eb82514b328ab47a211a533026cb25fc3e519b86adfc3c" +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + [[package]] name = "winnow" version = "0.5.15" @@ -362,3 +390,23 @@ dependencies = [ "bitflags", "raw-cpuid", ] + +[[package]] +name = "zerocopy" +version = "0.7.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "306dca4455518f1f31635ec308b6b3e4eb1b11758cefafc782827d0aa7acb5c7" +dependencies = [ + "zerocopy-derive", +] + +[[package]] +name = "zerocopy-derive" +version = "0.7.30" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be912bf68235a88fbefd1b73415cb218405958d1655b2ece9035a19920bdf6ba" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] diff --git a/Cargo.toml b/Cargo.toml index 90b8401fdb..6e78296fc8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,7 @@ toml = "0.7" [dependencies] bitflags = "1.2.1" bitfield = "0.13.2" +hashbrown = { version = "0.14.3", default-features = false, features = ["ahash", "inline-more"] } linked_list_allocator = "0.9.0" log = "0.4" redox_syscall = { path = "syscall" } diff --git a/rmm b/rmm index a992ae89ed..d7d824552b 160000 --- a/rmm +++ b/rmm @@ -1 +1 @@ -Subproject commit a992ae89ed63c10e17a9212274d66b6b3b5f8274 +Subproject commit d7d824552b4815139fb2e633612df540cb95248d diff --git a/src/acpi/mod.rs b/src/acpi/mod.rs index d1f91a4748..4ee210d0f6 100644 --- a/src/acpi/mod.rs +++ b/src/acpi/mod.rs @@ -1,11 +1,11 @@ //! # ACPI //! Code to parse the ACPI tables -use alloc::collections::BTreeMap; use alloc::string::String; use alloc::vec::Vec; use alloc::boxed::Box; +use hashbrown::HashMap; use spin::{Once, RwLock}; use crate::log::info; @@ -76,7 +76,7 @@ pub static RXSDT_ENUM: Once = Once::new(); pub unsafe fn init(already_supplied_rsdps: Option<(u64, u64)>) { { let mut sdt_ptrs = SDT_POINTERS.write(); - *sdt_ptrs = Some(BTreeMap::new()); + *sdt_ptrs = Some(HashMap::new()); } // Search for RSDP @@ -148,7 +148,7 @@ pub unsafe fn init(already_supplied_rsdps: Option<(u64, u64)>) { } pub type SdtSignature = (String, [u8; 6], [u8; 8]); -pub static SDT_POINTERS: RwLock>> = RwLock::new(None); +pub static SDT_POINTERS: RwLock>> = RwLock::new(None); pub fn find_sdt(name: &str) -> Vec<&'static Sdt> { let mut sdts: Vec<&'static Sdt> = vec!(); diff --git a/src/arch/x86/idt.rs b/src/arch/x86/idt.rs index beb0a99ec0..73aeededf7 100644 --- a/src/arch/x86/idt.rs +++ b/src/arch/x86/idt.rs @@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU32, Ordering}; use core::mem; use alloc::boxed::Box; -use alloc::collections::BTreeMap; +use hashbrown::HashMap; use x86::segmentation::Descriptor as X86IdtEntry; use x86::dtables::{self, DescriptorTablePointer}; @@ -68,7 +68,7 @@ impl Idt { static mut INIT_BSP_IDT: Idt = Idt::new(); // TODO: VecMap? -pub static IDTS: RwLock>> = RwLock::new(None); +pub static IDTS: RwLock>> = RwLock::new(None); #[inline] pub fn is_reserved(cpu_id: LogicalCpuId, index: u8) -> bool { @@ -128,7 +128,7 @@ const fn new_idt_reservations() -> [AtomicU32; 8] { /// Initialize the IDT for a pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: LogicalCpuId) { let mut idts_guard = IDTS.write(); - let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new); + let idts_btree = idts_guard.get_or_insert_with(HashMap::new); if is_bsp { idts_btree.insert(cpu_id, &mut INIT_BSP_IDT); diff --git a/src/arch/x86_64/idt.rs b/src/arch/x86_64/idt.rs index 1ea5e1b906..a3b2e18665 100644 --- a/src/arch/x86_64/idt.rs +++ b/src/arch/x86_64/idt.rs @@ -3,7 +3,7 @@ use core::sync::atomic::{AtomicU64, Ordering}; use core::mem; use alloc::boxed::Box; -use alloc::collections::BTreeMap; +use hashbrown::HashMap; use x86::segmentation::Descriptor as X86IdtEntry; use x86::dtables::{self, DescriptorTablePointer}; @@ -69,7 +69,7 @@ impl Idt { static mut INIT_BSP_IDT: Idt = Idt::new(); // TODO: VecMap? -pub static IDTS: RwLock>> = RwLock::new(None); +pub static IDTS: RwLock>> = RwLock::new(None); #[inline] pub fn is_reserved(cpu_id: LogicalCpuId, index: u8) -> bool { @@ -113,7 +113,7 @@ const fn new_idt_reservations() -> [AtomicU64; 4] { /// Initialize the IDT for a pub unsafe fn init_paging_post_heap(is_bsp: bool, cpu_id: LogicalCpuId) { let mut idts_guard = IDTS.write(); - let idts_btree = idts_guard.get_or_insert_with(BTreeMap::new); + let idts_btree = idts_guard.get_or_insert_with(HashMap::new); if is_bsp { idts_btree.insert(cpu_id, &mut INIT_BSP_IDT); diff --git a/src/common/int_like.rs b/src/common/int_like.rs index 8e6b20b1ae..5596e9c4fa 100644 --- a/src/common/int_like.rs +++ b/src/common/int_like.rs @@ -25,7 +25,7 @@ #[macro_export] macro_rules! int_like { ($new_type_name:ident, $backing_type: ident) => { - #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Debug, Clone, Copy)] + #[derive(Default, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy)] pub struct $new_type_name($backing_type); impl $new_type_name { diff --git a/src/context/list.rs b/src/context/list.rs index e98867ac98..3c83b40e1c 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -9,6 +9,7 @@ use super::context::{Context, ContextId}; /// Context list type pub struct ContextList { + // Using a BTreeMap for it's range method map: BTreeMap>>, next_id: usize } diff --git a/src/context/memory.rs b/src/context/memory.rs index 8927f115b8..8c4a83060c 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -1,5 +1,6 @@ use alloc::collections::BTreeMap; use alloc::{sync::Arc, vec::Vec}; +use hashbrown::HashMap; use syscall::{GrantFlags, MunmapFlags}; use core::cmp; use core::fmt::Debug; @@ -404,13 +405,15 @@ impl AddrSpace { #[derive(Debug)] pub struct UserGrants { + // Using a BTreeMap for it's range method. inner: BTreeMap, + // Using a BTreeMap for it's range method. holes: BTreeMap, // TODO: Would an additional map ordered by (size,start) to allow for O(log n) allocations be // beneficial? //TODO: technically VirtualAddress is from a scheme's context! - pub funmap: BTreeMap, + pub funmap: HashMap, } #[derive(Clone, Copy)] @@ -496,7 +499,7 @@ impl UserGrants { Self { inner: BTreeMap::new(), holes: core::iter::once((VirtualAddress::new(0), crate::USER_END_OFFSET)).collect::>(), - funmap: BTreeMap::new(), + funmap: HashMap::new(), } } /// Returns the grant, if any, which occupies the specified page diff --git a/src/debugger.rs b/src/debugger.rs index 0fc3dee64e..8679987862 100644 --- a/src/debugger.rs +++ b/src/debugger.rs @@ -5,18 +5,18 @@ use crate::paging::{RmmA, RmmArch, TableKind, PAGE_SIZE}; // Super unsafe due to page table switching and raw pointers! #[cfg(target_arch = "aarch64")] pub unsafe fn debugger(target_id: Option) { - use alloc::collections::{BTreeSet, BTreeMap}; + use hashbrown::HashSet; use crate::memory::{RefCount, get_page_info}; println!("DEBUGGER START"); println!(); - let mut tree = BTreeMap::new(); + let mut tree = HashMap::new(); let old_table = RmmA::table(TableKind::User); - let mut spaces = BTreeSet::new(); + let mut spaces = HashSet::new(); for (id, context_lock) in crate::context::contexts().iter() { if target_id.map_or(false, |target_id| *id != target_id) { continue; } @@ -174,7 +174,7 @@ pub unsafe fn debugger(target_id: Option) { // Super unsafe due to page table switching and raw pointers! #[cfg(target_arch = "x86_64")] pub unsafe fn debugger(target_id: Option) { - use alloc::collections::BTreeSet; + use hashbrown::HashSet; use crate::memory::{RefCount, get_page_info}; @@ -183,8 +183,8 @@ pub unsafe fn debugger(target_id: Option) { println!("DEBUGGER START"); println!(); - let mut tree = BTreeMap::new(); - let mut spaces = BTreeSet::new(); + let mut tree = HashMap::new(); + let mut spaces = HashSet::new(); let old_table = RmmA::table(TableKind::User); @@ -267,10 +267,10 @@ pub unsafe fn debugger(target_id: Option) { unsafe { x86::bits64::rflags::clac(); } } #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -use {alloc::collections::BTreeMap, crate::memory::Frame}; +use {hashbrown::HashMap, crate::memory::Frame}; #[cfg(any(target_arch = "aarch64", target_arch = "x86_64"))] -pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpace, new_as: bool, tree: &mut BTreeMap) { +pub unsafe fn check_consistency(addr_space: &mut crate::context::memory::AddrSpace, new_as: bool, tree: &mut HashMap) { use crate::context::memory::PageSpan; use crate::memory::{get_page_info, RefCount}; diff --git a/src/event.rs b/src/event.rs index 300a59f272..dbfb16be54 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,6 +1,6 @@ use alloc::sync::Arc; -use alloc::collections::BTreeMap; use core::sync::atomic::{AtomicUsize, Ordering}; +use hashbrown::HashMap; use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard}; use crate::context; @@ -64,7 +64,7 @@ impl EventQueue { } } -pub type EventQueueList = BTreeMap>; +pub type EventQueueList = HashMap>; // Next queue id static NEXT_QUEUE_ID: AtomicUsize = AtomicUsize::new(0); @@ -79,7 +79,7 @@ static QUEUES: Once> = Once::new(); /// Initialize queues, called if needed fn init_queues() -> RwLock { - RwLock::new(BTreeMap::new()) + RwLock::new(HashMap::new()) } /// Get the event queues list, const @@ -92,20 +92,20 @@ pub fn queues_mut() -> RwLockWriteGuard<'static, EventQueueList> { QUEUES.call_once(init_queues).write() } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct RegKey { pub scheme: SchemeId, pub number: usize, } -#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct QueueKey { pub queue: EventQueueId, pub id: usize, pub data: usize, } -type Registry = BTreeMap>; +type Registry = HashMap>; static REGISTRY: Once> = Once::new(); @@ -128,7 +128,7 @@ pub fn register(reg_key: RegKey, queue_key: QueueKey, flags: EventFlags) { let mut registry = registry_mut(); let entry = registry.entry(reg_key).or_insert_with(|| { - BTreeMap::new() + HashMap::new() }); if flags.is_empty() { diff --git a/src/main.rs b/src/main.rs index 04a561ba1e..2c28eb0c65 100644 --- a/src/main.rs +++ b/src/main.rs @@ -293,7 +293,7 @@ mod kernel_executable_offsets { /// This is usually but not necessarily the same as the APIC ID. // TODO: Differentiate between logical CPU IDs and hardware CPU IDs (e.g. APIC IDs) -#[derive(Clone, Copy, Eq, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Eq, PartialEq, Hash)] // TODO: NonMaxUsize? // TODO: Optimize away this type if not cfg!(feature = "multi_core") struct LogicalCpuId(u32); diff --git a/src/memory/mod.rs b/src/memory/mod.rs index d2cd33c014..024910c205 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -82,7 +82,7 @@ pub fn deallocate_frames(frame: Frame, count: usize) { } } -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Frame { // On x86/x86_64, all memory below 1 MiB is reserved, and although some frames in that range // may end up in the paging code, it's very unlikely that frame 0x0 would. diff --git a/src/ptrace.rs b/src/ptrace.rs index b7af6b4acd..94336c330d 100644 --- a/src/ptrace.rs +++ b/src/ptrace.rs @@ -19,14 +19,11 @@ use crate::{ use alloc::{ boxed::Box, - collections::{ - BTreeMap, - VecDeque, - btree_map::Entry - }, + collections::VecDeque, sync::Arc, }; use core::cmp; +use hashbrown::hash_map::{Entry, HashMap}; use spin::{Mutex, Once, RwLock, RwLockReadGuard, RwLockWriteGuard}; // ____ _ @@ -110,12 +107,12 @@ impl Session { } } -type SessionMap = BTreeMap>; +type SessionMap = HashMap>; static SESSIONS: Once> = Once::new(); fn init_sessions() -> RwLock { - RwLock::new(BTreeMap::new()) + RwLock::new(HashMap::new()) } fn sessions() -> RwLockReadGuard<'static, SessionMap> { SESSIONS.call_once(init_sessions).read() diff --git a/src/scheme/acpi.rs b/src/scheme/acpi.rs index 0b2742a12c..6c3ed154a9 100644 --- a/src/scheme/acpi.rs +++ b/src/scheme/acpi.rs @@ -39,6 +39,7 @@ enum HandleKind { ShutdownPipe, } +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); static NEXT_FD: AtomicUsize = AtomicUsize::new(0); diff --git a/src/scheme/debug.rs b/src/scheme/debug.rs index ce5a8f7509..51107eaeb2 100644 --- a/src/scheme/debug.rs +++ b/src/scheme/debug.rs @@ -18,6 +18,7 @@ struct Handle { flags: usize, } +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); /// Add to the input queue diff --git a/src/scheme/dtb.rs b/src/scheme/dtb.rs index ef570a1343..c46179400c 100644 --- a/src/scheme/dtb.rs +++ b/src/scheme/dtb.rs @@ -1,7 +1,7 @@ use core::sync::atomic::{self, AtomicUsize}; use alloc::boxed::Box; -use alloc::collections::BTreeMap; +use hashbrown::HashMap; use spin::{Once, RwLock}; use crate::dtb::DTB_BINARY; @@ -30,7 +30,7 @@ struct Handle { stat: bool, } -static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); +static HANDLES: RwLock> = RwLock::new(HashMap::new()); static NEXT_FD: AtomicUsize = AtomicUsize::new(0); static DATA: Once> = Once::new(); static SCHEME_ID: Once = Once::new(); @@ -157,7 +157,7 @@ impl KernelScheme for DtbScheme { let handles = HANDLES.read(); let handle = handles.get(&id).ok_or(Error::new(EBADF))?; buf.copy_exactly(&match handle.kind { - HandleKind::RawData => { + HandleKind::RawData => { let data = DATA.get().ok_or(Error::new(EBADFD))?; Stat { st_mode: MODE_FILE, diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index da88cdc589..be35dad4cf 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -21,6 +21,7 @@ use super::{GlobalSchemes, OpenResult, CallerCtx, calc_seek_offset}; /// IRQ queues pub(super) static COUNTS: Mutex<[usize; 224]> = Mutex::new([0; 224]); +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); /// These are IRQs 0..=15 (corresponding to interrupt vectors 32..=47). They are opened without the diff --git a/src/scheme/itimer.rs b/src/scheme/itimer.rs index 90e6a354c6..fca21d4845 100644 --- a/src/scheme/itimer.rs +++ b/src/scheme/itimer.rs @@ -12,6 +12,7 @@ use super::{KernelScheme, CallerCtx, OpenResult}; pub struct ITimerScheme; static NEXT_ID: AtomicUsize = AtomicUsize::new(1); +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); impl KernelScheme for ITimerScheme { diff --git a/src/scheme/mod.rs b/src/scheme/mod.rs index 8ea62745d0..6a6b261e55 100644 --- a/src/scheme/mod.rs +++ b/src/scheme/mod.rs @@ -13,6 +13,7 @@ use alloc::{ sync::Arc, vec::Vec, }; +use hashbrown::HashMap; use syscall::{MunmapFlags, SendFdFlags, EventFlags, SEEK_SET, SEEK_CUR, SEEK_END}; use core::sync::atomic::AtomicUsize; use spin::{Once, RwLock, RwLockReadGuard, RwLockWriteGuard}; @@ -95,7 +96,7 @@ int_like!(SchemeId, usize); int_like!(FileHandle, AtomicFileHandle, usize, AtomicUsize); pub struct SchemeIter<'a> { - inner: Option<::alloc::collections::btree_map::Iter<'a, Box, SchemeId>> + inner: Option, SchemeId>> } impl<'a> Iterator for SchemeIter<'a> { @@ -108,8 +109,8 @@ impl<'a> Iterator for SchemeIter<'a> { /// Scheme list type pub struct SchemeList { - map: BTreeMap, - pub(crate) names: BTreeMap, SchemeId>>, + map: HashMap, + pub(crate) names: HashMap, SchemeId>>, next_ns: usize, next_id: usize, } @@ -117,8 +118,8 @@ impl SchemeList { /// Create a new scheme list. pub fn new() -> Self { let mut list = SchemeList { - map: BTreeMap::new(), - names: BTreeMap::new(), + map: HashMap::new(), + names: HashMap::new(), // Scheme namespaces always start at 1. 0 is a reserved namespace, the null namespace next_ns: 1, next_id: MAX_GLOBAL_SCHEMES, @@ -150,7 +151,7 @@ impl SchemeList { /// Initialize the null namespace fn new_null(&mut self) { let ns = SchemeNamespace(0); - self.names.insert(ns, BTreeMap::new()); + self.names.insert(ns, HashMap::new()); //TODO: Only memory: is in the null namespace right now. It should be removed when //anonymous mmap's are implemented @@ -163,7 +164,7 @@ impl SchemeList { fn new_ns(&mut self) -> SchemeNamespace { let ns = SchemeNamespace(self.next_ns); self.next_ns += 1; - self.names.insert(ns, BTreeMap::new()); + self.names.insert(ns, HashMap::new()); self.insert(ns, "", |scheme_id| KernelSchemes::Root(Arc::new(RootScheme::new(ns, scheme_id)))).unwrap(); self.insert_global(ns, "event", GlobalSchemes::Event).unwrap(); diff --git a/src/scheme/pipe.rs b/src/scheme/pipe.rs index 73357b0b4a..4f81f3547b 100644 --- a/src/scheme/pipe.rs +++ b/src/scheme/pipe.rs @@ -19,6 +19,7 @@ use super::{KernelScheme, OpenResult, CallerCtx, GlobalSchemes}; static PIPE_NEXT_ID: AtomicUsize = AtomicUsize::new(1); // TODO: SLOB? +// Using BTreeMap as hashbrown doesn't have a const constructor. static PIPES: RwLock>> = RwLock::new(BTreeMap::new()); const MAX_QUEUE_SIZE: usize = 65536; diff --git a/src/scheme/proc.rs b/src/scheme/proc.rs index 64972d6f04..0286d6bc44 100644 --- a/src/scheme/proc.rs +++ b/src/scheme/proc.rs @@ -226,6 +226,7 @@ impl Handle { pub struct ProcScheme; static NEXT_ID: AtomicUsize = AtomicUsize::new(1); +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); #[derive(PartialEq)] diff --git a/src/scheme/root.rs b/src/scheme/root.rs index 58197dd1fc..a627b3fcac 100644 --- a/src/scheme/root.rs +++ b/src/scheme/root.rs @@ -1,10 +1,10 @@ use alloc::{ boxed::Box, - collections::BTreeMap, string::ToString, sync::Arc, vec::Vec, }; +use hashbrown::HashMap; use core::str; use core::sync::atomic::{AtomicUsize, Ordering}; use spin::{Mutex, RwLock}; @@ -54,7 +54,7 @@ pub struct RootScheme { scheme_ns: SchemeNamespace, scheme_id: SchemeId, next_id: AtomicUsize, - handles: RwLock>, + handles: RwLock>, } impl RootScheme { @@ -63,7 +63,7 @@ impl RootScheme { scheme_ns, scheme_id, next_id: AtomicUsize::new(0), - handles: RwLock::new(BTreeMap::new()), + handles: RwLock::new(HashMap::new()), } } } @@ -298,7 +298,7 @@ impl KernelScheme for RootScheme { } } } - + fn kfstat(&self, file: usize, buf: UserSliceWo) -> Result<()> { let handle = { let handles = self.handles.read(); diff --git a/src/scheme/serio.rs b/src/scheme/serio.rs index 02ea0b827b..198e874e79 100644 --- a/src/scheme/serio.rs +++ b/src/scheme/serio.rs @@ -22,6 +22,7 @@ struct Handle { flags: usize, } +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); /// Add to the input queue diff --git a/src/scheme/sys/mod.rs b/src/scheme/sys/mod.rs index 9b45eb7d6f..eff0051165 100644 --- a/src/scheme/sys/mod.rs +++ b/src/scheme/sys/mod.rs @@ -36,6 +36,7 @@ type SysFn = fn() -> Result>; /// System information scheme pub struct SysScheme; static NEXT_ID: AtomicUsize = AtomicUsize::new(1); +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); const FILES: &[(&'static str, SysFn)] = &[ diff --git a/src/scheme/time.rs b/src/scheme/time.rs index 1a109d049a..645bdad1c2 100644 --- a/src/scheme/time.rs +++ b/src/scheme/time.rs @@ -13,6 +13,7 @@ use crate::time; use super::{GlobalSchemes, KernelScheme, CallerCtx, OpenResult}; static NEXT_ID: AtomicUsize = AtomicUsize::new(1); +// Using BTreeMap as hashbrown doesn't have a const constructor. static HANDLES: RwLock> = RwLock::new(BTreeMap::new()); pub struct TimeScheme; diff --git a/src/scheme/user.rs b/src/scheme/user.rs index a7f343666b..e52a1063ff 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -1,13 +1,12 @@ -use alloc::collections::btree_map::Entry; use alloc::sync::{Arc, Weak}; use alloc::boxed::Box; -use alloc::collections::BTreeMap; use alloc::vec::Vec; use syscall::{SKMSG_FRETURNFD, SKMSG_PROVIDE_MMAP, MAP_FIXED_NOREPLACE, MunmapFlags, SKMSG_FOBTAINFD, FobtainFdFlags, SendFdFlags}; use core::mem::size_of; use core::num::NonZeroUsize; use core::sync::atomic::{AtomicBool, Ordering}; use core::{mem, usize}; +use hashbrown::hash_map::{Entry, HashMap}; use spin::{Mutex, RwLock}; use crate::context::context::HardBlockedReason; @@ -37,7 +36,7 @@ pub struct UserInner { next_id: Mutex, context: Weak>, todo: WaitQueue, - states: Mutex>, + states: Mutex>, unmounting: AtomicBool, } @@ -71,7 +70,7 @@ impl UserInner { context, todo: WaitQueue::new(), unmounting: AtomicBool::new(false), - states: Mutex::new(BTreeMap::new()), + states: Mutex::new(HashMap::new()), } } diff --git a/src/sync/wait_map.rs b/src/sync/wait_map.rs index 8033758ce2..b21acf8520 100644 --- a/src/sync/wait_map.rs +++ b/src/sync/wait_map.rs @@ -6,6 +6,7 @@ use crate::sync::WaitCondition; #[derive(Debug)] pub struct WaitMap { + // Using BTreeMap as this depends on .keys() providing elements in sorted order. pub inner: Mutex>, pub condition: WaitCondition }