diff --git a/src/structures/tss.rs b/src/structures/tss.rs index 882a3eebb..5b52db3d6 100644 --- a/src/structures/tss.rs +++ b/src/structures/tss.rs @@ -1,6 +1,7 @@ //! Provides a type for the task state segment structure. use crate::VirtAddr; +use core::mem::size_of; /// In 64-bit mode the TSS holds information that is not /// directly related to the task-switch mechanism, @@ -22,14 +23,18 @@ pub struct TaskStateSegment { } impl TaskStateSegment { - /// Creates a new TSS with zeroed privilege and interrupt stack table and a zero - /// `iomap_base`. + /// Creates a new TSS with zeroed privilege and interrupt stack table and an + /// empty I/O-Permission Bitmap. + /// + /// As we always set the TSS segment limit to + /// `size_of::() - 1`, this means that `iomap_base` is + /// initialized to `size_of::()`. #[inline] pub const fn new() -> TaskStateSegment { TaskStateSegment { privilege_stack_table: [VirtAddr::zero(); 3], interrupt_stack_table: [VirtAddr::zero(); 7], - iomap_base: 0, + iomap_base: size_of::() as u16, reserved_1: 0, reserved_2: 0, reserved_3: 0, @@ -37,3 +42,15 @@ impl TaskStateSegment { } } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + pub fn check_tss_size() { + // Per the SDM, the minimum size of a TSS is 0x68 bytes, giving a + // minimum limit of 0x67. + assert_eq!(size_of::(), 0x68); + } +}