From df0916ecf8f043441c0b1c331117c54d2c8e4819 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sat, 8 Jan 2022 16:05:31 +0100 Subject: [PATCH] Mac: Fix RAM detection for >2GB Sys_GetSystemRam() for OSX used some deprecated MacOS function from 1989 that used int32 for the amount of bytes. Now using sysctl() instead, should be supported since at least 10.2.8 at least it's in https://github.com/phracker/MacOSX-SDKs/blob/master/MacOSX10.2.8.sdk/usr/include/sys/sysctl.h --- neo/sys/osx/DOOMController.mm | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/neo/sys/osx/DOOMController.mm b/neo/sys/osx/DOOMController.mm index e10e4d7e..8cc45f9f 100644 --- a/neo/sys/osx/DOOMController.mm +++ b/neo/sys/osx/DOOMController.mm @@ -36,6 +36,10 @@ If you have questions concerning this license or the applicable additional terms #include #include "sys/platform.h" + +#include +#include + #include "idlib/Str.h" #include "framework/Common.h" @@ -91,10 +95,16 @@ returns in megabytes ================ */ int Sys_GetSystemRam( void ) { - SInt32 ramSize; - - if ( Gestalt( gestaltPhysicalRAMSize, &ramSize ) == noErr ) { - return ramSize / (1024*1024); + // from https://discussions.apple.com/thread/1775836?answerId=8396559022#8396559022 + // should work (at least) from the Mac OSX 10.2.8 SDK on + int mib[2]; + uint64_t memsize; + size_t len; + mib[0] = CTL_HW; + mib[1] = HW_MEMSIZE; /* uint64_t: physical ram size */ + len = sizeof(memsize); + if(sysctl(mib, 2, &memsize, &len, NULL, 0) == 0) { + return (int)(memsize / (1024*1024)); } else return 1024;