diff --git a/uefi/src/proto/security/memory_protection.rs b/uefi/src/proto/security/memory_protection.rs index 38c229547..84bfb48dd 100644 --- a/uefi/src/proto/security/memory_protection.rs +++ b/uefi/src/proto/security/memory_protection.rs @@ -6,9 +6,7 @@ use core::ops::Range; /// Protocol for getting and setting memory protection attributes. /// -/// This corresponds to the `EFI_MEMORY_ATTRIBUTE_PROTOCOL` [proposal]. -/// -/// [proposal]: https://bugzilla.tianocore.org/show_bug.cgi?id=3519 +/// Corresponds to the C type `EFI_MEMORY_ATTRIBUTE_PROTOCOL`. #[repr(C)] #[unsafe_protocol("f4560cf6-40ec-4b4a-a192-bf1d57d0b189")] pub struct MemoryProtection { @@ -43,9 +41,13 @@ impl MemoryProtection { /// If the attributes are not consistent within the region, /// [`Status::NO_MAPPING`] is returned. /// + /// Implementations typically require that the start and end of the memory + /// region are aligned to the [UEFI page size]. + /// /// [`READ_PROTECT`]: MemoryAttribute::READ_PROTECT /// [`EXECUTE_PROTECT`]: MemoryAttribute::EXECUTE_PROTECT /// [`READ_ONLY`]: MemoryAttribute::READ_ONLY + /// [UEFI page size]: uefi::table::boot::PAGE_SIZE pub fn get_memory_attributes( &self, byte_region: Range, @@ -63,9 +65,13 @@ impl MemoryProtection { /// The valid attributes to set are [`READ_PROTECT`], /// [`EXECUTE_PROTECT`], and [`READ_ONLY`]. /// + /// Implementations typically require that the start and end of the memory + /// region are aligned to the [UEFI page size]. + /// /// [`READ_PROTECT`]: MemoryAttribute::READ_PROTECT /// [`EXECUTE_PROTECT`]: MemoryAttribute::EXECUTE_PROTECT /// [`READ_ONLY`]: MemoryAttribute::READ_ONLY + /// [UEFI page size]: uefi::table::boot::PAGE_SIZE pub fn set_memory_attributes( &self, byte_region: Range, @@ -80,9 +86,13 @@ impl MemoryProtection { /// The valid attributes to clear are [`READ_PROTECT`], /// [`EXECUTE_PROTECT`], and [`READ_ONLY`]. /// + /// Implementations typically require that the start and end of the memory + /// region are aligned to the [UEFI page size]. + /// /// [`READ_PROTECT`]: MemoryAttribute::READ_PROTECT /// [`EXECUTE_PROTECT`]: MemoryAttribute::EXECUTE_PROTECT /// [`READ_ONLY`]: MemoryAttribute::READ_ONLY + /// [UEFI page size]: uefi::table::boot::PAGE_SIZE pub fn clear_memory_attributes( &self, byte_region: Range, diff --git a/uefi/src/table/boot.rs b/uefi/src/table/boot.rs index f3d97eb5e..69ce11fb5 100644 --- a/uefi/src/table/boot.rs +++ b/uefi/src/table/boot.rs @@ -32,6 +32,12 @@ static IMAGE_HANDLE: GlobalImageHandle = GlobalImageHandle { handle: UnsafeCell::new(None), }; +/// Size in bytes of a UEFI page. +/// +/// Note that this is not necessarily the processor's page size. The UEFI page +/// size is always 4 KiB. +pub const PAGE_SIZE: usize = 4096; + /// Contains pointers to all of the boot services. /// /// # Accessing `BootServices`