pub struct IOPermissionBitmap<T = [u8]>(_)
where
    T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized
;
Available on x86 or x86-64 only.
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 below FlagRegister::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§

Size in bytes required to map all I/O ports

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);

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));

The number of bytes in this structure.

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.

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.

Set the value in this bitmap that indicates whether the port should be subject to privilege level checks.

Panics

Panics if the given port is greater than max_port.

Trait Implementations§

Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.