@@ -602,6 +602,8 @@ pub type DivergingHandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame) -
602
602
/// A handler function with an error code that must not return, e.g. for a double fault exception.
603
603
pub type DivergingHandlerFuncWithErrCode =
604
604
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 > ) ;
605
607
606
608
impl < F > Entry < F > {
607
609
/// Creates a non-present IDT entry (but sets the must-be-one bits).
@@ -923,13 +925,22 @@ macro_rules! set_general_handler {
923
925
$crate:: set_general_handler!( $idt, $handler, $idx..=$idx) ;
924
926
} ;
925
927
( $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) ;
931
943
}
932
- set_general_handler( $idt, $range) ;
933
944
} } ;
934
945
}
935
946
0 commit comments