Implement an alloc_init feature to allow initializing custom allocators.
diff --git a/core/Cargo.toml b/core/Cargo.toml index 94f3c8f..636755c 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml
@@ -5,7 +5,8 @@ edition = "2018" [features] -alloc = [ "linked_list_allocator" ] +alloc = ["alloc_init", "linked_list_allocator"] +alloc_init = [] custom_panic_handler = [] custom_alloc_error_handler = []
diff --git a/core/src/alloc.rs b/core/src/alloc.rs index 05e9669..1c58edc 100644 --- a/core/src/alloc.rs +++ b/core/src/alloc.rs
@@ -4,7 +4,12 @@ use core::ptr::NonNull; use linked_list_allocator::Heap; -pub static mut HEAP: Heap = Heap::empty(); +static mut HEAP: Heap = Heap::empty(); + +#[no_mangle] +unsafe fn alloc_init(app_heap_start: usize, app_heap_size: usize) { + HEAP.init(app_heap_start, app_heap_size); +} struct TockAllocator;
diff --git a/core/src/entry_point/mod.rs b/core/src/entry_point/mod.rs index 40bdb62..0a63b8e 100644 --- a/core/src/entry_point/mod.rs +++ b/core/src/entry_point/mod.rs
@@ -127,8 +127,8 @@ // Tell the kernel the new app heap break. memop::set_brk(app_heap_end as *const u8); - #[cfg(feature = "alloc")] - crate::alloc::HEAP.init(app_heap_start, app_heap_size); + #[cfg(feature = "alloc_init")] + crate::alloc_init(app_heap_start, app_heap_size); main(0, ptr::null());
diff --git a/core/src/lib.rs b/core/src/lib.rs index e465f4d..a529b55 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs
@@ -8,6 +8,11 @@ #[cfg(any(target_arch = "arm", target_arch = "riscv32"))] mod lang_items; +#[cfg(feature = "alloc_init")] +extern "Rust" { + fn alloc_init(app_heap_start: usize, app_heap_size: usize); +} + pub mod callback; pub mod debug; pub mod memop;