MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / MemLogVA

Function MemLogVA

Library/MemLogLibDefault/MemLogLib.c:230–308  ·  view source on GitHub ↗

Prints a log message to memory buffer. @param Timing TRUE to prepend timing to log. @param DebugMode DebugMode will be passed to Callback function if it is set. @param Format The format string for the debug message to print. @param Marker VA_LIST with variable arguments for Format. **/

Source from the content-addressed store, hash-verified

228
229**/
230VOID
231EFIAPI
232MemLogVA (
233 IN CONST BOOLEAN Timing,
234 IN CONST INTN DebugMode,
235 IN CONST CHAR8 *Format,
236 IN VA_LIST Marker
237 )
238{
239 EFI_STATUS Status;
240 UINTN DataWritten;
241 CHAR8 *LastMessage;
242
243 if (Format == NULL) {
244 return;
245 }
246
247 if (mMemLog == NULL) {
248 Status = MemLogInit ();
249 if (EFI_ERROR(Status)) {
250 return;
251 }
252 }
253
254 //
255 // Check if buffer can accept MEM_LOG_MAX_LINE_SIZE chars.
256 // Increase buffer if not.
257 //
258 if ((UINTN)(mMemLog->Cursor - mMemLog->Buffer) + MEM_LOG_MAX_LINE_SIZE > mMemLog->BufferSize) {
259 UINTN Offset;
260 // not enough place for max line - make buffer bigger
261 // but not too big (if something gets out of controll)
262 if (mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE > MEM_LOG_MAX_SIZE) {
263 // Out of resources!
264 return;
265 }
266 Offset = mMemLog->Cursor - mMemLog->Buffer;
267 mMemLog->Buffer = ReallocatePool(mMemLog->BufferSize, mMemLog->BufferSize + MEM_LOG_INITIAL_SIZE, mMemLog->Buffer);
268 mMemLog->BufferSize += MEM_LOG_INITIAL_SIZE;
269 mMemLog->Cursor = mMemLog->Buffer + Offset;
270 }
271
272 //
273 // Add log to buffer
274 //
275 LastMessage = mMemLog->Cursor;
276 if (Timing) {
277 //
278 // Write timing only at the beginning of a new line
279 //
280 if ((mMemLog->Buffer[0] == '\0') || (mMemLog->Cursor[-1] == '\n')) {
281 DataWritten = AsciiSPrint(
282 mMemLog->Cursor,
283 mMemLog->BufferSize - (mMemLog->Cursor - mMemLog->Buffer),
284 "%a ",
285 GetTiming ());
286 mMemLog->Cursor += DataWritten;
287 }

Callers 1

MemLogFunction · 0.85

Calls 6

MemLogInitFunction · 0.85
GetTimingFunction · 0.70
ReallocatePoolFunction · 0.50
AsciiSPrintFunction · 0.50
AsciiVSPrintFunction · 0.50
DebugPrintFunction · 0.50

Tested by

no test coverage detected