]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/DxeReportStatusCodeLib/ReportStatusCodeLib.c
Prevent infinite recursion when ASSERT(), DEBUG(), or any other use of ReportStatusCo...
[mirror_edk2.git] / MdeModulePkg / Library / DxeReportStatusCodeLib / ReportStatusCodeLib.c
index f5789c1a71bedcbe4813140e19be85d1099b9c98..70b40b9c8a37d5edc45eaa395df390b1f48c89e4 100644 (file)
 #include <Guid/StatusCodeDataTypeId.h>\r
 #include <Guid/StatusCodeDataTypeDebug.h>\r
 \r
+//\r
+// Define the maximum extended data size that is supported when a status code is \r
+// reported at TPL_HIGH_LEVEL.\r
+//\r
+#define MAX_EXTENDED_DATA_SIZE  0x200\r
+\r
 EFI_STATUS_CODE_PROTOCOL  *mReportStatusCodeLibStatusCodeProtocol = NULL;\r
 \r
 /**\r
@@ -484,6 +490,8 @@ ReportStatusCodeEx (
 {\r
   EFI_STATUS            Status;\r
   EFI_STATUS_CODE_DATA  *StatusCodeData;\r
+  EFI_TPL               Tpl;\r
+  UINT64                Buffer[MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)];\r
 \r
   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
@@ -493,12 +501,32 @@ ReportStatusCodeEx (
   }\r
 \r
   //\r
-  // Allocate space for the Status Code Header and its buffer\r
+  // Retrieve the current TPL\r
   //\r
+  Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+  gBS->RestoreTPL (Tpl);\r
+  \r
   StatusCodeData = NULL;\r
-  gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+  if (Tpl <= TPL_NOTIFY) {\r
+    //\r
+    // Allocate space for the Status Code Header and its buffer\r
+    //\r
+    gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+  }\r
+\r
   if (StatusCodeData == NULL) {\r
-    return EFI_OUT_OF_RESOURCES;\r
+    //\r
+    // If a buffer could not be allocated, then see if the local variable Buffer can be used\r
+    //\r
+    if (ExtendedDataSize > (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
+      //\r
+      // The local variable Buffer not large enough to hold the extended data associated\r
+      // with the status code being  reported.\r
+      //\r
+      ASSERT (FALSE);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    StatusCodeData = (EFI_STATUS_CODE_DATA  *)Buffer;\r
   }\r
 \r
   //\r
@@ -529,7 +557,9 @@ ReportStatusCodeEx (
   //\r
   // Free the allocated buffer\r
   //\r
-  gBS->FreePool (StatusCodeData);\r
+  if (StatusCodeData != (EFI_STATUS_CODE_DATA  *)Buffer) {\r
+    gBS->FreePool (StatusCodeData);\r
+  }\r
 \r
   return Status;\r
 }\r