From 297af25c93284d5e3cfd89239dee4fd48a1e8777 Mon Sep 17 00:00:00 2001 From: Satoshi Tanda Date: Thu, 5 Mar 2020 07:21:47 -0800 Subject: [PATCH] Workaround page fault with ASSERT() --- Sources/MemoryAccess.c | 1 + Sources/Platform/EFI/EfiCommon.h | 23 ++++++++++++++++++-- Sources/Platform/EFI/EfiHostInitialization.c | 1 + Sources/Utils.c | 1 + 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Sources/MemoryAccess.c b/Sources/MemoryAccess.c index 0aaa7e9..506722e 100644 --- a/Sources/MemoryAccess.c +++ b/Sources/MemoryAccess.c @@ -11,6 +11,7 @@ #include "HostUtils.h" #include "Platform.h" #include "MemoryManager.h" +#include "Logger.h" /*! @brief Split a 2MB EPT PDE to 512 EPT PTEs. diff --git a/Sources/Platform/EFI/EfiCommon.h b/Sources/Platform/EFI/EfiCommon.h index f6ee8e5..31e9861 100644 --- a/Sources/Platform/EFI/EfiCommon.h +++ b/Sources/Platform/EFI/EfiCommon.h @@ -26,12 +26,31 @@ #define MV_DEBUG_BREAK() #define MV_SECTION_INIT #define MV_SECTION_PAGED -#define MV_ASSERT(x) ASSERT(x) + +/*! + @brief Custom ASSERT. + + @details This is a workaround of that the EFI standard ASSERT can cause page + fault (null pointer access) when it fires in the host code. The author + has not been able to find out the root cause and a fix. + */ #if !defined(MDEPKG_NDEBUG) -#define MV_VERIFY(x) ASSERT(x) +#define MV_ASSERT(x) \ + if (!(x)) \ + { \ + LOG_ERROR("ASSERT %a(%d): %a", __FILE__, __LINE__, #x); \ + MV_PANIC(); \ + } (VOID*)NULL +#else +#define MV_ASSERT(x) +#endif + +#if !defined(MDEPKG_NDEBUG) +#define MV_VERIFY(x) MV_ASSERT(x) #else #define MV_VERIFY(x) (x) #endif + #define MV_MAX(x, y) MAX((x), (y)) #define MV_MIN(x, y) MIN((x), (y)) diff --git a/Sources/Platform/EFI/EfiHostInitialization.c b/Sources/Platform/EFI/EfiHostInitialization.c index cd7ef9a..3d6e202 100644 --- a/Sources/Platform/EFI/EfiHostInitialization.c +++ b/Sources/Platform/EFI/EfiHostInitialization.c @@ -34,6 +34,7 @@ #include "EfiAsm.h" #include "EfiPlatform.h" #include "../../Utils.h" +#include "EfiLogger.h" // // The format of the IDT. diff --git a/Sources/Utils.c b/Sources/Utils.c index 6fc637c..90cfdd9 100644 --- a/Sources/Utils.c +++ b/Sources/Utils.c @@ -10,6 +10,7 @@ */ #include "Utils.h" #include "Asm.h" +#include "Logger.h" _Use_decl_annotations_ UINT64