Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sysinfo: Add memory size detection support for GNU/Hurd #658

Merged
merged 1 commit into from
Sep 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading