summaryrefslogtreecommitdiffstats
path: root/src/fundamental
diff options
context:
space:
mode:
Diffstat (limited to 'src/fundamental')
-rw-r--r--src/fundamental/efivars-fundamental.h1
-rw-r--r--src/fundamental/macro-fundamental.h30
-rw-r--r--src/fundamental/meson.build2
-rw-r--r--src/fundamental/sha256-fundamental.c (renamed from src/fundamental/sha256.c)13
-rw-r--r--src/fundamental/sha256-fundamental.h (renamed from src/fundamental/sha256.h)0
-rw-r--r--src/fundamental/string-util-fundamental.c16
-rw-r--r--src/fundamental/string-util-fundamental.h4
-rw-r--r--src/fundamental/uki.c1
-rw-r--r--src/fundamental/uki.h1
9 files changed, 46 insertions, 22 deletions
diff --git a/src/fundamental/efivars-fundamental.h b/src/fundamental/efivars-fundamental.h
index 2d25d22..01b18ec 100644
--- a/src/fundamental/efivars-fundamental.h
+++ b/src/fundamental/efivars-fundamental.h
@@ -33,6 +33,7 @@
#define EFI_STUB_FEATURE_CMDLINE_ADDONS (UINT64_C(1) << 5)
#define EFI_STUB_FEATURE_CMDLINE_SMBIOS (UINT64_C(1) << 6)
#define EFI_STUB_FEATURE_DEVICETREE_ADDONS (UINT64_C(1) << 7)
+#define EFI_STUB_FEATURE_PICK_UP_CONFEXTS (UINT64_C(1) << 8)
typedef enum SecureBootMode {
SECURE_BOOT_UNSUPPORTED,
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h
index 797330d..5ccbda5 100644
--- a/src/fundamental/macro-fundamental.h
+++ b/src/fundamental/macro-fundamental.h
@@ -158,6 +158,10 @@
__atomic_exchange_n(&(o), true, __ATOMIC_SEQ_CST); \
})
+#define U64_KB UINT64_C(1024)
+#define U64_MB (UINT64_C(1024) * U64_KB)
+#define U64_GB (UINT64_C(1024) * U64_MB)
+
#undef MAX
#define MAX(a, b) __MAX(UNIQ, (a), UNIQ, (b))
#define __MAX(aq, a, bq, b) \
@@ -245,6 +249,30 @@
CONST_ISPOWEROF2(_x); \
}))
+#define ADD_SAFE(ret, a, b) (!__builtin_add_overflow(a, b, ret))
+#define INC_SAFE(a, b) __INC_SAFE(UNIQ, a, b)
+#define __INC_SAFE(q, a, b) \
+ ({ \
+ const typeof(a) UNIQ_T(A, q) = (a); \
+ ADD_SAFE(UNIQ_T(A, q), *UNIQ_T(A, q), b); \
+ })
+
+#define SUB_SAFE(ret, a, b) (!__builtin_sub_overflow(a, b, ret))
+#define DEC_SAFE(a, b) __DEC_SAFE(UNIQ, a, b)
+#define __DEC_SAFE(q, a, b) \
+ ({ \
+ const typeof(a) UNIQ_T(A, q) = (a); \
+ SUB_SAFE(UNIQ_T(A, q), *UNIQ_T(A, q), b); \
+ })
+
+#define MUL_SAFE(ret, a, b) (!__builtin_mul_overflow(a, b, ret))
+#define MUL_ASSIGN_SAFE(a, b) __MUL_ASSIGN_SAFE(UNIQ, a, b)
+#define __MUL_ASSIGN_SAFE(q, a, b) \
+ ({ \
+ const typeof(a) UNIQ_T(A, q) = (a); \
+ MUL_SAFE(UNIQ_T(A, q), *UNIQ_T(A, q), b); \
+ })
+
#define LESS_BY(a, b) __LESS_BY(UNIQ, (a), UNIQ, (b))
#define __LESS_BY(aq, a, bq, b) \
({ \
@@ -294,7 +322,7 @@
const typeof(y) UNIQ_T(A, q) = (y); \
const typeof(x) UNIQ_T(B, q) = DIV_ROUND_UP((x), UNIQ_T(A, q)); \
typeof(x) UNIQ_T(C, q); \
- __builtin_mul_overflow(UNIQ_T(B, q), UNIQ_T(A, q), &UNIQ_T(C, q)) ? (typeof(x)) -1 : UNIQ_T(C, q); \
+ MUL_SAFE(&UNIQ_T(C, q), UNIQ_T(B, q), UNIQ_T(A, q)) ? UNIQ_T(C, q) : (typeof(x)) -1; \
})
#define ROUND_UP(x, y) __ROUND_UP(UNIQ, (x), (y))
diff --git a/src/fundamental/meson.build b/src/fundamental/meson.build
index b7ca6cf..f5f57ac 100644
--- a/src/fundamental/meson.build
+++ b/src/fundamental/meson.build
@@ -5,7 +5,7 @@ fundamental_include = include_directories('.')
fundamental_sources = files(
'bootspec-fundamental.c',
'efivars-fundamental.c',
- 'sha256.c',
+ 'sha256-fundamental.c',
'string-util-fundamental.c',
'uki.c',
)
diff --git a/src/fundamental/sha256.c b/src/fundamental/sha256-fundamental.c
index 4389e9e..f8524ba 100644
--- a/src/fundamental/sha256.c
+++ b/src/fundamental/sha256-fundamental.c
@@ -29,21 +29,14 @@
#endif
#include "macro-fundamental.h"
-#include "sha256.h"
+#include "sha256-fundamental.h"
#include "unaligned-fundamental.h"
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
# define SWAP(n) \
- (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24))
+ __builtin_bswap32(n)
# define SWAP64(n) \
- (((n) << 56) \
- | (((n) & 0xff00) << 40) \
- | (((n) & 0xff0000) << 24) \
- | (((n) & 0xff000000) << 8) \
- | (((n) >> 8) & 0xff000000) \
- | (((n) >> 24) & 0xff0000) \
- | (((n) >> 40) & 0xff00) \
- | ((n) >> 56))
+ __builtin_bswap64(n)
#else
# define SWAP(n) (n)
# define SWAP64(n) (n)
diff --git a/src/fundamental/sha256.h b/src/fundamental/sha256-fundamental.h
index dbb08e3..dbb08e3 100644
--- a/src/fundamental/sha256.h
+++ b/src/fundamental/sha256-fundamental.h
diff --git a/src/fundamental/string-util-fundamental.c b/src/fundamental/string-util-fundamental.c
index a5bafc6..a18b2bc 100644
--- a/src/fundamental/string-util-fundamental.c
+++ b/src/fundamental/string-util-fundamental.c
@@ -33,14 +33,14 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) {
return (sd_char*) s + l;
}
-sd_char* endswith(const sd_char *s, const sd_char *postfix) {
+sd_char* endswith(const sd_char *s, const sd_char *suffix) {
size_t sl, pl;
assert(s);
- assert(postfix);
+ assert(suffix);
sl = strlen(s);
- pl = strlen(postfix);
+ pl = strlen(suffix);
if (pl == 0)
return (sd_char*) s + sl;
@@ -48,20 +48,20 @@ sd_char* endswith(const sd_char *s, const sd_char *postfix) {
if (sl < pl)
return NULL;
- if (strcmp(s + sl - pl, postfix) != 0)
+ if (!streq(s + sl - pl, suffix))
return NULL;
return (sd_char*) s + sl - pl;
}
-sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) {
+sd_char* endswith_no_case(const sd_char *s, const sd_char *suffix) {
size_t sl, pl;
assert(s);
- assert(postfix);
+ assert(suffix);
sl = strlen(s);
- pl = strlen(postfix);
+ pl = strlen(suffix);
if (pl == 0)
return (sd_char*) s + sl;
@@ -69,7 +69,7 @@ sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) {
if (sl < pl)
return NULL;
- if (strcasecmp(s + sl - pl, postfix) != 0)
+ if (!strcaseeq(s + sl - pl, suffix))
return NULL;
return (sd_char*) s + sl - pl;
diff --git a/src/fundamental/string-util-fundamental.h b/src/fundamental/string-util-fundamental.h
index b537b2e..419f1cc 100644
--- a/src/fundamental/string-util-fundamental.h
+++ b/src/fundamental/string-util-fundamental.h
@@ -59,8 +59,8 @@ static inline size_t strlen_ptr(const sd_char *s) {
sd_char *startswith(const sd_char *s, const sd_char *prefix) _pure_;
sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
-sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_;
-sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_;
+sd_char *endswith(const sd_char *s, const sd_char *suffix) _pure_;
+sd_char *endswith_no_case(const sd_char *s, const sd_char *suffix) _pure_;
static inline bool isempty(const sd_char *a) {
return !a || a[0] == '\0';
diff --git a/src/fundamental/uki.c b/src/fundamental/uki.c
index b1fa044..3887bf5 100644
--- a/src/fundamental/uki.c
+++ b/src/fundamental/uki.c
@@ -13,6 +13,7 @@ const char* const unified_sections[_UNIFIED_SECTION_MAX + 1] = {
[UNIFIED_SECTION_OSREL] = ".osrel",
[UNIFIED_SECTION_CMDLINE] = ".cmdline",
[UNIFIED_SECTION_INITRD] = ".initrd",
+ [UNIFIED_SECTION_UCODE] = ".ucode",
[UNIFIED_SECTION_SPLASH] = ".splash",
[UNIFIED_SECTION_DTB] = ".dtb",
[UNIFIED_SECTION_UNAME] = ".uname",
diff --git a/src/fundamental/uki.h b/src/fundamental/uki.h
index ffa960f..8ab742d 100644
--- a/src/fundamental/uki.h
+++ b/src/fundamental/uki.h
@@ -10,6 +10,7 @@ typedef enum UnifiedSection {
UNIFIED_SECTION_OSREL,
UNIFIED_SECTION_CMDLINE,
UNIFIED_SECTION_INITRD,
+ UNIFIED_SECTION_UCODE,
UNIFIED_SECTION_SPLASH,
UNIFIED_SECTION_DTB,
UNIFIED_SECTION_UNAME,