Skip to content

Commit 2a45f5c

Browse files
ryanbreenclaude
andcommitted
fix(interrupts): use transmute to satisfy IDT type requirements
The x86-interrupt ABI doesn't support return types, but the IDT expects a diverging handler for double faults. Using transmute to convert our handler to the expected type signature. The panic\! ensures the function never returns in practice. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ff820f1 commit 2a45f5c

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

kernel/src/interrupts.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ pub fn init_idt() {
6666
idt.invalid_opcode.set_handler_fn(invalid_opcode_handler);
6767
idt.general_protection_fault.set_handler_fn(general_protection_fault_handler);
6868
unsafe {
69-
idt.double_fault.set_handler_fn(double_fault_handler)
69+
// The x86-interrupt ABI doesn't support return types, but the IDT expects
70+
// a diverging handler. The panic! ensures it never returns.
71+
let handler: extern "x86-interrupt" fn(InterruptStackFrame, u64) -> ! =
72+
core::mem::transmute(double_fault_handler as extern "x86-interrupt" fn(InterruptStackFrame, u64));
73+
idt.double_fault.set_handler_fn(handler)
7074
.set_stack_index(gdt::DOUBLE_FAULT_IST_INDEX);
7175
}
7276
idt.page_fault.set_handler_fn(page_fault_handler);
@@ -148,7 +152,7 @@ extern "x86-interrupt" fn breakpoint_handler(stack_frame: InterruptStackFrame) {
148152
extern "x86-interrupt" fn double_fault_handler(
149153
stack_frame: InterruptStackFrame,
150154
_error_code: u64,
151-
) -> ! {
155+
) {
152156
// Log additional debug info before panicking
153157
log::error!("DOUBLE FAULT - Error Code: {:#x}", _error_code);
154158
log::error!("Instruction Pointer: {:#x}", stack_frame.instruction_pointer.as_u64());
@@ -162,11 +166,6 @@ extern "x86-interrupt" fn double_fault_handler(
162166
log::error!("Current page table frame: {:?}", frame);
163167

164168
panic!("EXCEPTION: DOUBLE FAULT\n{:#?}", stack_frame);
165-
// This is unreachable but needed to satisfy the type checker
166-
#[allow(unreachable_code)]
167-
loop {
168-
x86_64::instructions::hlt();
169-
}
170169
}
171170

172171

0 commit comments

Comments
 (0)