@@ -59,53 +59,36 @@ extern crate alloc;
59
59
60
60
#[ cfg( target_arch = "aarch64" ) ]
61
61
use core:: arch:: asm;
62
- use core:: fmt:: { self , Display , Formatter } ;
63
62
use paging:: {
64
63
Attributes , Constraints , Descriptor , MemoryRegion , PhysicalAddress , RootTable , Translation ,
65
64
TranslationRegime , VaRange , VirtualAddress ,
66
65
} ;
66
+ use thiserror:: Error ;
67
67
68
68
/// An error attempting to map some range in the page table.
69
- #[ derive( Clone , Debug , Eq , PartialEq ) ]
69
+ #[ derive( Clone , Debug , Eq , Error , PartialEq ) ]
70
70
pub enum MapError {
71
71
/// The address requested to be mapped was out of the range supported by the page table
72
72
/// configuration.
73
+ #[ error( "Virtual address {0} out of range" ) ]
73
74
AddressRange ( VirtualAddress ) ,
74
75
/// The address requested to be mapped was not valid for the mapping in use.
76
+ #[ error( "Invalid virtual address {0} for mapping" ) ]
75
77
InvalidVirtualAddress ( VirtualAddress ) ,
76
78
/// The end of the memory region is before the start.
79
+ #[ error( "End of memory region {0} is before start." ) ]
77
80
RegionBackwards ( MemoryRegion ) ,
78
81
/// There was an error while updating a page table entry.
82
+ #[ error( "Error updating page table entry {0:?}" ) ]
79
83
PteUpdateFault ( Descriptor ) ,
80
84
/// The requested flags are not supported for this mapping
85
+ #[ error( "Flags {0:?} unsupported for mapping." ) ]
81
86
InvalidFlags ( Attributes ) ,
82
87
/// Updating the range violates break-before-make rules and the mapping is live
88
+ #[ error( "Cannot remap region {0} while translation is live." ) ]
83
89
BreakBeforeMakeViolation ( MemoryRegion ) ,
84
90
}
85
91
86
- impl Display for MapError {
87
- fn fmt ( & self , f : & mut Formatter ) -> fmt:: Result {
88
- match self {
89
- Self :: AddressRange ( va) => write ! ( f, "Virtual address {} out of range" , va) ,
90
- Self :: InvalidVirtualAddress ( va) => {
91
- write ! ( f, "Invalid virtual address {} for mapping" , va)
92
- }
93
- Self :: RegionBackwards ( region) => {
94
- write ! ( f, "End of memory region {} is before start." , region)
95
- }
96
- Self :: PteUpdateFault ( desc) => {
97
- write ! ( f, "Error updating page table entry {:?}" , desc)
98
- }
99
- Self :: InvalidFlags ( flags) => {
100
- write ! ( f, "Flags {flags:?} unsupported for mapping." )
101
- }
102
- Self :: BreakBeforeMakeViolation ( region) => {
103
- write ! ( f, "Cannot remap region {region} while translation is live." )
104
- }
105
- }
106
- }
107
- }
108
-
109
92
/// Manages a level 1 page table and associated state.
110
93
///
111
94
/// Mappings should be added with [`map_range`](Self::map_range) before calling
0 commit comments