Refactor RT_VARIABLES as a class and RtVariables as a XObjArray.

Renamed RtVariables to BlockRtVariableArray.
This commit is contained in:
jief666 2020-08-31 09:22:21 +03:00
parent babba4de6e
commit 823e0efc9f
4 changed files with 27 additions and 19 deletions

View File

@ -67,7 +67,6 @@ EFI_GUID gDataHubPlatformGuid = {
extern EFI_GUID gDataHubPlatformGuid; extern EFI_GUID gDataHubPlatformGuid;
extern APPLE_SMC_IO_PROTOCOL *gAppleSmc; extern APPLE_SMC_IO_PROTOCOL *gAppleSmc;
extern UINTN RtVariablesNum;
typedef union { typedef union {
@ -175,11 +174,11 @@ OvrSetVariable(
EFI_STATUS Status; EFI_STATUS Status;
UINTN i; UINTN i;
for (i = 0; i < RtVariablesNum; i++) { for (i = 0; i < BlockRtVariableArray.size(); i++) {
if (!CompareGuid(&RtVariables[i].VarGuid, VendorGuid)) { if (!CompareGuid(&BlockRtVariableArray[i].VarGuid, VendorGuid)) {
continue; continue;
} }
if (!RtVariables[i].Name || RtVariables[i].Name[0] == L'*' || StrCmp(VariableName, RtVariables[i].Name) == 0) { if (BlockRtVariableArray[i].Name.isEmpty() || BlockRtVariableArray[i].Name[0] == L'*' || BlockRtVariableArray[i].Name == LStringW(VariableName) ) {
return EFI_SUCCESS; return EFI_SUCCESS;
} }
} }
@ -218,7 +217,7 @@ SetVariablesForOSX(LOADER_ENTRY *Entry)
// //
// firmware Variables // firmware Variables
// //
if (RtVariablesNum > 0) { if (BlockRtVariableArray.size() > 0) {
OvrRuntimeServices(gRT); OvrRuntimeServices(gRT);
} }

View File

@ -103,8 +103,7 @@ UINTN DsdtsNum = 0;
CHAR16 *DsdtsList[20]; CHAR16 *DsdtsList[20];
UINTN AudioNum; UINTN AudioNum;
HDA_OUTPUTS AudioList[20]; HDA_OUTPUTS AudioList[20];
UINTN RtVariablesNum; XObjArray<RT_VARIABLES> BlockRtVariableArray;
RT_VARIABLES *RtVariables;
// firmware // firmware
BOOLEAN gFirmwareClover = FALSE; BOOLEAN gFirmwareClover = FALSE;
@ -5808,8 +5807,9 @@ GetUserSettings(const TagDict* CfgDict)
if (BlockArray != NULL) { if (BlockArray != NULL) {
INTN i; INTN i;
INTN Count = BlockArray->arrayContent().size(); INTN Count = BlockArray->arrayContent().size();
RtVariablesNum = 0; BlockRtVariableArray.setEmpty();
RtVariables = (__typeof__(RtVariables))AllocateZeroPool(Count * sizeof(RT_VARIABLES)); RT_VARIABLES* RtVariablePtr = new RT_VARIABLES();
RT_VARIABLES& RtVariable = *RtVariablePtr;
for (i = 0; i < Count; i++) { for (i = 0; i < Count; i++) {
CfgDict = BlockArray->dictElementAt(i, "Block"_XS8); CfgDict = BlockArray->dictElementAt(i, "Block"_XS8);
const TagStruct* Prop2 = CfgDict->propertyForKey("Comment"); const TagStruct* Prop2 = CfgDict->propertyForKey("Comment");
@ -5833,7 +5833,7 @@ GetUserSettings(const TagDict* CfgDict)
}else{ }else{
if( Prop2->getString()->stringValue().notEmpty() ) { if( Prop2->getString()->stringValue().notEmpty() ) {
if (IsValidGuidAsciiString(Prop2->getString()->stringValue())) { if (IsValidGuidAsciiString(Prop2->getString()->stringValue())) {
StrToGuidLE(Prop2->getString()->stringValue(), &RtVariables[RtVariablesNum].VarGuid); StrToGuidLE(Prop2->getString()->stringValue(), &RtVariable.VarGuid);
}else{ }else{
DBG("Error: invalid GUID for RT var '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n", Prop->getString()->stringValue().c_str()); DBG("Error: invalid GUID for RT var '%s' - should be in the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n", Prop->getString()->stringValue().c_str());
} }
@ -5842,17 +5842,17 @@ GetUserSettings(const TagDict* CfgDict)
} }
Prop2 = CfgDict->propertyForKey("Name"); Prop2 = CfgDict->propertyForKey("Name");
RtVariables[RtVariablesNum].Name = NULL; RtVariable.Name.setEmpty();
if ( Prop2 != NULL ) { if ( Prop2 != NULL ) {
if ( !Prop2->isString() ) { if ( !Prop2->isString() ) {
MsgLog("ATTENTION : property not string in Block/Name\n"); MsgLog("ATTENTION : property not string in Block/Name\n");
}else{ }else{
if( Prop2->getString()->stringValue().notEmpty() ) { if( Prop2->getString()->stringValue().notEmpty() ) {
snwprintf(RtVariables[RtVariablesNum].Name, 64, "%s", Prop2->getString()->stringValue().c_str()); RtVariable.Name = Prop2->getString()->stringValue();
} }
} }
} }
RtVariablesNum++; BlockRtVariableArray.AddReference(RtVariablePtr, true);
} }
} }
} }

View File

@ -702,13 +702,21 @@ public:
~SIDELOAD_KEXT() { delete Next; delete PlugInList; } ~SIDELOAD_KEXT() { delete Next; delete PlugInList; }
}; };
typedef struct RT_VARIABLES RT_VARIABLES; class RT_VARIABLES
struct RT_VARIABLES { {
// BOOLEAN Disabled; public:
CHAR16 *Name; XStringW Name;
EFI_GUID VarGuid; EFI_GUID VarGuid;
RT_VARIABLES() : Name(), VarGuid{0} {};
RT_VARIABLES(const RT_VARIABLES& other) = delete; // Can be defined if needed
const RT_VARIABLES& operator = ( const RT_VARIABLES & ) = delete; // Can be defined if needed
~RT_VARIABLES() { }
}; };
extern RT_VARIABLES *RtVariables;
extern XObjArray<RT_VARIABLES> BlockRtVariableArray;
extern UINTN AudioNum; extern UINTN AudioNum;
extern HDA_OUTPUTS AudioList[20]; extern HDA_OUTPUTS AudioList[20];

View File

@ -8,7 +8,8 @@ const char* config_all =
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> \ <!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"> \
<plist version=\"1.0\"> \ <plist version=\"1.0\"> \
<dict> \ <dict> \
<key>ACPI</key> \ <key>Test null data</key> \
<data></data> \
<dict> \ <dict> \
<key>AutoMerge</key> \ <key>AutoMerge</key> \
<true/> \ <true/> \