Skip to content

Commit

Permalink
Merge pull request #362 from rust-osdev/align
Browse files Browse the repository at this point in the history
Increase alginment for packed structures
  • Loading branch information
josephlr authored Mar 30, 2022
2 parents aab60f7 + 4174de8 commit 6ae5b6a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/structures/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,28 @@ pub mod tss;
/// A struct describing a pointer to a descriptor table (GDT / IDT).
/// This is in a format suitable for giving to 'lgdt' or 'lidt'.
#[derive(Debug, Clone, Copy)]
#[repr(C, packed)]
#[repr(C, packed(2))]
pub struct DescriptorTablePointer {
/// Size of the DT.
pub limit: u16,
/// Pointer to the memory region containing the DT.
pub base: VirtAddr,
}

#[cfg(test)]
mod tests {
use super::*;
use std::mem::size_of;

#[test]
pub fn check_descriptor_pointer_size() {
// Per the SDM, a descriptor pointer has to be 2+8=10 bytes
assert_eq!(size_of::<DescriptorTablePointer>(), 10);
// Make sure that we can reference a pointer's limit
let p = DescriptorTablePointer {
limit: 5,
base: VirtAddr::zero(),
};
let _: &u16 = &p.limit;
}
}
2 changes: 1 addition & 1 deletion src/structures/tss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::mem::size_of;
/// but is used for finding kernel level stack
/// if interrupts arrive while in kernel mode.
#[derive(Debug, Clone, Copy)]
#[repr(C, packed)]
#[repr(C, packed(4))]
pub struct TaskStateSegment {
reserved_1: u32,
/// The full 64-bit canonical forms of the stack pointers (RSP) for privilege levels 0-2.
Expand Down

0 comments on commit 6ae5b6a

Please sign in to comment.