]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/boot/efi/util.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
7 #include "string-util-fundamental.h"
9 #define OFFSETOF(x,y) __builtin_offsetof(x,y)
11 static inline UINTN
ALIGN_TO(UINTN l
, UINTN ali
) {
12 return ((l
+ ali
- 1) & ~(ali
- 1));
15 EFI_STATUS
parse_boolean(const CHAR8
*v
, BOOLEAN
*b
);
17 UINT64
ticks_read(void);
18 UINT64
ticks_freq(void);
19 UINT64
time_usec(void);
21 EFI_STATUS
efivar_set(const EFI_GUID
*vendor
, const CHAR16
*name
, const CHAR16
*value
, UINT32 flags
);
22 EFI_STATUS
efivar_set_raw(const EFI_GUID
*vendor
, const CHAR16
*name
, const VOID
*buf
, UINTN size
, UINT32 flags
);
23 EFI_STATUS
efivar_set_uint_string(const EFI_GUID
*vendor
, const CHAR16
*name
, UINTN i
, UINT32 flags
);
24 EFI_STATUS
efivar_set_uint32_le(const EFI_GUID
*vendor
, const CHAR16
*NAME
, UINT32 value
, UINT32 flags
);
25 EFI_STATUS
efivar_set_uint64_le(const EFI_GUID
*vendor
, const CHAR16
*name
, UINT64 value
, UINT32 flags
);
26 VOID
efivar_set_time_usec(const EFI_GUID
*vendor
, const CHAR16
*name
, UINT64 usec
);
28 EFI_STATUS
efivar_get(const EFI_GUID
*vendor
, const CHAR16
*name
, CHAR16
**value
);
29 EFI_STATUS
efivar_get_raw(const EFI_GUID
*vendor
, const CHAR16
*name
, CHAR8
**buffer
, UINTN
*size
);
30 EFI_STATUS
efivar_get_uint_string(const EFI_GUID
*vendor
, const CHAR16
*name
, UINTN
*i
);
31 EFI_STATUS
efivar_get_uint32_le(const EFI_GUID
*vendor
, const CHAR16
*name
, UINT32
*ret
);
32 EFI_STATUS
efivar_get_uint64_le(const EFI_GUID
*vendor
, const CHAR16
*name
, UINT64
*ret
);
33 EFI_STATUS
efivar_get_boolean_u8(const EFI_GUID
*vendor
, const CHAR16
*name
, BOOLEAN
*ret
);
35 CHAR8
*strchra(const CHAR8
*s
, CHAR8 c
);
36 CHAR16
*stra_to_path(const CHAR8
*stra
);
37 CHAR16
*stra_to_str(const CHAR8
*stra
);
39 EFI_STATUS
file_read(EFI_FILE_HANDLE dir
, const CHAR16
*name
, UINTN off
, UINTN size
, CHAR8
**content
, UINTN
*content_size
);
41 static inline void FreePoolp(void *p
) {
42 void *q
= *(void**) p
;
50 #define _cleanup_freepool_ _cleanup_(FreePoolp)
52 static inline void FileHandleClosep(EFI_FILE_HANDLE
*handle
) {
56 uefi_call_wrapper((*handle
)->Close
, 1, *handle
);
60 * Allocated random UUID, intended to be shared across tools that implement
61 * the (ESP)\loader\entries\<vendor>-<revision>.conf convention and the
62 * associated EFI variables.
65 &(const EFI_GUID) { 0x4a67b082, 0x0a4c, 0x41cf, { 0xb6, 0xc7, 0x44, 0x0b, 0x29, 0xbb, 0x8c, 0x4f } }
66 #define EFI_GLOBAL_GUID &(const EFI_GUID) EFI_GLOBAL_VARIABLE
68 #define UINTN_MAX (~(UINTN)0)
69 #define INTN_MAX ((INTN)(UINTN_MAX>>1))
71 #define UINT32_MAX ((UINT32) -1)
74 #define UINT64_MAX ((UINT64) -1)
77 VOID
log_error_stall(const CHAR16
*fmt
, ...);
78 EFI_STATUS
log_oom(void);
80 /* This works just like log_error_errno() from userspace, but requires you
81 * to provide err a second time if you want to use %r in the message! */
82 #define log_error_status_stall(err, fmt, ...) \
84 log_error_stall(fmt, ##__VA_ARGS__); \
88 VOID
*memmem_safe(const VOID
*haystack
, UINTN haystack_len
, const VOID
*needle
, UINTN needle_len
);
90 static inline VOID
*mempmem_safe(const VOID
*haystack
, UINTN haystack_len
, const VOID
*needle
, UINTN needle_len
) {
91 CHAR8
*p
= memmem_safe(haystack
, haystack_len
, needle
, needle_len
);
92 return p
? p
+ needle_len
: NULL
;
95 VOID
print_at(UINTN x
, UINTN y
, UINTN attr
, const CHAR16
*str
);
96 VOID
clear_screen(UINTN attr
);