[PATCH] KMemoryInfo: add basic GNU/Hurd support
authorPino Toscano <pino@kde.org>
Fri, 3 Jul 2026 06:31:51 +0000 (08:31 +0200)
committerPino Toscano <pino@debian.org>
Fri, 3 Jul 2026 08:39:09 +0000 (10:39 +0200)
Add a basic support for reading the memory details on GNU/Hurd.

The swap support is not implemented yet, as it requires a bit more work
(i.e. query the default pager); since there are no users of the swap
APIs currently, then it can be implemented at a later stage if needed.

Gbp-Pq: Name upstream_KMemoryInfo-add-basic-GNU-Hurd-support.patch

src/lib/util/kmemoryinfo.cpp

index 35b538411c59451bd3aefd4c3b1615947dadd197..2dd3ebd622a3c2628e5d3c20f1e1f2829f4692dd 100644 (file)
@@ -39,6 +39,13 @@ Q_LOGGING_CATEGORY(LOG_KMEMORYINFO, "kf.coreaddons.kmemoryinfo", QtWarningMsg)
      #include <stdlib.h>
      #include <strings.h>
      #include <unistd.h>
+#elif defined(Q_OS_HURD)
+     extern "C" {
+          #include <mach/mach.h>
+          #include <mach/vm_param.h>
+          #include <mach/mach_interface.h>
+          #include <mach/gnumach.h>
+     }
 #endif
 // clang-format on
 
@@ -512,6 +519,35 @@ bool KMemoryInfo::update()
 
     return true;
 }
+
+#elif defined(Q_OS_HURD)
+/*****************************************************************************
+ * GNU/Hurd
+ ****************************************************************************/
+
+bool KMemoryInfo::update()
+{
+    vm_statistics_data_t vmstats;
+    vm_cache_statistics_data_t cache_stats;
+
+    if (vm_statistics(mach_task_self(), &vmstats) != 0) {
+        return false;
+    }
+
+    if (vm_cache_statistics(mach_task_self(), &cache_stats) != 0) {
+        return false;
+    }
+
+    d->m_totalPhysical = static_cast<quint64>(vmstats.free_count + vmstats.active_count + vmstats.inactive_count + vmstats.wire_count) * PAGE_SIZE;
+    d->m_freePhysical = static_cast<quint64>(vmstats.free_count) * PAGE_SIZE;
+    d->m_totalSwapFile = 0; // TODO
+    d->m_freeSwapFile = 0; // TODO
+    d->m_cached = static_cast<quint64>(cache_stats.cache_count) * PAGE_SIZE;
+    d->m_buffers = 0;
+    d->m_availablePhysical = d->m_totalPhysical - d->m_freePhysical;
+
+    return true;
+}
 #else
 /*****************************************************************************
  * Unsupported platform