Skip to content

Commit

Permalink
Update Arm Memory Attribute Protocol Logging (#134)
Browse files Browse the repository at this point in the history
## Description

Fixes #129 and
reformats the debug prints.

- [ ] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

CI Pipelines

## Integration Instructions

N/A
  • Loading branch information
TaylorBeebe authored Jun 27, 2023
1 parent bd7043d commit 9f454bc
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions ArmPkg/Drivers/CpuDxe/MemoryAttribute.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ GetMemoryAttributes (
EFI_STATUS Status;

if ((Length == 0) || (Attributes == NULL)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a invalid length 0x%llx or attributes %p are null\n",
__func__,
(UINT64)RegionLength,
Attributes
)); // MU_CHANGE: Better memory attributes protocol logging
"%a: Length is zero or Attributes is NULL\n",
__func__
));
// MU_CHANGE END
return EFI_INVALID_PARAMETER;
}

Expand Down Expand Up @@ -208,13 +208,14 @@ SetMemoryAttributes (
if ((Length == 0) ||
((Attributes & ~(EFI_MEMORY_RO | EFI_MEMORY_RP | EFI_MEMORY_XP)) != 0))
{
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a invalid length: 0x%llx or attributes 0x%llx\n",
"%a: Length is zero or Attributes (0x%Lx) is invalid\n",
__func__,
Length,
Attributes
)); // MU_CHANGE: Better memory attributes protocol logging
));
// MU_CHANGE END
return EFI_INVALID_PARAMETER;
}

Expand All @@ -227,44 +228,50 @@ SetMemoryAttributes (
if ((Attributes & EFI_MEMORY_RP) != 0) {
Status = ArmSetMemoryRegionNoAccess (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to set EFI_MEMORY_RP on BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to set EFI_MEMORY_RP on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}

if ((Attributes & EFI_MEMORY_RO) != 0) {
Status = ArmSetMemoryRegionReadOnly (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to set EFI_MEMORY_RO on BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to set EFI_MEMORY_RO on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}

if ((Attributes & EFI_MEMORY_XP) != 0) {
Status = ArmSetMemoryRegionNoExec (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to set EFI_MEMORY_XP on BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to set EFI_MEMORY_XP on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}
Expand Down Expand Up @@ -325,13 +332,14 @@ ClearMemoryAttributes (
if ((Length == 0) ||
((Attributes & ~(EFI_MEMORY_RO | EFI_MEMORY_RP | EFI_MEMORY_XP)) != 0))
{
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a invalid length: 0x%llx or attributes 0x%llx\n",
"%a: Length is zero or Attributes (0x%Lx) is invalid\n",
__func__,
Length,
Attributes
)); // MU_CHANGE: Better memory attributes protocol logging
));
// MU_CHANGE END
return EFI_INVALID_PARAMETER;
}

Expand All @@ -344,44 +352,50 @@ ClearMemoryAttributes (
if ((Attributes & EFI_MEMORY_RP) != 0) {
Status = ArmClearMemoryRegionNoAccess (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to clear EFI_MEMORY_RP from BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to clear EFI_MEMORY_RP on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}

if ((Attributes & EFI_MEMORY_RO) != 0) {
Status = ArmClearMemoryRegionReadOnly (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to clear EFI_MEMORY_RO from BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to clear EFI_MEMORY_RO on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}

if ((Attributes & EFI_MEMORY_XP) != 0) {
Status = ArmClearMemoryRegionNoExec (BaseAddress, Length);
if (EFI_ERROR (Status)) {
// MU_CHANGE START: Update protocol logging
DEBUG ((
DEBUG_ERROR,
"%a failed to clear EFI_MEMORY_XP from BaseAddress 0x%llx of length 0x%llx with status %r!\n",
"%a: Failed to clear EFI_MEMORY_XP on range 0x%Lx-0x%Lx! Status: %r\n",
__func__,
BaseAddress,
Length,
BaseAddress + Length,
Status
)); // MU_CHANGE: Better memory attribute protocol logging
));
// MU_CHANGE END
return EFI_UNSUPPORTED;
}
}
Expand Down

0 comments on commit 9f454bc

Please sign in to comment.