Skip to content

Commit 6cd1a99

Browse files
RestiosonFreax13
authored andcommitted
doc & iomap limit calculation
1 parent e17b928 commit 6cd1a99

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/structures/gdt.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::structures::tss::TaskStateSegment;
55
use crate::PrivilegeLevel;
66
use bit_field::BitField;
77
use bitflags::bitflags;
8-
use core::fmt;
8+
use core::{fmt, cmp, mem};
99
// imports for intra-doc links
1010
#[cfg(doc)]
1111
use crate::registers::segmentation::{Segment, CS, SS};
@@ -449,8 +449,8 @@ impl Descriptor {
449449
///
450450
/// # Safety
451451
///
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`
454454
pub unsafe fn tss_segment_with_iomap(
455455
tss: &'static TaskStateSegment,
456456
iomap_size: u16,
@@ -465,9 +465,10 @@ impl Descriptor {
465465
low.set_bits(16..40, ptr.get_bits(0..24));
466466
low.set_bits(56..64, ptr.get_bits(24..32));
467467
// limit (the `-1` is needed since the bound is inclusive)
468+
let iomap_limit = tss.iomap_base as u64 + iomap_size as u64 - 1;
468469
low.set_bits(
469470
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),
471472
);
472473
// type (0b1001 = available 64-bit tss)
473474
low.set_bits(40..44, 0b1001);

0 commit comments

Comments
 (0)