Global (macOS): queries SMBIOS data directly on Intel Mac

This commit is contained in:
Carter Li
2026-03-21 18:38:01 +08:00
parent a4bc3c812d
commit ab17fb08ef
4 changed files with 93 additions and 8 deletions
+66
View File
@@ -536,4 +536,70 @@ const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
return &table;
}
#elif defined(__APPLE__)
#include "common/apple/cf_helpers.h"
const FFSmbiosHeaderTable* ffGetSmbiosHeaderTable()
{
static CFDataRef smbiosDataBuffer;
static FFSmbiosHeaderTable table;
if (smbiosDataBuffer == NULL)
{
FF_DEBUG("Initializing SMBIOS buffer on Apple platform");
FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t registryEntry = IOServiceGetMatchingService(MACH_PORT_NULL, IOServiceMatching("AppleSMBIOS"));
if (!registryEntry)
{
FF_DEBUG("IOServiceGetMatchingService() failed to find AppleSMBIOS");
smbiosDataBuffer = CFDataCreate(NULL, NULL, 0);
return NULL;
}
FF_DEBUG("AppleSMBIOS service found, retrieving SMBIOS data");
smbiosDataBuffer = IORegistryEntryCreateCFProperty(registryEntry, CFSTR("SMBIOS"), kCFAllocatorDefault, kNilOptions);
if (!smbiosDataBuffer)
{
FF_DEBUG("IORegistryEntryCreateCFProperty() failed to get SMBIOS data");
smbiosDataBuffer = CFDataCreate(NULL, NULL, 0);
return NULL;
}
FF_DEBUG("Successfully retrieved SMBIOS data: %lu bytes", CFDataGetLength(smbiosDataBuffer));
FF_DEBUG("Parsing SMBIOS table structures");
FF_MAYBE_UNUSED int structureCount = 0;
for (
const FFSmbiosHeader* header = (const FFSmbiosHeader*) CFDataGetBytePtr(smbiosDataBuffer),
*end = (const FFSmbiosHeader*) ((const uint8_t*) header + CFDataGetLength(smbiosDataBuffer));
header < end;
header = ffSmbiosNextEntry(header)
)
{
if (header->Type < FF_SMBIOS_TYPE_END_OF_TABLE)
{
if (!table[header->Type]) {
table[header->Type] = header;
FF_DEBUG("Found SMBIOS structure type %u, handle 0x%04X, length %u",
header->Type, header->Handle, header->Length);
structureCount++;
}
}
else if (header->Type == FF_SMBIOS_TYPE_END_OF_TABLE) {
FF_DEBUG("Reached end-of-table marker");
break;
}
}
FF_DEBUG("Parsed %d SMBIOS structures", structureCount);
}
if (CFDataGetLength(smbiosDataBuffer) == 0)
{
FF_DEBUG("No valid SMBIOS data available");
return NULL;
}
return &table;
}
#endif