Skip to content

Commit 7f3661e

Browse files
committed
Disable interrupts while modifying the IRQ handler list
By disabling interrupts while we lock the IRQs list, we can be confident that the list is always unlocked when we handle interrupts, allowing us to lock the list, rather than trying to lock it and having a fallback option if that fails. This means we should avoid ignoring interrupts because of a failed attempt to lock the list. Signed-off-by: SlyMarbo <[email protected]>
1 parent d33700c commit 7f3661e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

kernel/src/interrupts.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use crate::{gdt, halt_loop, println, time};
3232
use lazy_static::lazy_static;
3333
use pic8259::ChainedPics;
34+
use x86_64::instructions::interrupts;
3435
use x86_64::registers::control::Cr2;
3536
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame, PageFaultErrorCode};
3637

@@ -130,11 +131,8 @@ fn irq_handler_none(_frame: InterruptStackFrame, _irq: u8) {}
130131

131132
#[inline]
132133
fn irq_handler_generic(frame: InterruptStackFrame, irq: u8) {
133-
let irqs = IRQS.try_lock();
134-
if let Some(irqs) = irqs {
135-
let handler = irqs[irq as usize];
136-
handler(frame, irq);
137-
}
134+
let handler = IRQS.lock()[irq as usize];
135+
handler(frame, irq);
138136

139137
unsafe {
140138
PICS.lock()
@@ -218,16 +216,18 @@ static IRQS: spin::Mutex<[IrqHandler; 16]> = spin::Mutex::new([irq_handler_none;
218216
/// panics.
219217
///
220218
pub fn register_irq(irq: u8, handler: IrqHandler) {
221-
let mut irqs = IRQS.lock();
222219
if irq > 15 {
223220
panic!("invalid IRQ {} passed to register_irq", irq);
224221
}
225222

226-
if irqs[irq as usize] != irq_handler_none {
227-
panic!("IRQ {} has already been registered", irq);
228-
}
223+
interrupts::without_interrupts(|| {
224+
let mut irqs = IRQS.lock();
225+
if irqs[irq as usize] != irq_handler_none {
226+
panic!("IRQ {} has already been registered", irq);
227+
}
229228

230-
irqs[irq as usize] = handler;
229+
irqs[irq as usize] = handler;
230+
});
231231
}
232232

233233
// Tests

0 commit comments

Comments
 (0)