Skip to content

Commit

Permalink
ArmPkg: ArmExceptionLib: Fixing exception vector and type casting
Browse files Browse the repository at this point in the history
The current VectorBase is taking value from a 64bit PCD into a UINTN
value, which could have truncated value for 32bit system.

In addition, the comparison between UINTN and INTN could lead to
undesired comparison outcome or compiler complaints.

This change updates all of them to be UINT64 based operation.

Cc: Leif Lindholm <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: Sami Mujawar <[email protected]>

Signed-off-by: Kun Qin <[email protected]>
  • Loading branch information
kuqin12 authored and mergify[bot] committed Dec 11, 2024
1 parent b689c38 commit e8b7d7a
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ InitializeCpuExceptionHandlers (
)
{
RETURN_STATUS Status;
UINTN VectorBase;
UINT64 VectorBase;

Status = EFI_SUCCESS;

Expand All @@ -113,17 +113,17 @@ InitializeCpuExceptionHandlers (

// We do not copy the Exception Table at PcdGet64(PcdCpuVectorBaseAddress). We just set Vector
// Base Address to point into CpuDxe code.
VectorBase = (UINTN)ExceptionHandlersStart;
VectorBase = (UINT64)(UINTN)ExceptionHandlersStart;

Status = RETURN_SUCCESS;
}

if (!RETURN_ERROR (Status)) {
// call the architecture-specific routine to prepare for the new vector
// configuration to take effect
ArchVectorConfig (VectorBase);
ArchVectorConfig ((UINTN)VectorBase);

ArmWriteVBar (VectorBase);
ArmWriteVBar ((UINTN)VectorBase);
}

return RETURN_SUCCESS;
Expand Down Expand Up @@ -172,7 +172,7 @@ CopyExceptionHandlers (
}

// Copy our assembly code into the page that contains the exception vectors.
CopyMem ((VOID *)VectorBase, (VOID *)ExceptionHandlersStart, Length);
CopyMem ((VOID *)VectorBase, (VOID *)(UINTN)ExceptionHandlersStart, Length);

//
// Initialize the C entry points for interrupts
Expand Down Expand Up @@ -226,7 +226,7 @@ RegisterCpuInterruptHandler (
IN EFI_CPU_INTERRUPT_HANDLER ExceptionHandler
)
{
if (ExceptionType > gMaxExceptionNumber) {
if ((UINTN)ExceptionType > gMaxExceptionNumber) {
return RETURN_UNSUPPORTED;
}

Expand Down Expand Up @@ -273,7 +273,7 @@ CommonCExceptionHandler (
IN OUT EFI_SYSTEM_CONTEXT SystemContext
)
{
if (ExceptionType <= gMaxExceptionNumber) {
if ((UINTN)ExceptionType <= gMaxExceptionNumber) {
if (gExceptionHandlers[ExceptionType]) {
gExceptionHandlers[ExceptionType](ExceptionType, SystemContext);
return;
Expand Down

0 comments on commit e8b7d7a

Please sign in to comment.