Skip to content

Commit 7d2fa06

Browse files
committed
doc & iomap limit calculation
1 parent 290d0c6 commit 7d2fa06

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
@@ -4,7 +4,7 @@ use crate::structures::{tss::TaskStateSegment, DescriptorTablePointer};
44
use crate::PrivilegeLevel;
55
use bit_field::BitField;
66
use 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

Comments
 (0)