From a01b000af79c9240428278032c8463d833b14b71 Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 30 Jan 2023 21:53:58 -0500 Subject: [PATCH 1/2] uefi: Add PAGE_SIZE constant The UEFI page size is always 4KiB (see `EFI_BOOT_SERVICES.AllocatePages` in the spec). --- uefi/src/table/boot.rs | 6 ++++++ 1 file changed, 6 insertions(+) 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` From 253d5da4eb6871f15a4487e68f58b4fcd850370d Mon Sep 17 00:00:00 2001 From: Nicholas Bishop Date: Mon, 30 Jan 2023 21:58:07 -0500 Subject: [PATCH 2/2] uefi: Update MemoryProtection protocol docs - Drop reference to the proposal for this protocol, as of UEFI 2.10 it's in the official spec. - Mention the C type for ease of searching the spec. - Update the method docs to note that implementations typically require that the memory region is page-aligned. This isn't mentioned in the spec. --- uefi/src/proto/security/memory_protection.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) 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,