Add support for older DMI formats on Linux.

This commit is contained in:
XMRig 2021-01-18 22:56:57 +07:00
parent 05e6f66169
commit 3b8d081c8c
No known key found for this signature in database
GPG key ID: 446A53638BE94409
5 changed files with 72 additions and 14 deletions

View file

@ -129,7 +129,7 @@ static void print_memory()
const double percent = freeMem > 0 ? ((totalMem - freeMem) / totalMem * 100.0) : 100.0;
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%.1f/%.1f GB") BLACK_BOLD(" (%.0f%%)"),
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%.1f/%.1f") CYAN(" GB") BLACK_BOLD(" (%.0f%%)"),
"MEMORY",
(totalMem - freeMem) / oneGiB,
totalMem / oneGiB,
@ -148,11 +148,11 @@ static void print_memory()
}
if (!memory.size()) {
Log::print(WHITE_BOLD(" %-13s") WHITE_BOLD("%s: ") BLACK_BOLD("<empty>"), "", memory.slot().data());
Log::print(WHITE_BOLD(" %-13s") "%s: " BLACK_BOLD("<empty>"), "", memory.slot().data());
continue;
}
Log::print(WHITE_BOLD(" %-13s") WHITE_BOLD("%s: ") CYAN_BOLD("%" PRIu64 " GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"),
Log::print(WHITE_BOLD(" %-13s") "%s: " CYAN_BOLD("%" PRIu64) CYAN(" GB ") WHITE_BOLD("%s @ %" PRIu64 " MHz ") BLACK_BOLD("%s"),
"", memory.slot().data(), memory.size() / oneGiB, memory.type(), memory.speed() / 1000000ULL, memory.product().data());
}

View file

@ -38,6 +38,16 @@ static void dmi_get_header(dmi_header *h, uint8_t *data)
} // namespace xmrig
bool xmrig::DmiReader::decode(uint8_t *buf, const Cleanup &cleanup)
{
const bool rc = decode(buf);
cleanup();
return rc;
}
bool xmrig::DmiReader::decode(uint8_t *buf)
{
if (!buf) {

View file

@ -26,6 +26,9 @@
#include "hw/dmi/DmiMemory.h"
#include <functional>
namespace xmrig {
@ -42,6 +45,9 @@ public:
bool read();
private:
using Cleanup = std::function<void()>;
bool decode(uint8_t *buf, const Cleanup &cleanup);
bool decode(uint8_t *buf);
DmiBoard m_board;

View file

@ -157,7 +157,46 @@ static uint8_t *smbios3_decode(uint8_t *buf, const char *devmem, uint32_t &size,
size = dmi_get<uint32_t>(buf + 0x0C);
const u64 offset = dmi_get<u64>(buf + 0x10);
return dmi_table(((off_t)offset.h << 32) | offset.l, size, devmem, flags);;
return dmi_table(((off_t)offset.h << 32) | offset.l, size, devmem, flags);
}
static uint8_t *smbios_decode(uint8_t *buf, const char *devmem, uint32_t &size, uint32_t &version, uint32_t flags)
{
if (buf[0x05] > 0x20 || !checksum(buf, buf[0x05]) || memcmp(buf + 0x10, "_DMI_", 5) != 0 || !checksum(buf + 0x10, 0x0F)) {
return nullptr;
}
version = (buf[0x06] << 8) + buf[0x07];
switch (version) {
case 0x021F:
case 0x0221:
version = 0x0203;
break;
case 0x0233:
version = 0x0206;
break;
}
version = version << 8;
size = dmi_get<uint16_t>(buf + 0x16);
return dmi_table(dmi_get<uint32_t>(buf + 0x18), size, devmem, flags);
}
static uint8_t *legacy_decode(uint8_t *buf, const char *devmem, uint32_t &size, uint32_t &version, uint32_t flags)
{
if (!checksum(buf, 0x0F)) {
return nullptr;
}
version = ((buf[0x0E] & 0xF0) << 12) + ((buf[0x0E] & 0x0F) << 8);
size = dmi_get<uint16_t>(buf + 0x06);
return dmi_table(dmi_get<uint32_t>(buf + 0x08), size, devmem, flags);
}
@ -175,14 +214,18 @@ bool xmrig::DmiReader::read()
if (size >= 24 && memcmp(buf, "_SM3_", 5) == 0) {
smb = smbios3_decode(buf, kSysTableFile, m_size, m_version, FLAG_NO_FILE_OFFSET);
}
else if (size >= 31 && memcmp(buf, "_SM_", 4) == 0) {
smb = smbios_decode(buf, kSysTableFile, m_size, m_version, FLAG_NO_FILE_OFFSET);
}
else if (size >= 15 && memcmp(buf, "_DMI_", 5) == 0) {
smb = legacy_decode(buf, kSysTableFile, m_size, m_version, FLAG_NO_FILE_OFFSET);
}
if (smb) {
decode(smb);
free(smb);
free(buf);
return true;
return decode(smb, [smb, buf]() {
free(smb);
free(buf);
});
}
}

View file

@ -62,8 +62,7 @@ bool xmrig::DmiReader::read()
m_version = (smb->SMBIOSMajorVersion << 16) + (smb->SMBIOSMinorVersion << 8) + smb->DmiRevision;
m_size = smb->Length;
const bool rc = decode(smb->SMBIOSTableData);
HeapFree(GetProcessHeap(), 0, smb);
return rc;
return decode(smb->SMBIOSTableData, [smb]() {
HeapFree(GetProcessHeap(), 0, smb);
});
}