Skip to content

Commit 6ae5b6a

Browse files
authored
Merge pull request #362 from rust-osdev/align
Increase alginment for packed structures
2 parents aab60f7 + 4174de8 commit 6ae5b6a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/structures/mod.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ pub mod tss;
1313
/// A struct describing a pointer to a descriptor table (GDT / IDT).
1414
/// This is in a format suitable for giving to 'lgdt' or 'lidt'.
1515
#[derive(Debug, Clone, Copy)]
16-
#[repr(C, packed)]
16+
#[repr(C, packed(2))]
1717
pub struct DescriptorTablePointer {
1818
/// Size of the DT.
1919
pub limit: u16,
2020
/// Pointer to the memory region containing the DT.
2121
pub base: VirtAddr,
2222
}
23+
24+
#[cfg(test)]
25+
mod tests {
26+
use super::*;
27+
use std::mem::size_of;
28+
29+
#[test]
30+
pub fn check_descriptor_pointer_size() {
31+
// Per the SDM, a descriptor pointer has to be 2+8=10 bytes
32+
assert_eq!(size_of::<DescriptorTablePointer>(), 10);
33+
// Make sure that we can reference a pointer's limit
34+
let p = DescriptorTablePointer {
35+
limit: 5,
36+
base: VirtAddr::zero(),
37+
};
38+
let _: &u16 = &p.limit;
39+
}
40+
}

src/structures/tss.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use core::mem::size_of;
88
/// but is used for finding kernel level stack
99
/// if interrupts arrive while in kernel mode.
1010
#[derive(Debug, Clone, Copy)]
11-
#[repr(C, packed)]
11+
#[repr(C, packed(4))]
1212
pub struct TaskStateSegment {
1313
reserved_1: u32,
1414
/// The full 64-bit canonical forms of the stack pointers (RSP) for privilege levels 0-2.

0 commit comments

Comments
 (0)