Skip to content

Add PAGE_SIZE constant and update MemoryProtection protocol docs #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions uefi/src/proto/security/memory_protection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<PhysicalAddress>,
Expand All @@ -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<PhysicalAddress>,
Expand All @@ -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<PhysicalAddress>,
Expand Down
6 changes: 6 additions & 0 deletions uefi/src/table/boot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down