]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/ReportStatusCodeLib.c
1) Update code to use PcdFixedUsbCredentialProviderTokenFileName and PcdMaxVaria...
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / DxeReportStatusCodeLibFramework / ReportStatusCodeLib.c
index 941d01f92bdd55f8954adcd7fdf4eb6681152a0a..a3603f862ff5d5c547214f819f77c82eff32b7a9 100644 (file)
@@ -1,8 +1,8 @@
 /** @file\r
   Report Status Code Library for DXE Phase.\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation<BR>\r
-  All rights reserved. This program and the accompanying materials\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+  This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
   http://opensource.org/licenses/bsd-license.php\r
 #include <Guid/StatusCodeDataTypeDebug.h>\r
 #include <Protocol/StatusCode.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_REPORT_STATUS_CODE  mReportStatusCode = NULL;\r
 \r
 /**\r
   Locate the report status code service.\r
 \r
   @return   Function pointer to the report status code service.\r
+            NULL is returned if no status code service is available.\r
 \r
 **/\r
 EFI_REPORT_STATUS_CODE\r
@@ -281,7 +288,8 @@ ReportStatusCodeExtractDebugInfo (
   *ErrorLevel = DebugInfo->ErrorLevel;\r
 \r
   //\r
-  // Here the address returned in Marker is 64-bit aligned.\r
+  // The first 12 * sizeof (UINT64) bytes following EFI_DEBUG_INFO are for variable arguments\r
+  // of format in DEBUG string. Its address is returned in Marker and has to be 64-bit aligned.\r
   // It must be noticed that EFI_DEBUG_INFO follows EFI_STATUS_CODE_DATA, whose size is\r
   // 20 bytes. The size of EFI_DEBUG_INFO is 4 bytes, so we can ensure that Marker\r
   // returned is 64-bit aligned.\r
@@ -289,10 +297,6 @@ ReportStatusCodeExtractDebugInfo (
   // cause unalignment exception.\r
   //\r
   *Marker = (BASE_LIST) (DebugInfo + 1);\r
-  //\r
-  // The first 12 * UINTN bytes of the string are really an\r
-  // argument stack to support varargs on the Format string.\r
-  //\r
   *Format = (CHAR8 *)(((UINT64 *)*Marker) + 12);\r
 \r
   return TRUE;\r
@@ -489,23 +493,49 @@ ReportStatusCodeEx (
 {\r
   EFI_STATUS            Status;\r
   EFI_STATUS_CODE_DATA  *StatusCodeData;\r
+  EFI_TPL               Tpl;\r
+  UINT64                Buffer[(MAX_EXTENDED_DATA_SIZE / sizeof (UINT64)) + 1];\r
 \r
   ASSERT (!((ExtendedData == NULL) && (ExtendedDataSize != 0)));\r
   ASSERT (!((ExtendedData != NULL) && (ExtendedDataSize == 0)));\r
 \r
+  if (gBS == NULL || gBS->AllocatePool == NULL || gBS->FreePool == NULL) {\r
+    return EFI_UNSUPPORTED;\r
+  }\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
-  StatusCodeData = AllocatePool (sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize);\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
+      DEBUG ((EFI_D_ERROR, "Status code extended data is too large to be reported!\n"));\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    StatusCodeData = (EFI_STATUS_CODE_DATA  *)Buffer;\r
   }\r
 \r
   //\r
   // Fill in the extended data header\r
   //\r
-  StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
+  StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
   StatusCodeData->Size = (UINT16)ExtendedDataSize;\r
   if (ExtendedDataGuid == NULL) {\r
     ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
@@ -530,7 +560,9 @@ ReportStatusCodeEx (
   //\r
   // Free the allocated buffer\r
   //\r
-  FreePool (StatusCodeData);\r
+  if (StatusCodeData != (EFI_STATUS_CODE_DATA  *)Buffer) {\r
+    gBS->FreePool (StatusCodeData);\r
+  }\r
 \r
   return Status;\r
 }\r