Struct GlobalDescriptorTable
pub struct GlobalDescriptorTable<const MAX: usize = 8> {
table: [Entry; MAX],
len: usize,
}Expand description
A 64-bit mode global descriptor table (GDT).
In 64-bit mode, segmentation is not supported. The GDT is used nonetheless, for example for switching between user and kernel mode or for loading a TSS.
The GDT has a fixed maximum size given by the MAX const generic parameter.
Overflowing this limit by adding too many Descriptors via
GlobalDescriptorTable::append will panic.
You do not need to add a null segment descriptor yourself - this is already done
internally. This means you can add up to MAX - 1 additional Entrys to
this table. Note that some Descriptors may take up 2 Entrys.
Data segment registers in ring 0 can be loaded with the null segment selector. When running in
ring 3, the ss register must point to a valid data segment which can be obtained through the
Descriptor::user_data_segment() function. Code segments must
be valid and non-null at all times and can be obtained through the
Descriptor::kernel_code_segment() and
Descriptor::user_code_segment() in rings 0 and 3
respectively.
For more info, see:
x86 Instruction Reference for mov,
Intel Manual,
AMD Manual
§Example
use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor};
let mut gdt = GlobalDescriptorTable::new();
gdt.append(Descriptor::kernel_code_segment());
gdt.append(Descriptor::user_code_segment());
gdt.append(Descriptor::user_data_segment());
// Add entry for TSS, call gdt.load() then update segment registersFields§
§table: [Entry; MAX]§len: usizeImplementations§
§impl GlobalDescriptorTable
impl GlobalDescriptorTable
pub const fn new() -> GlobalDescriptorTable
pub const fn new() -> GlobalDescriptorTable
Creates an empty GDT with the default length of 8.
§impl<const MAX: usize> GlobalDescriptorTable<MAX>
impl<const MAX: usize> GlobalDescriptorTable<MAX>
pub const fn empty() -> GlobalDescriptorTable<MAX>
pub const fn empty() -> GlobalDescriptorTable<MAX>
Creates an empty GDT which can hold MAX number of Entrys.
pub const fn from_raw_entries(slice: &[u64]) -> GlobalDescriptorTable<MAX>
pub const fn from_raw_entries(slice: &[u64]) -> GlobalDescriptorTable<MAX>
Forms a GDT from a slice of u64.
This method allows for creation of a GDT with malformed or invalid
entries. However, it is safe because loading a GDT with invalid
entries doesn’t do anything until those entries are used. For example,
[CS::set_reg] and load_tss
are both unsafe for this reason.
Panics if:
- the provided slice has more than
MAXentries - the provided slice is empty
- the first entry is not zero
pub const fn append(&mut self, entry: Descriptor) -> SegmentSelector
pub const fn append(&mut self, entry: Descriptor) -> SegmentSelector
Appends the given segment descriptor to the GDT, returning the segment selector.
Note that depending on the type of the Descriptor this may append
either one or two new Entrys to the table.
Panics if the GDT doesn’t have enough free entries.
pub fn load(&'static self)
pub fn load(&'static self)
Loads the GDT in the CPU using the lgdt instruction. This does not alter any of the
segment registers; you must (re)load them yourself using the appropriate
functions:
[SS::set_reg()] and [CS::set_reg()].
pub unsafe fn load_unsafe(&self)
pub unsafe fn load_unsafe(&self)
Loads the GDT in the CPU using the lgdt instruction. This does not alter any of the
segment registers; you must (re)load them yourself using the appropriate
functions:
[SS::set_reg()] and [CS::set_reg()].
§Safety
Unlike load this function will not impose a static lifetime constraint
this means its up to the user to ensure that there will be no modifications
after loading and that the GDT will live for as long as it’s loaded.
Trait Implementations§
§impl<const MAX: usize> Clone for GlobalDescriptorTable<MAX>
impl<const MAX: usize> Clone for GlobalDescriptorTable<MAX>
§fn clone(&self) -> GlobalDescriptorTable<MAX>
fn clone(&self) -> GlobalDescriptorTable<MAX>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<const MAX: usize> Debug for GlobalDescriptorTable<MAX>
impl<const MAX: usize> Debug for GlobalDescriptorTable<MAX>
§impl Default for GlobalDescriptorTable
impl Default for GlobalDescriptorTable
§fn default() -> GlobalDescriptorTable
fn default() -> GlobalDescriptorTable
Auto Trait Implementations§
impl<const MAX: usize = 8> !Freeze for GlobalDescriptorTable<MAX>
impl<const MAX: usize> RefUnwindSafe for GlobalDescriptorTable<MAX>
impl<const MAX: usize> Send for GlobalDescriptorTable<MAX>
impl<const MAX: usize> Sync for GlobalDescriptorTable<MAX>
impl<const MAX: usize> Unpin for GlobalDescriptorTable<MAX>
impl<const MAX: usize> UnsafeUnpin for GlobalDescriptorTable<MAX>
impl<const MAX: usize> UnwindSafe for GlobalDescriptorTable<MAX>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more