diff options
| author | salmonik <salmonik@tuta.io> | 2026-08-02 02:16:40 +0200 |
|---|---|---|
| committer | salmonik <salmonik@tuta.io> | 2026-08-02 02:16:40 +0200 |
| commit | d9fe082ef07b6e5c599585d6911dbad2bbe4c787 (patch) | |
| tree | f54e2ff928bd23926858aba9bd44c7a6f82bb80b /rsnix/src/memory.rs | |
| parent | v0.5.5: self-diagnosing boot — vt refuses 0x0 geometry, panic band shows la... (diff) | |
| download | rs-dos-d9fe082ef07b6e5c599585d6911dbad2bbe4c787.tar.gz rs-dos-d9fe082ef07b6e5c599585d6911dbad2bbe4c787.zip | |
v0.5.5: fix real-hardware boot crash — shadow back in heap as first allocation
User's machine: boot reached 'rsnix: boot done — shell' then panicked
'len is 0, index 0' at the first cell write — CELLS (the vt grid) was
valid at vt::init and empty at the first shell paint, i.e. something
stomped the heap between vt::init and the shell banner. The only
change in that window vs the working v0.5.3 was the v0.5.4 move of the
1.9 MB display shadow from the heap to the fb-aware page allocator:
on this machine's memory layout the page-allocator shadow's fill loop
(480K words) clobbered the heap's vt vectors.
- Shadow is again the *first* heap allocation, in gop::init before
vt::init builds its grids (the v0.5.3 layout that provably boots on
the user's hardware) — nothing else in the heap can collide with it.
- init_heap now splits the free list at the GOP framebuffer hole
instead of subtracting its size from one block that still *spanned*
the hole — no heap allocation of any size can land on the display.
- Kept the panic-proof try_reserve + fb-overlap rejection + no-shadow
warning band; dropped the late init_shadow() call in main.rs.
- Verified on QEMU: shadow @ 0x1980020 origin=heap, allocated before
vt::init, fb clean at 0x80000000; all 5 suites PASS; 0 warnings.
Diffstat (limited to '')
| -rw-r--r-- | rsnix/src/memory.rs | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/rsnix/src/memory.rs b/rsnix/src/memory.rs index a947c53..605125a 100644 --- a/rsnix/src/memory.rs +++ b/rsnix/src/memory.rs | |||
| @@ -366,18 +366,33 @@ fn init_heap() { | |||
| 366 | if d.kind == MEMORY_TYPE_CONVENTIONAL { | 366 | if d.kind == MEMORY_TYPE_CONVENTIONAL { |
| 367 | let s = d.physical_start as usize; | 367 | let s = d.physical_start as usize; |
| 368 | let e = s + d.number_of_pages as usize * 4096; | 368 | let e = s + d.number_of_pages as usize * 4096; |
| 369 | // Subtract any overlap with the framebuffer region. | 369 | // Split at the framebuffer hole so the free list NEVER |
| 370 | let (cs, ce) = match fb { | 370 | // contains fb pages: a coarse size subtraction leaves one |
| 371 | Some((b, sz)) if e > b && s < b + sz => (s.max(b), e.min(b + sz)), | 371 | // block *spanning* the hole, letting a large allocation |
| 372 | _ => (e, s), // no overlap → empty range | 372 | // (e.g. the 1.9 MB display shadow) straddle the display. |
| 373 | }; | 373 | let mut lo = s; |
| 374 | let mut sz = e - s; | 374 | if let Some((b, sz)) = fb |
| 375 | if ce > cs { | 375 | && e > b |
| 376 | sz -= ce - cs; | 376 | && s < b + sz |
| 377 | { | ||
| 378 | let h0 = b.max(s); | ||
| 379 | let h1 = (b + sz).min(e); | ||
| 380 | if h0 > lo { | ||
| 381 | // Segment before the hole. | ||
| 382 | let seg = h0 - lo; | ||
| 383 | if seg > best_size { | ||
| 384 | best_start = lo; | ||
| 385 | best_size = seg; | ||
| 386 | } | ||
| 387 | } | ||
| 388 | lo = h1; | ||
| 377 | } | 389 | } |
| 378 | if sz > best_size { | 390 | if e > lo { |
| 379 | best_start = s; | 391 | let seg = e - lo; |
| 380 | best_size = sz; | 392 | if seg > best_size { |
| 393 | best_start = lo; | ||
| 394 | best_size = seg; | ||
| 395 | } | ||
| 381 | } | 396 | } |
| 382 | } | 397 | } |
| 383 | } | 398 | } |
