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

Provide null segment selector as associated constant on SegmentSelector #373

Merged
merged 3 commits into from
Apr 12, 2022
Merged
Changes from 1 commit
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
Next Next commit
Provide a method to retrieve the null segment descriptor.
This may be useful when used to load into a data register in ring 0.
e.g.
```
DS::set_reg(gdt.null_segment_descriptor())
```
Michael Jenny committed Apr 8, 2022
commit 6797d6303f78bb05508345ffef421679d3107bf1
8 changes: 8 additions & 0 deletions src/structures/gdt.rs
Original file line number Diff line number Diff line change
@@ -93,6 +93,14 @@ impl GlobalDescriptorTable {
&self.table[..self.len]
}

/// Get the GDT's null segment descriptor.
///
/// Can be used as a selector into a non-existent segment and assigned to segment registers.
#[inline]
pub fn null_segment_descriptor(&self) -> SegmentSelector {
SegmentSelector::new(0u16, PrivilegeLevel::from_u16(0u16))
}

/// Adds the given segment descriptor to the GDT, returning the segment selector.
///
/// Panics if the GDT doesn't have enough free entries to hold the Descriptor.