XeOS/tests/stack_overflow.rs

61 lines
1.2 KiB
Rust
Raw Normal View History

2019-10-23 23:19:02 +00:00
#![no_std]
#![no_main]
#![feature(abi_x86_interrupt)]
use core::panic::PanicInfo;
use xe_os::serial_print;
#[no_mangle]
pub extern "C" fn _start() -> ! {
serial_print!("stack_overflow... ");
xe_os::gdt::init();
init_test_idt();
stack_overflow();
panic!("Execution continued after stack overflow");
}
#[allow(unconditional_recursion)]
fn stack_overflow() {
stack_overflow();
}
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
xe_os::test_panic_handler(info)
}
use lazy_static::lazy_static;
use x86_64::structures::idt::InterruptDescriptorTable;
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(xe_os::gdt::DOUBLE_FAULT_IST_INDEX);
}
idt
};
}
use x86_64::structures::idt::InterruptStackFrame;
2019-10-24 00:30:47 +00:00
use xe_os::{exit_qemu, serial_println, QemuExitCode};
2019-10-23 23:19:02 +00:00
extern "x86-interrupt" fn test_double_fault_handler(
_stack_frame: &mut InterruptStackFrame,
_error_code: u64,
) {
serial_println!("[ok]");
exit_qemu(QemuExitCode::Success);
loop {}
}
pub fn init_test_idt() {
TEST_IDT.load();
}