Skip to content

Commit

Permalink
Merge pull request #428 from SamZhang3/tss_segment_unchecked
Browse files Browse the repository at this point in the history
Add `Descriptor::tss_segment_unchecked`
  • Loading branch information
Freax13 committed Jul 22, 2023
2 parents ae5c6ec + 8a37f16 commit 3c3ac3c
Showing 1 changed file with 13 additions and 1 deletion.
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

0 comments on commit 3c3ac3c

Please sign in to comment.