fix: stacks at top of user VA in own 1 MiB band (guard, heap kept below), 8/16 pages default; kernel fault msg names pid, kind, flags stack overflow; flaky OVERFLOW + spawntest/test-qemu check it

This commit is contained in:
2026-10-28 16:03:06 +01:00
parent 18e8b3ecb8
commit 495bf03484
12 changed files with 93 additions and 22 deletions

View File

@@ -0,0 +1,18 @@
//! Where things sit in every program's address space, below 1 GiB (the
//! RISC-V adapter's user window): the arguments page at `start_arg::
//! ARGS_VA`, the image from 0x10000, the heap above it (wherever the
//! kernel finds room, below `HEAP_END`), and the stack at the very top,
//! in a band of its own. The band's pages below the stack are never
//! mapped, so running off the stack faults there, and the kernel says so.
/// The first thread's stack ends here (the top of the user window).
pub const STACK_TOP: usize = 0x4000_0000;
/// The band the stack grows down into: its unmapped rest is the guard.
pub const STACK_BAND: usize = 0x10_0000;
/// The heap stays below the stack's band.
pub const HEAP_END: usize = STACK_TOP - STACK_BAND;
/// Whether a fault at `va` is a stack running off its end.
pub const fn is_stack_overflow(va: usize) -> bool {
va >= HEAP_END && va < STACK_TOP
}

View File

@@ -12,6 +12,7 @@ pub mod gatekeeper;
pub mod generation;
pub mod id;
pub mod input;
pub mod layout;
pub mod log;
pub mod macros;
pub mod mapping;

View File

@@ -12,8 +12,8 @@
use crate::budget::Limits;
pub const SPAWN: usize = 0;
/// Where init puts the child's stack top (its stack ends at the image).
pub const STACK_TOP: usize = 0x10000;
/// Where init puts the child's stack top (see `layout`).
pub const STACK_TOP: usize = crate::layout::STACK_TOP;
/// A slot word meaning "none".
pub const NONE: usize = usize::MAX;

View File

@@ -14,7 +14,8 @@ const PERMISSIONS_SHIFT: u32 = 48;
const SESSION_SHIFT: u32 = 56;
/// Where the arguments page sits: the program's arguments, NUL separated,
/// the first its name. Below the stack, which ends at the image.
/// the first its name. Above the unmapped page 0, below the image (see
/// `layout`).
pub const ARGS_VA: usize = 0x1000;
pub const ARGS_SIZE: usize = 4096;