]> git.proxmox.com Git - efi-boot-shim.git/blob - errlog.c
Merge branch 'fixes20240429' into 'master'
[efi-boot-shim.git] / errlog.c
1 // SPDX-License-Identifier: BSD-2-Clause-Patent
2 /*
3 * errlog.c
4 * Copyright Peter Jones <pjones@redhat.com>
5 */
6
7 #include "shim.h"
8
9 static CHAR16 **errs = NULL;
10 static UINTN nerrs = 0;
11
12 EFI_STATUS EFIAPI
13 vdprint_(const CHAR16 *fmt, const char *file, int line, const char *func,
14 ms_va_list args)
15 {
16 ms_va_list args2;
17 EFI_STATUS efi_status = EFI_SUCCESS;
18
19 if (verbose) {
20 ms_va_copy(args2, args);
21 console_print(L"%a:%d:%a() ", file, line, func);
22 efi_status = VPrint(fmt, args2);
23 ms_va_end(args2);
24 }
25 return efi_status;
26 }
27
28 EFI_STATUS EFIAPI
29 VLogError(const char *file, int line, const char *func, const CHAR16 *fmt,
30 ms_va_list args)
31 {
32 ms_va_list args2;
33 CHAR16 **newerrs;
34
35 newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs),
36 (nerrs + 3) * sizeof(*errs));
37 if (!newerrs)
38 return EFI_OUT_OF_RESOURCES;
39
40 newerrs[nerrs] = PoolPrint(L"%a:%d %a() ", file, line, func);
41 if (!newerrs[nerrs])
42 return EFI_OUT_OF_RESOURCES;
43 ms_va_copy(args2, args);
44 newerrs[nerrs+1] = VPoolPrint(fmt, args2);
45 if (!newerrs[nerrs+1])
46 return EFI_OUT_OF_RESOURCES;
47 ms_va_end(args2);
48
49 nerrs += 2;
50 newerrs[nerrs] = NULL;
51 errs = newerrs;
52
53 return EFI_SUCCESS;
54 }
55
56 EFI_STATUS EFIAPI
57 LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
58 {
59 ms_va_list args;
60 EFI_STATUS efi_status;
61
62 ms_va_start(args, fmt);
63 efi_status = VLogError(file, line, func, fmt, args);
64 ms_va_end(args);
65
66 return efi_status;
67 }
68
69 VOID
70 LogHexdump_(const char *file, int line, const char *func, const void *data, size_t sz)
71 {
72 hexdumpat(file, line, func, data, sz, 0);
73 }
74
75 VOID
76 PrintErrors(VOID)
77 {
78 UINTN i;
79
80 if (!verbose)
81 return;
82
83 for (i = 0; i < nerrs; i++)
84 console_print(L"%s", errs[i]);
85 }
86
87 VOID
88 ClearErrors(VOID)
89 {
90 UINTN i;
91
92 for (i = 0; i < nerrs; i++)
93 FreePool(errs[i]);
94 FreePool(errs);
95 nerrs = 0;
96 errs = NULL;
97 }
98
99 // vim:fenc=utf-8:tw=75