/** @file\r
Report Status Code Library for DXE Phase.\r
\r
- Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2006 - 2018, 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
#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
//\r
return mReportStatusCodeLibStatusCodeProtocol->ReportStatusCode (Type, Value, Instance, (EFI_GUID *)CallerId, Data);\r
}\r
- \r
+\r
return EFI_UNSUPPORTED;\r
}\r
\r
{\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
+ if (ExtendedDataSize <= (MAX_EXTENDED_DATA_SIZE - sizeof (EFI_STATUS_CODE_DATA))) {\r
+ //\r
+ // Use Buffer instead of allocating if possible.\r
+ //\r
+ StatusCodeData = (EFI_STATUS_CODE_DATA *)Buffer;\r
+ } else {\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
- //\r
- StatusCodeData = NULL;\r
- gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
- if (StatusCodeData == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ //\r
+ // Retrieve the current TPL\r
+ //\r
+ Tpl = gBS->RaiseTPL (TPL_HIGH_LEVEL);\r
+ gBS->RestoreTPL (Tpl);\r
+\r
+ if (Tpl > TPL_NOTIFY) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ //\r
+ // Allocate space for the Status Code Header and its buffer\r
+ //\r
+ StatusCodeData = NULL;\r
+ gBS->AllocatePool (EfiBootServicesData, sizeof (EFI_STATUS_CODE_DATA) + ExtendedDataSize, (VOID **)&StatusCodeData);\r
+ if (StatusCodeData == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
}\r
\r
//\r
// Fill in the extended data header\r
//\r
- StatusCodeData->HeaderSize = sizeof (EFI_STATUS_CODE_DATA);\r
- StatusCodeData->Size = (UINT16)ExtendedDataSize;\r
+ StatusCodeData->HeaderSize = (UINT16) sizeof (EFI_STATUS_CODE_DATA);\r
+ StatusCodeData->Size = (UINT16) ExtendedDataSize;\r
if (ExtendedDataGuid == NULL) {\r
ExtendedDataGuid = &gEfiStatusCodeSpecificDataGuid;\r
}\r
//\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