Skip to content

Commit 6667531

Browse files
committed
add Display impl for InvalidIoMap
1 parent 411b42b commit 6667531

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/structures/tss.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Provides a type for the task state segment structure.
22
33
use crate::VirtAddr;
4-
use core::mem::size_of;
4+
use core::{
5+
fmt::{self, Display},
6+
mem::size_of,
7+
};
58

69
/// In 64-bit mode the TSS holds information that is not
710
/// directly related to the task-switch mechanism,
@@ -83,6 +86,34 @@ pub enum InvalidIoMap {
8386
},
8487
}
8588

89+
impl Display for InvalidIoMap {
90+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
91+
match *self {
92+
InvalidIoMap::IoMapBeforeTss => {
93+
write!(f, "the IO permissions bitmap is before the TSS")
94+
}
95+
InvalidIoMap::TooFarFromTss { distance } => write!(
96+
f,
97+
"the IO permissions bitmap is too far from the TSS (distance {distance})"
98+
),
99+
InvalidIoMap::InvalidTerminatingByte { byte } => write!(
100+
f,
101+
"The final byte of the IO permissions bitmap was not 0xff ({byte}"
102+
),
103+
InvalidIoMap::TooLong { len } => {
104+
write!(
105+
f,
106+
"The IO permissions bitmap exceeds the maximum length ({len} > 8193)"
107+
)
108+
}
109+
InvalidIoMap::InvalidBase { expected, got } => write!(
110+
f,
111+
"the `iomap_base` in the `TaskStateSegment` struct was not what was expected (expected {expected}, got {got})"
112+
),
113+
}
114+
}
115+
}
116+
86117
#[cfg(test)]
87118
mod tests {
88119
use super::*;

0 commit comments

Comments
 (0)