Skip to content

Commit 5e06ff3

Browse files
author
Tom Dohrmann
committed
add GeneralHandlerFunc for set_general_handler
1 parent 8252697 commit 5e06ff3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

src/structures/idt.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,8 @@ pub type DivergingHandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame) -
602602
/// A handler function with an error code that must not return, e.g. for a double fault exception.
603603
pub type DivergingHandlerFuncWithErrCode =
604604
extern "x86-interrupt" fn(InterruptStackFrame, error_code: u64) -> !;
605+
/// A general handler function for an interrupt or an exception with the interrupt/exceptions's index and an optional error code.
606+
pub type GeneralHandlerFunc = fn(InterruptStackFrame, index: u8, error_code: Option<u64>);
605607

606608
impl<F> Entry<F> {
607609
/// Creates a non-present IDT entry (but sets the must-be-one bits).
@@ -923,13 +925,22 @@ macro_rules! set_general_handler {
923925
$crate::set_general_handler!($idt, $handler, $idx..=$idx);
924926
};
925927
($idt:expr, $handler:ident, $range:expr) => {{
926-
fn set_general_handler(
927-
idt: &mut $crate::structures::idt::InterruptDescriptorTable,
928-
range: impl core::ops::RangeBounds<usize>,
929-
) {
930-
$crate::set_general_handler_recursive_bits!(idt, $handler, range);
928+
/// This constant is used to avoid spamming the same compilation error ~200 times
929+
/// when the handler's signature is wrong.
930+
/// If we just passed `$handler` to `set_general_handler_recursive_bits`
931+
/// an error would be reported for every interrupt handler that tried to call it.
932+
/// With `GENERAL_HANDLER` the error is only reported once for this constant.
933+
const GENERAL_HANDLER: $crate::structures::idt::GeneralHandlerFunc = $handler;
934+
935+
{
936+
fn set_general_handler(
937+
idt: &mut $crate::structures::idt::InterruptDescriptorTable,
938+
range: impl ::core::ops::RangeBounds<usize>,
939+
) {
940+
$crate::set_general_handler_recursive_bits!(idt, GENERAL_HANDLER, range);
941+
}
942+
set_general_handler($idt, $range);
931943
}
932-
set_general_handler($idt, $range);
933944
}};
934945
}
935946

0 commit comments

Comments
 (0)