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

tss: Initialize iopb to be empty instead of zero #357

Merged
merged 1 commit into from
Mar 26, 2022
Merged
Changes from all commits
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
23 changes: 20 additions & 3 deletions src/structures/tss.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -22,18 +23,34 @@ 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::<TaskStateSegment>() - 1`, this means that `iomap_base` is
/// initialized to `size_of::<TaskStateSegment>()`.
#[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::<TaskStateSegment>() as u16,
reserved_1: 0,
reserved_2: 0,
reserved_3: 0,
reserved_4: 0,
}
}
}

#[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::<TaskStateSegment>(), 0x68);
}
}