summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-13 15:41:34 +0100
committerAmlal El Mahrouss <amlalelmahrouss@icloud.com>2024-02-13 15:41:34 +0100
commita9ac78b47dd040e04afc4990dace2472df2302e4 (patch)
tree42ec5a5719ec3a307218b6ef0b13d99e448d914e
parenta4af4dc720a0ba8d4c3a23e05825989329a48a2f (diff)
HCR-15: fix GApplication class, add static on Shared() function.
Signed-off-by: Amlal El Mahrouss <amlalelmahrouss@icloud.com>
-rw-r--r--Private/KernelKit/MSDOS.hpp13
-rw-r--r--Private/NewBoot/Source/RuntimeMain.cxx20
-rw-r--r--Public/Kits/GKit/Core.hpp8
3 files changed, 23 insertions, 18 deletions
diff --git a/Private/KernelKit/MSDOS.hpp b/Private/KernelKit/MSDOS.hpp
index 4f098249..2276f3cb 100644
--- a/Private/KernelKit/MSDOS.hpp
+++ b/Private/KernelKit/MSDOS.hpp
@@ -16,6 +16,8 @@
#include <NewKit/Defines.hpp>
+#include "PE.hpp"
+
typedef HCore::UInt32 DosWord;
typedef HCore::Long DosLong;
@@ -41,4 +43,15 @@ typedef struct _DosHeader {
DosLong eLfanew;
} DosHeader, *DosHeaderPtr;
+namespace HCore {
+/// @brief Find the PE header inside the the blob.
+inline auto rt_find_exec_header(DosHeaderPtr ptrDos) -> VoidPtr {
+ if (!ptrDos) return nullptr;
+ if (ptrDos->eMagic[0] != kMagMz0) return nullptr;
+ if (ptrDos->eMagic[0] != kMagMz1) return nullptr;
+
+ return (VoidPtr)(&ptrDos->eLfanew + 1);
+}
+} // namespace HCore
+
#endif /* ifndef __MSDOS_EXEC__ */
diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx
index a520b980..a6e4015c 100644
--- a/Private/NewBoot/Source/RuntimeMain.cxx
+++ b/Private/NewBoot/Source/RuntimeMain.cxx
@@ -15,15 +15,7 @@
#include <KernelKit/PE.hpp>
#include <NewKit/Ref.hpp>
-namespace Detail {
-constexpr Int32 kBufferReadSz = 2048;
-
-auto FindPEHeader(DosHeaderPtr ptrDos) -> ExecHeaderPtr {
- if (!ptrDos) return nullptr;
-
- return (ExecHeaderPtr)(&ptrDos->eLfanew + 1);
-}
-} // namespace Detail
+#define kBufferReadSz 2048
EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
EfiSystemTable* SystemTable) {
@@ -54,17 +46,17 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle,
BFileReader img(L"HCOREKRNL.EXE", ImageHandle);
- img.Size() = Detail::kBufferReadSz;
+ img.Size() = kBufferReadSz;
img.Read();
if (img.Error() == BFileReader::kOperationOkay) {
BlobType blob = (BlobType)img.Blob();
- DosHeaderPtr ptrDos = reinterpret_cast<DosHeaderPtr>(blob);
- ExecHeaderPtr ptrHdr = Detail::FindPEHeader(ptrDos);
+ ExecHeaderPtr ptrHdr = reinterpret_cast<ExecHeaderPtr>(
+ HCore::rt_find_exec_header(reinterpret_cast<DosHeaderPtr>(blob)));
- if (ptrDos->eMagic[0] == kMagMz0 && ptrDos->eMagic[1] == kMagMz1 &&
- ptrHdr->mMachine == EFI::Platform() && ptrHdr->mMagic == kPeMagic) {
+ if (ptrHdr && ptrHdr->mMachine == EFI::Platform() &&
+ ptrHdr->mMagic == kPeMagic) {
if (ptrHdr->mNumberOfSections > 1) {
UInt64 MapKey = 0;
diff --git a/Public/Kits/GKit/Core.hpp b/Public/Kits/GKit/Core.hpp
index 00ae524e..39eb341b 100644
--- a/Public/Kits/GKit/Core.hpp
+++ b/Public/Kits/GKit/Core.hpp
@@ -132,12 +132,12 @@ class G_API GApplication final {
GDocument* Document() noexcept { return nullptr; }
- GApplication* Shared() noexcept {
- STATIC GApplication* gApp = nullptr;
+ static GApplication* Shared() noexcept {
+ STATIC GApplication* kApp = nullptr;
- if (!gApp) gApp = new GApplication();
+ if (!kApp) kApp = new GApplication();
- return gApp;
+ return kApp;
}
};