Skip to content

Commit e1159d7

Browse files
nicholasbishopphip1611
authored andcommitted
uefi: Use raw MemoryAttributeProtocol
1 parent aee8045 commit e1159d7

File tree

1 file changed

+11
-28
lines changed

1 file changed

+11
-28
lines changed

uefi/src/proto/security/memory_protection.rs

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,16 @@
11
use crate::data_types::PhysicalAddress;
22
use crate::proto::unsafe_protocol;
33
use crate::table::boot::MemoryAttribute;
4-
use crate::{Result, Status, StatusExt};
4+
use crate::{Result, StatusExt};
55
use core::ops::Range;
6+
use uefi_raw::protocol::memory_protection::MemoryAttributeProtocol;
67

78
/// Protocol for getting and setting memory protection attributes.
89
///
910
/// 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);
3414

3515
impl MemoryProtection {
3616
/// Get the attributes of a memory region.
@@ -47,6 +27,7 @@ impl MemoryProtection {
4727
/// [`READ_PROTECT`]: MemoryAttribute::READ_PROTECT
4828
/// [`EXECUTE_PROTECT`]: MemoryAttribute::EXECUTE_PROTECT
4929
/// [`READ_ONLY`]: MemoryAttribute::READ_ONLY
30+
/// [`Status::NO_MAPPING`]: crate::Status::NO_MAPPING
5031
/// [UEFI page size]: uefi::table::boot::PAGE_SIZE
5132
pub fn get_memory_attributes(
5233
&self,
@@ -55,7 +36,7 @@ impl MemoryProtection {
5536
let mut attributes = MemoryAttribute::empty();
5637
let (base_address, length) = range_to_base_and_len(byte_region);
5738
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)
5940
.to_result_with_val(|| attributes)
6041
}
6142
}
@@ -78,7 +59,9 @@ impl MemoryProtection {
7859
attributes: MemoryAttribute,
7960
) -> Result {
8061
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+
}
8265
}
8366

8467
/// Clear the attributes of a memory region.
@@ -100,7 +83,7 @@ impl MemoryProtection {
10083
) -> Result {
10184
let (base_address, length) = range_to_base_and_len(byte_region);
10285
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()
10487
}
10588
}
10689
}

0 commit comments

Comments
 (0)