diff options
| -rw-r--r-- | Private/EFIKit/Api.hxx | 8 | ||||
| -rw-r--r-- | Private/EFIKit/EFI.hxx | 2 | ||||
| -rw-r--r-- | Private/NewBoot/BootKit/BootKit.hxx | 4 | ||||
| -rw-r--r-- | Private/NewBoot/Source/RuntimeMain.cxx | 25 |
4 files changed, 27 insertions, 12 deletions
diff --git a/Private/EFIKit/Api.hxx b/Private/EFIKit/Api.hxx index 4a23c747..b39c4991 100644 --- a/Private/EFIKit/Api.hxx +++ b/Private/EFIKit/Api.hxx @@ -31,7 +31,13 @@ inline void ExitBootServices(UInt64 MapKey, EfiHandlePtr ImageHandle) noexcept { if (!ST) return; ST->ConOut->OutputString(ST->ConOut, L"HCoreLdr: Exit BootServices...\r\n"); - ST->BootServices->ExitBootServices(ImageHandle, MapKey); + + /// The MapKey may be invalid. + /// If so, then hang the computer. + if (ST->BootServices->ExitBootServices(ImageHandle, MapKey) != kEfiOk) { + ST->ConOut->OutputString(ST->ConOut, L"HCoreLdr: Hanging...\r\n"); + EFI::Stop(); + } } enum { diff --git a/Private/EFIKit/EFI.hxx b/Private/EFIKit/EFI.hxx index 8e1b46c7..30899ca9 100644 --- a/Private/EFIKit/EFI.hxx +++ b/Private/EFIKit/EFI.hxx @@ -679,7 +679,7 @@ typedef struct EfiFileProtocol { struct EfiIOToken *Token); EfiStatusType(EFI_API *FlushEx)(EfiFileProtocol *This, struct EfiIOToken *Token); -} EfiFileProtocol; +} EfiFileProtocol, *EfiFileProtocolPtr; typedef UInt64 EfiCursorType; diff --git a/Private/NewBoot/BootKit/BootKit.hxx b/Private/NewBoot/BootKit/BootKit.hxx index 68d91deb..2eaea9d1 100644 --- a/Private/NewBoot/BootKit/BootKit.hxx +++ b/Private/NewBoot/BootKit/BootKit.hxx @@ -77,7 +77,7 @@ class BFileReader final { Int32 &Error() { return mErrorCode; } VoidPtr Blob() { return mBlob; } - EfiFileProtocol *File() { return mFile; } + EfiFileProtocolPtr File() { return mFile; } UInt64 &Size() { return mSizeFile; } public: @@ -93,6 +93,8 @@ class BFileReader final { UInt64 mSizeFile{0}; }; +typedef UInt8 *BlobType; + #define kMaxReadSize (320) /***********************************************************************************/ diff --git a/Private/NewBoot/Source/RuntimeMain.cxx b/Private/NewBoot/Source/RuntimeMain.cxx index ff6eb730..aeaf013a 100644 --- a/Private/NewBoot/Source/RuntimeMain.cxx +++ b/Private/NewBoot/Source/RuntimeMain.cxx @@ -54,29 +54,36 @@ EFI_EXTERN_C EFI_API Int EfiMain(EfiHandlePtr ImageHandle, img.ReadAll(); if (img.Error() == BFileReader::kOperationOkay) { - UInt8* blob = (UInt8*)img.Blob(); + BlobType blob = (BlobType)img.Blob(); DosHeaderPtr ptrDos = reinterpret_cast<DosHeaderPtr>(blob); ExecHeaderPtr ptrHdr = Detail::FindPEHeader(ptrDos); if (ptrDos->eMagic[0] == kMagMz0 && ptrDos->eMagic[1] == kMagMz1 && ptrHdr->mMachine == EFI::Platform() && ptrHdr->mMagic == kPeMagic) { - UInt64 MapKey = 0; + if (ptrHdr->mNumberOfSections > 1) { + UInt64 MapKey = 0; - writer.WriteString(L"HCoreLdr: Booting...").WriteString(L"\r\n"); + writer.WriteString(L"HCoreLdr: Booting...").WriteString(L"\r\n"); - EFI::ExitBootServices(MapKey, ImageHandle); + EFI::ExitBootServices(MapKey, ImageHandle); - // Launch PE app. + // Launch PE app. - EFI::Stop(); + EFI::Stop(); - return kEfiOk; + return kEfiOk; + } else { + writer.WriteString( + L"HCoreLdr: Error! HCOREKRNL.EXE is missing critical " + L"components!\r\n"); + } } + } else { + writer.WriteString( + L"HCoreLdr: Error! HCOREKRNL.EXE is not an executable!\r\n"); } - writer.WriteString(L"HCoreLdr: Error! HCOREKRNL.EXE missing or invalid!\r\n"); - EFI::Stop(); return kEfiFail; |
