pub struct IOPermissionBitmap<T = [u8]>(/* private fields */)
where
T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized;
Expand description
Bitmap that controls which I/O port addresses are covered by privilege checks.
For bit N
of this structure (bit N mod 8
of byte floor(N / 8)
), up to
max_port
:
- If the bit is set, then access to I/O port
N
is not allowed at privilege levels belowFlagRegister::io_privilege_level
(greater numbers). - If the bit is unset, then access to I/O port
N
is allowed from any privilege level.
This structure is stored in the task state segment (TSS) at a variable location
indicated by its
io_permission_map_offset
. It is
also variable-sized: if there are fewer than MAX_SIZE
bytes
between the start of the permission map and the limit
of
the containing TSS, then the processor acts as though the bits for all ports past
max_port_for_size(limit - offset)
are set.
Implementations§
Source§impl IOPermissionBitmap
impl IOPermissionBitmap
Sourcepub const fn required_size(max_port: u16) -> usize
pub const fn required_size(max_port: u16) -> usize
Calculate the size in bytes of a map that has bits for ports up to and including
max_port
.
Note that because of the way the processor reads this map, it requires an extra byte at the end that does not map any ports.
assert_eq!(IOPermissionBitmap::required_size(0), 2);
assert_eq!(IOPermissionBitmap::required_size(7), 2);
assert_eq!(IOPermissionBitmap::required_size(8), 3);
assert_eq!(IOPermissionBitmap::required_size(0xa587), 0x14b2);
assert_eq!(IOPermissionBitmap::required_size(0xffff), 0x2001);
Sourcepub const fn max_port_for_size(size: usize) -> Option<NonZeroU16>
pub const fn max_port_for_size(size: usize) -> Option<NonZeroU16>
Calculate the last I/O port that is covered by a map of the given size.
Note that because of the way the processor reads this map, it requires an extra
byte at the end that does not map any ports. Therefore, empty or single-byte maps
cannot represent any ports, and this function returns None
in those cases.
assert_eq!(IOPermissionBitmap::max_port_for_size(0), None);
assert_eq!(IOPermissionBitmap::max_port_for_size(1), None);
assert_eq!(IOPermissionBitmap::max_port_for_size(2), NonZeroU16::new(7));
assert_eq!(IOPermissionBitmap::max_port_for_size(4), NonZeroU16::new(23));
assert_eq!(IOPermissionBitmap::max_port_for_size(0x2000), NonZeroU16::new(0xfff7));
assert_eq!(IOPermissionBitmap::max_port_for_size(0x2001), NonZeroU16::new(0xffff));
assert_eq!(IOPermissionBitmap::max_port_for_size(0x2002), NonZeroU16::new(0xffff));
assert_eq!(IOPermissionBitmap::max_port_for_size(usize::MAX), NonZeroU16::new(0xffff));
Source§impl<T> IOPermissionBitmap<T>
impl<T> IOPermissionBitmap<T>
Sourcepub fn max_port(&self) -> Option<NonZeroU16>
pub fn max_port(&self) -> Option<NonZeroU16>
The last I/O port that is covered by this map. The bits for all ports greater than this value are assumed to be set.
Sourcepub fn is_port_checked(&self, port: u16) -> bool
pub fn is_port_checked(&self, port: u16) -> bool
Get the value in this bitmap that indicates whether the port should be subject to privilege level checks.
If the given port is beyond the range covered by this map
max_port
, this will return true, in line with the processor’s
behavior.