Skip to content

Commit 8fe252f

Browse files
committed
add PcidTooBig error
1 parent 3b8a597 commit 8fe252f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/instructions/tlb.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Functions to flush the translation lookaside buffer (TLB).
22
3+
use core::fmt;
4+
35
use crate::VirtAddr;
46

57
/// Invalidate the given address in the TLB using the `invlpg` instruction.
@@ -55,9 +57,9 @@ pub struct Pcid(u16);
5557
impl Pcid {
5658
/// Create a new PCID. Will result in a failure if the value of
5759
/// PCID is out of expected bounds.
58-
pub const fn new(pcid: u16) -> Result<Pcid, &'static str> {
60+
pub const fn new(pcid: u16) -> Result<Pcid, PcidTooBig> {
5961
if pcid >= 4096 {
60-
Err("PCID should be < 4096.")
62+
Err(PcidTooBig(pcid))
6163
} else {
6264
Ok(Pcid(pcid))
6365
}
@@ -69,6 +71,18 @@ impl Pcid {
6971
}
7072
}
7173

74+
/// A passed `u16` was not a valid PCID.
75+
///
76+
/// A PCID has to be <= 4096 for x86_64.
77+
#[derive(Debug)]
78+
pub struct PcidTooBig(u16);
79+
80+
impl fmt::Display for PcidTooBig {
81+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
82+
write!(f, "PCID should be < 4096, got {}", self.0)
83+
}
84+
}
85+
7286
/// Invalidate the given address in the TLB using the `invpcid` instruction.
7387
///
7488
/// ## Safety

0 commit comments

Comments
 (0)