Skip to content
Snippets Groups Projects
Commit 1b3d15bf authored by Rocky Automation's avatar Rocky Automation :tv:
Browse files

import shim-unsigned-x64-15.4-4.el8_1

parent ca41472c
No related branches found
No related tags found
No related merge requests found
Showing
with 1957 additions and 10 deletions
From 822d07ad4f07ef66fe447a130e1027c88d02a394 Mon Sep 17 00:00:00 2001
From: Adam Williamson <awilliam@redhat.com>
Date: Thu, 8 Apr 2021 22:39:02 -0700
Subject: [PATCH 01/10] Fix handling of ignore_db and user_insecure_mode
Subject: [PATCH 01/26] Fix handling of ignore_db and user_insecure_mode
In 65be350308783a8ef537246c8ad0545b4e6ad069, import_mok_state() is split
up into a function that manages the whole mok state, and one that
......
From a0f701501f73a0aabd1ef8d568183d05611b0a52 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 31 Mar 2021 09:44:53 -0400
Subject: [PATCH 02/10] shim-15.4 branch: update .gitmodules to point at
Subject: [PATCH 02/26] shim-15.4 branch: update .gitmodules to point at
shim-15.4 in gnu-efi
This is purely superficial, as the commit points at the shim-15.4 branch
......
From 5b3ca0d2f7b5f425ba1a14db8ce98b8d95a2f89f Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 31 Mar 2021 14:54:52 -0400
Subject: [PATCH 03/10] Fix a broken file header on ia32
Subject: [PATCH 03/26] Fix a broken file header on ia32
Commit c6281c6a195edee61185 needs to have included a ". = ALIGN(4096)"
directive before .reloc, but fails to do so.
......
From 4068fd42c891ea6ebdec056f461babc6e4048844 Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Thu, 8 Apr 2021 16:23:03 +0800
Subject: [PATCH 04/10] mok: allocate MOK config table as BootServicesData
Subject: [PATCH 04/26] mok: allocate MOK config table as BootServicesData
Linux kernel is picky when reserving the memory for x86 and it only
expects BootServicesData:
......
From 493bd940e5c6e28e673034687de7adef9529efff Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Sat, 10 Apr 2021 16:05:23 -0400
Subject: [PATCH 05/10] Don't call QueryVariableInfo() on EFI 1.10 machines
Subject: [PATCH 05/26] Don't call QueryVariableInfo() on EFI 1.10 machines
The EFI 1.10 spec (and presumably earlier revisions as well) didn't have
RT->QueryVariableInfo(), and on Chris Murphy's MacBookPro8,2 , that
......
From 05875f3aed1c90fe071c66de05744ca2bcbc2b9e Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 13 May 2021 20:42:18 -0400
Subject: [PATCH 06/10] Post-process our PE to be sure.
Subject: [PATCH 06/26] Post-process our PE to be sure.
On some versions of binutils[0], including binutils-2.23.52.0.1-55.el7,
do not correctly initialize the data when computing the PE optional
......
From 9f973e4e95b1136b8c98051dbbdb1773072cc998 Mon Sep 17 00:00:00 2001
From: Gary Lin <glin@suse.com>
Date: Tue, 11 May 2021 10:41:43 +0800
Subject: [PATCH 07/10] Relax the check for import_mok_state()
Subject: [PATCH 07/26] Relax the check for import_mok_state()
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
......
From 9a8a6cdb5e862648ee663eee6124bed05208639a Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge@hallyn.com>
Date: Wed, 14 Jul 2021 07:49:34 -0500
Subject: [PATCH 08/10] SBAT.md: trivial fixes
Subject: [PATCH 08/26] SBAT.md: trivial fixes
1. Use : instead of , to separate a list.
2. Fix spelling of therefore.
......
From 0f40cb0d08798ed7557887958b382a42253c715d Mon Sep 17 00:00:00 2001
From: Serge Hallyn <serge@hallyn.com>
Date: Wed, 14 Jul 2021 08:01:48 -0500
Subject: [PATCH 09/10] SBAT.md: fix "will should"
Subject: [PATCH 09/26] SBAT.md: fix "will should"
Use the stronger "will" rather than "will should". I'm not sure based on
what's there, but suspect "must" would be appropriate instead?
......
From 4d64389c6c941d21548b06423b8131c872e3c3c7 Mon Sep 17 00:00:00 2001
From: Chris Coulson <chris.coulson@canonical.com>
Date: Mon, 7 Jun 2021 16:34:18 +0100
Subject: [PATCH 10/10] shim: another attempt to fix load options handling
Subject: [PATCH 10/26] shim: another attempt to fix load options handling
The load options handling is quite complicated and tries to accomodate
several scenarios, but there are currently multiple issues:
......
From 352a741bc5fa9a71776d56750f51d80f9f2e808f Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 14:37:04 -0400
Subject: [PATCH 11/26] .gitignore: ignore .gdb*, not just .gdbinit
Signed-off-by: Peter Jones <pjones@redhat.com>
---
.gitignore | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.gitignore b/.gitignore
index d37fcd6..2a4598b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -14,7 +14,7 @@ Make.local
*.efi.debug
*.efi.signed
*.esl
-*.gdbinit
+*.gdb*
*.hash
*.key
*.key
--
2.32.0
From 3ecfa301f4a8c4c2168f95f27d0313f4158ab53d Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 13:11:59 -0400
Subject: [PATCH 12/26] shim: rename pause() to wait_for_debug()
pause() is a posix function, and having it named the same as this makes
it hard to include the asm.h header in some test cases.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/asm.h | 6 +++---
shim.c | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/include/asm.h b/include/asm.h
index 8458d5d..03b0655 100644
--- a/include/asm.h
+++ b/include/asm.h
@@ -26,17 +26,17 @@ static inline uint64_t read_counter(void)
}
#if defined(__x86_64__) || defined(__i386__) || defined(__i686__)
-static inline void pause(void)
+static inline void wait_for_debug(void)
{
__asm__ __volatile__("pause");
}
#elif defined(__aarch64__)
-static inline void pause(void)
+static inline void wait_for_debug(void)
{
__asm__ __volatile__("wfi");
}
#else
-static inline void pause(void)
+static inline void wait_for_debug(void)
{
uint64_t a, b;
int x;
diff --git a/shim.c b/shim.c
index ecf6ee5..2ae6024 100644
--- a/shim.c
+++ b/shim.c
@@ -1817,7 +1817,7 @@ debug_hook(void)
if (x > 12000)
break;
#endif
- pause();
+ wait_for_debug();
}
x = 1;
}
--
2.32.0
From 32697356c6a99a53bf0027ceb3e348278799b9ef Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 13:10:38 -0400
Subject: [PATCH 13/26] test.h: make some of the asserts a little more friendly
to pointer types.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.h | 87 ++++++++++++++++++++++++++------------------------
1 file changed, 45 insertions(+), 42 deletions(-)
diff --git a/include/test.h b/include/test.h
index 012ffc5..1d9c7be 100644
--- a/include/test.h
+++ b/include/test.h
@@ -63,24 +63,24 @@ extern int debug;
assert(cond); \
})
-#define assert_true_as_expr(a, status, fmt, ...) \
- ({ \
- int rc_ = 0; \
- if (!(a)) { \
- printf("%s:%d:got %lld, expected nonzero " fmt, \
- __func__, __LINE__, (long long)(a), \
- ##__VA_ARGS__); \
- printf("%s:%d:Assertion `%s' failed.\n", __func__, \
- __LINE__, __stringify(!(a))); \
- rc_ = status; \
- } \
- rc_; \
+#define assert_true_as_expr(a, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = 0; \
+ if (!(a)) { \
+ printf("%s:%d:got %lld, expected nonzero " fmt, \
+ __func__, __LINE__, (long long)(uintptr_t)(a), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(!(a))); \
+ rc_ = status; \
+ } \
+ rc_; \
})
#define assert_nonzero_as_expr(a, ...) assert_true_as_expr(a, ##__VA_ARGS__)
#define assert_false_as_expr(a, status, fmt, ...) \
({ \
- int rc_ = 0; \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
if (a) { \
printf("%s:%d:got %lld, expected zero " fmt, __func__, \
__LINE__, (long long)(a), ##__VA_ARGS__); \
@@ -94,7 +94,7 @@ extern int debug;
#define assert_positive_as_expr(a, status, fmt, ...) \
({ \
- int rc_ = 0; \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
if ((a) <= 0) { \
printf("%s:%d:got %lld, expected > 0 " fmt, __func__, \
__LINE__, (long long)(a), ##__VA_ARGS__); \
@@ -107,7 +107,7 @@ extern int debug;
#define assert_negative_as_expr(a, status, fmt, ...) \
({ \
- int rc_ = 0; \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
if ((a) >= 0) { \
printf("%s:%d:got %lld, expected < 0 " fmt, __func__, \
__LINE__, (long long)(a), ##__VA_ARGS__); \
@@ -120,7 +120,7 @@ extern int debug;
#define assert_equal_as_expr(a, b, status, fmt, ...) \
({ \
- int rc_ = 0; \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
if (!((a) == (b))) { \
printf("%s:%d:" fmt, __func__, __LINE__, (a), (b), \
##__VA_ARGS__); \
@@ -133,7 +133,7 @@ extern int debug;
#define assert_as_expr(cond, status, fmt, ...) \
({ \
- int rc_ = 0; \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
if (!(cond)) { \
printf("%s:%d:" fmt, __func__, __LINE__, \
##__VA_ARGS__); \
@@ -144,51 +144,54 @@ extern int debug;
rc_; \
})
-#define assert_true_return(a, status, fmt, ...) \
- ({ \
- int rc_ = assert_true_as_expr(a, status, fmt, ##__VA_ARGS__); \
- if (rc_ != 0) \
- return rc_; \
+#define assert_true_return(a, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = \
+ assert_true_as_expr(a, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
})
#define assert_nonzero_return(a, ...) assert_true_return(a, ##__VA_ARGS__)
-#define assert_false_return(a, status, fmt, ...) \
- ({ \
- int rc_ = assert_false_as_expr(a, status, fmt, ##__VA_ARGS__); \
- if (rc_ != 0) \
- return rc_; \
+#define assert_false_return(a, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = \
+ assert_false_as_expr(a, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
})
#define assert_zero_return(a, ...) assert_false_return(a, ##__VA_ARGS__)
#define assert_positive_return(a, status, fmt, ...) \
({ \
- int rc_ = assert_positive_as_expr(a, status, fmt, \
- ##__VA_ARGS__); \
+ __typeof__(status) rc_ = assert_positive_as_expr( \
+ a, status, fmt, ##__VA_ARGS__); \
if (rc_ != 0) \
return rc_; \
})
#define assert_negative_return(a, status, fmt, ...) \
({ \
- int rc_ = assert_negative_as_expr(a, status, fmt, \
- ##__VA_ARGS__); \
+ __typeof__(status) rc_ = assert_negative_as_expr( \
+ a, status, fmt, ##__VA_ARGS__); \
if (rc_ != 0) \
return rc_; \
})
-#define assert_equal_return(a, b, status, fmt, ...) \
- ({ \
- int rc_ = assert_equal_as_expr(a, b, status, fmt, \
- ##__VA_ARGS__); \
- if (rc_ != 0) \
- return rc_; \
+#define assert_equal_return(a, b, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = assert_equal_as_expr( \
+ a, b, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
})
-#define assert_return(cond, status, fmt, ...) \
- ({ \
- int rc_ = assert_as_expr(cond, status, fmt, ##__VA_ARGS__); \
- if (rc_ != 0) \
- return rc_; \
+#define assert_return(cond, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = \
+ assert_as_expr(cond, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
})
#define assert_goto(cond, label, fmt, ...) \
--
2.32.0
From 5f08e671e4eb4ec43c1bf667e67f02b7454e13b0 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 13:57:40 -0400
Subject: [PATCH 14/26] test.h: add some decls for some of the stuff in
efilib.h
In some test cases, it's useful to be able to call some of the very
common stuff in gnu-efi's efilib.h (i.e. CompareGuid()), but including
that header itself is too big for me to tackle right now.
This patch adds a few more decls to test.h.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.h | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/include/test.h b/include/test.h
index 1d9c7be..811f92b 100644
--- a/include/test.h
+++ b/include/test.h
@@ -48,6 +48,17 @@
#define FreePool(x) free(x)
#define ReallocatePool(old, oldsz, newsz) realloc(old, newsz)
+INTN StrnCmp(IN CONST CHAR16 *s1,
+ IN CONST CHAR16 *s2,
+ IN UINTN len);
+CHAR16 *StrDuplicate(IN CONST CHAR16 *Src);
+UINTN StrLen(IN CONST CHAR16 *s1);
+UINTN StrSize(IN CONST CHAR16 *s1);
+VOID StrCat(IN CHAR16 *Dest, IN CONST CHAR16 *Src);
+CHAR16 *DevicePathToStr(EFI_DEVICE_PATH *DevPath);
+
+#define CompareGuid(a, b) memcmp(a, b, sizeof(a))
+
extern int debug;
#ifdef dprint
#undef dprint
--
2.32.0
From b092c85fc3e9caec83728b244a34ed8325a02c6d Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 14:05:47 -0400
Subject: [PATCH 15/26] test.c: Conditionally do not declare stuff that's in
other places
test.c duplicates a couple of objects (StrnCmp, StrCmp) that are
in libefi.a, as well as SHIM_LOCK_GUID from lib/guid.o. While it's nice
to have these at some places, we need to disable them if we're actually
linking a test case against either of those.
This patch adds HAVE_foo guards around those objects.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
test.c | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/test.c b/test.c
index dc71941..9da5cf5 100644
--- a/test.c
+++ b/test.c
@@ -22,6 +22,7 @@ LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
return EFI_SUCCESS;
}
+#ifndef HAVE_STRCMP
INTN
StrCmp(CONST CHAR16 *s1, CONST CHAR16 *s2) {
assert(s1 != NULL);
@@ -34,7 +35,9 @@ StrCmp(CONST CHAR16 *s1, CONST CHAR16 *s2) {
}
return 0;
}
+#endif
+#ifndef HAVE_STRNCMP
INTN
StrnCmp(CONST CHAR16 *s1, CONST CHAR16 *s2, UINTN len) {
assert(s1 != NULL);
@@ -48,20 +51,27 @@ StrnCmp(CONST CHAR16 *s1, CONST CHAR16 *s2, UINTN len) {
}
return 0;
}
+#endif
+#ifndef HAVE_GET_VARIABLE_ATTR
EFI_STATUS
get_variable_attr(const CHAR16 * const var, UINT8 **data, UINTN *len,
EFI_GUID owner, UINT32 *attributes)
{
return EFI_UNSUPPORTED;
}
+#endif
+#ifndef HAVE_GET_VARIABLE
EFI_STATUS
get_variable(const CHAR16 * const var, UINT8 **data, UINTN *len, EFI_GUID owner)
{
return get_variable_attr(var, data, len, owner, NULL);
}
+#endif
+#ifndef HAVE_SHIM_LOCK_GUID
EFI_GUID SHIM_LOCK_GUID = {0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } };
+#endif
// vim:fenc=utf-8:tw=75:noet
--
2.32.0
From f1ef8dffd374048fbf8dd584923c42e5a784bbf2 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Thu, 15 Jul 2021 10:07:14 -0400
Subject: [PATCH 16/26] Make test cases link against libefi.a
This allows us to use library functions from libefi.a in our test
programs.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.mk | 20 +++++++++++++++++---
lib/variables.c | 48 ++++++++++++++++++++++++++----------------------
test.c | 37 ++++++-------------------------------
3 files changed, 49 insertions(+), 56 deletions(-)
diff --git a/include/test.mk b/include/test.mk
index 62cf983..c66b46d 100644
--- a/include/test.mk
+++ b/include/test.mk
@@ -5,6 +5,8 @@
.SUFFIXES:
+include Make.defaults
+
CC = gcc
VALGRIND ?=
DEBUG_PRINTS ?= 0
@@ -28,6 +30,15 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
-DSHIM_UNIT_TEST \
"-DDEFAULT_DEBUG_PRINT_STATE=$(DEBUG_PRINTS)"
+libefi-test.a :
+ $(MAKE) -C gnu-efi ARCH=$(ARCH_GNUEFI) TOPDIR=$(TOPDIR)/gnu-efi \
+ -f $(TOPDIR)/gnu-efi/Makefile \
+ clean lib
+ mv gnu-efi/$(ARCH)/lib/libefi.a $@
+ $(MAKE) -C gnu-efi ARCH=$(ARCH_GNUEFI) TOPDIR=$(TOPDIR)/gnu-efi \
+ -f $(TOPDIR)/gnu-efi/Makefile \
+ clean
+
$(wildcard test-*.c) :: %.c : test-random.h
$(patsubst %.c,%,$(wildcard test-*.c)) :: | test-random.h
$(patsubst %.c,%.o,$(wildcard test-*.c)) : | test-random.h
@@ -36,19 +47,22 @@ test-random.h:
dd if=/dev/urandom bs=512 count=17 of=random.bin
xxd -i random.bin test-random.h
-test-sbat_FILES = csv.c
+test-sbat_FILES = csv.c lib/variables.c lib/guid.c
+test-sbat :: CFLAGS+=-DHAVE_GET_VARIABLE -DHAVE_GET_VARIABLE_ATTR -DHAVE_SHIM_LOCK_GUID
+
test-str_FILES = lib/string.c
tests := $(patsubst %.c,%,$(wildcard test-*.c))
+$(tests) :: test-% : | libefi-test.a
$(tests) :: test-% : test.c test-%.c $(test-%_FILES)
- $(CC) $(CFLAGS) -o $@ $^ $(wildcard $*.c) $(test-$*_FILES)
+ $(CC) $(CFLAGS) -o $@ $^ $(wildcard $*.c) $(test-$*_FILES) libefi-test.a
$(VALGRIND) ./$@
test : $(tests)
clean :
- @rm -vf test-random.h random.bin
+ @rm -vf test-random.h random.bin libefi-test.a
all : clean test
diff --git a/lib/variables.c b/lib/variables.c
index f606e24..ff61d0e 100644
--- a/lib/variables.c
+++ b/lib/variables.c
@@ -12,6 +12,10 @@
*/
#include "shim.h"
+extern EFI_SYSTEM_TABLE *ST;
+extern EFI_BOOT_SERVICES *BS;
+extern EFI_RUNTIME_SERVICES *RT;
+
EFI_STATUS
fill_esl(const EFI_SIGNATURE_DATA *first_sig, const size_t howmany,
const EFI_GUID *type, const UINT32 sig_size,
@@ -154,7 +158,7 @@ CreateTimeBasedPayload(IN OUT UINTN * DataSize, IN OUT UINT8 ** Data)
DescriptorData = (EFI_VARIABLE_AUTHENTICATION_2 *) (NewData);
ZeroMem(&Time, sizeof(EFI_TIME));
- efi_status = gRT->GetTime(&Time, NULL);
+ efi_status = RT->GetTime(&Time, NULL);
if (EFI_ERROR(efi_status)) {
FreePool(NewData);
return efi_status;
@@ -225,7 +229,7 @@ SetSecureVariable(const CHAR16 * const var, UINT8 *Data, UINTN len,
return efi_status;
}
- efi_status = gRT->SetVariable((CHAR16 *)var, &owner,
+ efi_status = RT->SetVariable((CHAR16 *)var, &owner,
EFI_VARIABLE_NON_VOLATILE |
EFI_VARIABLE_RUNTIME_ACCESS |
EFI_VARIABLE_BOOTSERVICE_ACCESS |
@@ -241,8 +245,8 @@ GetOSIndications(void)
UINTN DataSize = sizeof(indications);
EFI_STATUS efi_status;
- efi_status = gRT->GetVariable(L"OsIndicationsSupported", &GV_GUID,
- NULL, &DataSize, &indications);
+ efi_status = RT->GetVariable(L"OsIndicationsSupported", &GV_GUID,
+ NULL, &DataSize, &indications);
if (EFI_ERROR(efi_status))
return 0;
@@ -255,15 +259,15 @@ SETOSIndicationsAndReboot(UINT64 indications)
UINTN DataSize = sizeof(indications);
EFI_STATUS efi_status;
- efi_status = gRT->SetVariable(L"OsIndications", &GV_GUID,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_RUNTIME_ACCESS |
- EFI_VARIABLE_BOOTSERVICE_ACCESS,
- DataSize, &indications);
+ efi_status = RT->SetVariable(L"OsIndications", &GV_GUID,
+ EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_RUNTIME_ACCESS |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS,
+ DataSize, &indications);
if (EFI_ERROR(efi_status))
return efi_status;
- gRT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
+ RT->ResetSystem(EfiResetWarm, EFI_SUCCESS, 0, NULL);
/* does not return */
return EFI_SUCCESS;
@@ -280,7 +284,7 @@ get_variable_attr(const CHAR16 * const var, UINT8 **data, UINTN *len,
*len = 0;
- efi_status = gRT->GetVariable((CHAR16 *)var, &owner, NULL, len, NULL);
+ efi_status = RT->GetVariable((CHAR16 *)var, &owner, NULL, len, NULL);
if (efi_status != EFI_BUFFER_TOO_SMALL) {
if (!EFI_ERROR(efi_status)) /* this should never happen */
return EFI_PROTOCOL_ERROR;
@@ -298,7 +302,7 @@ get_variable_attr(const CHAR16 * const var, UINT8 **data, UINTN *len,
if (!*data)
return EFI_OUT_OF_RESOURCES;
- efi_status = gRT->GetVariable((CHAR16 *)var, &owner, attributes, len, *data);
+ efi_status = RT->GetVariable((CHAR16 *)var, &owner, attributes, len, *data);
if (EFI_ERROR(efi_status)) {
FreePool(*data);
*data = NULL;
@@ -341,7 +345,7 @@ EFI_STATUS
set_variable(CHAR16 *var, EFI_GUID owner, UINT32 attributes,
UINTN datasize, void *data)
{
- return gRT->SetVariable(var, &owner, attributes, datasize, data);
+ return RT->SetVariable(var, &owner, attributes, datasize, data);
}
EFI_STATUS
@@ -394,8 +398,8 @@ variable_is_setupmode(int default_return)
UINTN DataSize = sizeof(SetupMode);
EFI_STATUS efi_status;
- efi_status = gRT->GetVariable(L"SetupMode", &GV_GUID, NULL,
- &DataSize, &SetupMode);
+ efi_status = RT->GetVariable(L"SetupMode", &GV_GUID, NULL,
+ &DataSize, &SetupMode);
if (EFI_ERROR(efi_status))
return default_return;
@@ -411,8 +415,8 @@ variable_is_secureboot(void)
EFI_STATUS efi_status;
DataSize = sizeof(SecureBoot);
- efi_status = gRT->GetVariable(L"SecureBoot", &GV_GUID, NULL,
- &DataSize, &SecureBoot);
+ efi_status = RT->GetVariable(L"SecureBoot", &GV_GUID, NULL,
+ &DataSize, &SecureBoot);
if (EFI_ERROR(efi_status))
return 0;
@@ -445,10 +449,10 @@ variable_enroll_hash(const CHAR16 * const var, EFI_GUID owner,
efi_status = SetSecureVariable(var, sig, sizeof(sig), owner,
EFI_VARIABLE_APPEND_WRITE, 0);
else
- efi_status = gRT->SetVariable((CHAR16 *)var, &owner,
- EFI_VARIABLE_NON_VOLATILE |
- EFI_VARIABLE_BOOTSERVICE_ACCESS |
- EFI_VARIABLE_APPEND_WRITE,
- sizeof(sig), sig);
+ efi_status = RT->SetVariable((CHAR16 *)var, &owner,
+ EFI_VARIABLE_NON_VOLATILE |
+ EFI_VARIABLE_BOOTSERVICE_ACCESS |
+ EFI_VARIABLE_APPEND_WRITE,
+ sizeof(sig), sig);
return efi_status;
}
diff --git a/test.c b/test.c
index 9da5cf5..11e0c64 100644
--- a/test.c
+++ b/test.c
@@ -22,37 +22,6 @@ LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
return EFI_SUCCESS;
}
-#ifndef HAVE_STRCMP
-INTN
-StrCmp(CONST CHAR16 *s1, CONST CHAR16 *s2) {
- assert(s1 != NULL);
- assert(s2 != NULL);
-
- int i;
- for (i = 0; s1[i] && s2[i]; i++) {
- if (s1[i] != s2[i])
- return s2[i] - s1[i];
- }
- return 0;
-}
-#endif
-
-#ifndef HAVE_STRNCMP
-INTN
-StrnCmp(CONST CHAR16 *s1, CONST CHAR16 *s2, UINTN len) {
- assert(s1 != NULL);
- assert(s2 != NULL);
-
- UINTN i;
- for (i = 0; i < len && s1[i] && s2[i]; i++) {
- if (s1[i] != s2[i])
- return s2[i] - s1[i];
-
- }
- return 0;
-}
-#endif
-
#ifndef HAVE_GET_VARIABLE_ATTR
EFI_STATUS
get_variable_attr(const CHAR16 * const var, UINT8 **data, UINTN *len,
@@ -74,4 +43,10 @@ get_variable(const CHAR16 * const var, UINT8 **data, UINTN *len, EFI_GUID owner)
EFI_GUID SHIM_LOCK_GUID = {0x605dab50, 0xe046, 0x4300, {0xab, 0xb6, 0x3d, 0xd8, 0x10, 0xdd, 0x8b, 0x23 } };
#endif
+UINTN EFIAPI
+console_print(const CHAR16 *fmt, ...)
+{
+ return 0;
+}
+
// vim:fenc=utf-8:tw=75:noet
--
2.32.0
From 8600b635624c52f24459c82848ae5907992571c7 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 14:24:12 -0400
Subject: [PATCH 17/26] test.c: add some simple mock functions for
BS->{Allocate,Free}*
In some test cases, it may be useful to call libefi.a functions, such as
the device path parsing functions, which allocate pages via
BS->AllocatePool() or BS->AllocatePages.
This patch ads a simple mock implementation of those functions, as well
as the EFI_SYSTEM_TABLE, EFI_BOOT_SERVICES, and EFI_RUNTIME_SERVICES
variables *ST, *BS, and *RT (respectively), and initializes them before
the test cases run.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.h | 4 +++
test.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 78 insertions(+)
diff --git a/include/test.h b/include/test.h
index 811f92b..9a4fdb1 100644
--- a/include/test.h
+++ b/include/test.h
@@ -57,6 +57,10 @@ UINTN StrSize(IN CONST CHAR16 *s1);
VOID StrCat(IN CHAR16 *Dest, IN CONST CHAR16 *Src);
CHAR16 *DevicePathToStr(EFI_DEVICE_PATH *DevPath);
+extern EFI_SYSTEM_TABLE *ST;
+extern EFI_BOOT_SERVICES *BS;
+extern EFI_RUNTIME_SERVICES *RT;
+
#define CompareGuid(a, b) memcmp(a, b, sizeof(a))
extern int debug;
diff --git a/test.c b/test.c
index 11e0c64..81578c5 100644
--- a/test.c
+++ b/test.c
@@ -15,6 +15,80 @@ int debug = DEFAULT_DEBUG_PRINT_STATE;
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-function"
+static EFI_STATUS EFIAPI
+mock_efi_allocate_pages(EFI_ALLOCATE_TYPE type,
+ EFI_MEMORY_TYPE memory_type,
+ UINTN nmemb,
+ EFI_PHYSICAL_ADDRESS *memory)
+{
+ /*
+ * XXX so far this does not honor the type at all, and there's no
+ * tracking for memory_type either.
+ */
+ *memory = (EFI_PHYSICAL_ADDRESS)(uintptr_t)calloc(nmemb, 4096);
+ if ((void *)(uintptr_t)(*memory) == NULL)
+ return EFI_OUT_OF_RESOURCES;
+
+ return EFI_SUCCESS;
+}
+
+static EFI_STATUS EFIAPI
+mock_efi_free_pages(EFI_PHYSICAL_ADDRESS memory,
+ UINTN nmemb)
+{
+ free((void *)(uintptr_t)memory);
+
+ return EFI_SUCCESS;
+}
+
+static EFI_STATUS EFIAPI
+mock_efi_allocate_pool(EFI_MEMORY_TYPE pool_type,
+ UINTN size,
+ VOID **buf)
+{
+ *buf = calloc(1, size);
+ if (*buf == NULL)
+ return EFI_OUT_OF_RESOURCES;
+
+ return EFI_SUCCESS;
+}
+
+static EFI_STATUS EFIAPI
+mock_efi_free_pool(void *buf)
+{
+ free(buf);
+
+ return EFI_SUCCESS;
+}
+
+EFI_BOOT_SERVICES mock_bs = {
+ .RaiseTPL = NULL,
+ .RestoreTPL = NULL,
+
+ .AllocatePages = mock_efi_allocate_pages,
+ .FreePages = mock_efi_free_pages,
+ .AllocatePool = mock_efi_allocate_pool,
+ .FreePool = mock_efi_free_pool,
+};
+
+EFI_RUNTIME_SERVICES mock_rt = {
+ .Hdr = { 0, },
+ .GetVariable = NULL,
+};
+
+EFI_SYSTEM_TABLE mock_st = {
+ .Hdr = { 0, },
+ .BootServices = &mock_bs,
+ .RuntimeServices = &mock_rt,
+};
+
+void CONSTRUCTOR init_efi_system_table(void)
+{
+ ST = &mock_st;
+ BS = &mock_bs;
+ RT = &mock_rt;
+}
+
EFI_STATUS EFIAPI
LogError_(const char *file, int line, const char *func, const CHAR16 *fmt, ...)
{
--
2.32.0
From fea0a3fd026f1f4ec82a513269764b8349ffd4a5 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Fri, 2 Jul 2021 14:56:10 -0400
Subject: [PATCH 18/26] test.h: add assert_not_equal_*()
This test helper was conspicuously missing, so this patch just adds it
at the obvious place.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.h | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/include/test.h b/include/test.h
index 9a4fdb1..49a27a9 100644
--- a/include/test.h
+++ b/include/test.h
@@ -146,6 +146,19 @@ extern int debug;
rc_; \
})
+#define assert_not_equal_as_expr(a, b, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = (__typeof__(status))0; \
+ if (!((a) != (b))) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), (b), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(a != b)); \
+ rc_ = status; \
+ } \
+ rc_; \
+ })
+
#define assert_as_expr(cond, status, fmt, ...) \
({ \
__typeof__(status) rc_ = (__typeof__(status))0; \
@@ -201,6 +214,14 @@ extern int debug;
return rc_; \
})
+#define assert_not_equal_return(a, b, status, fmt, ...) \
+ ({ \
+ __typeof__(status) rc_ = assert_not_equal_as_expr( \
+ a, b, status, fmt, ##__VA_ARGS__); \
+ if (rc_ != 0) \
+ return rc_; \
+ })
+
#define assert_return(cond, status, fmt, ...) \
({ \
__typeof__(status) rc_ = \
@@ -231,6 +252,41 @@ extern int debug;
} \
})
+#define assert_not_equal_goto(a, b, label, fmt, ...) \
+ ({ \
+ if (!((a) != (b))) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), (b), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(a != b)); \
+ goto label; \
+ } \
+ })
+
+#define assert_true_goto(a, label, fmt, ...) \
+ ({ \
+ if (!(a)) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(!(a))); \
+ goto label; \
+ } \
+ })
+#define assert_nonzero_goto(a, ...) assert_true_goto(a, ##__VA_ARGS__)
+
+#define assert_false_goto(a, label, fmt, ...) \
+ ({ \
+ if (a) { \
+ printf("%s:%d:" fmt, __func__, __LINE__, (a), \
+ ##__VA_ARGS__); \
+ printf("%s:%d:Assertion `%s' failed.\n", __func__, \
+ __LINE__, __stringify(a)); \
+ goto label; \
+ } \
+ })
+#define assert_zero_goto(a, ...) assert_false_goto(a, ##__VA_ARGS__)
+
#define assert_negative_goto(a, label, fmt, ...) \
({ \
int rc_ = assert_negative_as_expr(a, -1, fmt, ##__VA_ARGS__); \
--
2.32.0
From cedfa69e6afe381a074d22bdf1e6f2d9e6731038 Mon Sep 17 00:00:00 2001
From: Peter Jones <pjones@redhat.com>
Date: Wed, 14 Jul 2021 16:36:44 -0400
Subject: [PATCH 19/26] test: Add a basic traceback printer
Some tests have some complex flows, and it's useful to be able to see
the call path when there's a failure.
This patch adds a very simple traceback printer, along with changing the
test build arguments to include more debug information.
The result you get from this traceback printer just gives you a function
name and the index into its .txt content, so to use it for more than
"which function calls which", you'll need to use eu-addr2line with the
output.
Signed-off-by: Peter Jones <pjones@redhat.com>
---
include/test.h | 2 ++
include/test.mk | 21 ++++++++++++++++-----
test.c | 26 ++++++++++++++++++++++++++
3 files changed, 44 insertions(+), 5 deletions(-)
diff --git a/include/test.h b/include/test.h
index 49a27a9..fedeb78 100644
--- a/include/test.h
+++ b/include/test.h
@@ -69,6 +69,8 @@ extern int debug;
#define dprint(fmt, ...) {( if (debug) printf("%s:%d:" fmt, __func__, __LINE__, ##__VA_ARGS__); })
#endif
+void print_traceback(int skip);
+
#define eassert(cond, fmt, ...) \
({ \
if (!(cond)) { \
diff --git a/include/test.mk b/include/test.mk
index c66b46d..23bf805 100644
--- a/include/test.mk
+++ b/include/test.mk
@@ -14,14 +14,25 @@ CFLAGS = -O2 -ggdb -std=gnu11 \
-isystem $(TOPDIR)/include/system \
$(EFI_INCLUDES) \
-Iinclude -iquote . \
- -fshort-wchar -flto -fno-builtin \
- -Wall \
- -Wextra \
+ -isystem /usr/include \
+ -isystem $(shell $(CC) $(ARCH_CFLAGS) -print-file-name=include) \
+ $(ARCH_CFLAGS) \
+ -fshort-wchar \
+ -flto \
+ -fno-builtin \
+ -rdynamic \
+ -fno-inline \
+ -fno-eliminate-unused-debug-types \
+ -fno-eliminate-unused-debug-symbols \
+ -gpubnames \
+ -grecord-gcc-switches \
+ $(DEFAULT_WARNFLAGS) \
-Wsign-compare \
-Wno-deprecated-declarations \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-variable \
-Wno-pointer-sign \
- -Wno-unused \
- -Werror \
+ $(DEFAULT_WERRFLAGS) \
-Werror=nonnull \
$(shell $(CC) -Werror=nonnull-compare -E -x c /dev/null >/dev/null 2>&1 && echo -Werror=nonnull-compare) \
$(ARCH_DEFINES) \
diff --git a/test.c b/test.c
index 81578c5..d9902eb 100644
--- a/test.c
+++ b/test.c
@@ -9,9 +9,35 @@
#endif
#include "shim.h"
+#include <execinfo.h>
+#include <stdio.h>
+#include <string.h>
+
+#define BT_BUF_SIZE (4096/sizeof(void *))
+
+static void *frames[BT_BUF_SIZE] = { 0, };
+
UINT8 in_protocol = 0;
int debug = DEFAULT_DEBUG_PRINT_STATE;
+void
+print_traceback(int skip)
+{
+ int nptrs;
+ char **strings;
+
+ nptrs = backtrace(frames, BT_BUF_SIZE);
+ if (nptrs < skip)
+ return;
+
+ strings = backtrace_symbols(frames, nptrs);
+ for (int i = skip; strings != NULL && i < nptrs; i++) {
+ printf("%p %s\n", (void *)frames[i], strings[i]);
+ }
+ if (strings)
+ free(strings);
+}
+
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wunused-function"
--
2.32.0
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment