Skip to content

Commit 8695b39

Browse files
author
Tom Dohrmann
committed
add GeneralHandlerFunc for set_general_handler
1 parent f9b134e commit 8695b39

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

src/structures/idt.rs

+18-6
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,9 @@ pub type DivergingHandlerFuncWithErrCode =
685685
#[derive(Copy, Clone, Debug)]
686686
pub struct DivergingHandlerFuncWithErrCode(());
687687

688+
/// A general handler function for an interrupt or an exception with the interrupt/exceptions's index and an optional error code.
689+
pub type GeneralHandlerFunc = fn(InterruptStackFrame, index: u8, error_code: Option<u64>);
690+
688691
impl<F> Entry<F> {
689692
/// Creates a non-present IDT entry (but sets the must-be-one bits).
690693
#[inline]
@@ -1153,13 +1156,22 @@ macro_rules! set_general_handler {
11531156
$crate::set_general_handler!($idt, $handler, $idx..=$idx);
11541157
};
11551158
($idt:expr, $handler:ident, $range:expr) => {{
1156-
fn set_general_handler(
1157-
idt: &mut $crate::structures::idt::InterruptDescriptorTable,
1158-
range: impl core::ops::RangeBounds<usize>,
1159-
) {
1160-
$crate::set_general_handler_recursive_bits!(idt, $handler, range);
1159+
/// This constant is used to avoid spamming the same compilation error ~200 times
1160+
/// when the handler's signature is wrong.
1161+
/// If we just passed `$handler` to `set_general_handler_recursive_bits`
1162+
/// an error would be reported for every interrupt handler that tried to call it.
1163+
/// With `GENERAL_HANDLER` the error is only reported once for this constant.
1164+
const GENERAL_HANDLER: $crate::structures::idt::GeneralHandlerFunc = $handler;
1165+
1166+
{
1167+
fn set_general_handler(
1168+
idt: &mut $crate::structures::idt::InterruptDescriptorTable,
1169+
range: impl ::core::ops::RangeBounds<usize>,
1170+
) {
1171+
$crate::set_general_handler_recursive_bits!(idt, GENERAL_HANDLER, range);
1172+
}
1173+
set_general_handler($idt, $range);
11611174
}
1162-
set_general_handler($idt, $range);
11631175
}};
11641176
}
11651177

0 commit comments

Comments
 (0)