From 425d79417fac00150a5de8b6621985da978fcd41 Mon Sep 17 00:00:00 2001 From: Sergey Fedorov Date: Fri, 7 Aug 2026 03:17:35 +0000 Subject: [PATCH 28/38] memory (Apple): fall back to 32-bit host_statistics() on old/PowerPC targets host_statistics64()/vm_statistics64_data_t require a newer Mach API; use the 32-bit host_statistics()/vm_statistics_data_t pair together with the pre-10.7 available-pages formula on __i386__/__ppc__ or when targeting macOS below 10.6/10.7. Ported from https://github.com/macos-powerpc/powerpc-ports/blob/main/sysutils/fastfetch/files/0006-memory_apple-fix-for-32-bit.patch --- src/detection/memory/memory_apple.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/detection/memory/memory_apple.c b/src/detection/memory/memory_apple.c index b4f926467..51a84f036 100644 --- a/src/detection/memory/memory_apple.c +++ b/src/detection/memory/memory_apple.c @@ -5,6 +5,7 @@ #include #include #include +#include const char* ffDetectMemory(FFMemoryResult* ram) { size_t length = sizeof(ram->bytesTotal); @@ -19,17 +20,33 @@ const char* ffDetectMemory(FFMemoryResult* ram) { } #endif +#if defined(__i386__) || defined(__ppc__) || MAC_OS_X_VERSION_MIN_REQUIRED < 1060 + mach_msg_type_number_t count = HOST_VM_INFO_COUNT; + vm_statistics_data_t vmstat; + if(host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t) (&vmstat), &count) != KERN_SUCCESS) { + return "Failed to read host_statistics"; + } +#else mach_msg_type_number_t count = HOST_VM_INFO64_COUNT; vm_statistics64_data_t vmstat; if (host_statistics64(mach_host_self(), HOST_VM_INFO64, (host_info64_t) (&vmstat), &count) != KERN_SUCCESS) { return "Failed to read host_statistics64"; } - +#endif // https://github.com/st3fan/osx-10.9/blob/34e34a6a539b5a822cda4074e56a7ced9b57da71/system_cmds-597.1.1/vm_stat.tproj/vm_stat.c#L139 - +#if MAC_OS_X_VERSION_MIN_REQUIRED < 1070 + uint64_t pagesFree = vmstat.free_count; +#ifdef VM_STAT_HAS_SPECULATIVE_COUNT + if (count >= HOST_VM_INFO_REV2_COUNT) { + pagesFree -= vmstat.speculative_count; // speculative pages are included in free_count + } +#endif + uint64_t pagesAvailable = pagesFree + vmstat.inactive_count + vmstat.purgeable_count; + ram->bytesUsed = ram->bytesTotal - pagesAvailable * instance.state.platform.sysinfo.pageSize; +#else uint64_t pagesFree = vmstat.free_count - vmstat.speculative_count; uint64_t pagesFileBacked = vmstat.external_page_count; // Cached files ram->bytesUsed = ram->bytesTotal - (pagesFree + pagesFileBacked) * instance.state.platform.sysinfo.pageSize; - +#endif return nullptr; } -- 2.43.0