1 | /* $Id: VBoxOemHookStatusCodeLib.c 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * DxeVBoxOemHookStatusCodeLib.c - Logging.
|
---|
4 | */
|
---|
5 |
|
---|
6 |
|
---|
7 | /*
|
---|
8 | * Copyright (C) 2009-2024 Oracle and/or its affiliates.
|
---|
9 | *
|
---|
10 | * This file is part of VirtualBox base platform packages, as
|
---|
11 | * available from https://www.virtualbox.org.
|
---|
12 | *
|
---|
13 | * This program is free software; you can redistribute it and/or
|
---|
14 | * modify it under the terms of the GNU General Public License
|
---|
15 | * as published by the Free Software Foundation, in version 3 of the
|
---|
16 | * License.
|
---|
17 | *
|
---|
18 | * This program is distributed in the hope that it will be useful, but
|
---|
19 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
21 | * General Public License for more details.
|
---|
22 | *
|
---|
23 | * You should have received a copy of the GNU General Public License
|
---|
24 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
25 | *
|
---|
26 | * The contents of this file may alternatively be used under the terms
|
---|
27 | * of the Common Development and Distribution License Version 1.0
|
---|
28 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
29 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
30 | * CDDL are applicable instead of those of the GPL.
|
---|
31 | *
|
---|
32 | * You may elect to license modified versions of this file under the
|
---|
33 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
34 | *
|
---|
35 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | /*********************************************************************************************************************************
|
---|
40 | * Header Files *
|
---|
41 | *********************************************************************************************************************************/
|
---|
42 | #include <Library/ReportStatusCodeLib.h>
|
---|
43 | #include <Library/OemHookStatusCodeLib.h>
|
---|
44 | #include <Library/PrintLib.h>
|
---|
45 | #include <Library/BaseMemoryLib.h>
|
---|
46 | #include <Guid/StatusCodeDataTypeId.h>
|
---|
47 | #include <Guid/StatusCodeDataTypeDebug.h>
|
---|
48 | #if 0 /* See VBoxSecExtractDebugInfo */
|
---|
49 | # include <DebugInfo.h>
|
---|
50 | #endif
|
---|
51 |
|
---|
52 | #include "VBoxDebugLib.h"
|
---|
53 | #include "DevEFI.h"
|
---|
54 |
|
---|
55 |
|
---|
56 |
|
---|
57 | EFI_STATUS EFIAPI
|
---|
58 | OemHookStatusCodeInitialize(VOID)
|
---|
59 | {
|
---|
60 | VBoxPrintString("OemHookStatusCodeInitialize\n");
|
---|
61 | return EFI_SUCCESS;
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | #if 0 /* vvl: With thbe new version the API changed a bit and VA_LIST isn't used any more. Before applying
|
---|
66 | * any changes here I would like to understand in which cases we need this help function.
|
---|
67 | * bird: Some components sent information in this format. Search for the UUID or EFI_DEBUG_INFO usage.
|
---|
68 | */
|
---|
69 | /**
|
---|
70 | * Helper VBoxSecPeiReportStatusCode uses for catching some odd reports.
|
---|
71 | */
|
---|
72 | static BOOLEAN
|
---|
73 | VBoxSecExtractDebugInfo(IN CONST EFI_STATUS_CODE_DATA *pData,
|
---|
74 | OUT UINT32 *puErrorLevel,
|
---|
75 | OUT VA_LIST *pVa,
|
---|
76 | OUT CHAR8 **ppszFormat)
|
---|
77 | {
|
---|
78 | EFI_DEBUG_INFO *pDebugInfo;
|
---|
79 |
|
---|
80 | if ( !CompareGuid(&pData->Type, &gEfiStatusCodeSpecificDataGuid)
|
---|
81 | || pData->HeaderSize != sizeof(*pData)
|
---|
82 | || pData->Size <= sizeof(UINT64) * 12 + sizeof(EFI_DEBUG_INFO) + 1)
|
---|
83 | return FALSE;
|
---|
84 |
|
---|
85 | pDebugInfo = (EFI_DEBUG_INFO *)(pData + 1);
|
---|
86 | *pVa = (VA_LIST)(pDebugInfo + 1);
|
---|
87 | *ppszFormat = (CHAR8 *)((UINT64 *)pVa + 12);
|
---|
88 | return TRUE;
|
---|
89 | }
|
---|
90 | #endif
|
---|
91 |
|
---|
92 | /** Worker that dumps the raw data. */
|
---|
93 | static void
|
---|
94 | VBoxOemHookStatusCodeReportRawDump(EFI_STATUS_CODE_TYPE Type,
|
---|
95 | EFI_STATUS_CODE_VALUE Value,
|
---|
96 | UINT32 Instance,
|
---|
97 | CONST EFI_GUID *CallerId)
|
---|
98 | {
|
---|
99 | VBoxPrintString("Report: Type=");
|
---|
100 | VBoxPrintHex(Type, sizeof(Type));
|
---|
101 | VBoxPrintString(" Value=");
|
---|
102 | VBoxPrintHex(Value, sizeof(Value));
|
---|
103 |
|
---|
104 | VBoxPrintString(" Instance=");
|
---|
105 | VBoxPrintHex(Instance, sizeof(Instance));
|
---|
106 | if (CallerId)
|
---|
107 | {
|
---|
108 | VBoxPrintString(" CallerId=");
|
---|
109 | VBoxPrintGuid(CallerId);
|
---|
110 | }
|
---|
111 |
|
---|
112 | #define CASE_PRINT(Head,Print,Tail) \
|
---|
113 | case Head ## Print ## Tail : VBoxPrintString(" " #Print); break
|
---|
114 | switch (Type & EFI_STATUS_CODE_SEVERITY_MASK) /* quick guess work... */
|
---|
115 | {
|
---|
116 | CASE_PRINT(EFI_ERROR_,MINOR,);
|
---|
117 | CASE_PRINT(EFI_ERROR_,MAJOR,);
|
---|
118 | CASE_PRINT(EFI_ERROR_,UNRECOVERED,);
|
---|
119 | CASE_PRINT(EFI_ERROR_,UNCONTAINED,);
|
---|
120 | }
|
---|
121 | switch (Type & EFI_STATUS_CODE_TYPE_MASK) /* quick guess work... */
|
---|
122 | {
|
---|
123 | CASE_PRINT(EFI_,PROGRESS,_CODE);
|
---|
124 | CASE_PRINT(EFI_,ERROR,_CODE);
|
---|
125 | CASE_PRINT(EFI_,DEBUG,_CODE);
|
---|
126 | }
|
---|
127 | #undef CASE_PRINT
|
---|
128 | VBoxPrintChar('\n');
|
---|
129 | }
|
---|
130 |
|
---|
131 |
|
---|
132 | EFI_STATUS EFIAPI
|
---|
133 | OemHookStatusCodeReport(IN EFI_STATUS_CODE_TYPE Type,
|
---|
134 | IN EFI_STATUS_CODE_VALUE Value,
|
---|
135 | IN UINT32 Instance,
|
---|
136 | IN EFI_GUID *CallerId OPTIONAL,
|
---|
137 | IN EFI_STATUS_CODE_DATA *Data OPTIONAL)
|
---|
138 | {
|
---|
139 | /*
|
---|
140 | * Try figure out the data payload
|
---|
141 | */
|
---|
142 | if (Data != NULL)
|
---|
143 | {
|
---|
144 | CHAR8 *pszFilename;
|
---|
145 | CHAR8 *pszDescription;
|
---|
146 | UINT32 uLine;
|
---|
147 | UINT32 uErrorLevel;
|
---|
148 | BASE_LIST bs;
|
---|
149 | CHAR8 *pszFormat;
|
---|
150 |
|
---|
151 | if (ReportStatusCodeExtractAssertInfo(Type, Value, Data, &pszFilename,
|
---|
152 | &pszDescription, &uLine))
|
---|
153 | {
|
---|
154 | VBoxPrintString("Assertion Failed! Line=0x");
|
---|
155 | VBoxPrintHex(uLine, sizeof(uLine));
|
---|
156 | if (pszFilename)
|
---|
157 | {
|
---|
158 | VBoxPrintString(" File=");
|
---|
159 | VBoxPrintString(pszFilename);
|
---|
160 | }
|
---|
161 | if (pszDescription)
|
---|
162 | {
|
---|
163 | VBoxPrintString(" Desc=");
|
---|
164 | VBoxPrintString(pszDescription);
|
---|
165 | }
|
---|
166 | VBoxPrintChar('\n');
|
---|
167 | }
|
---|
168 | else if ( ReportStatusCodeExtractDebugInfo(Data, &uErrorLevel, &bs, &pszFormat)
|
---|
169 | #if 0 /* See question at VBoxSecExtractDebugInfo. */
|
---|
170 | || VBoxSecExtractDebugInfo(Data, &uErrorLevel, &va, &pszFormat)
|
---|
171 | #endif
|
---|
172 | )
|
---|
173 | {
|
---|
174 | CHAR8 szBuf[128];
|
---|
175 | UINTN cch;
|
---|
176 |
|
---|
177 | cch = AsciiBSPrint(szBuf, sizeof(szBuf), pszFormat, bs);
|
---|
178 | if (cch >= sizeof(szBuf))
|
---|
179 | cch = sizeof(szBuf) - 1;
|
---|
180 | while ( cch > 0
|
---|
181 | && ( szBuf[cch - 1] == '\n'
|
---|
182 | || szBuf[cch - 1] == '\r'))
|
---|
183 | cch--;
|
---|
184 | szBuf[cch] = '\0';
|
---|
185 |
|
---|
186 | VBoxPrintString("DBG/");
|
---|
187 | VBoxPrintHex(uErrorLevel, sizeof(uErrorLevel));
|
---|
188 | VBoxPrintString(": ");
|
---|
189 | VBoxPrintString(szBuf);
|
---|
190 | VBoxPrintChar('\n');
|
---|
191 | }
|
---|
192 | else
|
---|
193 | {
|
---|
194 | /*
|
---|
195 | * Unknown data, resort to raw dump of everything.
|
---|
196 | */
|
---|
197 | VBoxOemHookStatusCodeReportRawDump(Type, Value, Instance, CallerId);
|
---|
198 |
|
---|
199 | VBoxPrintString("OemReport: Unknown data type ");
|
---|
200 | VBoxPrintGuid(&Data->Type);
|
---|
201 | VBoxPrintString(" (Size=");
|
---|
202 | VBoxPrintHex(Data->Size, sizeof(Data->Size));
|
---|
203 | VBoxPrintString(" HeaderSize=");
|
---|
204 | VBoxPrintHex(Data->HeaderSize, sizeof(Data->HeaderSize));
|
---|
205 | VBoxPrintString(")\n");
|
---|
206 | if (Data->Size > 0 && Data->Size <= 128)
|
---|
207 | VBoxPrintHexDump(Data + 1, Data->Size);
|
---|
208 | }
|
---|
209 | }
|
---|
210 | /*
|
---|
211 | * No data, do a raw dump.
|
---|
212 | */
|
---|
213 | else
|
---|
214 | VBoxOemHookStatusCodeReportRawDump(Type, Value, Instance, CallerId);
|
---|
215 |
|
---|
216 | return EFI_SUCCESS;
|
---|
217 | }
|
---|
218 |
|
---|