Skip to content

Commit e5b83eb

Browse files
author
Requiem
committed
moved query for _OSI parameters and CPU signatures out of ACPI table enumeration loop
1 parent c5365c1 commit e5b83eb

File tree

1 file changed

+65
-58
lines changed

1 file changed

+65
-58
lines changed

src/vmaware.hpp

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8915,12 +8915,20 @@ struct VM {
89158915
SystemFirmwareTableInformation = 76
89168916
} SYSTEM_INFORMATION_CLASS;
89178917

8918-
typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION {
8918+
typedef enum _SYSTEM_FIRMWARE_TABLE_ACTION
8919+
{
8920+
SystemFirmwareTableEnumerate,
8921+
SystemFirmwareTableGet,
8922+
SystemFirmwareTableMax
8923+
} SYSTEM_FIRMWARE_TABLE_ACTION;
8924+
8925+
typedef struct _SYSTEM_FIRMWARE_TABLE_INFORMATION
8926+
{
89198927
ULONG ProviderSignature;
8920-
ULONG Action;
8928+
SYSTEM_FIRMWARE_TABLE_ACTION Action;
89218929
ULONG TableID;
89228930
ULONG TableBufferLength;
8923-
UCHAR TableBuffer[1];
8931+
_Field_size_bytes_(TableBufferLength) UCHAR TableBuffer[1];
89248932
} SYSTEM_FIRMWARE_TABLE_INFORMATION, * PSYSTEM_FIRMWARE_TABLE_INFORMATION;
89258933
#pragma warning (default : 4459)
89268934

@@ -8963,13 +8971,13 @@ struct VM {
89638971
return true;
89648972
};
89658973

8966-
auto query_table = [&](DWORD provider, ULONG tableID, bool rawEnum, PULONG outDataSize) -> PSYSTEM_FIRMWARE_TABLE_INFORMATION {
8974+
auto query_table = [&](DWORD provider, DWORD tableID, PULONG outDataSize) -> PSYSTEM_FIRMWARE_TABLE_INFORMATION {
89678975
const ULONG header = sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION);
89688976
if (!ensure_buffer(header)) return nullptr;
89698977

89708978
auto hdr = reinterpret_cast<PSYSTEM_FIRMWARE_TABLE_INFORMATION>(qsiBuffer);
89718979
hdr->ProviderSignature = provider;
8972-
hdr->Action = rawEnum ? 0 : 1;
8980+
hdr->Action = SystemFirmwareTableEnumerate;
89738981
hdr->TableID = _byteswap_ulong(tableID);
89748982
hdr->TableBufferLength = 0;
89758983

@@ -8982,7 +8990,7 @@ struct VM {
89828990

89838991
hdr = reinterpret_cast<PSYSTEM_FIRMWARE_TABLE_INFORMATION>(qsiBuffer);
89848992
hdr->ProviderSignature = provider;
8985-
hdr->Action = rawEnum ? 0 : 1;
8993+
hdr->Action = SystemFirmwareTableEnumerate;
89868994
hdr->TableID = _byteswap_ulong(tableID);
89878995
hdr->TableBufferLength = fullSize - header;
89888996

@@ -8993,9 +9001,9 @@ struct VM {
89939001
return hdr;
89949002
};
89959003

8996-
auto check_firmware_table = [&](DWORD signature, ULONG tableID) -> bool {
9004+
auto check_firmware_table = [&](DWORD signature, DWORD tableID) -> bool {
89979005
ULONG gotSize = 0;
8998-
auto info = query_table(signature, tableID, true, &gotSize);
9006+
auto info = query_table(signature, tableID, &gotSize);
89999007
if (!info) return false;
90009008

90019009
const UCHAR* buf = info->TableBuffer;
@@ -9038,7 +9046,7 @@ struct VM {
90389046

90399047
// ACPI enumeration
90409048
ULONG totalLen = 0;
9041-
auto listInfo = query_table(ACPI_SIG, 0UL, true, &totalLen);
9049+
auto listInfo = query_table(ACPI_SIG, 0UL, &totalLen);
90429050
if (!listInfo) {
90439051
free(qsiBuffer);
90449052
return false;
@@ -9053,7 +9061,7 @@ struct VM {
90539061
}
90549062

90559063
// count SSDT
9056-
const DWORD ssdtSig = 'TDSS';
9064+
constexpr DWORD ssdtSig = 'TDSS';
90579065
ULONG ssdtCount = 0;
90589066
for (ULONG i = 0; i < tableCount; ++i) {
90599067
if (tables[i] == ssdtSig)
@@ -9066,14 +9074,13 @@ struct VM {
90669074
return true;
90679075
}
90689076

9069-
// iterate all ACPI tables
9070-
constexpr DWORD dsdtSig = 'TDSD';
90719077
constexpr DWORD facpSig = 'PCAF';
90729078
for (ULONG i = 0; i < tableCount; ++i) {
9073-
DWORD sig = tables[i];
9079+
ULONG sig = tables[i];
9080+
90749081
if (sig == facpSig) {
90759082
ULONG fSize = 0;
9076-
auto fadt = query_table(ACPI_SIG, sig, false, &fSize);
9083+
auto fadt = query_table(ACPI_SIG, sig, &fSize);
90779084
if (!fadt) continue;
90789085
BYTE* buf = reinterpret_cast<BYTE*>(fadt->TableBuffer);
90799086
// https://uefi.org/htmlspecs/ACPI_Spec_6_4_html/05_ACPI_Software_Programming_Model/ACPI_Software_Programming_Model.html#preferred-pm-profile-system-types
@@ -9082,56 +9089,56 @@ struct VM {
90829089
return true;
90839090
}
90849091
}
9085-
if (sig == dsdtSig) {
9086-
ULONG dsdtSize = 0;
9087-
auto dsdt = query_table(ACPI_SIG, sig, false, &dsdtSize);
9088-
if (dsdt) {
9089-
const char* tb = reinterpret_cast<const char*>(dsdt->TableBuffer);
9090-
bool foundCPU = false;
9091-
9092-
for (ULONG j = 0; j + 8 <= dsdtSize; ++j) {
9093-
if (memcmp(tb + j, "ACPI0007", 8) == 0) { // idea by dmfrpro
9094-
foundCPU = true;
9095-
break;
9096-
}
9097-
}
9092+
if (check_firmware_table(ACPI_SIG, sig)) {
9093+
free(qsiBuffer);
9094+
return true;
9095+
}
9096+
}
90989097

9099-
if (!foundCPU) {
9100-
free(qsiBuffer);
9101-
return true;
9102-
}
9098+
constexpr DWORD dsdtSig = 'DSDT';
9099+
ULONG dsdtSize = 0;
9100+
auto dsdt = query_table(ACPI_SIG, dsdtSig, &dsdtSize);
9101+
if (dsdt) {
9102+
const char* tb = reinterpret_cast<const char*>(dsdt->TableBuffer);
9103+
bool foundCPU = false;
91039104

9104-
constexpr const char* osi_targets[] = {
9105-
"Windows 95", "Windows 98",
9106-
"Windows 2000", "Windows 2000.1",
9107-
"Windows ME: Millennium Edition",
9108-
"Windows ME: Millennium Edition", // some firmwares omit space
9109-
"Windows XP", "Windows 2001",
9110-
"Windows 2006", "Windows 2009",
9111-
"Windows 2012", "Windows 2015",
9112-
"Windows 2020", "Windows 2022",
9113-
};
9114-
constexpr size_t n_osi = sizeof(osi_targets) / sizeof(osi_targets[0]);
9115-
9116-
bool foundOSI = false;
9117-
for (size_t t = 0; t < n_osi && !foundOSI; ++t) {
9118-
const char* s = osi_targets[t];
9119-
size_t len = strlen(s);
9120-
for (ULONG j = 0; j + len <= dsdtSize; ++j) {
9121-
if (memcmp(tb + j, s, len) == 0) {
9122-
foundOSI = true;
9123-
break;
9124-
}
9125-
}
9126-
}
9105+
for (ULONG j = 0; j + 8 <= dsdtSize; ++j) {
9106+
if (memcmp(tb + j, "ACPI0007", 8) == 0) { // idea by dmfrpro
9107+
foundCPU = true;
9108+
break;
9109+
}
9110+
}
91279111

9128-
if (!foundOSI) {
9129-
free(qsiBuffer);
9130-
return true;
9112+
if (!foundCPU) {
9113+
free(qsiBuffer);
9114+
return true;
9115+
}
9116+
9117+
constexpr const char* osi_targets[] = {
9118+
"Windows 95", "Windows 98",
9119+
"Windows 2000", "Windows 2000.1",
9120+
"Windows ME: Millennium Edition",
9121+
"Windows ME: Millennium Edition", // some firmwares omit space
9122+
"Windows XP", "Windows 2001",
9123+
"Windows 2006", "Windows 2009",
9124+
"Windows 2012", "Windows 2015",
9125+
"Windows 2020", "Windows 2022",
9126+
};
9127+
constexpr size_t n_osi = sizeof(osi_targets) / sizeof(osi_targets[0]);
9128+
9129+
bool foundOSI = false;
9130+
for (size_t t = 0; t < n_osi && !foundOSI; ++t) {
9131+
const char* s = osi_targets[t];
9132+
size_t len = strlen(s);
9133+
for (ULONG j = 0; j + len <= dsdtSize; ++j) {
9134+
if (memcmp(tb + j, s, len) == 0) {
9135+
foundOSI = true;
9136+
break;
91319137
}
91329138
}
91339139
}
9134-
if (check_firmware_table(ACPI_SIG, sig)) {
9140+
9141+
if (!foundOSI) {
91359142
free(qsiBuffer);
91369143
return true;
91379144
}

0 commit comments

Comments
 (0)