Update BaseLib.h with macro BASE_LIST_FOR_EACH.

Introduce class apd (automatic pointer destruction)
Introduce MemoryTracker
Weak symbols in MemoryAllocationLib to be able to redefine them (see
MemoryTracker).
Embed LegacyOS instead of a pointer.
Fixed a lot of memory leaks.
This commit is contained in:
jief 2023-11-18 11:04:54 +01:00
parent bdb7a95d94
commit 32fbf76326
64 changed files with 1453 additions and 475 deletions

View File

@ -7,6 +7,12 @@
objects = {
/* Begin PBXBuildFile section */
9A0064A52B08298E0016E3EB /* MemoryTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0064A32B08298D0016E3EB /* MemoryTracker.cpp */; };
9A0064A62B08298E0016E3EB /* MemoryTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0064A32B08298D0016E3EB /* MemoryTracker.cpp */; };
9A0064A72B08298E0016E3EB /* MemoryTracker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9A0064A32B08298D0016E3EB /* MemoryTracker.cpp */; };
9A0064A82B08298E0016E3EB /* MemoryTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0064A42B08298D0016E3EB /* MemoryTracker.h */; };
9A0064A92B08298E0016E3EB /* MemoryTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0064A42B08298D0016E3EB /* MemoryTracker.h */; };
9A0064AA2B08298E0016E3EB /* MemoryTracker.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0064A42B08298D0016E3EB /* MemoryTracker.h */; };
9A27545B263801930095D456 /* Self.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A275455263801920095D456 /* Self.h */; };
9A27545C263801930095D456 /* Self.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A275455263801920095D456 /* Self.h */; };
9A27545D263801930095D456 /* Self.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A275455263801920095D456 /* Self.h */; };
@ -1097,6 +1103,8 @@
/* End PBXBuildFile section */
/* Begin PBXFileReference section */
9A0064A32B08298D0016E3EB /* MemoryTracker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MemoryTracker.cpp; sourceTree = "<group>"; };
9A0064A42B08298D0016E3EB /* MemoryTracker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryTracker.h; sourceTree = "<group>"; };
9A275455263801920095D456 /* Self.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Self.h; sourceTree = "<group>"; };
9A275456263801920095D456 /* SelfOem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelfOem.h; sourceTree = "<group>"; };
9A275457263801930095D456 /* SelfOem.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelfOem.cpp; sourceTree = "<group>"; };
@ -1686,6 +1694,8 @@
9A8787D126186896000B9362 /* cpp_lib */ = {
isa = PBXGroup;
children = (
9A0064A32B08298D0016E3EB /* MemoryTracker.cpp */,
9A0064A42B08298D0016E3EB /* MemoryTracker.h */,
9AF4D932263004E200487D15 /* XmlLiteArrayTypes.cpp */,
9AF4D930263004E200487D15 /* XmlLiteArrayTypes.h */,
9AF4D92B263004E100487D15 /* XmlLiteCompositeTypes.cpp */,
@ -2209,6 +2219,7 @@
9A878B1926186897000B9362 /* cpu.h in Headers */,
9A878CA526186898000B9362 /* XArray.h in Headers */,
9A878C3026186898000B9362 /* MSKEK.h in Headers */,
9A0064A82B08298E0016E3EB /* MemoryTracker.h in Headers */,
9A878A6826186897000B9362 /* AmlGenerator.h in Headers */,
9A878B4326186897000B9362 /* Volumes.h in Headers */,
9A878C7226186898000B9362 /* screen.h in Headers */,
@ -2484,6 +2495,7 @@
9A2754B3263802230095D456 /* ConfigPlistAbstract.h in Headers */,
9A878BC226186898000B9362 /* XIcon.h in Headers */,
9A878C3126186898000B9362 /* MSKEK.h in Headers */,
9A0064A92B08298E0016E3EB /* MemoryTracker.h in Headers */,
9A878C4C26186898000B9362 /* menu_globals.h in Headers */,
9A878A8D26186897000B9362 /* Settings.h in Headers */,
9A8789D326186897000B9362 /* VolumeTypes.h in Headers */,
@ -2691,6 +2703,7 @@
9A2754B4263802230095D456 /* ConfigPlistAbstract.h in Headers */,
9A878BC326186898000B9362 /* XIcon.h in Headers */,
9A878C3226186898000B9362 /* MSKEK.h in Headers */,
9A0064AA2B08298E0016E3EB /* MemoryTracker.h in Headers */,
9A878C4D26186898000B9362 /* menu_globals.h in Headers */,
9A878A8E26186897000B9362 /* Settings.h in Headers */,
9A8789D426186897000B9362 /* VolumeTypes.h in Headers */,
@ -2920,6 +2933,7 @@
9ACD7ACB299304690095F00A /* load_icns.c in Sources */,
9A878B6D26186897000B9362 /* egemb_icons_dark.cpp in Sources */,
9A878B2226186897000B9362 /* VersionString.cpp in Sources */,
9A0064A52B08298E0016E3EB /* MemoryTracker.cpp in Sources */,
9A878B0426186897000B9362 /* MemoryOperation.c in Sources */,
9ACBC043264484A5001EB94B /* config-test.cpp in Sources */,
9A878A2326186897000B9362 /* xml.cpp in Sources */,
@ -3037,6 +3051,7 @@
9A878A5D26186897000B9362 /* kext_patcher.cpp in Sources */,
9A87895826186897000B9362 /* LoadOptions_test.cpp in Sources */,
9A878A1B26186897000B9362 /* plist.cpp in Sources */,
9A0064A62B08298E0016E3EB /* MemoryTracker.cpp in Sources */,
9A8789FA26186897000B9362 /* TagFloat.cpp in Sources */,
9A87893426186897000B9362 /* globals_ctor.cpp in Sources */,
9A878ABD26186897000B9362 /* Nvram.cpp in Sources */,
@ -3203,6 +3218,7 @@
9A878A5E26186897000B9362 /* kext_patcher.cpp in Sources */,
9A87895926186897000B9362 /* LoadOptions_test.cpp in Sources */,
9A878A1C26186897000B9362 /* plist.cpp in Sources */,
9A0064A72B08298E0016E3EB /* MemoryTracker.cpp in Sources */,
9A8789FB26186897000B9362 /* TagFloat.cpp in Sources */,
9A87893526186897000B9362 /* globals_ctor.cpp in Sources */,
9A878ABE26186897000B9362 /* Nvram.cpp in Sources */,
@ -3404,6 +3420,7 @@
DISABLE_PRINTLIB,
OC_TARGET_NOOPT,
DISABLE_SECURE_BOOT,
IS_UEFI_MODULE,
);
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_MISSING_FIELD_INITIALIZERS = YES;

View File

@ -10,6 +10,7 @@
XBool ReadAllKeyStrokes(void);
void PauseForKey();
void PauseForKey(const XString8& msg);
//void DebugPause(void);

View File

@ -38,6 +38,7 @@
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "../cpp_lib/MemoryTracker.h"
#include "../include/OSTypes.h"
#include "Nvram.h"
#include "platformdata.h"
@ -498,7 +499,9 @@ SetVariablesForOSX(LOADER_ENTRY *Entry)
void
AddSMCkey(SMC_KEY Key, SMC_DATA_SIZE Size, SMC_KEY_TYPE Type, SMC_DATA *Data)
{
if (gAppleSmc && (gAppleSmc->Signature == NON_APPLE_SMC_SIGNATURE)) {
if (gAppleSmc && (gAppleSmc->Signature == NON_APPLE_SMC_SIGNATURE))
{
MemoryStopRecord msr; // Do not record allocation made by SmcAddKey
gAppleSmc->SmcAddKey(gAppleSmc, Key, Size, Type, 0xC0);
gAppleSmc->SmcWriteValue(gAppleSmc, Key, Size, Data);
}

View File

@ -42,14 +42,11 @@ EFI_STATUS
InitializeEdidOverride ()
{
EFI_STATUS Status;
EFI_EDID_OVERRIDE_PROTOCOL *EdidOverride;
EdidOverride = (__typeof__(EdidOverride))AllocateCopyPool(sizeof(EFI_EDID_OVERRIDE_PROTOCOL), &gEdidOverride);
Status = gBS->InstallMultipleProtocolInterfaces (
&gImageHandle,
&gEfiEdidOverrideProtocolGuid,
EdidOverride,
&gEdidOverride,
NULL
);
if (EFI_ERROR(Status)) {

View File

@ -452,7 +452,7 @@ GetSleepImageLocation(IN REFIT_VOLUME *Volume, REFIT_VOLUME **SleepImageVolume,
}
}
}
PrefDict->FreeTag();
PrefDict->ReleaseTag();
}
}

View File

@ -59,7 +59,7 @@ XStringW GetBundleVersion(const XStringW& pathUnderSelf)
if (InfoPlistPtr) {
FreePool(InfoPlistPtr);
}
if ( InfoPlistDict ) InfoPlistDict->FreeTag();
if ( InfoPlistDict ) InfoPlistDict->ReleaseTag();
return CFBundleVersion;
}

View File

@ -6,6 +6,7 @@
*/
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "../cpp_lib/MemoryTracker.h"
#include "../include/OSTypes.h"
#include "Nvram.h"
#include "BootOptions.h"
@ -34,7 +35,7 @@ TagDict* gNvramDict;
//
// always contains original efi-boot-device-data
EFI_DEVICE_PATH *gEfiBootDeviceData;
apd<EFI_DEVICE_PATH*> gEfiBootDeviceData;
// if gEfiBootDeviceData starts with MemoryMapped node, then gBootCampHD = "BootCampHD" var, otherwise == NULL
EFI_DEVICE_PATH *gBootCampHD;
@ -536,8 +537,12 @@ GetSmcKeys (XBool WriteToSMC)
DBG("%02hhX ", *((UINT8*)Data + Index));
}
DBG("\n");
if (gAppleSmc && WriteToSMC) {
if (gAppleSmc && WriteToSMC)
{
{
MemoryStopRecord msr;
Status = gAppleSmc->SmcAddKey(gAppleSmc, KeyFromName(Name), (SMC_DATA_SIZE)DataSize, TypeFromName(Name), 0xC0);
}
if (!EFI_ERROR(Status)) {
Status = gAppleSmc->SmcWriteValue(gAppleSmc, KeyFromName(Name), (SMC_DATA_SIZE)DataSize, Data);
// DBG("Write to AppleSMC status=%s\n", efiStrError(Status));
@ -552,6 +557,9 @@ GetSmcKeys (XBool WriteToSMC)
NKey[3] = NumKey & 0xFF;
NKey[2] = (NumKey >> 8) & 0xFF; //key, size, type, attr
DBG("Registered %lld SMC keys\n", NumKey);
{
MemoryStopRecord msr;
Status = gAppleSmc->SmcAddKey(gAppleSmc, FourCharKey("#KEY"), 4, SmcKeyTypeUint32, 0xC0);
if (!EFI_ERROR(Status)) {
Status = gAppleSmc->SmcWriteValue(gAppleSmc, FourCharKey("#KEY"), 4, (SMC_DATA *)&NKey);
@ -569,6 +577,7 @@ GetSmcKeys (XBool WriteToSMC)
Status = gAppleSmc->SmcWriteValue(gAppleSmc, FourCharKey("RMde"), 1, (SMC_DATA *)&Mode);
}
}
}
FreePool(Name);
}
#if CHECK_SMC
@ -791,14 +800,13 @@ GetEfiBootDeviceFromNvram ()
return EFI_SUCCESS;
}
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData))GetNvramVariable(L"efi-boot-next-data", gEfiAppleBootGuid, NULL, &Size);
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData.get()))GetNvramVariable(L"efi-boot-next-data", gEfiAppleBootGuid, NULL, &Size);
if (gEfiBootDeviceData != NULL) {
DBG("Got efi-boot-next-data size=%lld\n", Size);
if (IsDevicePathValid(gEfiBootDeviceData, Size)) {
// DBG(" - efi-boot-next-data: %ls\n", FileDevicePathToStr (gEfiBootDeviceData));
} else {
DBG(" - device path for efi-boot-next-data is invalid\n");
FreePool(gEfiBootDeviceData);
gEfiBootDeviceData = NULL;
}
}
@ -808,9 +816,9 @@ GetEfiBootDeviceFromNvram ()
EFI_STATUS Status;
Status = GetVariable2 (L"aptiofixflag", gEfiAppleBootGuid, &Value, &Size2);
if (EFI_ERROR(Status)) {
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData))GetNvramVariable(L"efi-boot-device-data", gEfiAppleBootGuid, NULL, &Size);
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData.get()))GetNvramVariable(L"efi-boot-device-data", gEfiAppleBootGuid, NULL, &Size);
} else {
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData))GetNvramVariable(L"specialbootdevice", gEfiAppleBootGuid, NULL, &Size);
gEfiBootDeviceData = (__typeof__(gEfiBootDeviceData.get()))GetNvramVariable(L"specialbootdevice", gEfiAppleBootGuid, NULL, &Size);
}
if (gEfiBootDeviceData != NULL) {
@ -1394,7 +1402,7 @@ FindStartupDiskVolume (
//DBG(" checking legacy entry %d. %ls\n", Index, LegacyEntry.Title);
//DBG(" %ls\n", DevicePathToStr (Volume->DevicePath));
//DBG(" OSType = %d\n", Volume->OSType);
if (Volume->LegacyOS->Type == OSTYPE_WIN) {
if (Volume->LegacyOS.Type == OSTYPE_WIN) {
// that's the one - legacy win partition
DBG(" - found legacy entry %lld. '%ls', Volume '%ls'\n", Index, LegacyEntry.Title.s(), Volume->VolName.wc_str());
return Index;

View File

@ -15,7 +15,7 @@
extern EFI_GUID gEfiBootDeviceGuid;
extern EFI_DEVICE_PATH_PROTOCOL *gEfiBootDeviceData;
extern apd<EFI_DEVICE_PATH_PROTOCOL*> gEfiBootDeviceData;

View File

@ -142,7 +142,7 @@ UINT32 GetCrc32(UINT8 *Buffer, UINTN Size)
return x;
}
#ifndef UNIT_TESTS_MACOS
//#ifndef UNIT_TESTS_MACOS
extern "C" {
#include <Library/OcMemoryLib.h>
@ -157,7 +157,7 @@ void displayFreeMemory(const XString8& prefix)
DebugLog(1, "--> %s: Firmware has %llu free pages (%llu in lower 4 GB)\n", prefix.c_str(), TotalMemory, LowMemory);
}
#endif
//#endif
XBool haveError = false;

View File

@ -130,10 +130,10 @@ extern XBool haveError;
#endif // __cplusplus
#ifndef UNIT_TESTS_MACOS
//#ifndef UNIT_TESTS_MACOS
extern "C" {
void displayFreeMemory(const XString8& prefix);
}
#endif
//#endif
#endif // _UTILS_H_

View File

@ -102,7 +102,7 @@ GetRootUUID (IN REFIT_VOLUME *Volume)
}
}
Dict->FreeTag();
Dict->ReleaseTag();
FreePool(PlistBuffer);
}

View File

@ -10,6 +10,7 @@
#include "../include/VolumeTypes.h"
#include <Efi.h>
#include "../cpp_foundation/apd.h"
#include "../cpp_foundation/XString.h"
#include "../libeg/libeg.h"
#include "../Platform/guid.h"
@ -17,14 +18,9 @@
class LEGACY_OS
{
public:
UINT8 Type;
XStringW IconName;
XStringW Name;
LEGACY_OS() : Type(0), IconName(), Name() {}
LEGACY_OS(const LEGACY_OS& other) = delete; // Can be defined if needed
const LEGACY_OS& operator = ( const LEGACY_OS & ) = delete; // Can be defined if needed
~LEGACY_OS() {}
UINT8 Type = 0;
XStringW IconName = XStringW();
XStringW Name = XStringW();
};
class REFIT_VOLUME {
@ -36,7 +32,7 @@ public:
XStringW VolName = XStringW(); // comes from EfiLibFileSystemInfo, EfiLibFileSystemVolumeLabelInfo, "EFI" if gEfiPartTypeSystemPartGuid or "Unknown HD"
XStringW VolLabel = XStringW(); // comes from \\.VolumeLabel.txt, or empty.
UINT8 DiskKind = 0;
LEGACY_OS *LegacyOS = 0;
LEGACY_OS LegacyOS = LEGACY_OS();
XBool Hidden = false;
UINT8 BootType = 0;
XBool IsAppleLegacy = false;
@ -46,7 +42,7 @@ public:
EFI_BLOCK_IO *BlockIO = 0;
UINT64 BlockIOOffset = 0;
EFI_BLOCK_IO *WholeDiskBlockIO = 0;
EFI_DEVICE_PATH *WholeDiskDevicePath = 0;
apd<EFI_DEVICE_PATH*> WholeDiskDevicePath = NULL;
EFI_HANDLE WholeDiskDeviceHandle = 0;
MBR_PARTITION_INFO *MbrPartitionTable = 0;
UINT32 DriveCRC32 = 0;

View File

@ -44,7 +44,9 @@
#include "TagArray.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagArray> TagArray::tagsFree;
#endif
XBool TagArray::operator == (const TagStruct& other) const
{
@ -79,26 +81,28 @@ XBool TagArray::debugIsEqual(const TagStruct& other, const XString8& label) cons
}
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagArray* TagArray::getEmptyTag()
{
TagArray* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagArray;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagArray::FreeTag()
void TagArray::ReleaseTag()
{
//while ( tagIdx < _dictOrArrayContent.notEmpty() ) {
// _dictOrArrayContent[0].FreeTag();
@ -107,10 +111,18 @@ void TagArray::FreeTag()
// this loop is better because removing objects from the end don't do any memory copying.
for (size_t tagIdx = _arrayContent.size() ; tagIdx > 0 ; ) {
tagIdx--;
_arrayContent[tagIdx].FreeTag();
#ifdef TagStruct_USE_CACHE
_arrayContent[tagIdx].ReleaseTag();
_arrayContent.RemoveWithoutFreeingAtIndex(tagIdx);
#else
_arrayContent.RemoveAtIndex(tagIdx);
#endif
}
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
const TagStruct* TagArray::elementAt(size_t idx) const

View File

@ -12,10 +12,12 @@
class TagArray : public TagStruct
{
static XObjArray<TagArray> tagsFree;
XObjArray<TagStruct> _arrayContent;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagArray> tagsFree;
#endif
TagArray() : _arrayContent() {}
TagArray(const TagArray& other) = delete; // Can be defined if needed
@ -31,7 +33,7 @@ public:
virtual XBool isArray() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Array"_XS8; }
static TagArray* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -44,31 +44,39 @@
#include "TagBool.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagBool> TagBool::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagBool* TagBool::getEmptyTag()
{
TagBool* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagBool;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagBool::FreeTag()
void TagBool::ReleaseTag()
{
value = false;
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagBool::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagBool : public TagStruct
{
static XObjArray<TagBool> tagsFree;
XBool value;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagBool> tagsFree;
#endif
TagBool() : value(false) {}
TagBool(const TagBool& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isBool() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Bool"_XS8; }
static TagBool* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -46,31 +46,39 @@
#include "TagData.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagData> TagData::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagData* TagData::getEmptyTag()
{
TagData* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagData;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagData::FreeTag()
void TagData::ReleaseTag()
{
dataBuffer.setEmpty();
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagData::operator == (const TagStruct& other) const

View File

@ -13,10 +13,12 @@
class TagData : public TagStruct
{
static XObjArray<TagData> tagsFree;
XBuffer<UINT8> dataBuffer;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagData> tagsFree;
#endif
TagData() : dataBuffer() {}
TagData(const TagData& other) = delete; // Can be defined if needed
@ -31,7 +33,7 @@ public:
virtual XBool isData() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Data"_XS8; }
static TagData* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -45,31 +45,39 @@
#include "TagDate.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagDate> TagDate::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagDate* TagDate::getEmptyTag()
{
TagDate* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagDate;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagDate::FreeTag()
void TagDate::ReleaseTag()
{
string.setEmpty();
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagDate::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagDate : public TagStruct
{
static XObjArray<TagDate> tagsFree;
XString8 string;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagDate> tagsFree;
#endif
TagDate() : string() {}
TagDate(const TagDate& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isDict() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Dict"_XS8; }
static TagDate* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -44,35 +44,47 @@
#include "TagDict.h"
XObjArray<TagDict> TagDict::tagsFree;
#ifdef TagStruct_USE_CACHE
TagsDictFreeArray TagDict::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagDict* TagDict::getEmptyTag()
{
TagDict* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagDict;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagDict::FreeTag()
void TagDict::ReleaseTag()
{
for (size_t tagIdx = _dictContent.size() ; tagIdx > 0 ; ) {
tagIdx--;
_dictContent[tagIdx].FreeTag();
#ifdef TagStruct_USE_CACHE
_dictContent[tagIdx].ReleaseTag();
_dictContent.RemoveWithoutFreeingAtIndex(tagIdx);
#else
_dictContent.RemoveAtIndex(tagIdx);
#endif
}
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagDict::operator == (const TagStruct& other) const

View File

@ -10,12 +10,22 @@
#include "plist.h"
class TagsDictFreeArray : public XObjArray<TagDict>
{
public:
~TagsDictFreeArray () {
NOP;
}
};
class TagDict : public TagStruct
{
static XObjArray<TagDict> tagsFree;
XObjArray<TagStruct> _dictContent;
public:
#ifdef TagStruct_USE_CACHE
static TagsDictFreeArray tagsFree;
#endif
TagDict() : _dictContent() {}
TagDict(const TagDict& other) = delete; // Can be defined if needed
@ -31,7 +41,7 @@ public:
virtual XBool isDict() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Dict"_XS8; }
static TagDict* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -45,32 +45,40 @@
#include "TagFloat.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagFloat> TagFloat::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagFloat* TagFloat::getEmptyTag()
{
TagFloat* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagFloat;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagFloat::FreeTag()
void TagFloat::ReleaseTag()
{
value = 0;
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagFloat::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagFloat : public TagStruct
{
static XObjArray<TagFloat> tagsFree;
float value;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagFloat> tagsFree;
#endif
TagFloat() : value(0) {}
TagFloat(const TagFloat& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isFloat() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Float"_XS8; }
static TagFloat* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -45,32 +45,40 @@
#include "TagInt64.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagInt64> TagInt64::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagInt64* TagInt64::getEmptyTag()
{
TagInt64* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagInt64;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagInt64::FreeTag()
void TagInt64::ReleaseTag()
{
value = 0;
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagInt64::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagInt64 : public TagStruct
{
static XObjArray<TagInt64> tagsFree;
INT64 value;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagInt64> tagsFree;
#endif
TagInt64() : value(0) {}
TagInt64(const TagInt64& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isInt64() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Int64"_XS8; }
static TagInt64* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -45,32 +45,40 @@
#include "TagKey.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagKey> TagKey::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagKey* TagKey::getEmptyTag()
{
TagKey* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagKey;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagKey::FreeTag()
void TagKey::ReleaseTag()
{
_string.setEmpty();
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagKey::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagKey : public TagStruct
{
static XObjArray<TagKey> tagsFree;
XString8 _string;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagKey> tagsFree;
#endif
TagKey() : _string() {}
TagKey(const TagKey& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isKey() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "Key"_XS8; }
static TagKey* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -44,32 +44,40 @@
#include "TagString8.h"
#ifdef TagStruct_USE_CACHE
XObjArray<TagString> TagString::tagsFree;
#endif
//UINTN newtagcount = 0;
//UINTN tagcachehit = 0;
TagString* TagString::getEmptyTag()
{
TagString* tag;
#ifdef TagStruct_USE_CACHE
if ( tagsFree.size() > 0 ) {
tag = &tagsFree[0];
tagsFree.RemoveWithoutFreeingAtIndex(0);
//tagcachehit++;
//DBG("tagcachehit=%lld\n", tagcachehit);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachehit++;
#endif
return tag;
}
#endif
tag = new TagString;
//newtagcount += 1;
//DBG("newtagcount=%lld\n", newtagcount);
#ifdef TagStruct_COUNT_CACHEHITMISS
cachemiss++;
#endif
return tag;
}
void TagString::FreeTag()
void TagString::ReleaseTag()
{
_string.setEmpty();
#ifdef TagStruct_USE_CACHE
tagsFree.AddReference(this, true);
#else
delete this;
#endif
}
XBool TagString::operator == (const TagStruct& other) const

View File

@ -12,10 +12,12 @@
class TagString : public TagStruct
{
static XObjArray<TagString> tagsFree;
XString8 _string;
public:
#ifdef TagStruct_USE_CACHE
static XObjArray<TagString> tagsFree;
#endif
TagString() : _string() {}
TagString(const TagString& other) = delete; // Can be defined if needed
@ -30,7 +32,7 @@ public:
virtual XBool isString() const { return true; }
virtual const XString8 getTypeAsXString8() const { return "String8"_XS8; }
static TagString* getEmptyTag();
virtual void FreeTag();
virtual void ReleaseTag();
virtual void sprintf(unsigned int ident, XString8* s) const;

View File

@ -29,6 +29,7 @@
*/
//Slice - rewrite for UEFI with more functions like Copyright (c) 2003 Apple Computer
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "../../cpp_foundation/apd.h"
#include "../b64cdecode.h"
#include "plist.h"
#include "../../libeg/FloatLib.h"
@ -76,6 +77,25 @@ EFI_STATUS FixDataMatchingTag( CHAR8* buffer, CONST CHAR8* tag,UINT32* lenPtr);
#include "TagInt64.h"
#include "TagString8.h"
#ifdef TagStruct_COUNT_CACHEHITMISS
size_t TagStruct::cachemiss = 0;
size_t TagStruct::cachehit = 0;
#endif
void TagStruct::EmptyCache()
{
#ifdef TagStruct_USE_CACHE
TagArray::tagsFree.setEmpty();
TagBool::tagsFree.setEmpty();
TagData::tagsFree.setEmpty();
TagDate::tagsFree.setEmpty();
TagDict::tagsFree.setEmpty();
TagFloat::tagsFree.setEmpty();
TagInt64::tagsFree.setEmpty();
TagKey::tagsFree.setEmpty();
TagString::tagsFree.setEmpty();
#endif
}
XBool TagStruct::debugIsEqual(const TagStruct& other, const XString8& label) const
{
@ -140,7 +160,7 @@ EFI_STATUS ParseXML(const UINT8* buffer, TagDict** dict, size_t bufSize)
UINT32 length = 0;
UINT32 pos = 0;
TagStruct* tag = NULL;
CHAR8* configBuffer = NULL;
apd<CHAR8*> configBuffer = NULL;
size_t bufferSize = 0;
UINTN i;
@ -154,7 +174,7 @@ EFI_STATUS ParseXML(const UINT8* buffer, TagDict** dict, size_t bufSize)
return EFI_INVALID_PARAMETER;
}
configBuffer = (__typeof__(configBuffer))malloc(bufferSize+1);
configBuffer = (CHAR8*)malloc(bufferSize+1);
memset(configBuffer, 0, bufferSize+1);
if(configBuffer == NULL) {
return EFI_OUT_OF_RESOURCES;
@ -185,7 +205,7 @@ EFI_STATUS ParseXML(const UINT8* buffer, TagDict** dict, size_t bufSize)
break;
}
tag->FreeTag();
tag->ReleaseTag();
tag = NULL;
}
// FreePool(configBuffer);
@ -383,7 +403,7 @@ EFI_STATUS __ParseTagList(XBool isArray, CHAR8* buffer, TagStruct** tag, UINT32
}
if (EFI_ERROR(Status)) {
dictOrArrayTag->FreeTag();
dictOrArrayTag->ReleaseTag();
return Status;
}
}
@ -506,7 +526,7 @@ EFI_STATUS ParseTagInteger(CHAR8* buffer, TagStruct** tag, UINT32* lenPtr)
else {
MsgLog("ParseTagInteger hex error (0x%hhX) in buffer %s\n", *val, buffer);
// getchar();
tmpTag->FreeTag();
tmpTag->ReleaseTag();
return EFI_UNSUPPORTED;
}
}
@ -523,7 +543,7 @@ EFI_STATUS ParseTagInteger(CHAR8* buffer, TagStruct** tag, UINT32* lenPtr)
if (*val < '0' || *val > '9') {
MsgLog("ParseTagInteger decimal error (0x%hhX) in buffer %s\n", *val, buffer);
// getchar();
tmpTag->FreeTag();
tmpTag->ReleaseTag();
return EFI_UNSUPPORTED;
}
integer = (integer * 10) + (*val++ - '0');

View File

@ -26,6 +26,9 @@
#include "../../include/TagTypes.h"
#define TagStruct_USE_CACHE
//#define TagStruct_COUNT_CACHEHITMISS
class TagDict;
class TagKey;
class TagString;
@ -40,15 +43,18 @@ class TagStruct
{
public:
#ifdef TagStruct_COUNT_CACHEHITMISS
static size_t cachemiss;
static size_t cachehit;
#endif
static void EmptyCache();
TagStruct() {}
TagStruct(const TagStruct& other) = delete; // Can be defined if needed
const TagStruct& operator = ( const TagStruct & ) = delete; // Can be defined if needed
virtual ~TagStruct() { }
// static TagStruct* getEmptyTag();
// static TagStruct* getEmptyDictTag();
// static TagStruct* getEmptyArrayTag();
virtual void FreeTag() = 0;
virtual void ReleaseTag() = 0;
virtual XBool operator == (const TagStruct& other) const = 0;
virtual XBool operator != (const TagStruct& other) const { return !(*this == other); };

View File

@ -39,6 +39,19 @@ XBool ReadAllKeyStrokes(void)
return GotKeyStrokes;
}
void PauseForKey()
{
UINTN index;
if (ReadAllKeyStrokes()) { // remove buffered key strokes
gBS->Stall(5000000); // 5 seconds delay
ReadAllKeyStrokes(); // empty the buffer again
}
gBS->WaitForEvent(1, &gST->ConIn->WaitForKey, &index);
ReadAllKeyStrokes(); // empty the buffer to protect the menu
}
void PauseForKey(const XString8& msg)
{
UINTN index;

View File

@ -103,13 +103,16 @@ void construct_globals_objects(EFI_HANDLE ImageHandle)
// unsigned char* cp = (unsigned char*)p;
// for (size_t i=0 ; i<2467264 ; i +=16) DBG("%c %c %c %c %c %c %c %c %c %c %c %c %c %c %c %c\n",cp[0]>=32 ? cp[i+0] : '.',cp[i+1]>=32 ? cp[i+1] : '.',cp[i+2]>=32 ? cp[i+2] : '.',cp[i+3]>=32 ? cp[i+3] : '.',cp[i+4]>=32 ? cp[i+4] : '.',cp[i+5]>=32 ? cp[i+5] : '.',cp[i+6]>=32 ? cp[i+6] : '.',cp[i+7]>=32 ? cp[i+7] : '.',cp[i+8]>=32 ? cp[i+8] : '.',cp[i+9]>=32 ? cp[i+9] : '.',cp[i+10]>=32 ? cp[i+10] : '.',cp[i+11]>=32 ? cp[i+11] : '.',cp[i+12]>=32 ? cp[i+12] : '.',cp[i+13]>=32 ? cp[i+13] : '.',cp[i+14]>=32 ? cp[i+14] : '.',cp[i+15]>=32 ? cp[i+15] : '.');
// egSaveFile(&self.getCloverDir(), L"dump.bin", LoadedImage->ImageBase, 3000000);
#endif
DBG("CTORS %llX(%lld), offset from file beginning %llX(%lld) size %ld\n", (UINTN)p, (UINTN)p, (UINTN)p - (UINTN)LoadedImage->ImageBase, (UINTN)p - (UINTN)LoadedImage->ImageBase, pend-p );
#else
DBG("CTORS %llX(%lld), size %ld\n", (UINTN)p, (UINTN)p, pend-p );
#endif
size_t ctor_idx = 0;
while ( p < pend ) {
DBG("CTOR %llX(%lld)\n", (UINTN)p[0], (UINTN)p[0]);
DBG("CTOR %zu adr=%llX(%lld)\n", ctor_idx, (UINTN)p[0], (UINTN)p[0]);
(*p)();
p++;
ctor_idx++;
}
// DBG("CTOR %X %d\n", (UINTN)__CTOR_LIST__, (UINTN)__CTOR_LIST__);
// __do_init();

View File

@ -1,4 +1,5 @@
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "../../cpp_lib/MemoryTracker.h"
#if 0
#define DBG(...) DebugLog(2, __VA_ARGS__)
@ -57,6 +58,7 @@ extern "C" int atexit(void(__cdecl *destructor_func)(void))
DBG("atexit(%p, %p, %p, %d)\n", destructor_func, objptr, dso, sizeof(atexit_func_entry_t));
#endif
MemoryStopRecord msr;
if ( !atexit_func_entry_array )
{
DBG("atexit : allocate\n");

View File

@ -48,7 +48,7 @@ void operator delete ( void* ptr ) noexcept
{
// ++operator_delete_count1;
// MemLogf(false, 0, "operator delete(%llx) %lld\n", uintptr_t(ptr), operator_delete_count1);
return FreePool(ptr);
FreePool(ptr);
}
#ifdef _MSC_VER
@ -59,7 +59,7 @@ void operator delete (void * ptr, UINTN count)
{
// ++operator_delete_count2;
// MemLogf(false, 0, "operator delete(%llx, %lld) %lld\n", uintptr_t(ptr), count, operator_delete_count2);
return FreePool(ptr);
FreePool(ptr);
}
@ -71,7 +71,7 @@ void operator delete[](void * ptr, UINTN count)
{
// ++operator_delete_count3;
// MemLogf(false, 0, "operator delete[](%llx, %lld) %lld\n", uintptr_t(ptr), count, operator_delete_count3);
return FreePool(ptr);
FreePool(ptr);
}

View File

@ -21,6 +21,7 @@ Headers collection for procedures
#include "../cpp_foundation/XObjArray.h"
#include "../include/remove_ref.h"
#include "../cpp_lib/undefinable.h"
#include "../cpp_foundation/apd.h"
#endif
#include "../include/OneLinerMacros.h"

View File

@ -1,2 +1,37 @@
//#define UINT_MAX
#define SIZE_T_MAX MAX_UINTN
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
#define CHAR_MIN (-128)
#define SCHAR_MIN (-128)
#define SHRT_MIN (-32768)
#define INT_MIN INT32_MIN
#define LONG_MIN INT64_MIN
#define LLONG_MIN INT64_MIN
#define CHAR_MAX 127
#define SCHAR_MAX 127
#define SHRT_MAX 32767
#define INT_MAX INT32_MAX
#define LONG_MAX INT64_MAX
#define LLONG_MAX INT64_MAX
#define UCHAR_MAX 255
#define USHRT_MAX 65535
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT64_MAX
#define ULLONG_MAX UINT64_MAX

View File

@ -7,46 +7,12 @@
static_assert(sizeof(char) == 1, "sizeof(char) != 1");
static_assert(sizeof(short) == 2, "sizeof(short) != 2");
static_assert(sizeof(int) == 4, "sizeof(int) != 4");
//static_assert(sizeof(long) == 8, "sizeof(long) != 8"); // Jief : I think this break on Windows. Conditional compilation rquired to restore Windows compatibility
static_assert(sizeof(long) == 8, "sizeof(long) != 8"); // Jief : I think this break on Windows. Conditional compilation required to restore Windows compatibility
//so why EDK2 never used "long". It uses INT32.
static_assert(sizeof(long long) == 8, "sizeof(long long) != 8");
static_assert(true, "true");
#endif
#define INT8_MIN (-128)
#define INT16_MIN (-32768)
#define INT32_MIN (-2147483647 - 1)
#define INT64_MIN (-9223372036854775807LL - 1)
#define INT8_MAX 127
#define INT16_MAX 32767
#define INT32_MAX 2147483647
#define INT64_MAX 9223372036854775807LL
#define UINT8_MAX 0xff /* 255U */
#define UINT16_MAX 0xffff /* 65535U */
#define UINT32_MAX 0xffffffff /* 4294967295U */
#define UINT64_MAX 0xffffffffffffffffULL /* 18446744073709551615ULL */
#define CHAR_MIN (-128)
#define SCHAR_MIN (-128)
#define SHRT_MIN (-32768)
#define INT_MIN INT32_MIN
#define LONG_MIN INT64_MIN
#define LLONG_MIN INT64_MIN
#define CHAR_MAX 127
#define SCHAR_MAX 127
#define SHRT_MAX 32767
#define INT_MAX INT32_MAX
#define LONG_MAX INT64_MAX
#define LLONG_MAX INT64_MAX
#define UCHAR_MAX 255
#define USHRT_MAX 65535
#define UINT_MAX UINT32_MAX
#define ULONG_MAX UINT64_MAX
#define ULLONG_MAX UINT64_MAX
typedef UINT8 uint8_t;
typedef UINT16 uint16_t;

View File

@ -5,6 +5,8 @@
* Author: jief
*/
#include <Platform.h>
#include "../cpp_lib/MemoryTracker.h"
#include "ConfigManager.h"
#include "../Settings/SelfOem.h"
#include "../refit/lib.h"
@ -484,7 +486,8 @@ EFI_STATUS LoadPlist(const XStringW& ConfName, C* plist)
{
EFI_STATUS Status = EFI_NOT_FOUND;
UINTN Size = 0;
UINT8* ConfigPtr = NULL;
UINT8* ConfigPtr = NULL; // not needed. but avoids warning
apd<UINT8*> apdConfigPtr;
// XStringW ConfigPlistPath;
// XStringW ConfigOemPath;
@ -503,6 +506,7 @@ EFI_STATUS LoadPlist(const XStringW& ConfName, C* plist)
configPlistPath = SWPrintf("%ls\\%ls.plist", selfOem.getOemFullPath().wc_str(), ConfName.wc_str());
if (FileExists (&selfOem.getOemDir(), configFilename)) {
Status = egLoadFile(&selfOem.getOemDir(), configFilename.wc_str(), &ConfigPtr, &Size);
apdConfigPtr = ConfigPtr; // This will automatically destruct ConfigPtr when the method exit.
if (EFI_ERROR(Status)) {
DBG("Cannot find %ls at path (%s): '%ls', trying '%ls'\n", configFilename.wc_str(), efiStrError(Status), selfOem.getOemFullPath().wc_str(), self.getCloverDirFullPath().wc_str());
}else{
@ -514,6 +518,7 @@ EFI_STATUS LoadPlist(const XStringW& ConfName, C* plist)
configPlistPath = SWPrintf("%ls\\%ls.plist", self.getCloverDirFullPath().wc_str(), ConfName.wc_str());
if ( FileExists(&self.getCloverDir(), configFilename.wc_str())) {
Status = egLoadFile(&self.getCloverDir(), configFilename.wc_str(), &ConfigPtr, &Size);
apdConfigPtr = ConfigPtr; // This will automatically destruct ConfigPtr when the method exit.
}
if (EFI_ERROR(Status)) {
DBG("Cannot find %ls at path '%ls' : %s\n", configFilename.wc_str(), self.getCloverDirFullPath().wc_str(), efiStrError(Status));

View File

@ -43,9 +43,9 @@
#include "ConfigPlistAbstract.h"
extern XStringWArray ThemeNameArray;
extern XStringWArray ConfigsList;
extern XStringWArray DsdtsList;
//extern XStringWArray ThemeNameArray;
//extern XStringWArray ConfigsList;
//extern XStringWArray DsdtsList;
extern XStringWArray SmbiosList;

View File

@ -9,6 +9,7 @@
#define PLATFORM_SELF_H_
#include "../cpp_foundation/XString.h"
#include "../cpp_foundation/apd.h"
extern "C" {
#include <Uefi/UefiSpec.h>
#include <Protocol/LoadedImage.h>
@ -26,8 +27,8 @@ public:
protected:
EFI_HANDLE m_SelfImageHandle {}; // this efi.
EFI_LOADED_IMAGE* m_SelfLoadedImage {}; // this efi.
EFI_DEVICE_PATH* m_SelfDevicePath {}; // path to device containing this efi.
EFI_LOADED_IMAGE* m_SelfLoadedImage = NULL; // this efi.
apd<EFI_DEVICE_PATH*> m_SelfDevicePath = NULL; // path to device containing this efi.
// XStringW m_SelfDevicePathAsXStringW; // path to device containing this efi.
EFI_SIMPLE_FILE_SYSTEM_PROTOCOL* m_SelfSimpleVolume {}; // Volume containing this efi.

View File

@ -12,7 +12,8 @@
#ifdef __cplusplus
#include <stddef.h> // size_t
#include <stdint.h> // CHAR_MIN etc.
#include <limits.h> // CHAR_MIN etc.
#include <stdint.h> // UINT16_MAX etc.
@ -22,14 +23,19 @@ template< class T > struct _xtools__remove_ref<T&> { typedef T type;
template< class T > struct _xtools__remove_const { typedef T type; };
template< class T > struct _xtools__remove_const<const T> { typedef T type; };
template< class T > struct _xtools__remove_const<const T&> { typedef T& type; };
template< class T > struct _xtools__remove_const<const T*> { typedef T* type; };
template< class T > struct _xtools__remove_const<const T*> { typedef T* type; }; // this match type with [] and [size]
template< class T > struct _xtools__remove_ptr { typedef T type; };
template< class T > struct _xtools__remove_ptr<T*> { typedef T type; };
template< class T > struct _xtools__remove_ptr<T[]> { typedef T type; };
template <class T, size_t n> struct _xtools__remove_ptr<T[n]> { typedef T type; };
template< class T > struct _xtools__remove_const_ptr { typedef T type; };
template< class T > struct _xtools__remove_const_ptr<const T> { typedef T type; };
template< class T > struct _xtools__remove_const_ptr<T*> { typedef T type; };
template< class T > struct _xtools__remove_const_ptr<const T*> { typedef T type; };
template< class T, int n > struct _xtools__remove_const_ptr<T[n]> { typedef T type; };
template< class T, int n > struct _xtools__remove_const_ptr<const T[n]> { typedef T type; };
template< class T, size_t n > struct _xtools__remove_const_ptr<T[n]> { typedef T type; };
template< class T, size_t n > struct _xtools__remove_const_ptr<const T[n]> { typedef T type; };
@ -217,6 +223,7 @@ struct _xtools__has_type_member<T, _xtools__void_t<typename T::char_t>> : _xtool
#define remove_const(x) typename _xtools__remove_const<x>::type
#define remove_ptr(x) typename _xtools__remove_ptr<x>::type
#define unsigned_type(x) typename _xtools__make_unsigned<remove_const(x)>::type
#define remove_ref(x) typename _xtools__remove_ref<x>::type
#define remove_const_ptr(x) typename _xtools__remove_const_ptr<x>::type

View File

@ -0,0 +1,74 @@
/*
* apd.h
*
* Created on: Nov 11, 2023
* Author: jief
*/
#ifndef CPP_FOUNDATION_APD_H_
#define CPP_FOUNDATION_APD_H_
template<typename T>
class apd
{
protected:
T t = 0;
public:
using type = T;
apd() : t(NULL) {};
apd(T _t) : t(_t) {};
apd(const apd<T>& other) {
panic("You must NOT copy an apd object. Use shared_ptr instead\n");
}
apd& operator=(const apd<T>& other) {
panic("You must NOT copy an apd object. Use shared_ptr instead\n");
return *this;
}
apd& operator=(T _t) {
delete t;
t = _t;
return *this;
}
constexpr bool isNull() const { return t == NULL; }
constexpr bool notNull() const { return !isNull(); }
remove_ptr(T)& operator * () {
return *t;
}
T operator -> () {
return t;
}
T* operator & ()
{
return &t;
}
T& get() {
return t;
}
const T& get() const {
return t;
}
operator T () {
return t;
}
operator const T () const {
return t;
}
/* [] */
template<typename IntegralType, enable_if(is_integral(IntegralType))>
remove_ptr(T)& operator [](IntegralType i) const { return t[i]; }
~apd() {
delete t;
}
};
#endif /* CPP_FOUNDATION_APD_H_ */

View File

@ -0,0 +1,391 @@
/*
* MemoryTracker.cpp
*
* Created on: Nov 9, 2023
* Author: jief
*/
#include <Platform.h>
#include "MemoryTracker.h"
#include "../cpp_foundation/XString.h"
#ifndef DEBUG_ALL
#define DEBUG_MT 1
#else
#define DEBUG_MT DEBUG_ALL
#endif
#if DEBUG_MT == 0
#define DBG(...)
#else
#define DBG(...) DebugLog(DEBUG_MT, __VA_ARGS__)
#endif
#ifdef MEMORY_TRACKER_ENABLED
uint64_t MT_alloc_count = 0;
bool MT_recording = false;
MTArray<uintptr_t> allocatedPtrArray;
MTArray<uint64_t> allocatedPtrInfoArray;
void MT_import(const void* p)
{
// printf("MT_import ptr %llx\n", uintptr_t(p));
MT_recording = false;
auto count = MT_alloc_count;
allocatedPtrArray.Add(uintptr_t(p)); // this can allocate memory, so don't record that.
allocatedPtrInfoArray.Add(count); // this can allocate memory, so don't record that.
MT_recording = true;
}
//
//void MT_delete(const void* p)
//{
// if ( p ) {
// uintptr_t ref2 = uintptr_t(p);
// auto idx = allocatedPtrArray.indexOf(ref2);
// if ( idx == MAX_XSIZE ) {
//// printf("MT_delete unknown ptr %llx\n", uintptr_t(p));
// }else{
////if ( allocatedPtrInfoArray[idx]->alloc_idx == 15579 ) printf("MT_delete(0x%llx) - %lld\n", uintptr_t(p), allocatedPtrInfoArray[idx]->alloc_idx);
// allocatedPtrArray.RemoveAtIndex(idx);
// allocatedPtrInfoArray.RemoveAtIndex(idx);
// }
// }
//}
extern "C" {
void* real_malloc(size_t size);
void* real_type_malloc(EFI_MEMORY_TYPE MemoryType, size_t size);
void* my_malloc(size_t size);
void real_free(void*);
void my_free(void*);
//#define MAGIC_BEGINNING 0xDEADBEEF32659821
//#define MAGIC_END 0x1245788956231973
#define MAGIC_BEGINNING 0xDEADBEEFBBBBBBBB
#define MAGIC_END 0xEEEEEEEEDEADBEEF
uint64_t MT_count_to_break_into = 0;
#if defined(IS_UEFI_MODULE)
VOID *
InternalAllocatePool (
IN EFI_MEMORY_TYPE MemoryType,
IN UINTN AllocationSize
)
#else
void* my_malloc(size_t AllocationSize)
#endif
{
VOID *Memory = NULL;
#ifdef JIEF_DEBUG
if ( MT_alloc_count == 4028 || MT_alloc_count == MT_count_to_break_into ) {
NOP;
}
#endif
if ( MT_recording )
{
Memory = real_type_malloc(MemoryType, AllocationSize+24);
if ( !Memory ) return NULL;
*(uint64_t*)Memory = AllocationSize;
// void* p = ((uint64_t*)Memory + 1) ;
*((uint64_t*)Memory + 1) = MAGIC_BEGINNING;
*(uint64_t*)( ((uint8_t*)Memory) + 16 + AllocationSize ) = MAGIC_END;
if ( MT_recording ) {
MT_import( ((uint8_t*)Memory) + 16 );
++MT_alloc_count; // do this only if !MT_recording because MT_import is doing an allocation.
}
return ((uint8_t*)Memory) + 16;
}else{
Memory = real_type_malloc(MemoryType, AllocationSize);
return Memory;
}
}
#if defined(IS_UEFI_MODULE)
void (EFIAPI FreePool)(IN void *MemoryPlus16)
#else
void my_free(IN void *MemoryPlus16)
#endif
{
if ( !MemoryPlus16 ) return;
uintptr_t ref2 = uintptr_t(MemoryPlus16);
auto idx = allocatedPtrArray.indexOf(ref2);
if ( idx == MAX_XSIZE ) {
//DBG("Delete non recorded ptr %llx\n", uintptr_t(MemoryPlus16));
real_free(MemoryPlus16);
return;
}
uint8_t* Memory = ((uint8_t*)MemoryPlus16) - 16;
uint64_t AllocationSize = *(uint64_t*)Memory;
if ( *((uint64_t*)Memory + 1) != MAGIC_BEGINNING ) {
DBG("Buffer underrun for ptr %llx count %lld\n", uintptr_t(MemoryPlus16), allocatedPtrInfoArray[idx]);
}
if ( *(uint64_t*)( ((uint8_t*)Memory) + 16 + AllocationSize ) != MAGIC_END ) {
DBG("Buffer overrun for ptr %llx count %lld\n", uintptr_t(MemoryPlus16), allocatedPtrInfoArray[idx]);
}
allocatedPtrArray.RemoveAtIndex(idx);
allocatedPtrInfoArray.RemoveAtIndex(idx);
real_free( Memory );
}
} // extern "C"
void MemoryTrackerCheck()
{
size_t nb_ptr = allocatedPtrArray.length();
DBG("-- %zu pointers :\n", nb_ptr);
for( size_t idx=0 ; idx < nb_ptr ; ++idx )
{
uint8_t* Memory = ((uint8_t*)allocatedPtrArray[idx]) - 16;
uint64_t AllocationSize = *(uint64_t*)Memory;
if ( *((uint64_t*)Memory + 1) != MAGIC_BEGINNING ) {
DBG("Buffer underrun for ptr %llx count %lld\n", uintptr_t(Memory + 16), allocatedPtrInfoArray[idx]);
}
if ( *(uint64_t*)( ((uint8_t*)Memory) + 16 + AllocationSize ) != MAGIC_END ) {
DBG("Buffer overrun for ptr %llx count %lld\n", uintptr_t(Memory + 16), allocatedPtrInfoArray[idx]);
}
}
}
void MemoryTrackerInit()
{
MT_alloc_count = 0;
MT_recording = false;
}
/*
* In fact, the hook is already in place. We just have to activate it now.
*/
void MemoryTrackerInstallHook()
{
MT_recording = true;
}
void MT_outputDanglingPtr()
{
size_t nb_ptr = allocatedPtrArray.length();
DBG("-- %zu lost pointer :\n", nb_ptr);
for( size_t idx=0 ; idx < nb_ptr ; ++idx ) {
DBG(" Dangling ptr %llx count=%lld\n", allocatedPtrArray[idx], allocatedPtrInfoArray[idx]);
}
}
uint64_t MT_getAllocCount() { return MT_alloc_count; };
uint64_t MT_getDanglingPtrCount() { return allocatedPtrArray.length(); };
MemoryStopRecord::MemoryStopRecord() : recording(MT_recording) { MT_recording = false; };
MemoryStopRecord::~MemoryStopRecord() { MT_recording = recording; };
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// MTArray
//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
template<class TYPE>
MTArray<TYPE>::MTArray() : m_data(0), m_len(0), m_allocatedSize(4096)
{
m_data = (TYPE*)real_malloc(4096 * sizeof(TYPE));
if ( !m_data ) {
#ifdef JIEF_DEBUG
panic("MTArray<TYPE>:: MTArray() : OldAllocatePool(%zu) returned NULL. System halted\n", 4096 * sizeof(TYPE));
#endif
}
}
template<class TYPE>
size_t MTArray<TYPE>::indexOf(TYPE& e) const
{
size_t i;
for ( i=0 ; i<length() ; i+=1 ) {
if ( m_data[i] == e ) return i;
}
return MAX_XSIZE;
}
/* CheckSize() // nNewSize is number of TYPE, not in bytes */
template<class TYPE>
void MTArray<TYPE>::CheckSize(size_t nNewSize, size_t nGrowBy)
{
//MTArray_DBG("CheckSize: m_len=%d, m_size=%d, nGrowBy=%d, nNewSize=%d\n", m_len, m_size, nGrowBy, nNewSize);
if ( nNewSize > m_allocatedSize ) {
nNewSize += nGrowBy;
TYPE* new_data;
new_data = (TYPE*)real_malloc(nNewSize * sizeof(TYPE));
if ( !new_data ) {
#ifdef JIEF_DEBUG
panic("MTArray<TYPE>::CheckSize(nNewSize=%zu, nGrowBy=%zu) : OldAllocatePool(%zu, %lu, %" PRIuPTR ") returned NULL. System halted\n", nNewSize, nGrowBy, m_allocatedSize, nNewSize*sizeof(TYPE), (uintptr_t)m_data);
#endif
}
memcpy(new_data, m_data, m_allocatedSize * sizeof(TYPE));
real_free(m_data);
m_data = new_data;
// memset(&_Data[_Size], 0, (nNewSize-_Size) * sizeof(TYPE)); // Could help for debugging, but zeroing in not needed.
m_allocatedSize = nNewSize;
}
}
/* CheckSize() */
template<class TYPE>
void MTArray<TYPE>::CheckSize(size_t nNewSize)
{
CheckSize(nNewSize, 4096);
}
/* Add(TYPE, size_t) */
template<class TYPE>
size_t MTArray<TYPE>::Add(const TYPE newElement, size_t count)
{
// MTArray_DBG("size_t MTArray<TYPE>::Add(const TYPE newElement, size_t count) -> Enter. count=%d _Len=%d _Size=%d\n", count, m_len, m_size);
size_t i;
CheckSize(m_len+count);
for ( i=0 ; i<count ; i++ ) {
m_data[m_len+i] = newElement;
}
m_len += count;
return m_len-count;
}
/* RemoveAtIndex(size_t) */
template<class TYPE>
void MTArray<TYPE>::RemoveAtIndex(size_t nIndex)
{
if ( nIndex < m_len ) {
if ( nIndex<m_len-1 ) memmove(&m_data[nIndex], &m_data[nIndex+1], (m_len-nIndex-1)*sizeof(TYPE));
m_len -= 1;
return;
}
#if defined(_DEBUG) && defined(TRACE)
TRACE("MTArray::Remove(size_t) -> nIndex > m_len\n");
#endif
}
/* FreeAndRemoveAtIndex(size_t) */
template<class TYPE>
void MTArray<TYPE>::FreeAndRemoveAtIndex(size_t nIndex)
{
if ( nIndex < m_len ) {
#ifdef UNIT_TESTS_MACOS // won't be needed soon as I'll improve the EFI mock
free(m_data[nIndex]);
#else
OldFreePool(m_data[nIndex]);
#endif
if ( nIndex<m_len-1 ) memmove(&m_data[nIndex], &m_data[nIndex+1], (m_len-nIndex-1)*sizeof(TYPE));
m_len -= 1;
return;
}
#if defined(_DEBUG) && defined(TRACE)
TRACE("MTArray::FreeAndRemoveAtIndex(size_t) -> nIndex > m_len\n");
#endif
}
#undef malloc
#undef free
void* real_type_malloc(EFI_MEMORY_TYPE MemoryType, size_t size)
{
#if defined(IS_UEFI_MODULE)
void* Memory;
EFI_STATUS Status = gBS->AllocatePool(MemoryType, size, &Memory); // AllocatePool in MemoryAllocationLib uses EfiBootServicesData, not EfiConventionalMemory
if (EFI_ERROR(Status)) return NULL;
return Memory;
#else
return malloc(AllocationSize);
#endif
}
void* real_malloc(size_t size) { return real_type_malloc(EfiBootServicesData, size); }
void real_free(void* p)
{
#if defined(IS_UEFI_MODULE)
EFI_STATUS Status = gBS->FreePool(p);
if (EFI_ERROR(Status)) {
// What to do ?
}
#else
free(p);
#endif
}
#if !defined(IS_UEFI_MODULE)
extern "C" {
#if !defined(IS_UEFI_MODULE)
void* malloc(size_t size);
void free(void* p);
#endif
} //extern C
#endif // !defined(IS_UEFI_MODULE)
#else // MEMORY_TRACKER_ENABLED
void MemoryTrackerInit() {};
void MemoryTrackerInstallHook() {};
void MT_outputDanglingPtr() {};
uint64_t MT_getAllocCount() { return 0; };
uint64_t MT_getDanglingPtrCount() { return 0; };
MemoryStopRecord::MemoryStopRecord() {};
MemoryStopRecord::~MemoryStopRecord() {};
void MemoryTrackerCheck() {};
#undef malloc
#undef free
void* my_malloc(size_t size)
{
return malloc(size);
}
void my_free(void* p)
{
free(p);
}
#endif// MEMORY_TRACKER_ENABLED

View File

@ -0,0 +1,98 @@
/*
* MemoryTracker.h
*
* Created on: Nov 9, 2023
* Author: jief
*/
#ifndef CPP_LIB_MEMORYTRACKER_H_
#define CPP_LIB_MEMORYTRACKER_H_
#ifdef JIEF_DEBUG
#define MEMORY_TRACKER_ENABLED
#endif
extern "C" {
void MemoryTrackerInit();
void MemoryTrackerInstallHook();
}
void MT_outputDanglingPtr();
uint64_t MT_getAllocCount();
uint64_t MT_getDanglingPtrCount();
void MemoryTrackerCheck();
class MemoryStopRecord
{
protected:
bool recording;
public:
MemoryStopRecord();
~MemoryStopRecord();
};
#ifdef MEMORY_TRACKER_ENABLED
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
// MTArray
//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
template<class TYPE>
class MTArray
{
protected:
TYPE* m_data;
size_t m_len;
size_t m_allocatedSize;
public:
MTArray();
size_t length() const { return m_len; }
////--------------------------------------------------
TYPE &operator[](size_t index)
{
#ifdef JIEF_DEBUG
if ( index < 0 ) {
panic("MTArray::ElementAt(int) -> Operator [] : index < 0");
}
if ( (unsigned int)index >= m_len ) { // cast safe, index > 0
panic("MTArray::ElementAt(int) -> Operator [] : index > m_len");
}
#endif
return m_data[index];
}
void CheckSize(size_t nNewSize);
void CheckSize(size_t nNewSize, size_t nGrowBy);
size_t Add(const TYPE newElement, size_t count = 1);
void RemoveAtIndex(size_t nIndex);
void FreeAndRemoveAtIndex(size_t nIndex);
size_t indexOf(TYPE& e) const;
};
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//
//
//
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
extern MTArray<uintptr_t> allocatedPtrArray;
extern MTArray<uint64_t> allocatedPtrInfoArray;
#endif
#endif /* CPP_LIB_MEMORYTRACKER_H_ */

View File

@ -8,6 +8,7 @@
#ifndef __XML_LITE_H__
#define __XML_LITE_H__
#include "../cpp_foundation/apd.h"
#include "../cpp_foundation/XBool.h"
#include "../cpp_foundation/XStringArray.h"
#include "../cpp_lib/XmlLiteSimpleTypes.h"
@ -73,7 +74,7 @@ class XmlLiteParser
{
friend class XmlParserPosition;
char* p_start = NULL;
apd<char*> p_start = NULL;
char* p_end = NULL;
XmlParserPosition currentPos = XmlParserPosition();
XObjArray<XmlParserMessage> XmlParserMessageArray = XObjArray<XmlParserMessage>();

View File

@ -8,6 +8,8 @@
#ifndef CPP_LIB_DEF_TYPES_H_
#define CPP_LIB_DEF_TYPES_H_
#include "../cpp_foundation/XBool.h"
template <class T>
class undefinable
{

View File

@ -0,0 +1,132 @@
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "../cpp_lib/MemoryTracker.h"
#include "../cpp_foundation/XStringArray.h"
static int breakpoint(int v)
{
return v;
}
//
//class TestAlloc {
//public:
//// MemoryAllocation4Object objma;
// void* ptr1 = 0;
// void* ptr2 = 0;
//
// TestAlloc() {};
// ~TestAlloc() {
//// objma.free(ptr1, "ptr1"_XS8);
// MT_delete(ptr1, ""_XS8);
// };
//
// void* testAlloc2()
// {
// printf("--TestAlloc.testAlloc2 - begin\n");
//// MemoryAllocation ma(__FILE_NAME__, __PRETTY_FUNCTION__, __LINE__);
// ptr1 = MT_alloc(10, "ptr1 (supposed to be a memory leak)"_XS8); (void)ptr1;
//// objma.takeOwnership(ptr1, "ptr1"_XS8);
// void* ptrl1 = MT_alloc(10, "ptrl1"_XS8); (void)ptrl1;
// MT_delete(ptrl1, "ptrl1"_XS8);
// void* ptrl2 = MT_alloc(10, "ptrl2 bis"_XS8);
// printf("--TestAlloc.testAlloc2 - end\n");
//// MT_export(q2);
//// return ma.return_(ptrl2);
// return ptrl2;
// }
//};
//
//void* testAlloc2()
//{
// printf("--testAlloc2 - begin\n");
//
// MemoryAllocation ma(__FILE__, __PRETTY_FUNCTION__, __LINE__);
// void* p2 = MT_alloc(10, "p2 (supposed to be a memory leak)"_XS8); (void)p2;
// void* q2 = MT_alloc(10, "q2"_XS8); (void)q2;
// MT_delete(q2, "q2"_XS8);
// q2 = MT_alloc(10, "q2 bis"_XS8);
//
//
// printf("--testAlloc2 - end\n");
// return ma.return_(q2);
//}
//
//void testAlloc1()
//{
// printf("--testAlloc1 - begin\n");
// MemoryAllocation ma(__FILE__, __PRETTY_FUNCTION__, __LINE__);
// void* p = MT_alloc(10, "p (supposed to be a memory leak)"_XS8); (void)p;
// void* q = MT_alloc(10, "q"_XS8); (void)q;
// void* t = testAlloc2(); (void)t;
// MT_delete(q, "q"_XS8);
// q = MT_alloc(10, "q bis (supposed to be a memory leak)"_XS8);
// printf("--testAlloc1 - end\n");
//}
//
//
//TestAlloc g_ta;
//
void f_p1void(void* p)
{
void* q = p;
(void)q;
}
int MemoryTracker_tests()
{
#ifdef MEMORY_TRACKER_ENABLED
void* p; (void)p;
// int t1_v = 3;
//// apd<int*> apdTest1 = &t1_v; // this would crash because this ptr cannot be freed
// apd<int*> apdTest1 = new int(t1_v); // this is ok
// int* q = &(*apdTest1);
//// int* qq = *apdTest1;
// int* const* r = &apdTest1;
// **r = 7;
//
// void* u = apdTest1;
// auto uuu = &apdTest1.get();
//
// f_p1void(apdTest1);
//
// auto apdTest1_get = apdTest1.get();
// auto apdTest1_adr_of_get = &apdTest1.get();
// auto apdTest1_getAdrOfPtr = &apdTest1;
MemoryTrackerInstallHook();
{
new char();
char* pp = (char*)malloc(2);
*(pp-1) = 0;
free(pp);
}
{
new char();
char* pp = (char*)malloc(2);
*(pp+3) = 0;
free(pp);
}
MT_outputDanglingPtr();
if ( MT_getDanglingPtrCount() != 2 ) return breakpoint(1);
// testAlloc1();
// printf("------------------\n");
// {
// TestAlloc ta;
// p = ta.testAlloc2();
// MT_delete(p, "return ta.testAlloc2()"_XS8);
// }
// printf("------------------\n");
// p = g_ta.testAlloc2();
// MT_delete(p, "return g_ta.testAlloc2()"_XS8);
// MT_outputDanglingPtr();
// printf("------------------\n");
#endif
return 0;
}

View File

@ -0,0 +1,3 @@
int MemoryTracker_tests();

View File

@ -24,6 +24,7 @@
#include "config-test.h"
#include "XToolsCommon_test.h"
#include "guid_tests.h"
#include "MemoryTracker_test.h"
#if defined(JIEF_DEBUG) && defined(CLOVER_BUILD)
#include "printlib-test.h"
@ -45,37 +46,16 @@ bool all_tests()
int ret;
ret = XString_tests();
ret = ParseXML_tests();
if ( ret != 0 ) {
printf("XString_tests() failed at test %d\n", ret);
printf("ParseXML_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XStringArray_tests();
ret = MemoryTracker_tests();
if ( ret != 0 ) {
printf("XStringArray_tests() failed at test %d\n", ret);
printf("MemoryTracker_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XToolsCommon_tests();
if ( ret != 0 ) {
printf("XToolsCommon_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = xml_lite_tests();
if ( ret != 0 ) {
printf("xml_lite_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = strcasecmp_tests();
if ( ret != 0 ) {
printf("strncmp_tests() failed at test %d\n", ret);
all_ok = false;
}
// ret = config_plist_tests();
// if ( ret != 0 ) {
// printf("config_plist_tests() failed at test %d\n", ret);
// all_ok = false;
// }
//
// ret = XUINTN_tests();
// if ( ret != 0 ) {
// printf("XUINTN_tests() failed at test %d\n", ret);
@ -83,7 +63,7 @@ if ( ret != 0 ) {
// }
#endif
#if defined(JIEF_DEBUG)
#if !defined(JIEF_DEBUG)
#if defined(JIEF_DEBUG) && defined(CLOVER_BUILD)
ret = printlib_tests();
@ -121,12 +101,12 @@ if ( ret != 0 ) {
}
ret = strcasecmp_tests();
if ( ret != 0 ) {
printf("strncmp_tests() failed at test %d\n", ret);
printf("strcasecmp_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XToolsCommon_tests();
if ( ret != 0 ) {
printf("printlib_tests() failed at test %d\n", ret);
printf("XToolsCommon_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = XArray_tests();
@ -161,17 +141,17 @@ if ( ret != 0 ) {
}
ret = find_replace_mask_Clover_tests();
if ( ret != 0 ) {
printf("xml_lite_tests() failed at test %d\n", ret);
printf("find_replace_mask_Clover_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = find_replace_mask_OC_tests();
if ( ret != 0 ) {
printf("xml_lite_tests() failed at test %d\n", ret);
printf("find_replace_mask_OC_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = ParseXML_tests();
if ( ret != 0 ) {
printf("plist_tests() failed at test %d\n", ret);
printf("ParseXML_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = MacOsVersion_tests();
@ -179,6 +159,11 @@ if ( ret != 0 ) {
printf("MacOsVersion_tests() failed at test %d\n", ret);
all_ok = false;
}
ret = xml_lite_tests();
if ( ret != 0 ) {
printf("xml_lite_tests() failed at test %d\n", ret);
all_ok = false;
}
#endif

View File

@ -912,6 +912,9 @@ int ParseXML_tests()
{
TagDict* dict = NULL;
EFI_STATUS Status = ParseXML((UINT8*)config_all, &dict, (UINT32)strlen(config_all));
dict->ReleaseTag();
TagStruct::EmptyCache();
if ( !EFI_ERROR(Status) ) {
XString8 s;
dict->sprintf(0, &s);

View File

@ -72,7 +72,7 @@ DBG(" AddLegacyEntry:\n");
}
DBG(" FullTitle=%ls\n", FullTitle.wc_str());
DBG(" LoaderTitle=%ls\n", _LoaderTitle.wc_str());
DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
DBG(" Volume->LegacyOS.Name=%ls\n", Volume->LegacyOS.Name.wc_str());
// Ignore this loader if it's device path is already present in another loader
for (UINTN i = 0; i < MainMenu.Entries.size(); ++i) {
@ -88,17 +88,17 @@ DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
XStringW LoaderTitle;
if ( _LoaderTitle.isEmpty() ) {
LoaderTitle = Volume->LegacyOS->Name;
LoaderTitle = Volume->LegacyOS.Name;
}else{
LoaderTitle = _LoaderTitle;
}
XStringW LTitle;
if (LoaderTitle.isEmpty()) {
if (Volume->LegacyOS->Name.notEmpty()) {
LTitle.takeValueFrom(Volume->LegacyOS->Name);
if (Volume->LegacyOS->Name[0] == 'W' || Volume->LegacyOS->Name[0] == 'L')
ShortcutLetter = (wchar_t)Volume->LegacyOS->Name[0]; // cast safe because value is 'W' or 'L'
if (Volume->LegacyOS.Name.notEmpty()) {
LTitle.takeValueFrom(Volume->LegacyOS.Name);
if (Volume->LegacyOS.Name[0] == 'W' || Volume->LegacyOS.Name[0] == 'L')
ShortcutLetter = (wchar_t)Volume->LegacyOS.Name[0]; // cast safe because value is 'W' or 'L'
} else
LTitle = L"Legacy OS"_XSW;
} else
@ -128,15 +128,15 @@ DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
if ( Image && !Image->isEmpty() ) {
Entry->Image = *Image;
} else {
Entry->Image = ThemeX->LoadOSIcon(Volume->LegacyOS->IconName);
Entry->Image = ThemeX->LoadOSIcon(Volume->LegacyOS.IconName);
if (Entry->Image.Image.isEmpty()) {
Entry->Image = ThemeX->GetIcon("os_win"_XS8); //we have no legacy.png
}
}
// DBG("IconName=%ls\n", Volume->LegacyOS->IconName);
// DBG("IconName=%ls\n", Volume->LegacyOS.IconName);
Entry->DriveImage = (DriveImage != NULL) ? *DriveImage : ScanVolumeDefaultIcon(Volume, Volume->LegacyOS->Type, Volume->DevicePath);
Entry->DriveImage = (DriveImage != NULL) ? *DriveImage : ScanVolumeDefaultIcon(Volume, Volume->LegacyOS.Type, Volume->DevicePath);
// DBG("HideBadges=%d Volume=%ls\n", GlobalConfig.HideBadges, Volume->VolName);
// DBG("Title=%ls OSName=%ls OSIconName=%ls\n", LoaderTitle, Volume->OSName, Volume->OSIconName);
@ -165,7 +165,7 @@ DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
if (Custom.settings.Volume.notEmpty()) {
if ( !Volume->DevicePathString.contains(Custom.settings.Volume) && !Volume->VolName.contains(Custom.settings.Volume) ) {
if (Custom.settings.Type != 0) {
if (Custom.settings.Type == Volume->LegacyOS->Type) {
if (Custom.settings.Type == Volume->LegacyOS.Type) {
Entry->Hidden = true;
}
} else {
@ -173,7 +173,7 @@ DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
}
}
} else if (Custom.settings.Type != 0) {
if (Custom.settings.Type == Volume->LegacyOS->Type) {
if (Custom.settings.Type == Volume->LegacyOS.Type) {
Entry->Hidden = true;
}
}
@ -201,7 +201,7 @@ DBG(" Volume->LegacyOS->Name=%ls\n", Volume->LegacyOS->Name.wc_str());
SubScreen->AddMenuEntry(&MenuEntryReturn, false);
Entry->SubScreen = SubScreen;
MainMenu.AddMenuEntry(Entry, true);
// DBG(" added '%ls' OSType=%d Icon=%ls\n", Entry->Title, Volume->LegacyOS->Type, Volume->LegacyOS->IconName);
// DBG(" added '%ls' OSType=%d Icon=%ls\n", Entry->Title, Volume->LegacyOS.Type, Volume->LegacyOS.IconName);
return true;
}
@ -363,11 +363,11 @@ void AddCustomLegacy(void)
continue;
}
// Check if the volume should be of certain os type
if ((Custom.settings.Type != 0) && (Custom.settings.Type != Volume->LegacyOS->Type)) {
if ((Custom.settings.Type != 0) && (Custom.settings.Type != Volume->LegacyOS.Type)) {
DBG("skipped because wrong type\n");
continue;
}
} else if ((Custom.settings.Type != 0) && (Custom.settings.Type != Volume->LegacyOS->Type)) {
} else if ((Custom.settings.Type != 0) && (Custom.settings.Type != Volume->LegacyOS.Type)) {
DBG("skipped because wrong type\n");
continue;
}

View File

@ -501,7 +501,7 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
}
Dict->FreeTag();
Dict->ReleaseTag();
}
}
}
@ -555,7 +555,7 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
}
Dict->FreeTag();
Dict->ReleaseTag();
}
}
@ -672,7 +672,7 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
}
Dict->FreeTag();
Dict->ReleaseTag();
}
}
}
@ -771,7 +771,7 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
}
Dict->FreeTag();
Dict->ReleaseTag();
}
}
}
@ -816,7 +816,7 @@ MacOsVersion GetOSVersion(int LoaderType, const EFI_GUID& APFSTargetUUID, const
}
}
}
Dict->FreeTag();
Dict->ReleaseTag();
} else if (FileExists (Volume->RootDir, L"\\com.apple.recovery.boot\\boot.efi")) {
// Special case - com.apple.recovery.boot/boot.efi exists but SystemVersion.plist doesn't --> 10.9 recovery
OSVersion = "10.9"_XS8;
@ -1745,6 +1745,7 @@ XString8 GetAuthRootDmg(const EFI_FILE& dir, const XStringW& path)
}
}
if ( PlistBuffer ) FreePool(PlistBuffer);
if ( Dict ) Dict->ReleaseTag();
return returnValue;
}

View File

@ -35,6 +35,7 @@
#include <Platform.h> // Only use angled for Platform, else, xcode project won't compile
#include "menu_items.h"
#include "../REFIT_MENU_SCREEN.h"
#include "../../libeg/libeg.h"
#include "../../refit/lib.h"
@ -45,6 +46,10 @@
#include "../../libeg/XPointer.h"
#endif
REFIT_ABSTRACT_MENU_ENTRY::~REFIT_ABSTRACT_MENU_ENTRY() {
delete SubScreen;
};
REFIT_MENU_ENTRY_CLOVER* REFIT_MENU_ENTRY_CLOVER::getPartiallyDuplicatedEntry() const
{
REFIT_MENU_ENTRY_CLOVER* DuplicateEntry = new REFIT_MENU_ENTRY_CLOVER;
@ -55,7 +60,7 @@ REFIT_MENU_ENTRY_CLOVER* REFIT_MENU_ENTRY_CLOVER::getPartiallyDuplicatedEntry()
DuplicateEntry->LoadOptions = LoadOptions;
DuplicateEntry->LoaderPath = LoaderPath;
DuplicateEntry->VolName = VolName;
DuplicateEntry->DevicePath = DevicePath;
DuplicateEntry->DevicePath = DuplicateDevicePath(DevicePath);
DuplicateEntry->Flags = Flags;
return DuplicateEntry;
}
@ -70,7 +75,7 @@ LOADER_ENTRY* LOADER_ENTRY::getPartiallyDuplicatedEntry() const
DuplicateEntry->LoadOptions = LoadOptions;
DuplicateEntry->LoaderPath = LoaderPath;
DuplicateEntry->DisplayedVolName= DisplayedVolName;
DuplicateEntry->DevicePath = DevicePath;
DuplicateEntry->DevicePath = DuplicateDevicePath(DevicePath);
DuplicateEntry->Flags = Flags;
DuplicateEntry->LoaderType = LoaderType;
DuplicateEntry->macOSVersion = macOSVersion;

View File

@ -115,7 +115,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
ACTION AtDoubleClick = ActionNone;
ACTION AtRightClick = ActionNone;
ACTION AtMouseOver = ActionNone;
REFIT_MENU_SCREEN *SubScreen = NULL;
REFIT_MENU_SCREEN* SubScreen = NULL; // we can't use apd<REFIT_MENU_SCREEN*> because of circular reference. We would need to include REFIT_MENU_SCREEN.h, but REFIT_MENU_SCREEN.h includes menu_items.h
virtual XIcon* getDriveImage() { return nullptr; };
virtual XIcon* getBadgeImage() { return nullptr; };
@ -150,7 +150,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
REFIT_ABSTRACT_MENU_ENTRY(const REFIT_ABSTRACT_MENU_ENTRY&) { panic("not yet defined"); }
REFIT_ABSTRACT_MENU_ENTRY& operator=(const REFIT_ABSTRACT_MENU_ENTRY&) { panic("not yet defined"); }
virtual ~REFIT_ABSTRACT_MENU_ENTRY() {}; // virtual destructor : this is vital
virtual ~REFIT_ABSTRACT_MENU_ENTRY(); // virtual destructor : this is vital
};
@ -288,7 +288,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
public:
UINT8 NoMemset; //HACK - some non zero value
UINT16 Flags;
EFI_DEVICE_PATH *DevicePath;
apd<EFI_DEVICE_PATH*> DevicePath;
void StartTool();
@ -307,7 +307,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
public:
REFIT_VOLUME *Volume;
XStringW VolName;
EFI_DEVICE_PATH *DevicePath;
apd<EFI_DEVICE_PATH*> DevicePath;
UINT16 Flags;
REFIT_MENU_ENTRY_CLOVER() : REFIT_MENU_ITEM_ABSTRACT_ENTRY_LOADER(), Volume(NULL), VolName(), DevicePath(NULL), Flags(0) {};
@ -356,7 +356,7 @@ class REFIT_ABSTRACT_MENU_ENTRY
XStringW DisplayedVolName;
XStringW OSName = XStringW();
EFI_DEVICE_PATH *DevicePath;
apd<EFI_DEVICE_PATH*> DevicePath;
UINT16 Flags;
UINT8 LoaderType;
MacOsVersion macOSVersion;

View File

@ -68,7 +68,7 @@ CONST XString8 ArgOptional[NUM_OPT] = {
};
CONST CHAR16 *VBIOS_BIN = L"misc\\c0000.bin";
INPUT_ITEM *InputItems = NULL;
INPUT_ITEM InputItems[135]; // INPUT_ITEM is a class, therefore default initialization is taking place.
INTN TextStyle; //why global? It will be class SCREEN member
UINT32 EncodeOptions(const XString8Array& Options)

View File

@ -17,7 +17,7 @@ extern INTN TextStyle; //why global? It will be class SCREEN member
extern CONST CHAR16 *VBIOS_BIN;
extern INPUT_ITEM *InputItems;
extern INPUT_ITEM InputItems[135];
void DecodeOptions(REFIT_MENU_ITEM_BOOTNUM *Entry);
UINT32 EncodeOptions(const XString8Array& Options);

View File

@ -153,7 +153,7 @@ displayFreeMemory("XTheme::ParseSVGXTheme begin"_XS8);
if ( nsvg__nbDanglingPtr() > 0 ) {
DBG("There is already dangling ptr. nano svg memory leak test not done\n");
}else{
char* buffer2 = (char*)malloc(Size);
apd<char*> buffer2 = (char*)malloc(Size);
memcpy(buffer2, buffer, Size);
nvsg__memoryallocation_verbose = false;
NSVGparser* p = nsvg__parse(buffer2, 72, 1.f); //the buffer will be modified, it is how nanosvg works

View File

@ -185,7 +185,7 @@ finish:
}
}
}
ThemeDict->FreeTag();
ThemeDict->ReleaseTag();
if (!ThemeX->Daylight) {
Status = StartupSoundPlay(&ThemeX->getThemeDir(), L"sound_night.wav");
@ -819,6 +819,7 @@ XIcon& XTheme::GetIconAlt(INTN Id, INTN Alt) //if not found then take embedded
XIcon *NewIcon = new XIcon(Id, true);
if (NewIcon->Image.isEmpty()) {
// check for embedded with ID=Alt
delete NewIcon;
NewIcon = new XIcon(Alt, true);
}
if (!NewIcon->Image.isEmpty()) {
@ -826,6 +827,7 @@ XIcon& XTheme::GetIconAlt(INTN Id, INTN Alt) //if not found then take embedded
Icons[IdFound].Image = NewIcon->Image;
Icons[IdFound].ImageNight = NewIcon->ImageNight;
}
delete NewIcon; // there is probably a way better way to do this. By initializing directly Icons[IdFound].Image instead of using dynamically allocated copy.
}
}

View File

@ -44,6 +44,7 @@
//#include "../include/OneLinerMacros.h"
#include "../Platform/Utils.h"
#include "BmLib.h"
#include "../include/OneLinerMacros.h"
#ifndef DEBUG_ALL
#define DEBUG_SVG 1
@ -111,20 +112,31 @@
#include "../cpp_foundation/XString.h"
int nvsg__memoryallocation_verbose = false;
uint64_t nsvg__alloc_count = 0;
XArray<uintptr_t> nsvg__allocatedPtr;
XArray<uint64_t> nsvg__allocatedPtrIdx;
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
XObjArray<XString8> nsvg__allocatedPtrMsg;
#endif
void nsvg__alloc_insert(void* p, const XString8& msg)
{
//if ( nsvg__alloc_count == 36602 ) {
//NOP;
//}
nsvg__allocatedPtr.Add(uintptr_t(p));
nsvg__allocatedPtrIdx.Add(nsvg__alloc_count++);
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.AddCopy(msg, true);
#endif
}
void* nsvg__alloc(UINTN size, const XString8& msg)
{
void* buffer = AllocatePool(size);
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__alloc(%lld) - %s = %llx\n", size, msg.c_str(), uintptr_t(buffer));
nsvg__allocatedPtr.Add(uintptr_t(buffer));
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.AddCopy(XString8(msg), true);
#endif
nsvg__alloc_insert(buffer, msg);
return buffer;
}
@ -132,10 +144,7 @@ void* nsvg__alloczero(UINTN size, const XString8& msg)
{
void* buffer = AllocateZeroPool(size);
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__alloczero(%lld) - %s = %llx\n", size, msg.c_str(), uintptr_t(buffer));
nsvg__allocatedPtr.Add(uintptr_t(buffer));
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.AddCopy(XString8(msg), true);
#endif
nsvg__alloc_insert(buffer, msg);
return buffer;
}
@ -143,10 +152,7 @@ void* nsvg__alloccopy(UINTN size, const void* ref, const XString8& msg)
{
void* buffer = AllocateCopyPool(size, ref);
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__alloccopy(%lld, %llx) - %s = %llx\n", size, uintptr_t(ref), msg.c_str(), uintptr_t(buffer));
nsvg__allocatedPtr.Add(uintptr_t(buffer));
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.AddCopy(XString8(msg), true);
#endif
nsvg__alloc_insert(buffer, msg);
return buffer;
}
@ -158,34 +164,35 @@ void* nsvg__realloc(UINTN oldsize, UINTN newsize, void* ref, const XString8& msg
void* buffer = ReallocatePool(oldsize, newsize, ref);
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__realloc(%lld, %lld, %llx) - %s = %llx\n", oldsize, newsize, uintptr_t(ref), msg.c_str(), uintptr_t(buffer));
nsvg__allocatedPtr.RemoveAtIndex(idx);
nsvg__allocatedPtrIdx.RemoveAtIndex(idx);
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.RemoveAtIndex(idx);
#endif
nsvg__allocatedPtr.Add(uintptr_t(buffer));
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.AddCopy(XString8(msg), true);
#endif
nsvg__alloc_insert(buffer, msg);
return buffer;
}
void nsvg__delete(void* buffer, const XString8& msg)
{
//if ( ThemeX->Icons.length() > 0 && buffer == ThemeX->Icons[0].ImageSVG ) {
// DBG("stop");
//}
uintptr_t ref2 = uintptr_t(buffer);
auto idx = nsvg__allocatedPtr.indexOf(ref2);
if ( idx == MAX_XSIZE ) {
log_technical_bug("nsvg__delete %llx", uintptr_t(buffer));
}
EFI_STATUS Status = gBS->FreePool(buffer);
// EFI_STATUS Status = gBS->FreePool(buffer);
// if ( EFI_ERROR(Status) ) {
// log_technical_bug("nsvg__delete %llx", uintptr_t(buffer));
// }
EFI_STATUS Status = 0;
(void)Status;
FreePool(buffer);
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__delete(%llx) - allocation msg %s - %s - Status = %s\n", uintptr_t(buffer), nsvg__allocatedPtrMsg[idx].c_str(), msg.c_str(), efiStrError(Status));
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__delete(%llx) - count=%lld - allocation msg %s - %s - Status = %s\n", uintptr_t(buffer), nsvg__allocatedPtrIdx[idx], nsvg__allocatedPtrMsg[idx].c_str(), msg.c_str(), efiStrError(Status));
#else
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__delete(%llx) - %s - Status = %s\n", uintptr_t(buffer), msg.c_str(), efiStrError(Status));
if ( nvsg__memoryallocation_verbose ) DBG("nsvg__delete[%zu](%llx) - %s - Status = %s\n", idx, uintptr_t(buffer), msg.c_str(), efiStrError(Status));
#endif
nsvg__allocatedPtr.RemoveAtIndex(idx);
nsvg__allocatedPtrIdx.RemoveAtIndex(idx);
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
nsvg__allocatedPtrMsg.RemoveAtIndex(idx);
#endif
@ -199,11 +206,11 @@ size_t nsvg__nbDanglingPtr()
void nsvg__outputDanglingPtr()
{
for(size_t i=0;i<nsvg__allocatedPtr.length();++i){
for(size_t idx=0;idx<nsvg__allocatedPtr.length();++idx){
#ifdef NANOSVG_MEMORY_ALLOCATION_TRACE_VERBOSE
DBG("Dangling ptr %llx %s\n", nsvg__allocatedPtr[i], nsvg__allocatedPtrMsg[i].c_str());
DBG("Dangling ptr %llx - count=%lld - allocation msg=%s\n", nsvg__allocatedPtr[idx], nsvg__allocatedPtrIdx[idx], nsvg__allocatedPtrMsg[idx].c_str());
#else
DBG("Dangling ptr %llx\n", nsvg__allocatedPtr[i]);
DBG("Dangling ptr[%zu] %llx\n", idx, nsvg__allocatedPtr[idx]);
#endif
}
}
@ -4693,7 +4700,7 @@ void nsvg__deleteShapes(NSVGshape* shape)
nsvg__deletePaths(shape->paths);
}
}
// nsvg__delete(shape, "nsvg__deleteShapes"_XS8); // TODO : BUG, it doesn't boot anymore if we do the delete. Something is wrong.
nsvg__delete(shape, "nsvg__deleteShapes"_XS8);
shape = snext;
}
}

View File

@ -291,8 +291,8 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
//CHAR16 *kind = NULL;
Volume->HasBootCode = false;
Volume->LegacyOS->IconName.setEmpty();
Volume->LegacyOS->Name.setEmpty();
Volume->LegacyOS.IconName.setEmpty();
Volume->LegacyOS.Name.setEmpty();
// Volume->BootType = BOOTING_BY_MBR; //default value
Volume->BootType = BOOTING_BY_EFI;
*Bootable = false;
@ -357,18 +357,18 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
if (AsciiStrStr((CHAR8*)&SectorBuffer[i], "APPLE")) {
// StrCpy(Volume->VolName, volumeName);
DBG(" Found AppleDVD\n");
Volume->LegacyOS->Type = OSTYPE_OSX;
Volume->LegacyOS.Type = OSTYPE_OSX;
Volume->BootType = BOOTING_BY_CD;
Volume->LegacyOS->IconName = L"mac"_XSW;
Volume->LegacyOS.IconName = L"mac"_XSW;
break;
}
} else if (SectorBuffer[i] == 'M') {
if (AsciiStrStr((CHAR8*)&SectorBuffer[i], "MICROSOFT")) {
// StrCpy(Volume->VolName, volumeName);
DBG(" Found Windows DVD\n");
Volume->LegacyOS->Type = OSTYPE_WIN;
Volume->LegacyOS.Type = OSTYPE_WIN;
Volume->BootType = BOOTING_BY_CD;
Volume->LegacyOS->IconName = L"win"_XSW;
Volume->LegacyOS.IconName = L"win"_XSW;
break;
}
@ -378,9 +378,9 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
// StrCpy(Volume->VolName, volumeName);
DBG(" Found Linux DVD\n");
Volume->LegacyOS->Type = OSTYPE_LIN;
Volume->LegacyOS.Type = OSTYPE_LIN;
Volume->BootType = BOOTING_BY_CD;
Volume->LegacyOS->IconName = L"linux"_XSW;
Volume->LegacyOS.IconName = L"linux"_XSW;
break;
}
}
@ -395,9 +395,9 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
*Bootable = true;
Volume->HasBootCode = true;
// DBG("The volume has bootcode\n");
Volume->LegacyOS->IconName = L"legacy";
Volume->LegacyOS->Name = L"Legacy";
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"legacy";
Volume->LegacyOS.Name = L"Legacy";
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
}
// */
@ -408,24 +408,24 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
CompareMem(SectorBuffer + 3, "SYSLINUX", 8) == 0 ||
FindMem(SectorBuffer, 2048, "ISOLINUX", 8) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"linux"_XSW;
Volume->LegacyOS->Name = L"Linux"_XSW;
Volume->LegacyOS->Type = OSTYPE_LIN;
Volume->LegacyOS.IconName = L"linux"_XSW;
Volume->LegacyOS.Name = L"Linux"_XSW;
Volume->LegacyOS.Type = OSTYPE_LIN;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "Geom\0Hard Disk\0Read\0 Error", 26) >= 0) { // GRUB
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"grub,linux"_XSW;
Volume->LegacyOS->Name = L"Linux"_XSW;
Volume->LegacyOS.IconName = L"grub,linux"_XSW;
Volume->LegacyOS.Name = L"Linux"_XSW;
Volume->BootType = BOOTING_BY_PBR;
/*
} else if ((*((UINT32 *)(SectorBuffer)) == 0x4d0062e9 &&
*((UINT16 *)(SectorBuffer + 510)) == 0xaa55) ||
FindMem(SectorBuffer, 2048, "BOOT ", 10) >= 0) { //reboot Clover
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"clover";
Volume->LegacyOS->Name = L"Clover";
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"clover";
Volume->LegacyOS.Name = L"Clover";
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
// DBG("Detected Clover FAT32 bootcode\n");
*/
@ -435,79 +435,79 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
*((UINT16 *)(SectorBuffer + 510)) == 0xaa55) ||
FindMem(SectorBuffer, 2048, "Starting the BTX loader", 23) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"freebsd,linux"_XSW;
Volume->LegacyOS->Name = L"FreeBSD"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"freebsd,linux"_XSW;
Volume->LegacyOS.Name = L"FreeBSD"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "!Loading", 8) >= 0 ||
FindMem(SectorBuffer, 2048, "/cdboot\0/CDBOOT\0", 16) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"openbsd,linux"_XSW;
Volume->LegacyOS->Name = L"OpenBSD"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"openbsd,linux"_XSW;
Volume->LegacyOS.Name = L"OpenBSD"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "Not a bootxx image", 18) >= 0 ||
*((UINT32 *)(SectorBuffer + 1028)) == 0x7886b6d1) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"netbsd,linux"_XSW;
Volume->LegacyOS->Name = L"NetBSD"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"netbsd,linux"_XSW;
Volume->LegacyOS.Name = L"NetBSD"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 2048, "NTLDR", 5) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"win"_XSW;
Volume->LegacyOS->Name = L"Windows"_XSW;
Volume->LegacyOS->Type = OSTYPE_WIN;
Volume->LegacyOS.IconName = L"win"_XSW;
Volume->LegacyOS.Name = L"Windows"_XSW;
Volume->LegacyOS.Type = OSTYPE_WIN;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 2048, "BOOTMGR", 7) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"vista,win"_XSW;
Volume->LegacyOS->Name = L"Windows"_XSW;
Volume->LegacyOS->Type = OSTYPE_WIN;
Volume->LegacyOS.IconName = L"vista,win"_XSW;
Volume->LegacyOS.Name = L"Windows"_XSW;
Volume->LegacyOS.Type = OSTYPE_WIN;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "CPUBOOT SYS", 11) >= 0 ||
FindMem(SectorBuffer, 512, "KERNEL SYS", 11) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"freedos,win"_XSW;
Volume->LegacyOS->Name = L"FreeDOS"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"freedos,win"_XSW;
Volume->LegacyOS.Name = L"FreeDOS"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "OS2LDR", 6) >= 0 ||
FindMem(SectorBuffer, 512, "OS2BOOT", 7) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"ecomstation"_XSW;
Volume->LegacyOS->Name = L"eComStation"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"ecomstation"_XSW;
Volume->LegacyOS.Name = L"eComStation"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "Be Boot Loader", 14) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"beos"_XSW;
Volume->LegacyOS->Name = L"BeOS"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"beos"_XSW;
Volume->LegacyOS.Name = L"BeOS"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "yT Boot Loader", 14) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"zeta"_XSW;
Volume->LegacyOS->Name = L"ZETA"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"zeta"_XSW;
Volume->LegacyOS.Name = L"ZETA"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
} else if (FindMem(SectorBuffer, 512, "\x04" "beos\x06" "system\x05" "zbeos", 18) >= 0 ||
FindMem(SectorBuffer, 512, "haiku_loader", 12) >= 0) {
Volume->HasBootCode = true;
Volume->LegacyOS->IconName = L"haiku"_XSW;
Volume->LegacyOS->Name = L"Haiku"_XSW;
Volume->LegacyOS->Type = OSTYPE_VAR;
Volume->LegacyOS.IconName = L"haiku"_XSW;
Volume->LegacyOS.Name = L"Haiku"_XSW;
Volume->LegacyOS.Type = OSTYPE_VAR;
Volume->BootType = BOOTING_BY_PBR;
}
@ -519,8 +519,8 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
#if REFIT_DEBUG > 0
DBG(" Result of bootcode detection: %ls %ls (%ls)\n",
Volume->HasBootCode ? L"bootable" : L"non-bootable",
Volume->LegacyOS->Name.notEmpty() ? Volume->LegacyOS->Name.wc_str() : L"unknown",
Volume->LegacyOS->IconName.notEmpty() ? Volume->LegacyOS->IconName.wc_str() : L"legacy");
Volume->LegacyOS.Name.notEmpty() ? Volume->LegacyOS.Name.wc_str() : L"unknown",
Volume->LegacyOS.IconName.notEmpty() ? Volume->LegacyOS.IconName.wc_str() : L"legacy");
#endif
if (FindMem(SectorBuffer, 512, "Non-system disk", 15) >= 0) // dummy FAT boot sector
@ -529,9 +529,9 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
#ifdef JIEF_DEBUG
////*Bootable = true;
//Volume->HasBootCode = true;
//Volume->LegacyOS->IconName = L"win"_XSW;
//Volume->LegacyOS->Name = L"Windows"_XSW;
//Volume->LegacyOS->Type = OSTYPE_WIN;
//Volume->LegacyOS.IconName = L"win"_XSW;
//Volume->LegacyOS.Name = L"Windows"_XSW;
//Volume->LegacyOS.Type = OSTYPE_WIN;
//Volume->BootType = BOOTING_BY_PBR;
#endif
@ -564,8 +564,6 @@ static void ScanVolumeBootcode(IN OUT REFIT_VOLUME *Volume, OUT XBool *Bootable)
static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
{
EFI_STATUS Status;
EFI_DEVICE_PATH *DevicePath, *NextDevicePath;
EFI_DEVICE_PATH *DiskDevicePath, *RemainingDevicePath = NULL;
HARDDRIVE_DEVICE_PATH *HdPath = NULL;
EFI_HANDLE WholeDiskHandle;
UINTN PartialLength = 0;
@ -576,13 +574,15 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
XBool Bootable;
// EFI_INPUT_KEY Key;
{
// get device path
DiskDevicePath = DevicePathFromHandle(Volume->DeviceHandle);
EFI_DEVICE_PATH* DiskDevicePath = DevicePathFromHandle(Volume->DeviceHandle);
//Volume->DevicePath = DuplicateDevicePath(DevicePathFromHandle(Volume->DeviceHandle));
DevicePathSize = GetDevicePathSize (DiskDevicePath);
Volume->DevicePath = (__typeof__(Volume->DevicePath))AllocateAlignedPages(EFI_SIZE_TO_PAGES(DevicePathSize), 64);
CopyMem(Volume->DevicePath, DiskDevicePath, DevicePathSize);
Volume->DevicePathString = FileDevicePathToXStringW(Volume->DevicePath);
}
#if REFIT_DEBUG > 0
if (Volume->DevicePath != NULL) {
@ -622,41 +622,41 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
ScanVolumeBootcode(Volume, &Bootable);
// DBG(" ScanVolumeBootcode success\n");
// detect device type
DevicePath = DuplicateDevicePath(Volume->DevicePath);
while (DevicePath != NULL && !IsDevicePathEndType(DevicePath)) {
NextDevicePath = NextDevicePathNode(DevicePath);
if ((DevicePathType (DevicePath) == MESSAGING_DEVICE_PATH) &&
((DevicePathSubType (DevicePath) == MSG_SATA_DP) ||
(DevicePathSubType (DevicePath) == MSG_NVME_NAMESPACE_DP) ||
(DevicePathSubType (DevicePath) == MSG_ATAPI_DP))) {
apd<EFI_DEVICE_PATH*> DevicePath = DuplicateDevicePath(Volume->DevicePath);
EFI_DEVICE_PATH *NextDevicePath = NextDevicePathNode(DevicePath);
while (NextDevicePath != NULL && !IsDevicePathEndType(NextDevicePath))
{
if ((DevicePathType (NextDevicePath) == MESSAGING_DEVICE_PATH) &&
((DevicePathSubType (NextDevicePath) == MSG_SATA_DP) ||
(DevicePathSubType (NextDevicePath) == MSG_NVME_NAMESPACE_DP) ||
(DevicePathSubType (NextDevicePath) == MSG_ATAPI_DP))) {
// DBG(" HDD volume\n");
Volume->DiskKind = DISK_KIND_INTERNAL;
break;
}
if (DevicePathType(DevicePath) == MESSAGING_DEVICE_PATH &&
(DevicePathSubType(DevicePath) == MSG_USB_DP || DevicePathSubType(DevicePath) == MSG_USB_CLASS_DP)) {
if (DevicePathType(NextDevicePath) == MESSAGING_DEVICE_PATH &&
(DevicePathSubType(NextDevicePath) == MSG_USB_DP || DevicePathSubType(NextDevicePath) == MSG_USB_CLASS_DP)) {
// DBG(" USB volume\n");
Volume->DiskKind = DISK_KIND_EXTERNAL;
// break;
}
// FIREWIRE Devices
if (DevicePathType(DevicePath) == MESSAGING_DEVICE_PATH &&
(DevicePathSubType(DevicePath) == MSG_1394_DP || DevicePathSubType(DevicePath) == MSG_FIBRECHANNEL_DP)) {
if (DevicePathType(NextDevicePath) == MESSAGING_DEVICE_PATH &&
(DevicePathSubType(NextDevicePath) == MSG_1394_DP || DevicePathSubType(NextDevicePath) == MSG_FIBRECHANNEL_DP)) {
// DBG(" FireWire volume\n");
Volume->DiskKind = DISK_KIND_FIREWIRE;
break;
}
// CD-ROM Devices
if (DevicePathType(DevicePath) == MEDIA_DEVICE_PATH &&
DevicePathSubType(DevicePath) == MEDIA_CDROM_DP) {
if (DevicePathType(NextDevicePath) == MEDIA_DEVICE_PATH &&
DevicePathSubType(NextDevicePath) == MEDIA_CDROM_DP) {
// DBG(" CD-ROM volume\n");
Volume->DiskKind = DISK_KIND_OPTICAL; //it's impossible
break;
}
// VENDOR Specific Path
if (DevicePathType(DevicePath) == MEDIA_DEVICE_PATH &&
DevicePathSubType(DevicePath) == MEDIA_VENDOR_DP) {
if (DevicePathType(NextDevicePath) == MEDIA_DEVICE_PATH &&
DevicePathSubType(NextDevicePath) == MEDIA_VENDOR_DP) {
// DBG(" Vendor volume\n");
if ( Volume->ApfsFileSystemUUID.isNull() ) {
Volume->DiskKind = DISK_KIND_NODISK; // Jief, don't know why DISK_KIND_NODISK in that case. That prevents Recovery badge to appear. If it's not APFS, let's do it like it was before.
@ -664,15 +664,15 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
break;
}
// LEGACY CD-ROM
if (DevicePathType(DevicePath) == BBS_DEVICE_PATH &&
(DevicePathSubType(DevicePath) == BBS_BBS_DP || DevicePathSubType(DevicePath) == BBS_TYPE_CDROM)) {
if (DevicePathType(NextDevicePath) == BBS_DEVICE_PATH &&
(DevicePathSubType(NextDevicePath) == BBS_BBS_DP || DevicePathSubType(NextDevicePath) == BBS_TYPE_CDROM)) {
// DBG(" Legacy CD-ROM volume\n");
Volume->DiskKind = DISK_KIND_OPTICAL;
break;
}
// LEGACY HARDDISK
if (DevicePathType(DevicePath) == BBS_DEVICE_PATH &&
(DevicePathSubType(DevicePath) == BBS_BBS_DP || DevicePathSubType(DevicePath) == BBS_TYPE_HARDDRIVE)) {
if (DevicePathType(NextDevicePath) == BBS_DEVICE_PATH &&
(DevicePathSubType(NextDevicePath) == BBS_BBS_DP || DevicePathSubType(NextDevicePath) == BBS_TYPE_HARDDRIVE)) {
// DBG(" Legacy HDD volume\n");
Volume->DiskKind = DISK_KIND_INTERNAL;
break;
@ -682,7 +682,7 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
// diskKind = NVME
//#define MSG_NVME_NAMESPACE_DP 0x17
DevicePath = NextDevicePath;
NextDevicePath = NextDevicePathNode(NextDevicePath);
}
/* what is the bread?
@ -699,34 +699,34 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
*/
}
DevicePath = DuplicateDevicePath(Volume->DevicePath);
RemainingDevicePath = DevicePath; //initial value
{
apd<EFI_DEVICE_PATH*> DevicePath = DuplicateDevicePath(Volume->DevicePath);
EFI_DEVICE_PATH* walkDevicePath = DevicePath; //initial value
//
// find the partition device path node
//
while (DevicePath && !IsDevicePathEnd (DevicePath)) {
if ((DevicePathType (DevicePath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType (DevicePath) == MEDIA_HARDDRIVE_DP)) {
HdPath = (HARDDRIVE_DEVICE_PATH *)DevicePath;
while (walkDevicePath && !IsDevicePathEnd (walkDevicePath)) {
if ((DevicePathType (walkDevicePath) == MEDIA_DEVICE_PATH) &&
(DevicePathSubType (walkDevicePath) == MEDIA_HARDDRIVE_DP)) {
HdPath = (HARDDRIVE_DEVICE_PATH *)walkDevicePath;
// break;
}
DevicePath = NextDevicePathNode (DevicePath);
walkDevicePath = NextDevicePathNode (walkDevicePath);
}
// DBG("DevicePath scanned\n");
if (HdPath) {
// printf("Partition found %s\n", DevicePathToStr((EFI_DEVICE_PATH *)HdPath));
PartialLength = (UINTN)((UINT8 *)HdPath - (UINT8 *)(RemainingDevicePath));
PartialLength = (UINTN)((UINT8 *)HdPath - (UINT8 *)(DevicePath.get()));
if (PartialLength > 0x1000) {
PartialLength = sizeof(EFI_DEVICE_PATH); //something wrong here but I don't want to be freezed
// return EFI_SUCCESS;
}
DiskDevicePath = (EFI_DEVICE_PATH *)AllocatePool(PartialLength + sizeof(EFI_DEVICE_PATH));
apd<EFI_DEVICE_PATH*> DiskDevicePath = (EFI_DEVICE_PATH *)AllocatePool(PartialLength + sizeof(EFI_DEVICE_PATH));
CopyMem(DiskDevicePath, Volume->DevicePath, PartialLength);
CopyMem((UINT8 *)DiskDevicePath + PartialLength, DevicePath, sizeof(EFI_DEVICE_PATH)); //EndDevicePath
CopyMem((UINT8 *)DiskDevicePath.get() + PartialLength, walkDevicePath, sizeof(EFI_DEVICE_PATH)); //EndDevicePath
// DBG("WholeDevicePath %ls\n", DevicePathToStr(DiskDevicePath));
RemainingDevicePath = DiskDevicePath;
EFI_DEVICE_PATH* RemainingDevicePath = DiskDevicePath;
Status = gBS->LocateDevicePath(&gEfiDevicePathProtocolGuid, &RemainingDevicePath, &WholeDiskHandle);
if (EFI_ERROR(Status)) {
DBG("Can't find WholeDevicePath: %s\n", efiStrError(Status));
@ -748,7 +748,7 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
//CheckError(Status, L"from HandleProtocol");
}
}
FreePool(DiskDevicePath);
}
}
/* else {
DBG("HD path is not found\n"); //master volume!
@ -784,16 +784,16 @@ static EFI_STATUS ScanVolume(IN OUT REFIT_VOLUME *Volume)
} else if (Volume->VolName.isEmpty()) {
Volume->VolName = L"Whole Disc Boot"_XSW;
}
if (Volume->LegacyOS->IconName.isEmpty())
Volume->LegacyOS->IconName = L"legacy"_XSW;
if (Volume->LegacyOS.IconName.isEmpty())
Volume->LegacyOS.IconName = L"legacy"_XSW;
return EFI_SUCCESS;
}
if ( Volume->ApfsFileSystemUUID.notNull() ) {
APPLE_APFS_CONTAINER_INFO *ApfsContainerInfo;
APPLE_APFS_VOLUME_INFO *ApfsVolumeInfo;
Status = InternalGetApfsSpecialFileInfo(Volume->RootDir, &ApfsVolumeInfo, &ApfsContainerInfo);
apd<APPLE_APFS_CONTAINER_INFO*> ApfsContainerInfo;
apd<APPLE_APFS_VOLUME_INFO*> ApfsVolumeInfo;
Status = InternalGetApfsSpecialFileInfo(Volume->RootDir, &ApfsVolumeInfo.get(), &ApfsContainerInfo.get());
if ( !EFI_ERROR(Status) ) {
//DBG("Status : %s, APFS role : %x\n", efiStrError(Status), ApfsVolumeInfo->Role);
Volume->ApfsRole = ApfsVolumeInfo->Role;
@ -986,7 +986,6 @@ void ScanVolumes(void)
for (UINTN HandleIndex = 0; HandleIndex < HandleCount; HandleIndex++) {
REFIT_VOLUME* Volume = new REFIT_VOLUME;
Volume->LegacyOS = new LEGACY_OS;
Volume->DeviceHandle = Handles[HandleIndex];
if (Volume->DeviceHandle == self.getSelfDeviceHandle()) {
SelfVolume = Volume;
@ -999,7 +998,7 @@ void ScanVolumes(void)
Status = ScanVolume(Volume);
if (!EFI_ERROR(Status)) {
Volume->Index = HandleIndex;
Volumes.AddReference(Volume, false);
Volumes.AddReference(Volume, true);
for (size_t HVi = 0; HVi < gSettings.GUI.HVHideStrings.size(); HVi++) {
if ( Volume->DevicePathString.containsIC(gSettings.GUI.HVHideStrings[HVi]) ||
Volume->VolName.containsIC(gSettings.GUI.HVHideStrings[HVi])
@ -1010,11 +1009,11 @@ void ScanVolumes(void)
}
// Guid = FindGPTPartitionGuidInDevicePath(Volume->DevicePath);
if (Volume->LegacyOS->IconName.isEmpty()) {
Volume->LegacyOS->IconName = L"legacy"_XSW;
if (Volume->LegacyOS.IconName.isEmpty()) {
Volume->LegacyOS.IconName = L"legacy"_XSW;
}
// DBG(" Volume '%ls', LegacyOS '%ls', LegacyIcon(s) '%ls', EFI_GUID = %s\n",
// Volume->VolName, Volume->LegacyOS->Name ? Volume->LegacyOS->Name : L"", Volume->LegacyOS->IconName, Guid.toXString8().c_str());
// Volume->VolName, Volume->LegacyOS.Name ? Volume->LegacyOS.Name : L"", Volume->LegacyOS.IconName, Guid.toXString8().c_str());
if (SelfVolume == Volume) {
DBG(" This is SelfVolume !!\n");
}
@ -1034,7 +1033,7 @@ void ScanVolumes(void)
SelfVolume->RootDir = const_cast<EFI_FILE*>(&self.getSelfVolumeRootDir()); // TODO : SelfVolume->RootDir should be const ! we should duplicate ?
SelfVolume->DiskKind = DISK_KIND_BOOTER;
SelfVolume->VolName = L"Clover"_XSW;
SelfVolume->LegacyOS->Type = OSTYPE_EFI;
SelfVolume->LegacyOS.Type = OSTYPE_EFI;
SelfVolume->HasBootCode = true;
SelfVolume->BootType = BOOTING_BY_PBR;
// AddListElement((void ***) &Volumes, &VolumesCount, SelfVolume);
@ -1170,7 +1169,7 @@ void ReinitVolumes(void)
// CheckError(Status, L"from LocateDevicePath");
}
if (Volume->WholeDiskDevicePath != NULL) {
if (Volume->WholeDiskDevicePath.notNull()) {
// get the handle for that path
RemainingDevicePath = DuplicateDevicePath(Volume->WholeDiskDevicePath);
Status = gBS->LocateDevicePath(&gEfiBlockIoProtocolGuid, const_cast<EFI_DEVICE_PATH**>(&RemainingDevicePath), &WholeDiskHandle);

View File

@ -39,12 +39,14 @@
#include <cpp_util/globals_dtor.h>
#include "../cpp_foundation/XString.h"
#include "../cpp_lib/MemoryTracker.h"
#include "../cpp_unit_test/all_tests.h"
#include "../entry_scan/entry_scan.h"
#include "../libeg/nanosvg.h"
#include "../gui/menu_items/menu_globals.h"
#include "menu.h"
#include "../Platform/Utils.h"
#include "../Platform/Settings.h"
#include "../Platform/DataHubCpu.h"
#include "../Platform/Events.h"
@ -143,46 +145,105 @@ VOID
PrintMemoryMap()
{
EFI_MEMORY_DESCRIPTOR *MemMap;
EFI_MEMORY_DESCRIPTOR *MemMapPtr;
UINTN MemMapSize;
UINTN MapKey, DescriptorSize;
UINT32 DescriptorVersion;
UINT64 Bytes;
EFI_STATUS Status;
MemMapSize = 0;
MemMap = NULL;
DescriptorSize = 0;
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
// ASSERT (Status == EFI_BUFFER_TOO_SMALL);
MemMapSize += EFI_PAGE_SIZE;
if (Status != EFI_BUFFER_TOO_SMALL) {
DBG("GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
return;
}
Status = gBS->AllocatePool (EfiBootServicesData, MemMapSize, (void**)&MemMap);
// ASSERT (Status == EFI_SUCCESS);
if (EFI_ERROR(Status)) return;
MemMapSize += EFI_PAGE_SIZE;
MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
// ASSERT (Status == EFI_SUCCESS);
MemMapPtr = MemMap;
DBG("GetMemStatus=%s\n", efiStrError(Status));
// ASSERT (DescriptorVersion == EFI_MEMORY_DESCRIPTOR_VERSION);
for (UINTN Index = 0; Index < MemMapSize / DescriptorSize; Index ++) {
Bytes = LShiftU64 (MemMap->NumberOfPages, 12);
DBG ("%016llX-%016llX %08llX %02llX %02llX\n",
MemMap->PhysicalStart,
MemMap->PhysicalStart + Bytes - 1,
MemMap->NumberOfPages,
MemMap->Attribute,
(UINTN)MemMap->Type);
MemMap = (EFI_MEMORY_DESCRIPTOR *)((UINTN)MemMap + DescriptorSize);
if ( EFI_ERROR(Status) ) {
DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
return;
}
gBS->FreePool(MemMapPtr);
OcPrintMemoryMap(MemMapSize, MemMap, DescriptorSize);
gBS->FreePool(MemMap);
}
void AllocSmallBlocks(UINTN NumberOfPagesMax)
{
EFI_MEMORY_DESCRIPTOR *MemMap;
UINTN MemMapSize;
UINTN MapKey, DescriptorSize;
UINT32 DescriptorVersion;
EFI_STATUS Status;
MemMapSize = 0;
MemMap = NULL;
DescriptorSize = 0;
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
if (Status != EFI_BUFFER_TOO_SMALL) {
DBG("PrintMemoryMap: GetMemStatus=%s not EFI_BUFFER_TOO_SMALL\n", efiStrError(Status));
return;
}
MemMapSize += EFI_PAGE_SIZE;
MemMap = (EFI_MEMORY_DESCRIPTOR*)AllocatePool(MemMapSize);
Status = gBS->GetMemoryMap (&MemMapSize, MemMap, &MapKey, &DescriptorSize, &DescriptorVersion);
if ( EFI_ERROR(Status) ) {
DBG("PrintMemoryMap: GetMemoryMap failed=%s\n", efiStrError(Status));
return;
}
for (
EFI_MEMORY_DESCRIPTOR* EntryWalker = MemMap;
(UINT8 *)EntryWalker < ((UINT8 *)MemMap + MemMapSize);
EntryWalker = NEXT_MEMORY_DESCRIPTOR (EntryWalker, DescriptorSize))
{
if (EntryWalker->Type != EfiConventionalMemory) {
continue;
}
if ( (UINTN)EntryWalker->NumberOfPages < NumberOfPagesMax )
{
gBS->AllocatePages(AllocateAddress, EfiBootServicesData, EntryWalker->NumberOfPages, &EntryWalker->PhysicalStart);
}
}
FreePool(MemMap);
}
void AllocSmallBlocks()
{
CONST EFI_MEMORY_ATTRIBUTES_TABLE *MemoryAttributesTable;
PrintMemoryMap();
UINTN size = 64;
UINTN nb = 0;
AllocSmallBlocks(size); // 252KB
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
nb = MemoryAttributesTable->NumberOfEntries;
PrintMemoryMap();
while ( size <= 2048 && nb > 100 ) { // XNU seems to handle max 128 entries. So let's shrink a little bit under 128
size *= 2;
AllocSmallBlocks(size);
MemoryAttributesTable = OcGetMemoryAttributes (NULL);
nb = MemoryAttributesTable->NumberOfEntries;
PrintMemoryMap();
}
if ( size > 2048 ) {
DBG("Cannot shrink memory map enough. Nb entries = %lld\n", nb);
}
}
static EFI_STATUS LoadEFIImageList(IN EFI_DEVICE_PATH **DevicePaths,
IN CONST XStringW& ImageTitle,
@ -1218,7 +1279,6 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Uefi.Output.ProvideConsoleGop = gSettings.GUI.ProvideConsoleGop;
OC_STRING_ASSIGN(mOpenCoreConfiguration.Uefi.Output.Resolution, XString8(gSettings.GUI.ScreenResolution).c_str());
if ( OpenRuntimeEfiName.notEmpty() ) {
XStringW FileName = SWPrintf("%ls\\%ls\\%ls", self.getCloverDirFullPath().wc_str(), getDriversPath().wc_str(), OpenRuntimeEfiName.wc_str());
EFI_HANDLE DriverHandle;
@ -1663,14 +1723,13 @@ void LOADER_ENTRY::StartLoader()
mOpenCoreConfiguration.Kernel.Quirks.ProvideCurrentCpuInfo);
// EFI_STATUS sta = gBS->FreePages(SomePages, 90000);
// DBG("free 90000 pages status=%s\n", efiStrError(sta));
PrintMemoryMap();
DBG("Closing log\n");
if (SavePreBootLog) {
Status = SaveBooterLog(&self.getCloverDir(), PREBOOT_LOG);
}
AllocSmallBlocks(); // shrink memory map;
PrintMemoryMap();
displayFreeMemory("Just before launching image"_XS8);
Status = gBS->StartImage (ImageHandle, 0, NULL); // point to OcStartImage from OC
@ -1740,7 +1799,7 @@ void LEGACY_ENTRY::StartLegacy()
egClearScreen(&MenuBackgroundPixel);
BeginExternalScreen(true/*, L"Booting Legacy OS"*/);
XImage BootLogoX;
BootLogoX.LoadXImage(&ThemeX->getThemeDir(), Volume->LegacyOS->IconName);
BootLogoX.LoadXImage(&ThemeX->getThemeDir(), Volume->LegacyOS.IconName);
BootLogoX.Draw((UGAWidth - BootLogoX.GetWidth()) >> 1,
(UGAHeight - BootLogoX.GetHeight()) >> 1);
@ -1907,7 +1966,7 @@ static void ScanDriverDir(IN CONST CHAR16 *Path, OUT EFI_HANDLE **DriversToConne
#undef BOOLEAN_AT_INDEX
XStringW FileName = SWPrintf("%ls\\%ls\\%ls", self.getCloverDirFullPath().wc_str(), Path, DirEntry->FileName);
Status = StartEFIImage(FileDevicePath(self.getSelfLoadedImage().DeviceHandle, FileName), NullXString8Array, LStringW(DirEntry->FileName), XStringW().takeValueFrom(DirEntry->FileName), NULL, &DriverHandle);
Status = StartEFIImage(apd<EFI_DEVICE_PATH_PROTOCOL*>(FileDevicePath(self.getSelfLoadedImage().DeviceHandle, FileName)), NullXString8Array, LStringW(DirEntry->FileName), XStringW().takeValueFrom(DirEntry->FileName), NULL, &DriverHandle);
if (EFI_ERROR(Status)) {
continue;
}
@ -1931,6 +1990,7 @@ static void ScanDriverDir(IN CONST CHAR16 *Path, OUT EFI_HANDLE **DriversToConne
if (!EFI_ERROR(Status) && DriverBinding != NULL) {
DBG(" - driver needs connecting\n");
// standard UEFI driver - we would reconnect after loading - add to array
MemoryStopRecord msr; // DriversArr won't be deallocated because it's passed to RegisterDriversToHighestPriority that keeps it global.
if (DriversArrSize == 0) {
// new array
DriversArrSize = 16;
@ -2260,6 +2320,7 @@ static void LoadDrivers(void)
#else
ScanDriverDir(L"drivers32", &DriversToConnect, &DriversToConnectNum);
#endif
// DriversToConnect is allocated by ScanDriverDir, but DO NOT free it. RegisterDriversToHighestPriority will store it in the global var mPriorityDrivers.
VBiosPatchNeeded = gSettings.Graphics.PatchVBios || gSettings.Graphics.PatchVBiosBytes.getVBIOS_PATCH_BYTES_count() > 0;
if (VBiosPatchNeeded) {
@ -2622,11 +2683,11 @@ GetListOfThemes ()
}
//
// main entry point
// secondary main entry point
//
EFI_STATUS
EFIAPI
RefitMain (IN EFI_HANDLE ImageHandle,
RefitMainMain (IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
EFI_STATUS Status;
@ -2660,7 +2721,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
//#define DEBUG_ERALY_CRASH
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step1");
PauseForKey("press any key\n"_XS8);
// PauseForKey();
#endif
#ifdef DEBUG_ON_SERIAL_PORT
@ -2673,7 +2734,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step2");
PauseForKey("press any key\n"_XS8);
// PauseForKey();
#endif
// if ( !EFI_ERROR(Status) ) {
@ -2685,18 +2746,18 @@ RefitMain (IN EFI_HANDLE ImageHandle,
DBG("Clover ImageHandle = %llx\n", (uintptr_t)ImageHandle);
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step3");
PauseForKey("press any key\n"_XS8);
// PauseForKey();
#endif
}
#ifdef JIEF_DEBUG
gBS->Stall(2500000); // to give time to gdb to connect
// PauseForKey("press\n"_XS8);
gBS->Stall(5500000); // to give time to gdb to connect
// PauseForKey();
#endif
}
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step4");
PauseForKey("press any key\n"_XS8);
// PauseForKey();
#endif
#ifdef CLOVER_BUILD
@ -2705,11 +2766,13 @@ RefitMain (IN EFI_HANDLE ImageHandle,
construct_globals_objects(gImageHandle);
#endif
MemoryTrackerInstallHook();
gCPUStructure.TSCCalibr = GetMemLogTscTicksPerSecond(); //ticks for 1second
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step5");
PauseForKey("press any key\n"_XS8);
PauseForKey();
#endif
#ifdef JIEF_DEBUG
@ -2725,7 +2788,7 @@ RefitMain (IN EFI_HANDLE ImageHandle,
#ifdef DEBUG_ERALY_CRASH
SystemTable->ConOut->OutputString(SystemTable->ConOut, L"Step6");
PauseForKey("press any key\n"_XS8);
PauseForKey();
#endif
// firmware detection
@ -3149,7 +3212,9 @@ RefitMain (IN EFI_HANDLE ImageHandle,
gSettings.Boot.FastBoot = false; //Hmm... will never be here
}
#ifdef JIEF_DEBUG
MainMenu.TimeoutSeconds=60;
MainMenu.TimeoutSeconds=1;
DefaultEntry = NULL;
DefaultIndex = MainMenu.Entries.length()-1; // this should be "Exit Clover"
#endif
AfterTool = false;
gEvent = 0; //clear to cancel loop
@ -3458,6 +3523,9 @@ log_technical_bug("not done yet");
UninitializeConsoleSim ();
delete ThemeX; // do this before destruct_globals_objects()
FreePool(BlankLine); // Convert BlankLine to XStringW instead.
#ifdef CLOVER_BUILD
destruct_globals_objects(NULL);
#endif
@ -3465,4 +3533,27 @@ log_technical_bug("not done yet");
return EFI_SUCCESS;
}
//
// main entry point
//
EFI_STATUS
EFIAPI
RefitMain (IN EFI_HANDLE ImageHandle,
IN EFI_SYSTEM_TABLE *SystemTable)
{
MemoryTrackerInit();
EFI_STATUS Status = RefitMainMain(ImageHandle, SystemTable);
DBG("MT_alloc_count=%lld\n", MT_getAllocCount());
MT_outputDanglingPtr();
#ifdef TagStruct_COUNT_CACHEHIT
DBG("cache hits = %zu\n", TagStruct::cachehit);
DBG("cache miss = %zu\n", TagStruct::cachemiss);
#endif
return Status;
}

View File

@ -109,9 +109,6 @@ void FillInputs(XBool New)
tmp[40] = 0; //make it null-terminated
UINTN InputItemsCount = 0;
if (New) {
InputItems = new INPUT_ITEM[135];
}
InputItems[InputItemsCount].ItemType = ASString; //0
//even though Ascii we will keep value as Unicode to convert later