Skip to content

Commit

Permalink
fix(x86_64/CoreLocal): remove hardcoded field offsets
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed May 6, 2024
1 parent 9939d6f commit 4bc4766
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/arch/x86_64/kernel/core_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use alloc::boxed::Box;
use alloc::vec::Vec;
use core::arch::asm;
use core::cell::{Cell, RefCell, RefMut};
use core::ptr;
use core::sync::atomic::Ordering;
use core::{mem, ptr};

#[cfg(feature = "smp")]
use hermit_sync::InterruptTicketMutex;
Expand Down Expand Up @@ -81,7 +81,7 @@ impl CoreLocal {
debug_assert_ne!(VirtAddr::zero(), GsBase::read());
unsafe {
let raw: *const Self;
asm!("mov {}, gs:0", out(reg) raw, options(nomem, nostack, preserves_flags));
asm!("mov {}, gs:{}", out(reg) raw, const mem::offset_of!(Self, this), options(nomem, nostack, preserves_flags));
&*raw
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/arch/x86_64/kernel/syscall.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use core::arch::asm;
use core::mem;

use super::core_local::CoreLocal;
use crate::syscalls::table::SYSHANDLER_TABLE;

#[no_mangle]
Expand All @@ -19,7 +21,7 @@ pub(crate) unsafe extern "C" fn syscall_handler() -> ! {
// switch to kernel stack
"swapgs",
"mov rcx, rsp",
"mov rsp, gs:32",
"mov rsp, gs:{core_local_kernel_stack}",
// save user stack pointer
"push rcx",
// copy 4th argument to rcx to adhere x86_64 ABI
Expand All @@ -42,6 +44,7 @@ pub(crate) unsafe extern "C" fn syscall_handler() -> ! {
"pop rdx",
"pop rcx",
"sysretq",
core_local_kernel_stack = const mem::offset_of!(CoreLocal, kernel_stack),
table = sym SYSHANDLER_TABLE,
options(noreturn)
);
Expand Down

0 comments on commit 4bc4766

Please sign in to comment.