diff --git a/src/lib.rs b/src/lib.rs index c928a83b2f..da95c7c550 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -60,7 +60,6 @@ use arch::core_local::*; // Used for integration test status. #[doc(hidden)] pub use env::is_uhyve as _is_uhyve; -use mm::allocator::LockedAllocator; pub(crate) use crate::arch::*; pub use crate::config::DEFAULT_STACK_SIZE; @@ -124,10 +123,6 @@ fn trivial_test() { panic!("Test called"); } -#[cfg(target_os = "none")] -#[global_allocator] -static ALLOCATOR: LockedAllocator = LockedAllocator::new(); - /// Entry point of a kernel thread, which initialize the libos #[cfg(target_os = "none")] extern "C" fn initd(_arg: usize) { diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 815960c350..bc62d2a5a2 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -9,6 +9,7 @@ use hermit_sync::Lazy; #[cfg(feature = "newlib")] use hermit_sync::OnceCell; +use self::allocator::LockedAllocator; #[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))] use crate::arch::mm::paging::HugePageSize; #[cfg(target_arch = "x86_64")] @@ -22,6 +23,10 @@ use crate::arch::mm::PhysAddr; use crate::arch::mm::VirtAddr; use crate::{arch, env}; +#[cfg(target_os = "none")] +#[global_allocator] +pub static ALLOCATOR: LockedAllocator = LockedAllocator::new(); + /// Physical and virtual address range of the 2 MiB pages that map the kernel. static KERNEL_ADDR_RANGE: Lazy> = Lazy::new(|| { if cfg!(target_os = "none") { @@ -116,7 +121,7 @@ pub(crate) fn init() { unsafe { let start = allocate(kernel_heap_size, true); - crate::ALLOCATOR.init(start.as_mut_ptr(), kernel_heap_size); + ALLOCATOR.init(start.as_mut_ptr(), kernel_heap_size); info!("Kernel heap starts at {:#x}", start); } @@ -275,7 +280,7 @@ pub(crate) fn init() { #[cfg(not(feature = "newlib"))] unsafe { - crate::ALLOCATOR.init( + ALLOCATOR.init( heap_start_addr.as_mut_ptr(), (heap_end_addr - heap_start_addr).into(), ); diff --git a/src/syscalls/mod.rs b/src/syscalls/mod.rs index 052e6139ec..bac0a774fe 100644 --- a/src/syscalls/mod.rs +++ b/src/syscalls/mod.rs @@ -26,9 +26,9 @@ use crate::fd::{ IoError, OpenOption, PollFd, }; use crate::fs::{self, FileAttr}; -use crate::syscalls::interfaces::SyscallInterface; #[cfg(all(target_os = "none", not(feature = "common-os")))] -use crate::ALLOCATOR; +use crate::mm::ALLOCATOR; +use crate::syscalls::interfaces::SyscallInterface; mod condvar; mod entropy;