]> git.proxmox.com Git - efi-boot-shim.git/blob - errlog.c
dbx: generate our own UUID
[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 if (file == NULL || func == NULL || fmt == NULL)
36 return EFI_INVALID_PARAMETER;
37
38 newerrs = ReallocatePool(errs, (nerrs + 1) * sizeof(*errs),
39 (nerrs + 3) * sizeof(*errs));
40 if (!newerrs)
41 return EFI_OUT_OF_RESOURCES;
42
43 newerrs[nerrs] = PoolPrint(L"%a:%d %a() ", file, line, func);
44 if (!newerrs[nerrs])
45 return EFI_OUT_OF_RESOURCES;
46 ms_va_copy(args2, args);
47 newerrs[nerrs+1] = VPoolPrint(fmt, args2);
48 if (!newerrs[nerrs+1])
49 return EFI_OUT_OF_RESOURCES;
50 ms_va_end(args2);
51
52 nerrs += 2;
53 newerrs[nerrs] = NULL;
54 errs = newerrs;
55
56 return EFI_SUCCESS;
57 }
58
59 EFI_STATUS EFIAPI
60 LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
61 {
62 ms_va_list args;
63 EFI_STATUS efi_status;
64
65 ms_va_start(args, fmt);
66 efi_status = VLogError(file, line, func, fmt, args);
67 ms_va_end(args);
68
69 return efi_status;
70 }
71
72 VOID
73 LogHexdump_(const char *file, int line, const char *func, const void *data, size_t sz)
74 {
75 hexdumpat(file, line, func, data, sz, 0);
76 }
77
78 VOID
79 PrintErrors(VOID)
80 {
81 UINTN i;
82
83 if (!verbose)
84 return;
85
86 for (i = 0; i < nerrs; i++)
87 console_print(L"%s", errs[i]);
88 }
89
90 VOID
91 ClearErrors(VOID)
92 {
93 UINTN i;
94
95 for (i = 0; i < nerrs; i++)
96 FreePool(errs[i]);
97 FreePool(errs);
98 nerrs = 0;
99 errs = NULL;
100 }
101
102 // vim:fenc=utf-8:tw=75