@@ -5,7 +5,7 @@ use crate::structures::tss::TaskStateSegment;
5
5
use crate :: PrivilegeLevel ;
6
6
use bit_field:: BitField ;
7
7
use bitflags:: bitflags;
8
- use core:: fmt;
8
+ use core:: { fmt, cmp , mem } ;
9
9
// imports for intra-doc links
10
10
#[ cfg( doc) ]
11
11
use crate :: registers:: segmentation:: { Segment , CS , SS } ;
@@ -449,8 +449,8 @@ impl Descriptor {
449
449
///
450
450
/// # Safety
451
451
///
452
- /// If `iomap_size` is greater than zero, there ** must** be a valid IO map at `tss_ptr + iomap_base`.
453
- /// The size of the IO map must correspond with the given `iomap_size`.
452
+ /// There must be a valid IO map at `(tss as *const u8).offset(tss. iomap_base)`
453
+ /// of length `iomap_size`
454
454
pub unsafe fn tss_segment_with_iomap (
455
455
tss : & ' static TaskStateSegment ,
456
456
iomap_size : u16 ,
@@ -465,9 +465,10 @@ impl Descriptor {
465
465
low. set_bits ( 16 ..40 , ptr. get_bits ( 0 ..24 ) ) ;
466
466
low. set_bits ( 56 ..64 , ptr. get_bits ( 24 ..32 ) ) ;
467
467
// limit (the `-1` is needed since the bound is inclusive)
468
+ let iomap_limit = tss. iomap_base as u64 + iomap_size as u64 - 1 ;
468
469
low. set_bits (
469
470
0 ..16 ,
470
- ( size_of :: < TaskStateSegment > ( ) + ( tss . iomap_base + iomap_size ) as usize - 1 ) as u64 ,
471
+ cmp :: max ( mem :: size_of :: < TaskStateSegment > ( ) , iomap_limit ) ,
471
472
) ;
472
473
// type (0b1001 = available 64-bit tss)
473
474
low. set_bits ( 40 ..44 , 0b1001 ) ;
0 commit comments