@@ -4,7 +4,7 @@ use crate::structures::{tss::TaskStateSegment, DescriptorTablePointer};
4
4
use crate :: PrivilegeLevel ;
5
5
use bit_field:: BitField ;
6
6
use bitflags:: bitflags;
7
- use core:: fmt;
7
+ use core:: { fmt, cmp , mem } ;
8
8
9
9
/// Specifies which element to load into a segment from
10
10
/// descriptor tables (i.e., is a index to LDT or GDT table
@@ -314,8 +314,8 @@ impl Descriptor {
314
314
///
315
315
/// # Safety
316
316
///
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`
319
319
pub unsafe fn tss_segment_with_iomap (
320
320
tss : & ' static TaskStateSegment ,
321
321
iomap_size : u16 ,
@@ -330,9 +330,10 @@ impl Descriptor {
330
330
low. set_bits ( 16 ..40 , ptr. get_bits ( 0 ..24 ) ) ;
331
331
low. set_bits ( 56 ..64 , ptr. get_bits ( 24 ..32 ) ) ;
332
332
// limit (the `-1` is needed since the bound is inclusive)
333
+ let iomap_limit = tss. iomap_base as u64 + iomap_size as u64 - 1 ;
333
334
low. set_bits (
334
335
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 ) ,
336
337
) ;
337
338
// type (0b1001 = available 64-bit tss)
338
339
low. set_bits ( 40 ..44 , 0b1001 ) ;
0 commit comments