From d6916a46244e4233f696a5deace63a4aea44630c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 12 May 2022 16:11:09 +0200 Subject: [PATCH 1/3] Move alloc_error_handler to runtime_glue --- src/mm/mod.rs | 9 --------- src/runtime_glue.rs | 7 +++++++ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/mm/mod.rs b/src/mm/mod.rs index 59d499fe..98fe5c37 100644 --- a/src/mm/mod.rs +++ b/src/mm/mod.rs @@ -1,10 +1 @@ pub mod allocator; - -#[cfg(not(test))] -use core::alloc::Layout; - -#[cfg(not(test))] -#[alloc_error_handler] -fn alloc_error_handler(layout: Layout) -> ! { - panic!("[OOM] Allocation of {:?} failed", layout); -} diff --git a/src/runtime_glue.rs b/src/runtime_glue.rs index 1d83af17..680f90b3 100644 --- a/src/runtime_glue.rs +++ b/src/runtime_glue.rs @@ -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") +} From 0cca40666e608dcafb35db8734f0e7d5354b2919 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 12 May 2022 16:14:59 +0200 Subject: [PATCH 2/3] Move allocator module out of empty mm module --- src/{mm => }/allocator.rs | 0 src/lib.rs | 4 ++-- src/mm/mod.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) rename src/{mm => }/allocator.rs (100%) delete mode 100644 src/mm/mod.rs diff --git a/src/mm/allocator.rs b/src/allocator.rs similarity index 100% rename from src/mm/allocator.rs rename to src/allocator.rs diff --git a/src/lib.rs b/src/lib.rs index 3b3092f0..93d6e62b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,16 +18,16 @@ 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; +static ALLOCATOR: allocator::Allocator = allocator::Allocator; // FUNCTIONS pub unsafe fn sections_init() { diff --git a/src/mm/mod.rs b/src/mm/mod.rs deleted file mode 100644 index 98fe5c37..00000000 --- a/src/mm/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod allocator; From 5ca0888af06109eaf8a224267a02745db983bc31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Kr=C3=B6ning?= Date: Thu, 12 May 2022 16:15:59 +0200 Subject: [PATCH 3/3] Move global_allocator to allocator module --- src/allocator.rs | 3 +++ src/lib.rs | 3 --- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/allocator.rs b/src/allocator.rs index 6923813e..2064baa8 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -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; diff --git a/src/lib.rs b/src/lib.rs index 93d6e62b..099eee21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,9 +26,6 @@ mod runtime_glue; use core::ptr; -#[global_allocator] -static ALLOCATOR: allocator::Allocator = allocator::Allocator; - // FUNCTIONS pub unsafe fn sections_init() { extern "C" {