]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ArmPkg/Library/DefaultExceptionHandlerLib/Arm/DefaultExceptionHandler.c
ArmPkg/DefaultExceptionHandlerLib ARM: avoid endless loop in RELEASE builds
[mirror_edk2.git] / ArmPkg / Library / DefaultExceptionHandlerLib / Arm / DefaultExceptionHandler.c
index 0be21a6211dcee8edcd3fb9fc4b8ad4d08e139a5..cc79cb2fa3017bdd33fe7de616099f18a84aeb16 100644 (file)
 #include <Protocol/DebugSupport.h>\r
 #include <Library/DefaultExceptionHandlerLib.h>\r
 \r
-EFI_DEBUG_IMAGE_INFO_TABLE_HEADER *gDebugImageTableHeader = NULL;\r
+//\r
+// The number of elements in a CHAR8 array, including the terminating NUL, that\r
+// is meant to hold the string rendering of the CPSR.\r
+//\r
+#define CPSR_STRING_SIZE 32\r
 \r
 typedef struct {\r
   UINT32  BIT;\r
@@ -48,7 +52,8 @@ GetImageName (
   It is possible to add extra bits by adding them to CpsrChar array.\r
 \r
   @param  Cpsr         ARM CPSR register value\r
-  @param  ReturnStr    32 byte string that contains string version of CPSR\r
+  @param  ReturnStr    CPSR_STRING_SIZE byte string that contains string\r
+                       version of CPSR\r
 \r
 **/\r
 VOID\r
@@ -118,8 +123,10 @@ CpsrString (
     break;\r
   }\r
 \r
-  AsciiStrCat (Str, ModeStr);\r
-  return;\r
+  //\r
+  // See the interface contract in the leading comment block.\r
+  //\r
+  AsciiStrCatS (Str, CPSR_STRING_SIZE - (Str - ReturnStr), ModeStr);\r
 }\r
 \r
 CHAR8 *\r
@@ -186,7 +193,7 @@ DefaultExceptionHandler (
   UINT32    PcAdjust = 0;\r
 \r
   CharCount = AsciiSPrint (Buffer,sizeof (Buffer),"\n%a Exception PC at 0x%08x  CPSR 0x%08x ",\r
-         gExceptionTypeString[ExceptionType], SystemContext.SystemContextArm->PC, SystemContext.SystemContextArm->CPSR);\r
+         gExceptionTypeString[ExceptionType], SystemContext.SystemContextArm->PC, SystemContext.SystemContextArm->CPSR);\r
   SerialPortWrite ((UINT8 *) Buffer, CharCount);\r
 \r
   DEBUG_CODE_BEGIN ();\r
@@ -194,7 +201,8 @@ DefaultExceptionHandler (
     UINT32  ImageBase;\r
     UINT32  PeCoffSizeOfHeader;\r
     UINT32  Offset;\r
-    CHAR8   CpsrStr[32];  // char per bit. Lower 5-bits are mode that is a 3 char string\r
+    CHAR8   CpsrStr[CPSR_STRING_SIZE];  // char per bit. Lower 5-bits are mode\r
+                                        // that is a 3 char string\r
     CHAR8   Buffer[80];\r
     UINT8   *DisAsm;\r
     UINT32  ItBlock;\r
@@ -259,6 +267,8 @@ DefaultExceptionHandler (
   DEBUG ((EFI_D_ERROR, "\n"));\r
   ASSERT (FALSE);\r
 \r
+  CpuDeadLoop ();   // may return if executing under a debugger\r
+\r
   // Clear the error registers that we have already displayed incase some one wants to keep going\r
   SystemContext.SystemContextArm->DFSR = 0;\r
   SystemContext.SystemContextArm->IFSR = 0;\r