aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNatasha Moongrave <natasha@256phi.eu>2026-02-18 20:31:57 +0100
committerNatasha Moongrave <natasha@256phi.eu>2026-02-18 20:31:57 +0100
commit98fc4d3b83bb15c6b3a69b70b0cb4f1d2e09d8a1 (patch)
tree7c610cf5158810f55331a6dcead680794cb1242e
parentaf192783262192c44c16cb7198e049f0104a717b (diff)
added a test for stack_overflow
-rw-r--r--StrixKernel/Cargo.toml5
-rw-r--r--StrixKernel/tests/stack_overflow.rs58
2 files changed, 62 insertions, 1 deletions
diff --git a/StrixKernel/Cargo.toml b/StrixKernel/Cargo.toml
index cd7e04a..35b86bd 100644
--- a/StrixKernel/Cargo.toml
+++ b/StrixKernel/Cargo.toml
@@ -1,13 +1,16 @@
[package]
name = "strix_os"
version = "0.1.0"
-authors = ["Philipp Oppermann <dev@phil-opp.com>"]
edition = "2024"
[[test]]
name = "should_panic"
harness = false
+[[test]]
+name = "stack_overflow"
+harness = false
+
[dependencies]
bootloader = "0.9"
volatile = "0.2.6"
diff --git a/StrixKernel/tests/stack_overflow.rs b/StrixKernel/tests/stack_overflow.rs
new file mode 100644
index 0000000..66f52a3
--- /dev/null
+++ b/StrixKernel/tests/stack_overflow.rs
@@ -0,0 +1,58 @@
+#![no_std]
+#![no_main]
+#![feature(abi_x86_interrupt)]
+
+use strix_os::{QemuExitCode, exit_qemu, serial_print, serial_println};
+use core::panic::PanicInfo;
+use lazy_static::lazy_static;
+use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
+
+#[unsafe(no_mangle)]
+pub extern "C" fn _start() -> ! {
+ serial_print!("stack_overflow::stack_overflow...\t");
+
+ strix_os::gdt::init();
+ init_test_idt();
+
+ // trigger a stack overflow
+ stack_overflow();
+
+ panic!("Execution continued after stack overflow");
+}
+
+#[allow(unconditional_recursion)]
+fn stack_overflow() {
+ stack_overflow(); // for each recursion, the return address is pushed
+ volatile::Volatile::new(0).read(); // prevent tail recursion optimizations
+}
+
+lazy_static! {
+ static ref TEST_IDT: InterruptDescriptorTable = {
+ let mut idt = InterruptDescriptorTable::new();
+ unsafe {
+ idt.double_fault
+ .set_handler_fn(test_double_fault_handler)
+ .set_stack_index(strix_os::gdt::DOUBLE_FAULT_IST_INDEX);
+ }
+
+ idt
+ };
+}
+
+pub fn init_test_idt() {
+ TEST_IDT.load();
+}
+
+extern "x86-interrupt" fn test_double_fault_handler(
+ _stack_frame: InterruptStackFrame,
+ _error_code: u64,
+) -> ! {
+ serial_println!("[ok]");
+ exit_qemu(QemuExitCode::Success);
+ loop {}
+}
+
+#[panic_handler]
+fn panic(info: &PanicInfo) -> ! {
+ strix_os::test_panic_handler(info)
+} \ No newline at end of file