From e8b7d7a238e89992c029d951d10c40730f0deeab Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Thu, 10 Oct 2024 15:48:31 -0700 Subject: [PATCH] ArmPkg: ArmExceptionLib: Fixing exception vector and type casting 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 Cc: Ard Biesheuvel Cc: Sami Mujawar Signed-off-by: Kun Qin --- ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c index a521c33f3281..03ed24794a9f 100644 --- a/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c +++ b/ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.c @@ -91,7 +91,7 @@ InitializeCpuExceptionHandlers ( ) { RETURN_STATUS Status; - UINTN VectorBase; + UINT64 VectorBase; Status = EFI_SUCCESS; @@ -113,7 +113,7 @@ 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; } @@ -121,9 +121,9 @@ InitializeCpuExceptionHandlers ( 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; @@ -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 @@ -226,7 +226,7 @@ RegisterCpuInterruptHandler ( IN EFI_CPU_INTERRUPT_HANDLER ExceptionHandler ) { - if (ExceptionType > gMaxExceptionNumber) { + if ((UINTN)ExceptionType > gMaxExceptionNumber) { return RETURN_UNSUPPORTED; } @@ -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;