From 92d70f4167222b5d61728d9443e8d72207e96d50 Mon Sep 17 00:00:00 2001 From: nia Date: Sun, 12 Nov 2023 20:22:23 +0100 Subject: [PATCH] cpuinfo: Fix detection of physical memory above 2GB on NetBSD Rework the code to clearly prefer 64-bit sysctls first, then legacy sysctls, and eliminate a second ifdef. Signed-off-by: Nia Alarie (cherry picked from commit 69cae07cc1c216e35ddf3df98048378ad7aeaf92) --- src/cpuinfo/SDL_cpuinfo.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c index bdc6b3e0b..c5f1eb4a6 100644 --- a/src/cpuinfo/SDL_cpuinfo.c +++ b/src/cpuinfo/SDL_cpuinfo.c @@ -1079,16 +1079,19 @@ int SDL_GetSystemRAM(void) #endif #ifdef HAVE_SYSCTLBYNAME if (SDL_SystemRAM <= 0) { -#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__) || defined(__DragonFly__) -#ifdef HW_REALMEM +#ifdef HW_PHYSMEM64 + /* (64-bit): NetBSD since 2003, OpenBSD */ + int mib[2] = { CTL_HW, HW_PHYSMEM64 }; +#elif defined(HW_REALMEM) + /* (64-bit): FreeBSD since 2005, DragonFly */ int mib[2] = { CTL_HW, HW_REALMEM }; -#else - /* might only report up to 2 GiB */ - int mib[2] = { CTL_HW, HW_PHYSMEM }; -#endif /* HW_REALMEM */ -#else +#elif defined(HW_MEMSIZE) + /* (64-bit): Darwin */ int mib[2] = { CTL_HW, HW_MEMSIZE }; -#endif /* __FreeBSD__ || __FreeBSD_kernel__ */ +#else + /* (32-bit): very old BSD, might only report up to 2 GiB */ + int mib[2] = { CTL_HW, HW_PHYSMEM }; +#endif /* HW_PHYSMEM64 */ Uint64 memsize = 0; size_t len = sizeof(memsize);