From d1a1ac751c28ac0f4e8b09df0431512c281dffc1 Mon Sep 17 00:00:00 2001 From: Hankai Zhang Date: Sun, 11 Jun 2023 14:03:47 -0400 Subject: [PATCH] Remove `doors_alloc` With the current Rust nightly (2023-06-01 as of this writing), using `-Zbuild-std` to recompile the `core` and `alloc` crates while enabling the `no_global_oom_handling` cfg now works properly. Therefore there is no further need for the `doors_alloc` hack, which involved manually copying the source for `alloc` and adding it as a Cargo dependency. It is still not clear what change on the Rust/Cargo end fixed the bug that previously blocked using `-Zbuild-std` to set the cfg (at the time, trying to enable the cfg resulted in large numbers of mysterious "duplicate lang item" errors). Maybe rust-lang/rust#110649 is related. --- doors_alloc | 1 - kernel/.cargo/config.toml | 3 +++ kernel/Cargo.lock | 5 ----- kernel/Cargo.toml | 1 - kernel/src/errno.rs | 4 ++-- kernel/src/fs/filesystem.rs | 2 +- kernel/src/fs/initrd.rs | 2 +- kernel/src/hw/abstraction/timer.rs | 1 - kernel/src/loader.rs | 1 - kernel/src/main.rs | 2 ++ kernel/src/thread.rs | 3 +-- kernel/src/util/alloc.rs | 8 ++++---- 12 files changed, 14 insertions(+), 19 deletions(-) delete mode 160000 doors_alloc diff --git a/doors_alloc b/doors_alloc deleted file mode 160000 index 32e0d10..0000000 --- a/doors_alloc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 32e0d10239841c199c2bbca52a91ba63d3d044ab diff --git a/kernel/.cargo/config.toml b/kernel/.cargo/config.toml index f54ac45..507c961 100644 --- a/kernel/.cargo/config.toml +++ b/kernel/.cargo/config.toml @@ -1,3 +1,6 @@ [build] target = "x86_64-unknown-none" rustflags = "-C relocation-model=static -C link-arg=-Tlink.ld --cfg no_global_oom_handling" + +[unstable] +build-std = ["core", "alloc"] \ No newline at end of file diff --git a/kernel/Cargo.lock b/kernel/Cargo.lock index 8500d1f..d3a1813 100644 --- a/kernel/Cargo.lock +++ b/kernel/Cargo.lock @@ -24,17 +24,12 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" name = "doors" version = "0.1.0" dependencies = [ - "doors_alloc", "linked_list_allocator", "lock_api", "paste", "x86_64", ] -[[package]] -name = "doors_alloc" -version = "0.0.0" - [[package]] name = "linked_list_allocator" version = "0.10.5" diff --git a/kernel/Cargo.toml b/kernel/Cargo.toml index ff55180..26ff3ac 100644 --- a/kernel/Cargo.toml +++ b/kernel/Cargo.toml @@ -27,5 +27,4 @@ rustflags = ["--cfg", "doors_test"] lock_api = "0.4.9" x86_64 = "0.14.10" linked_list_allocator = { version = "0.10.5", default-features = false } -doors_alloc = { path = "../doors_alloc" } paste = "1.0.12" diff --git a/kernel/src/errno.rs b/kernel/src/errno.rs index 56feae4..ebac100 100644 --- a/kernel/src/errno.rs +++ b/kernel/src/errno.rs @@ -178,8 +178,8 @@ impl From for Errno { } } -impl From for Errno { - fn from(_value: doors_alloc::collections::TryReserveError) -> Self { +impl From for Errno { + fn from(_value: alloc::collections::TryReserveError) -> Self { Errno::ENOMEM } } diff --git a/kernel/src/fs/filesystem.rs b/kernel/src/fs/filesystem.rs index 77d775e..fcd3099 100644 --- a/kernel/src/fs/filesystem.rs +++ b/kernel/src/fs/filesystem.rs @@ -1,6 +1,6 @@ //! Defines the basic interface provided by filesystem implementations. -use doors_alloc::sync::{Arc, Weak}; +use alloc::sync::Weak; use crate::errno::Errno; use crate::sync::Spinlock; diff --git a/kernel/src/fs/initrd.rs b/kernel/src/fs/initrd.rs index 177ed08..825e999 100644 --- a/kernel/src/fs/initrd.rs +++ b/kernel/src/fs/initrd.rs @@ -144,7 +144,7 @@ impl FsImpl for Initrd { mod tests { use crate::errno::Errno; use crate::fs::filesystem; - use doors_alloc::sync::Arc; + use crate::util::alloc::*; fn check_file_contents(f: filesystem::FsTreePtr, s: &str) { let mut buffer: [u8; 1024] = [0; 1024]; f.read_exact(0, &mut buffer[..s.len()]).unwrap(); diff --git a/kernel/src/hw/abstraction/timer.rs b/kernel/src/hw/abstraction/timer.rs index eec98e8..c585ac6 100644 --- a/kernel/src/hw/abstraction/timer.rs +++ b/kernel/src/hw/abstraction/timer.rs @@ -182,7 +182,6 @@ pub static TIMER: Timer = Timer { declare_test!(timer_basic, { use core::sync::atomic::*; - use doors_alloc::sync::Arc; let counter = Arc::try_new(AtomicI32::new(0)).unwrap(); for i in (0..10).rev() { let copy = Arc::clone(&counter); diff --git a/kernel/src/loader.rs b/kernel/src/loader.rs index 3b2440b..8d49206 100644 --- a/kernel/src/loader.rs +++ b/kernel/src/loader.rs @@ -1,6 +1,5 @@ //! The program loader. -use doors_alloc::sync::Arc; use x86_64::structures::paging::{Page, PageTableFlags, Size4KiB}; use x86_64::VirtAddr; diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 282e4c7..38dba21 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -11,6 +11,8 @@ //! //! The Doors kernel. +extern crate alloc; + use core::panic::PanicInfo; use core::sync::atomic::{AtomicI32, Ordering}; diff --git a/kernel/src/thread.rs b/kernel/src/thread.rs index 4275f10..d445b0b 100644 --- a/kernel/src/thread.rs +++ b/kernel/src/thread.rs @@ -8,13 +8,12 @@ use crate::mm::virt::PageDirectory; use crate::sync::{InterruptSafeSpinlock, Spinlock}; use crate::util::alloc::*; use crate::util::singleton::InterruptSafeSingleton; +use alloc::alloc::{alloc, alloc_zeroed, Layout}; use core::arch::global_asm; use core::cell::UnsafeCell; use core::ptr::NonNull; use core::sync::atomic::*; use core::{mem, ptr}; -use doors_alloc::alloc::{alloc, alloc_zeroed, Layout}; -use doors_alloc::sync::Arc; use x86_64::instructions::interrupts::are_enabled as interrupts_are_enabled; use x86_64::VirtAddr; diff --git a/kernel/src/util/alloc.rs b/kernel/src/util/alloc.rs index 230a45f..42bf20f 100644 --- a/kernel/src/util/alloc.rs +++ b/kernel/src/util/alloc.rs @@ -8,10 +8,10 @@ //! This will automatically bring [`String`], [`Vec`], [`Box`], and [`Arc`] into scope as well. use crate::errno::Errno; -pub use doors_alloc::boxed::Box; -pub use doors_alloc::string::String; -pub use doors_alloc::sync::Arc; -pub use doors_alloc::vec::Vec; +pub use alloc::boxed::Box; +pub use alloc::string::String; +pub use alloc::sync::Arc; +pub use alloc::vec::Vec; /// Represents an error that occurred with the [`try_push`](VecExt::try_push) method. #[derive(Clone, Copy, Debug, PartialEq, Eq)]