Skip to content
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Fix panic in `tlsf::Heap::used`.
- Fix panic in `tlsf::Heap::free` in case the value returned from `insert_free_block_ptr`
does not conver the full memory range passed in.

## [v0.7.0] - 2026-01-03

Expand Down
18 changes: 13 additions & 5 deletions src/tlsf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,26 @@ impl Heap {
/// This function will panic if either of the following are true:
///
/// - this function is called more than ONCE.
/// - `size == 0`.
/// - `size`, after aligning start and end to `rlsf::GRANULARITY`, is smaller than `rlsf::GRANULARITY * 2`.
pub unsafe fn init(&self, start_addr: usize, size: usize) {
assert!(size > 0);
critical_section::with(|cs| {
let mut heap = self.heap.borrow_ref_mut(cs);
assert!(!heap.initialized);
heap.initialized = true;
let block: NonNull<[u8]> =
NonNull::slice_from_raw_parts(NonNull::new_unchecked(start_addr as *mut u8), size);
heap.tlsf.insert_free_block_ptr(block);
heap.raw_block = Some(block);
heap.raw_block_size = size;
if let Some(actual_size) = heap.tlsf.insert_free_block_ptr(block) {
let block: NonNull<[u8]> = NonNull::slice_from_raw_parts(
NonNull::new_unchecked(start_addr as *mut u8),
actual_size.get(),
);
heap.initialized = true;
heap.raw_block = Some(block);
heap.raw_block_size = size;
}
if !heap.initialized {
panic!("Allocation too small for heap");
}
});
}

Expand Down