From 94941daf4fc31cd5be92a30369776aa7f262667f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Tue, 16 Dec 2025 10:41:15 +0800 Subject: [PATCH] Memory (macOS): uses `hw.memsize_usable` --- CHANGELOG.md | 1 + src/detection/memory/memory_apple.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 611464eb5..886a7e692 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Features: * Adds a `tempSensor` option to specify the sensor name used for CPU temperature detection (CPU) * Example: `{ "type": "cpu", "tempSensor": "hwmon0" /* Use /sys/class/hwmon/hwmon0 for temperature detection */ }` * Minor optimizations +* Reports usable RAM size to match other platforms (Memory, macOS) Bugfixes: * Fixes cache line size detection (CPU, macOS) diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c index cabdab267..812def5e8 100644 --- a/src/detection/memory/memory_apple.c +++ b/src/detection/memory/memory_apple.c @@ -8,8 +8,11 @@ const char* ffDetectMemory(FFMemoryResult* ram) { size_t length = sizeof(ram->bytesTotal); - if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0)) - return "Failed to read hw.memsize"; + if (sysctlbyname("hw.memsize_usable", &ram->bytesTotal, &length, NULL, 0) != 0) + { + if (sysctl((int[]){ CTL_HW, HW_MEMSIZE }, 2, &ram->bytesTotal, &length, NULL, 0) != 0) + return "Failed to read hw.memsize"; + } mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; vm_statistics64_data_t vmstat;