pub struct IOPermissionBitmap<T = [u8]>(/* private fields */)
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§

source§

impl IOPermissionBitmap

source

pub const MAX_SIZE: usize = 8_193usize

Size in bytes required to map all I/O ports

source

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

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>
where T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized,

source

pub fn size(&self) -> usize

The number of bytes in this structure.

source

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.

source

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.

source

pub fn set_port_checked(&mut self, port: u16, value: bool)

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§

source§

impl<T> Debug for IOPermissionBitmap<T>
where T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T> PartialEq for IOPermissionBitmap<T>
where T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized + PartialEq,

source§

fn eq(&self, other: &IOPermissionBitmap<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> Eq for IOPermissionBitmap<T>
where T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized + Eq,

source§

impl<T> StructuralPartialEq for IOPermissionBitmap<T>
where T: AsRef<[u8]> + AsMut<[u8]> + Eq + ?Sized,

Auto Trait Implementations§

§

impl<T: ?Sized> RefUnwindSafe for IOPermissionBitmap<T>
where T: RefUnwindSafe,

§

impl<T: ?Sized> Send for IOPermissionBitmap<T>
where T: Send,

§

impl<T: ?Sized> Sync for IOPermissionBitmap<T>
where T: Sync,

§

impl<T: ?Sized> Unpin for IOPermissionBitmap<T>
where T: Unpin,

§

impl<T: ?Sized> UnwindSafe for IOPermissionBitmap<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.