`sysconf(_SC_PHYS_PAGES)` returns an error for i386 Mac binaries on any machine with more than 4 GB of RAM. From [the source code](https://github.com/apple-oss-distributions/Libc/blob/c5a3293354e22262702a3ad...) it's clear why--it calls `sysctlbyname()` to put the `hw.memsize` sysctl into a long, which is only 32-bits on i386. This returns an error on any Mac with more than 4GB: the value is too large for a 32-bit long.
The `sysctl` man page documents that an int64 should be used for `hw.memsize`, do that and divide by the page size ourselves.
From: Brendan Shanks bshanks@codeweavers.com
--- dlls/ntdll/unix/virtual.c | 9 +++++++++ 1 file changed, 9 insertions(+)
diff --git a/dlls/ntdll/unix/virtual.c b/dlls/ntdll/unix/virtual.c index 464f343a575..75e6319c007 100644 --- a/dlls/ntdll/unix/virtual.c +++ b/dlls/ntdll/unix/virtual.c @@ -3329,6 +3329,15 @@ void virtual_get_system_info( SYSTEM_BASIC_INFORMATION *info, BOOL wow64 ) ULONG64 total = (ULONG64)sinfo.totalram * sinfo.mem_unit; info->MmHighestPhysicalPage = max(1, total / page_size); } +#elif defined(__APPLE__) + /* sysconf(_SC_PHYS_PAGES) is buggy on macOS: in a 32-bit process, it + * returns an error on Macs with >4GB of RAM. + */ + INT64 memsize; + size_t len = sizeof(memsize); + + if (!sysctlbyname( "hw.memsize", &memsize, &len, NULL, 0 )) + info->MmHighestPhysicalPage = max(1, memsize / page_size); #elif defined(_SC_PHYS_PAGES) LONG64 phys_pages = sysconf( _SC_PHYS_PAGES );