Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Descriptor::tss_segment_unchecked #428

Merged
merged 2 commits into from
Jul 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/structures/gdt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,22 @@ impl Descriptor {
/// either be global or per-CPU).
#[inline]
pub fn tss_segment(tss: &'static TaskStateSegment) -> Descriptor {
// SAFETY: The pointer is derived from a &'static reference, which ensures its validity.
unsafe { Self::tss_segment_unchecked(tss) }
}

/// Similar to [`Descriptor::tss_segment`], but unsafe since it does not enforce a lifetime
/// constraint on the provided TSS.
///
/// # Safety
/// The caller must ensure that the passed pointer is valid for as long as the descriptor is
/// being used.
#[inline]
pub unsafe fn tss_segment_unchecked(tss: *const TaskStateSegment) -> Descriptor {
use self::DescriptorFlags as Flags;
use core::mem::size_of;

let ptr = tss as *const _ as u64;
let ptr = tss as u64;

let mut low = Flags::PRESENT.bits();
// base
Expand Down