File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change 11//! Provides a type for the task state segment structure.
22
33use crate :: VirtAddr ;
4+ use core:: mem:: size_of;
45
56/// In 64-bit mode the TSS holds information that is not
67/// directly related to the task-switch mechanism,
@@ -22,18 +23,34 @@ pub struct TaskStateSegment {
2223}
2324
2425impl TaskStateSegment {
25- /// Creates a new TSS with zeroed privilege and interrupt stack table and a zero
26- /// `iomap_base`.
26+ /// Creates a new TSS with zeroed privilege and interrupt stack table and an
27+ /// empty I/O-Permission Bitmap.
28+ ///
29+ /// As we always set the TSS segment limit to
30+ /// `size_of::<TaskStateSegment>() - 1`, this means that `iomap_base` is
31+ /// initialized to `size_of::<TaskStateSegment>()`.
2732 #[ inline]
2833 pub const fn new ( ) -> TaskStateSegment {
2934 TaskStateSegment {
3035 privilege_stack_table : [ VirtAddr :: zero ( ) ; 3 ] ,
3136 interrupt_stack_table : [ VirtAddr :: zero ( ) ; 7 ] ,
32- iomap_base : 0 ,
37+ iomap_base : size_of :: < TaskStateSegment > ( ) as u16 ,
3338 reserved_1 : 0 ,
3439 reserved_2 : 0 ,
3540 reserved_3 : 0 ,
3641 reserved_4 : 0 ,
3742 }
3843 }
3944}
45+
46+ #[ cfg( test) ]
47+ mod tests {
48+ use super :: * ;
49+
50+ #[ test]
51+ pub fn check_tss_size ( ) {
52+ // Per the SDM, the minimum size of a TSS is 0x68 bytes, giving a
53+ // minimum limit of 0x67.
54+ assert_eq ! ( size_of:: <TaskStateSegment >( ) , 0x68 ) ;
55+ }
56+ }
You can’t perform that action at this time.
0 commit comments