Skip to content

Commit 3c3ac3c

Browse files
authored
Merge pull request #428 from SamZhang3/tss_segment_unchecked
Add `Descriptor::tss_segment_unchecked`
2 parents ae5c6ec + 8a37f16 commit 3c3ac3c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/structures/gdt.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,22 @@ impl Descriptor {
330330
/// either be global or per-CPU).
331331
#[inline]
332332
pub fn tss_segment(tss: &'static TaskStateSegment) -> Descriptor {
333+
// SAFETY: The pointer is derived from a &'static reference, which ensures its validity.
334+
unsafe { Self::tss_segment_unchecked(tss) }
335+
}
336+
337+
/// Similar to [`Descriptor::tss_segment`], but unsafe since it does not enforce a lifetime
338+
/// constraint on the provided TSS.
339+
///
340+
/// # Safety
341+
/// The caller must ensure that the passed pointer is valid for as long as the descriptor is
342+
/// being used.
343+
#[inline]
344+
pub unsafe fn tss_segment_unchecked(tss: *const TaskStateSegment) -> Descriptor {
333345
use self::DescriptorFlags as Flags;
334346
use core::mem::size_of;
335347

336-
let ptr = tss as *const _ as u64;
348+
let ptr = tss as u64;
337349

338350
let mut low = Flags::PRESENT.bits();
339351
// base

0 commit comments

Comments
 (0)