mirror of
https://github.com/phil-opp/blog_os.git
synced 2025-12-16 14:27:49 +00:00
Simplify stack_overflow test
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
|
use blog_os::{exit_qemu, serial_print, serial_println, QemuExitCode};
|
||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn _start() -> ! {
|
pub extern "C" fn _start() -> ! {
|
||||||
@@ -16,10 +17,7 @@ pub extern "C" fn _start() -> ! {
|
|||||||
// trigger a stack overflow
|
// trigger a stack overflow
|
||||||
stack_overflow();
|
stack_overflow();
|
||||||
|
|
||||||
serial_println!("[failed]");
|
panic!("Execution continued after stack overflow");
|
||||||
serial_println!("Execution continued after stack overflow");
|
|
||||||
exit_qemu(QemuExitCode::Failed);
|
|
||||||
loop {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unconditional_recursion)]
|
#[allow(unconditional_recursion)]
|
||||||
@@ -27,22 +25,12 @@ fn stack_overflow() {
|
|||||||
stack_overflow(); // for each recursion, the return address is pushed
|
stack_overflow(); // for each recursion, the return address is pushed
|
||||||
}
|
}
|
||||||
|
|
||||||
#[panic_handler]
|
|
||||||
fn panic(info: &PanicInfo) -> ! {
|
|
||||||
serial_println!("[failed]");
|
|
||||||
serial_println!("{}", info);
|
|
||||||
exit_qemu(QemuExitCode::Failed);
|
|
||||||
loop {}
|
|
||||||
}
|
|
||||||
|
|
||||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref TEST_IDT: InterruptDescriptorTable = {
|
static ref TEST_IDT: InterruptDescriptorTable = {
|
||||||
let mut idt = InterruptDescriptorTable::new();
|
let mut idt = InterruptDescriptorTable::new();
|
||||||
unsafe {
|
unsafe {
|
||||||
idt.double_fault
|
idt.double_fault
|
||||||
.set_handler_fn(double_fault_handler)
|
.set_handler_fn(test_double_fault_handler)
|
||||||
.set_stack_index(blog_os::gdt::DOUBLE_FAULT_IST_INDEX);
|
.set_stack_index(blog_os::gdt::DOUBLE_FAULT_IST_INDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,7 +42,7 @@ pub fn init_test_idt() {
|
|||||||
TEST_IDT.load();
|
TEST_IDT.load();
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "x86-interrupt" fn double_fault_handler(
|
extern "x86-interrupt" fn test_double_fault_handler(
|
||||||
_stack_frame: &mut InterruptStackFrame,
|
_stack_frame: &mut InterruptStackFrame,
|
||||||
_error_code: u64,
|
_error_code: u64,
|
||||||
) {
|
) {
|
||||||
@@ -62,3 +50,8 @@ extern "x86-interrupt" fn double_fault_handler(
|
|||||||
exit_qemu(QemuExitCode::Success);
|
exit_qemu(QemuExitCode::Success);
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
fn panic(info: &PanicInfo) -> ! {
|
||||||
|
blog_os::test_panic_handler(info)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user