From 9c870a57f0e7979f652cf29fb1bb0b7c0f7201ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sat, 27 Dec 2025 15:57:20 +0800 Subject: [PATCH] PhysicalMemory (macOS): improves performance on Apple Silicon --- .../physicalmemory/physicalmemory_apple.m | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/src/detection/physicalmemory/physicalmemory_apple.m b/src/detection/physicalmemory/physicalmemory_apple.m index 243b35aca..b7b25d528 100644 --- a/src/detection/physicalmemory/physicalmemory_apple.m +++ b/src/detection/physicalmemory/physicalmemory_apple.m @@ -2,6 +2,7 @@ #include "common/processing.h" #include "util/smbiosHelper.h" #include "util/stringUtils.h" +#include "util/apple/cf_helpers.h" #import @@ -64,7 +65,7 @@ static void appendDevice( } } -const char* ffDetectPhysicalMemory(FFlist* result) +static const char* detectFromSystemProfiler(FFlist* result) { FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate(); if (ffProcessAppendStdOut(&buffer, (char* const[]) { @@ -119,3 +120,43 @@ const char* ffDetectPhysicalMemory(FFlist* result) return NULL; } + +FF_MAYBE_UNUSED static const char* detectFromIokit(FFlist* result) +{ + FF_IOOBJECT_AUTO_RELEASE io_registry_entry_t entryDevice = IORegistryEntryFromPath(kIOMainPortDefault, "IODeviceTree:/chosen"); + if (!entryDevice) + return "IORegistryEntryFromPath() failed"; + + FF_CFTYPE_AUTO_RELEASE CFTypeRef dramType = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-type"), kCFAllocatorDefault, 0); + FF_CFTYPE_AUTO_RELEASE CFTypeRef dramSize = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-size"), kCFAllocatorDefault, 0); + FF_CFTYPE_AUTO_RELEASE CFTypeRef dramVendor = IORegistryEntryCreateCFProperty(entryDevice, CFSTR("dram-vendor"), kCFAllocatorDefault, 0); + if (!dramType || !dramSize || !dramVendor) + return "IORegistryEntryCreateCFProperty() failed"; + + FFPhysicalMemoryResult* device = ffListAdd(result); + ffStrbufInit(&device->type); + ffStrbufInit(&device->formFactor); + ffStrbufInit(&device->locator); + ffStrbufInit(&device->vendor); + ffStrbufInit(&device->serial); + ffStrbufInit(&device->partNumber); + device->size = 0; + device->maxSpeed = 0; + device->runningSpeed = 0; + device->ecc = false; + + ffCfStrGetString(dramType, &device->type); + ffCfStrGetString(dramVendor, &device->vendor); + ffCfNumGetInt64(dramSize, (int64_t*) &device->size); + return NULL; +} + +const char* ffDetectPhysicalMemory(FFlist* result) +{ + #if __aarch64__ + if (detectFromIokit(result) == NULL) + return NULL; + #endif + + return detectFromSystemProfiler(result); +}