Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Move allocator module to crate root #66

Merged
merged 3 commits into from
May 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mm/allocator.rs → src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use core::alloc::GlobalAlloc;
use core::alloc::Layout;

#[global_allocator]
static ALLOCATOR: Allocator = Allocator;

/// Size of the preallocated space for the Bootstrap Allocator.
const BOOTSTRAP_HEAP_SIZE: usize = 2 * 1024 * 1024;

Expand Down
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,14 @@ extern crate bitflags;
#[macro_use]
pub mod macros;

pub mod allocator;
pub mod arch;
pub mod console;
pub mod kernel;
pub mod mm;
mod runtime_glue;

use core::ptr;

#[global_allocator]
static ALLOCATOR: mm::allocator::Allocator = mm::allocator::Allocator;

// FUNCTIONS
pub unsafe fn sections_init() {
extern "C" {
Expand Down
10 changes: 0 additions & 10 deletions src/mm/mod.rs

This file was deleted.

7 changes: 7 additions & 0 deletions src/runtime_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ fn panic(info: &PanicInfo<'_>) -> ! {

loop {}
}

#[cfg(not(test))]
#[alloc_error_handler]
fn rust_oom(layout: core::alloc::Layout) -> ! {
let size = layout.size();
panic!("memory allocation of {size} bytes failed")
}