From ad06ef0efbf7cafba5074a183fef1ad586f38caa Mon Sep 17 00:00:00 2001 From: Alex Bennée Date: Fri, 24 Jul 2020 07:44:57 +0100 Subject: util: add qemu_get_host_physmem utility function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used in a future patch. For POSIX systems _SC_PHYS_PAGES isn't standardised but at least appears in the man pages for Open/FreeBSD. The result is advisory so any users of it shouldn't just fail if we can't work it out. The win32 stub currently returns 0 until someone with a Windows system can develop and test a patch. Signed-off-by: Alex Bennée Reviewed-by: Richard Henderson Cc: BALATON Zoltan Cc: Christian Ehrhardt Message-Id: <20200724064509.331-5-alex.bennee@linaro.org> --- util/oslib-posix.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'util/oslib-posix.c') diff --git a/util/oslib-posix.c b/util/oslib-posix.c index d923674624..ad8001a4ad 100644 --- a/util/oslib-posix.c +++ b/util/oslib-posix.c @@ -841,3 +841,18 @@ char *qemu_get_host_name(Error **errp) return g_steal_pointer(&hostname); } + +size_t qemu_get_host_physmem(void) +{ +#ifdef _SC_PHYS_PAGES + long pages = sysconf(_SC_PHYS_PAGES); + if (pages > 0) { + if (pages > SIZE_MAX / qemu_real_host_page_size) { + return SIZE_MAX; + } else { + return pages * qemu_real_host_page_size; + } + } +#endif + return 0; +} -- cgit 1.4.1