Skip to content

Commit 0b5476e

Browse files
committed
gate HandlerFunc behind target_arch = "x86{_64}"
rustc is phasing out allowing the "x86-interrupt" ABI on non-x86 targets. Using "x86-interrupt" on a non-x86 target currently causes a warning, but this will become a hard error in a future version. Previously, if `abi_x86_interrupt` was enabled (it's enabled by default ), we used it in a pointer type for the declaration of the `HandlerFunc`- family of types and used a private empty tuple if `abi_x86_interrupt` wasn't enabled. This patch changes the cfg gate to only use the "x86-interrupt" abi on x86 targets. This is technically a breaking change, but I'd like to argue that we shouldn't treat it as such: The danger with treating this as a breaking change is that we can't release this fix as a patch update and so once rustc eventually treats this as an error, we might not yet have released the next breaking version leaving our users with not published fix. My hope is that there is no one using `HandlerFunc` on a non-x86 target. Even today, declaring a function (not just a function pointer) with the "x86-interrupt" abi on a non-x86 target causes an error, so it's unlikely that this will affect real code. It's technically possible to create a `HandlerFunc` on a non-x86 target by using transmute, but, again my hope is that no one is actually doing that. I'd also like to point out that the only use of a `HandlerFunc` on a non-x86 target would be to call set_handler_fn and any such calls could simply be replaced by calls to set_handler_addr.
1 parent 323d46c commit 0b5476e

File tree

1 file changed

+44
-11
lines changed

1 file changed

+44
-11
lines changed

src/structures/idt.rs

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -712,52 +712,82 @@ impl<T> PartialEq for Entry<T> {
712712
/// A handler function for an interrupt or an exception without error code.
713713
///
714714
/// This type alias is only usable with the `abi_x86_interrupt` feature enabled.
715-
#[cfg(feature = "abi_x86_interrupt")]
715+
#[cfg(all(
716+
any(target_arch = "x86", target_arch = "x86_64"),
717+
feature = "abi_x86_interrupt"
718+
))]
716719
pub type HandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame);
717720
/// This type is not usable without the `abi_x86_interrupt` feature.
718-
#[cfg(not(feature = "abi_x86_interrupt"))]
721+
#[cfg(not(all(
722+
any(target_arch = "x86", target_arch = "x86_64"),
723+
feature = "abi_x86_interrupt"
724+
)))]
719725
#[derive(Copy, Clone, Debug)]
720726
pub struct HandlerFunc(());
721727

722728
/// A handler function for an exception that pushes an error code.
723729
///
724730
/// This type alias is only usable with the `abi_x86_interrupt` feature enabled.
725-
#[cfg(feature = "abi_x86_interrupt")]
731+
#[cfg(all(
732+
any(target_arch = "x86", target_arch = "x86_64"),
733+
feature = "abi_x86_interrupt"
734+
))]
726735
pub type HandlerFuncWithErrCode = extern "x86-interrupt" fn(InterruptStackFrame, error_code: u64);
727736
/// This type is not usable without the `abi_x86_interrupt` feature.
728-
#[cfg(not(feature = "abi_x86_interrupt"))]
737+
#[cfg(not(all(
738+
any(target_arch = "x86", target_arch = "x86_64"),
739+
feature = "abi_x86_interrupt"
740+
)))]
729741
#[derive(Copy, Clone, Debug)]
730742
pub struct HandlerFuncWithErrCode(());
731743

732744
/// A page fault handler function that pushes a page fault error code.
733745
///
734746
/// This type alias is only usable with the `abi_x86_interrupt` feature enabled.
735-
#[cfg(feature = "abi_x86_interrupt")]
747+
#[cfg(all(
748+
any(target_arch = "x86", target_arch = "x86_64"),
749+
feature = "abi_x86_interrupt"
750+
))]
736751
pub type PageFaultHandlerFunc =
737752
extern "x86-interrupt" fn(InterruptStackFrame, error_code: PageFaultErrorCode);
738753
/// This type is not usable without the `abi_x86_interrupt` feature.
739-
#[cfg(not(feature = "abi_x86_interrupt"))]
754+
#[cfg(not(all(
755+
any(target_arch = "x86", target_arch = "x86_64"),
756+
feature = "abi_x86_interrupt"
757+
)))]
740758
#[derive(Copy, Clone, Debug)]
741759
pub struct PageFaultHandlerFunc(());
742760

743761
/// A handler function that must not return, e.g. for a machine check exception.
744762
///
745763
/// This type alias is only usable with the `abi_x86_interrupt` feature enabled.
746-
#[cfg(feature = "abi_x86_interrupt")]
764+
#[cfg(all(
765+
any(target_arch = "x86", target_arch = "x86_64"),
766+
feature = "abi_x86_interrupt"
767+
))]
747768
pub type DivergingHandlerFunc = extern "x86-interrupt" fn(InterruptStackFrame) -> !;
748769
/// This type is not usable without the `abi_x86_interrupt` feature.
749-
#[cfg(not(feature = "abi_x86_interrupt"))]
770+
#[cfg(not(all(
771+
any(target_arch = "x86", target_arch = "x86_64"),
772+
feature = "abi_x86_interrupt"
773+
)))]
750774
#[derive(Copy, Clone, Debug)]
751775
pub struct DivergingHandlerFunc(());
752776

753777
/// A handler function with an error code that must not return, e.g. for a double fault exception.
754778
///
755779
/// This type alias is only usable with the `abi_x86_interrupt` feature enabled.
756-
#[cfg(feature = "abi_x86_interrupt")]
780+
#[cfg(all(
781+
any(target_arch = "x86", target_arch = "x86_64"),
782+
feature = "abi_x86_interrupt"
783+
))]
757784
pub type DivergingHandlerFuncWithErrCode =
758785
extern "x86-interrupt" fn(InterruptStackFrame, error_code: u64) -> !;
759786
/// This type is not usable without the `abi_x86_interrupt` feature.
760-
#[cfg(not(feature = "abi_x86_interrupt"))]
787+
#[cfg(not(all(
788+
any(target_arch = "x86", target_arch = "x86_64"),
789+
feature = "abi_x86_interrupt"
790+
)))]
761791
#[derive(Copy, Clone, Debug)]
762792
pub struct DivergingHandlerFuncWithErrCode(());
763793

@@ -853,7 +883,10 @@ pub unsafe trait HandlerFuncType {
853883

854884
macro_rules! impl_handler_func_type {
855885
($f:ty) => {
856-
#[cfg(feature = "abi_x86_interrupt")]
886+
#[cfg(all(
887+
any(target_arch = "x86", target_arch = "x86_64"),
888+
feature = "abi_x86_interrupt"
889+
))]
857890
unsafe impl HandlerFuncType for $f {
858891
#[inline]
859892
fn to_virt_addr(self) -> VirtAddr {

0 commit comments

Comments
 (0)