Skip to content
This repository has been archived by the owner on Jan 1, 2024. It is now read-only.

Commit

Permalink
Remove doors_alloc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SamZhang3 committed Jun 11, 2023
1 parent abe1522 commit d1a1ac7
Show file tree
Hide file tree
Showing 12 changed files with 14 additions and 19 deletions.
1 change: 0 additions & 1 deletion doors_alloc
Submodule doors_alloc deleted from 32e0d1
3 changes: 3 additions & 0 deletions kernel/.cargo/config.toml
Original file line number Diff line number Diff line change
@@ -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"]
5 changes: 0 additions & 5 deletions kernel/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions kernel/src/errno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ impl From<core::alloc::AllocError> for Errno {
}
}

impl From<doors_alloc::collections::TryReserveError> for Errno {
fn from(_value: doors_alloc::collections::TryReserveError) -> Self {
impl From<alloc::collections::TryReserveError> for Errno {
fn from(_value: alloc::collections::TryReserveError) -> Self {
Errno::ENOMEM
}
}
2 changes: 1 addition & 1 deletion kernel/src/fs/filesystem.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion kernel/src/fs/initrd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 0 additions & 1 deletion kernel/src/hw/abstraction/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ pub static TIMER: Timer<PIT> = 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);
Expand Down
1 change: 0 additions & 1 deletion kernel/src/loader.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//! The program loader.

use doors_alloc::sync::Arc;
use x86_64::structures::paging::{Page, PageTableFlags, Size4KiB};
use x86_64::VirtAddr;

Expand Down
2 changes: 2 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
//!
//! The Doors kernel.

extern crate alloc;

use core::panic::PanicInfo;
use core::sync::atomic::{AtomicI32, Ordering};

Expand Down
3 changes: 1 addition & 2 deletions kernel/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 4 additions & 4 deletions kernel/src/util/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down

0 comments on commit d1a1ac7

Please sign in to comment.