File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 1
1
//! Functions to flush the translation lookaside buffer (TLB).
2
2
3
+ use core:: fmt;
4
+
3
5
use crate :: VirtAddr ;
4
6
5
7
/// Invalidate the given address in the TLB using the `invlpg` instruction.
@@ -55,9 +57,9 @@ pub struct Pcid(u16);
55
57
impl Pcid {
56
58
/// Create a new PCID. Will result in a failure if the value of
57
59
/// 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 > {
59
61
if pcid >= 4096 {
60
- Err ( "PCID should be < 4096." )
62
+ Err ( PcidTooBig ( pcid ) )
61
63
} else {
62
64
Ok ( Pcid ( pcid) )
63
65
}
@@ -69,6 +71,18 @@ impl Pcid {
69
71
}
70
72
}
71
73
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
+
72
86
/// Invalidate the given address in the TLB using the `invpcid` instruction.
73
87
///
74
88
/// ## Safety
You can’t perform that action at this time.
0 commit comments