1
1
use crate :: data_types:: PhysicalAddress ;
2
2
use crate :: proto:: unsafe_protocol;
3
3
use crate :: table:: boot:: MemoryAttribute ;
4
- use crate :: { Result , Status , StatusExt } ;
4
+ use crate :: { Result , StatusExt } ;
5
5
use core:: ops:: Range ;
6
+ use uefi_raw:: protocol:: memory_protection:: MemoryAttributeProtocol ;
6
7
7
8
/// Protocol for getting and setting memory protection attributes.
8
9
///
9
10
/// Corresponds to the C type `EFI_MEMORY_ATTRIBUTE_PROTOCOL`.
10
- #[ repr( C ) ]
11
- #[ unsafe_protocol( "f4560cf6-40ec-4b4a-a192-bf1d57d0b189" ) ]
12
- pub struct MemoryProtection {
13
- get_memory_attributes : unsafe extern "efiapi" fn (
14
- this : * const Self ,
15
- base_address : PhysicalAddress ,
16
- length : u64 ,
17
- attributes : * mut MemoryAttribute ,
18
- ) -> Status ,
19
-
20
- set_memory_attributes : unsafe extern "efiapi" fn (
21
- this : * const Self ,
22
- base_address : PhysicalAddress ,
23
- length : u64 ,
24
- attributes : MemoryAttribute ,
25
- ) -> Status ,
26
-
27
- clear_memory_attributes : unsafe extern "efiapi" fn (
28
- this : * const Self ,
29
- base_address : PhysicalAddress ,
30
- length : u64 ,
31
- attributes : MemoryAttribute ,
32
- ) -> Status ,
33
- }
11
+ #[ repr( transparent) ]
12
+ #[ unsafe_protocol( MemoryAttributeProtocol :: GUID ) ]
13
+ pub struct MemoryProtection ( MemoryAttributeProtocol ) ;
34
14
35
15
impl MemoryProtection {
36
16
/// Get the attributes of a memory region.
@@ -47,6 +27,7 @@ impl MemoryProtection {
47
27
/// [`READ_PROTECT`]: MemoryAttribute::READ_PROTECT
48
28
/// [`EXECUTE_PROTECT`]: MemoryAttribute::EXECUTE_PROTECT
49
29
/// [`READ_ONLY`]: MemoryAttribute::READ_ONLY
30
+ /// [`Status::NO_MAPPING`]: crate::Status::NO_MAPPING
50
31
/// [UEFI page size]: uefi::table::boot::PAGE_SIZE
51
32
pub fn get_memory_attributes (
52
33
& self ,
@@ -55,7 +36,7 @@ impl MemoryProtection {
55
36
let mut attributes = MemoryAttribute :: empty ( ) ;
56
37
let ( base_address, length) = range_to_base_and_len ( byte_region) ;
57
38
unsafe {
58
- ( self . get_memory_attributes ) ( self , base_address, length, & mut attributes)
39
+ ( self . 0 . get_memory_attributes ) ( & self . 0 , base_address, length, & mut attributes)
59
40
. to_result_with_val ( || attributes)
60
41
}
61
42
}
@@ -78,7 +59,9 @@ impl MemoryProtection {
78
59
attributes : MemoryAttribute ,
79
60
) -> Result {
80
61
let ( base_address, length) = range_to_base_and_len ( byte_region) ;
81
- unsafe { ( self . set_memory_attributes ) ( self , base_address, length, attributes) . to_result ( ) }
62
+ unsafe {
63
+ ( self . 0 . set_memory_attributes ) ( & self . 0 , base_address, length, attributes) . to_result ( )
64
+ }
82
65
}
83
66
84
67
/// Clear the attributes of a memory region.
@@ -100,7 +83,7 @@ impl MemoryProtection {
100
83
) -> Result {
101
84
let ( base_address, length) = range_to_base_and_len ( byte_region) ;
102
85
unsafe {
103
- ( self . clear_memory_attributes ) ( self , base_address, length, attributes) . to_result ( )
86
+ ( self . 0 . clear_memory_attributes ) ( & self . 0 , base_address, length, attributes) . to_result ( )
104
87
}
105
88
}
106
89
}
0 commit comments