@@ -4,7 +4,7 @@ use crate::structures::{tss::TaskStateSegment, DescriptorTablePointer};
44use crate :: PrivilegeLevel ;
55use bit_field:: BitField ;
66use bitflags:: bitflags;
7- use core:: fmt;
7+ use core:: { fmt, cmp , mem } ;
88
99/// Specifies which element to load into a segment from
1010/// descriptor tables (i.e., is a index to LDT or GDT table
@@ -314,8 +314,8 @@ impl Descriptor {
314314 ///
315315 /// # Safety
316316 ///
317- /// If `iomap_size` is greater than zero, there ** must** be a valid IO map at `tss_ptr + iomap_base`.
318- /// The size of the IO map must correspond with the given `iomap_size`.
317+ /// There must be a valid IO map at `(tss as *const u8).offset(tss. iomap_base)`
318+ /// of length `iomap_size`
319319 pub unsafe fn tss_segment_with_iomap (
320320 tss : & ' static TaskStateSegment ,
321321 iomap_size : u16 ,
@@ -330,9 +330,10 @@ impl Descriptor {
330330 low. set_bits ( 16 ..40 , ptr. get_bits ( 0 ..24 ) ) ;
331331 low. set_bits ( 56 ..64 , ptr. get_bits ( 24 ..32 ) ) ;
332332 // limit (the `-1` is needed since the bound is inclusive)
333+ let iomap_limit = tss. iomap_base as u64 + iomap_size as u64 - 1 ;
333334 low. set_bits (
334335 0 ..16 ,
335- ( size_of :: < TaskStateSegment > ( ) + ( tss . iomap_base + iomap_size ) as usize - 1 ) as u64 ,
336+ cmp :: max ( mem :: size_of :: < TaskStateSegment > ( ) , iomap_limit ) ,
336337 ) ;
337338 // type (0b1001 = available 64-bit tss)
338339 low. set_bits ( 40 ..44 , 0b1001 ) ;
0 commit comments