From dfc372d24167258243333924fd20b45996b8f87e Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Thu, 14 Sep 2023 14:43:46 +0200 Subject: [PATCH] Replace with rdgsbase dynamically in paranoid ISRs. --- src/arch/x86_64/interrupt/handler.rs | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/arch/x86_64/interrupt/handler.rs b/src/arch/x86_64/interrupt/handler.rs index 98cfe73c16..a44c24adea 100644 --- a/src/arch/x86_64/interrupt/handler.rs +++ b/src/arch/x86_64/interrupt/handler.rs @@ -263,21 +263,6 @@ macro_rules! swapgs_iff_ring3_fast_errorcode { " }; } -#[cfg(feature = "x86_fsbase")] -macro_rules! read_gsbase_into_rdx { - () => { "rdgsbase rdx;" } -} - -#[cfg(not(feature = "x86_fsbase"))] -macro_rules! read_gsbase_into_rdx { - () => { " - mov ecx, {IA32_GS_BASE} - rdmsr - shl rdx, 32 - or rdx, rax - " } -} - macro_rules! conditional_swapgs_paranoid { // For regular interrupt handlers and the syscall handler, managing IA32_GS_BASE and // IA32_KERNEL_GS_BASE (the "GSBASE registers") is more or less trivial when using the SWAPGS @@ -318,7 +303,16 @@ macro_rules! conditional_swapgs_paranoid { "sub rdi, {PCR_GDT_OFFSET};", // Read the current IA32_GS_BASE value into RDX. - read_gsbase_into_rdx!(), + alternative!( + feature: "fsgsbase", + then: ["rdgsbase rdx"], + default: [" + mov ecx, {IA32_GS_BASE} + rdmsr + shl rdx, 32 + or rdx, rax + "] + ), // If they were not equal, the PCR address must instead be in IA32_KERNEL_GS_BASE, // requiring a SWAPGS. GSBASE needs to be swapped back, so store the same flag in RBX.