]> git.proxmox.com Git - systemd.git/blame - src/boot/efi/util.h
New upstream version 242
[systemd.git] / src / boot / efi / util.h
CommitLineData
52ad194e 1/* SPDX-License-Identifier: LGPL-2.1+ */
6e866b33 2#pragma once
86f210e9
MP
3
4#include <efi.h>
5#include <efilib.h>
6
7#define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
6e866b33 8#define OFFSETOF(x,y) __builtin_offsetof(x,y)
86f210e9 9
bb4f798a
MB
10static inline UINTN ALIGN_TO(UINTN l, UINTN ali) {
11 return ((l + ali - 1) & ~(ali - 1));
12}
13
86f210e9
MP
14static inline const CHAR16 *yes_no(BOOLEAN b) {
15 return b ? L"yes" : L"no";
16}
17
6e866b33 18EFI_STATUS parse_boolean(const CHAR8 *v, BOOLEAN *b);
86f210e9
MP
19
20UINT64 ticks_read(void);
21UINT64 ticks_freq(void);
22UINT64 time_usec(void);
23
6e866b33
MB
24EFI_STATUS efivar_set(const CHAR16 *name, const CHAR16 *value, BOOLEAN persistent);
25EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, const CHAR16 *name, const VOID *buf, UINTN size, BOOLEAN persistent);
86f210e9
MP
26EFI_STATUS efivar_set_int(CHAR16 *name, UINTN i, BOOLEAN persistent);
27VOID efivar_set_time_usec(CHAR16 *name, UINT64 usec);
28
6e866b33
MB
29EFI_STATUS efivar_get(const CHAR16 *name, CHAR16 **value);
30EFI_STATUS efivar_get_raw(const EFI_GUID *vendor, const CHAR16 *name, CHAR8 **buffer, UINTN *size);
31EFI_STATUS efivar_get_int(const CHAR16 *name, UINTN *i);
86f210e9
MP
32
33CHAR8 *strchra(CHAR8 *s, CHAR8 c);
34CHAR16 *stra_to_path(CHAR8 *stra);
35CHAR16 *stra_to_str(CHAR8 *stra);
36
6e866b33 37EFI_STATUS file_read(EFI_FILE_HANDLE dir, const CHAR16 *name, UINTN off, UINTN size, CHAR8 **content, UINTN *content_size);
b012e921
MB
38
39static inline void FreePoolp(void *p) {
6e866b33
MB
40 void *q = *(void**) p;
41
42 if (!q)
43 return;
44
45 FreePool(q);
b012e921
MB
46}
47
6e866b33 48#define _cleanup_(x) __attribute__((__cleanup__(x)))
b012e921 49#define _cleanup_freepool_ _cleanup_(FreePoolp)
6e866b33
MB
50
51static inline void FileHandleClosep(EFI_FILE_HANDLE *handle) {
52 if (!*handle)
53 return;
54
55 uefi_call_wrapper((*handle)->Close, 1, *handle);
56}
57
58const EFI_GUID loader_guid;
59
60#define UINTN_MAX (~(UINTN)0)
61#define INTN_MAX ((INTN)(UINTN_MAX>>1))
bb4f798a
MB
62
63#define TAKE_PTR(ptr) \
64 ({ \
65 typeof(ptr) _ptr_ = (ptr); \
66 (ptr) = NULL; \
67 _ptr_; \
68 })