arch: arm64: detect kernel stack overflow condition

Currently, when a kernel stack overflow occures, the exception handler
blindly attempts to write the current context to the stack. If the SP
isn't valid this causes another fault, and so on - locking up the
system.

This commit re-arranges the stack layout, performs SP validation before
usage and switches to an emergency stack when SP isn't valid. This
allows the handler to run and panic gracefully.

Fixes: #98
This commit is contained in:
Matthew Leach
2026-01-03 15:34:48 +00:00
committed by Ashwin Naren
parent 57e0aa364c
commit d8bcc015de
8 changed files with 177 additions and 75 deletions

View File

@@ -152,7 +152,7 @@ impl<K: MemKind, T> Address<K, T> {
}
#[must_use]
pub fn add_bytes(self, n: usize) -> Self {
pub const fn add_bytes(self, n: usize) -> Self {
Self::from_value(self.value() + n)
}

View File

@@ -64,8 +64,8 @@ impl<T: MemKind> MemoryRegion<T> {
/// Create a memory region from a start and end address.
///
/// The size is calculated as `end - start`. No alignment is enforced.
pub fn from_start_end_address(start: Address<T, ()>, end: Address<T, ()>) -> Self {
assert!(end >= start);
pub const fn from_start_end_address(start: Address<T, ()>, end: Address<T, ()>) -> Self {
assert!(end.value() >= start.value());
Self {
address: start,