Skip to content
Draft
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
26 changes: 16 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ enum_dispatch = "0.3"
fdt = { version = "0.1", features = ["pretty-printing"] }
free-list = "0.3"
fuse-abi = { version = "0.2", features = ["linux"], optional = true }
good_memory_allocator = { version = "0.1.7", default-features = false }
hashbrown = { version = "0.16", default-features = false }
heapless = "0.9"
hermit-entry = { version = "0.10", features = ["kernel"] }
Expand All @@ -139,7 +140,6 @@ shell-words = { version = "1.1", default-features = false }
simple-shell = { version = "0.0.1", optional = true }
smallvec = { version = "1", features = ["const_new"] }
take-static = "0.1"
talc = { version = "4" }
thiserror = { version = "2", default-features = false }
time = { version = "0.3", default-features = false }
volatile = "0.6"
Expand Down
25 changes: 13 additions & 12 deletions src/mm/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

use core::alloc::{GlobalAlloc, Layout};

use hermit_sync::RawInterruptTicketMutex;
use talc::{ErrOnOom, Span, Talc, Talck};
use good_memory_allocator::Allocator;
use hermit_sync::InterruptTicketMutex;

pub struct LockedAllocator(Talck<RawInterruptTicketMutex, ErrOnOom>);
pub struct LockedAllocator(InterruptTicketMutex<Allocator>);

impl LockedAllocator {
pub const fn new() -> Self {
Self(Talc::new(ErrOnOom).lock())
Self(InterruptTicketMutex::new(Allocator::empty()))
}

#[inline]
Expand All @@ -22,9 +22,8 @@ impl LockedAllocator {
}

pub unsafe fn init(&self, heap_bottom: *mut u8, heap_size: usize) {
let arena = Span::from_base_size(heap_bottom, heap_size);
unsafe {
self.0.lock().claim(arena).unwrap();
self.0.lock().init(heap_bottom as usize, heap_size);
}
}
}
Expand All @@ -34,22 +33,24 @@ impl LockedAllocator {
unsafe impl GlobalAlloc for LockedAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let layout = Self::align_layout(layout);
unsafe { self.0.alloc(layout) }
unsafe { self.0.lock().alloc(layout) }
}

unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
let layout = Self::align_layout(layout);
unsafe { self.0.dealloc(ptr, layout) }
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
// TODO: do we need to consider the layout here? galloc docs don't mention this.
unsafe { self.0.lock().dealloc(ptr) }
}

unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 {
let layout = Self::align_layout(layout);
unsafe { self.0.alloc_zeroed(layout) }
let ptr = unsafe { self.0.lock().alloc(layout) };
unsafe { core::ptr::write_bytes(ptr, 0, layout.size()) };
ptr
}

unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
let layout = Self::align_layout(layout);
unsafe { self.0.realloc(ptr, layout, new_size) }
unsafe { self.0.lock().realloc(ptr, layout, new_size) }
}
}

Expand Down
Loading