Skip to content

Commit

Permalink
fix(model_specific): make {Fs,Gs,KernelGs}Base::write() unsafe
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 24, 2024
1 parent f5a91f1 commit d2ef402
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/registers/model_specific.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,13 @@ mod x86_64 {
///
/// If [`CR4.FSGSBASE`][Cr4Flags::FSGSBASE] is set, the more efficient
/// [`FS::write_base`] can be used instead.
///
/// ## Safety
///
/// The caller must ensure that this write operation has no unsafe side
/// effects, as the segment base address might be in use.
#[inline]
pub fn write(address: VirtAddr) {
pub unsafe fn write(address: VirtAddr) {
let mut msr = Self::MSR;
unsafe { msr.write(address.as_u64()) };
}
Expand All @@ -328,8 +333,13 @@ mod x86_64 {
///
/// If [`CR4.FSGSBASE`][Cr4Flags::FSGSBASE] is set, the more efficient
/// [`GS::write_base`] can be used instead.
///
/// ## Safety
///
/// The caller must ensure that this write operation has no unsafe side
/// effects, as the segment base address might be in use.
#[inline]
pub fn write(address: VirtAddr) {
pub unsafe fn write(address: VirtAddr) {
let mut msr = Self::MSR;
unsafe { msr.write(address.as_u64()) };
}
Expand All @@ -343,8 +353,13 @@ mod x86_64 {
}

/// Write a given virtual address to the KernelGsBase register.
///
/// ## Safety
///
/// The caller must ensure that this write operation has no unsafe side
/// effects, as the segment base address might be in use.
#[inline]
pub fn write(address: VirtAddr) {
pub unsafe fn write(address: VirtAddr) {
let mut msr = Self::MSR;
unsafe { msr.write(address.as_u64()) };
}
Expand Down

0 comments on commit d2ef402

Please sign in to comment.