Skip to content

Commit

Permalink
refactor: move ALLOCATOR to mm
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Mar 22, 2024
1 parent 8eec3c6 commit e382a37
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
5 changes: 0 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions src/mm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<Range<VirtAddr>> = Lazy::new(|| {
if cfg!(target_os = "none") {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(),
);
Expand Down
4 changes: 2 additions & 2 deletions src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e382a37

Please sign in to comment.