alloc user to access kernel backed heap (psram, if equiped)

This commit is contained in:
2025-10-27 12:25:57 -06:00
parent b872e6be7c
commit f6d5fb98ab
11 changed files with 150 additions and 82 deletions

View File

@@ -7,6 +7,4 @@ edition = "2024"
embedded-sdmmc = { version = "0.9.0", default-features = false }
embedded-graphics = "0.8.1"
abi_sys = { path = "../abi_sys" }
talc = "4.4.3"
spin = "0.10.0"
rand_core = "0.9.3"

View File

@@ -1,18 +1,26 @@
#![no_std]
pub use abi_sys::keyboard;
use abi_sys::{RngRequest, keyboard::KeyEvent};
use rand_core::RngCore;
use talc::*;
extern crate alloc;
static mut ARENA: [u8; 10000] = [0; 10000];
pub use abi_sys::keyboard;
use abi_sys::{RngRequest, alloc, dealloc, keyboard::KeyEvent};
use core::alloc::{GlobalAlloc, Layout};
use rand_core::RngCore;
#[global_allocator]
static ALLOCATOR: Talck<spin::Mutex<()>, ClaimOnOom> =
Talc::new(unsafe { ClaimOnOom::new(Span::from_array(core::ptr::addr_of!(ARENA).cast_mut())) })
.lock();
static ALLOC: Alloc = Alloc;
struct Alloc;
unsafe impl GlobalAlloc for Alloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
alloc(layout.into())
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
dealloc(ptr, layout.into());
}
}
pub fn print(msg: &str) {
abi_sys::print(msg.as_ptr(), msg.len());