summaryrefslogtreecommitdiffstats
path: root/rsnix/src/memory.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--rsnix/src/memory.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/rsnix/src/memory.rs b/rsnix/src/memory.rs
index d33c781..c80edab 100644
--- a/rsnix/src/memory.rs
+++ b/rsnix/src/memory.rs
@@ -436,6 +436,11 @@ pub fn heap_stats() -> HeapStats {
436/// the heap itself (fixed-size stack arrays only). Returns true on success. 436/// the heap itself (fixed-size stack arrays only). Returns true on success.
437pub fn self_test() -> bool { 437pub fn self_test() -> bool {
438 unsafe { 438 unsafe {
439 // Snapshot the heap before we start: earlier boot code (e.g. the
440 // vt cell grids) may legitimately hold live allocations. The test
441 // must return the heap to exactly this state, not to "empty".
442 let before = heap_stats();
443
439 const N: usize = 128; 444 const N: usize = 128;
440 // (ptr, size, align) triplets — fixed array on the stack. 445 // (ptr, size, align) triplets — fixed array on the stack.
441 let mut blocks: [(usize, usize, usize); N] = [(0, 0, 0); N]; 446 let mut blocks: [(usize, usize, usize); N] = [(0, 0, 0); N];
@@ -504,7 +509,7 @@ pub fn self_test() -> bool {
504 ALLOCATOR.dealloc(*ptr as *mut u8, layout); 509 ALLOCATOR.dealloc(*ptr as *mut u8, layout);
505 } 510 }
506 let stats = heap_stats(); 511 let stats = heap_stats();
507 stats.free_blocks == 1 && stats.free_bytes == stats.heap_size 512 stats.free_blocks == before.free_blocks && stats.free_bytes == before.free_bytes
508 } 513 }
509} 514}
510 515