-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_overflow_test.rs
62 lines (47 loc) · 1.34 KB
/
stack_overflow_test.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#![no_std]
#![no_main]
#![feature(abi_x86_interrupt)]
use core::panic::PanicInfo;
use lazy_static::lazy_static;
use x86_64::structures::idt::InterruptStackFrame;
use x86_64::structures::idt::InterruptDescriptorTable;
use lambda_os::qemu::{exit_qemu, QemuExitCode};
#[panic_handler]
fn panic(info: &PanicInfo) -> ! {
lambda_os::test_panic_handler(info)
}
#[no_mangle]
pub extern "C" fn _start() -> ! {
lambda_os::serial_print!("stack_overflow... ");
lambda_os::gdt::init();
init_test_idt();
// trigger a stack overflow
stack_overflow();
panic!("Execution continued after stack overflow");
}
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(lambda_os::gdt::DOUBLE_FAULT_IST_INDEX);
}
return idt;
};
}
extern "x86-interrupt" fn test_double_fault_handler(
_stack_frame: &mut InterruptStackFrame,
_error_code: u64,
) -> ! {
lambda_os::serial_println!("[ok]");
exit_qemu(QemuExitCode::Success);
loop {}
}
pub fn init_test_idt() {
TEST_IDT.load();
}
#[allow(unconditional_recursion)]
fn stack_overflow() {
stack_overflow(); // for each recursion, the return address is pushed
}