From 2a94d6e33faa8fe9b5de4bab7cc0523092c2cafa Mon Sep 17 00:00:00 2001 From: KWSys Upstream Date: Thu, 5 Nov 2026 09:26:48 -0500 Subject: [PATCH] KWSys 2026-11-05 (3f6dbdae) Code extracted from: https://gitlab.kitware.com/utils/kwsys.git at commit 3f6dbdae567f1cfb6a459359825677d106db6362 (master). Upstream Shortlog ----------------- Aymeric Wibo (2): 10b37500 SystemInformation: Fix reading hw.physmem on FreeBSD & DragonFly 642ccce9 SystemInformation: Implement getting available memory on FreeBSD --- SystemInformation.cxx | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 43c45f72b5..467450658f 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -5395,6 +5395,8 @@ bool SystemInformationImplementation::QueryBSDMemory() # if defined(HW_PHYSMEM64) int64_t k; ctrl[1] = HW_PHYSMEM64; +# elif defined(__FreeBSD__) || defined(__DragonFly__) + unsigned long k; # else int k; # endif @@ -5406,6 +5408,21 @@ bool SystemInformationImplementation::QueryBSDMemory() this->TotalPhysicalMemory = k >> 10 >> 10; +# if defined(__FreeBSD__) + u_int freeCount; + u_int pageSize; + sz = sizeof(freeCount); + if (sysctlbyname("vm.stats.vm.v_free_count", &freeCount, &sz, nullptr, 0) == + 0) { + sz = sizeof(pageSize); + if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &sz, nullptr, 0) == + 0) { + this->AvailablePhysicalMemory = + (static_cast(freeCount) * pageSize) >> 10 >> 10; + } + } +# endif + return true; #else return false;