Skip to content

Commit

Permalink
sysinfo: Add memory size detection support for GNU/Hurd
Browse files Browse the repository at this point in the history
  • Loading branch information
pinotree authored and ximion committed Sep 15, 2024
1 parent d4fbd56 commit 5665141
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/as-system-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
#include <sys/types.h>
#include <sys/sysctl.h>
#elif defined(__GNU__)
#include <mach/mach.h>
#include <mach/host_info.h>
#include <mach/mach_host.h>
#endif
#ifdef HAVE_SYSTEMD
#include <systemd/sd-hwdb.h>
Expand Down Expand Up @@ -498,6 +502,15 @@ as_get_physical_memory_total (void)
statex.dwLength = sizeof (statex);
GlobalMemoryStatusEx (&statex);
return statex.ullTotalPhys / (1024 * 1024);
#elif defined(__GNU__)
host_basic_info_data_t hbi;
mach_msg_type_number_t cnt = HOST_BASIC_INFO_COUNT;
int err = host_info (mach_host_self (), HOST_BASIC_INFO, (host_info_t) &hbi, &cnt);
if (err != 0) {
g_warning ("Unable to determine physical memory size: %s", g_strerror (err));
return 0;
}
return hbi.memory_size / MB_IN_BYTES;
#else
#error "Implementation of as_get_physical_memory_total() missing for this OS."
#endif
Expand Down

0 comments on commit 5665141

Please sign in to comment.