diff options
author | Christoph Egger <Christoph.Egger@amd.com> | 2011-01-27 19:03:42 +0000 |
---|---|---|
committer | Christoph Egger <Christoph.Egger@amd.com> | 2011-01-27 19:03:42 +0000 |
commit | e46432026803ad6f750db3b448d962dc20c656e9 (patch) | |
tree | 2610b0faf51f482de46c85cb623076ff65bee2d7 /tools/libxc/xc_linux.c | |
parent | 921fb156d4bd70020211e377207f52e06cb12e16 (diff) | |
download | xen-e46432026803ad6f750db3b448d962dc20c656e9.tar.gz xen-e46432026803ad6f750db3b448d962dc20c656e9.tar.bz2 xen-e46432026803ad6f750db3b448d962dc20c656e9.zip |
libxc: break xc_get_physmem out into os-dependent files
NetBSD doesn't have sysconf(_SC_PHYS_PAGES).
Factor physmem() out into os-dependent files and rename it to
xc_get_physmem() so as not to pollute the namespace.
Signed-off-by: Christoph Egger <Christoph.Egger@amd.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
Committed-by: Ian Jackson <ian.jackson@eu.citrix.com>
Diffstat (limited to 'tools/libxc/xc_linux.c')
-rw-r--r-- | tools/libxc/xc_linux.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/libxc/xc_linux.c b/tools/libxc/xc_linux.c index 9acf27573e..66b055cbe4 100644 --- a/tools/libxc/xc_linux.c +++ b/tools/libxc/xc_linux.c @@ -55,6 +55,27 @@ void discard_file_cache(xc_interface *xch, int fd, int flush) errno = saved_errno; } +uint64_t xc_get_physmem(void) +{ + uint64_t ret = 0; + const long pagesize = sysconf(_SC_PAGESIZE); + const long pages = sysconf(_SC_PHYS_PAGES); + + if ( (pagesize != -1) || (pages != -1) ) + { + /* + * According to docs, pagesize * pages can overflow. + * Simple case is 32-bit box with 4 GiB or more RAM, + * which may report exactly 4 GiB of RAM, and "long" + * being 32-bit will overflow. Casting to uint64_t + * hopefully avoids overflows in the near future. + */ + ret = (uint64_t)(pagesize) * (uint64_t)(pages); + } + + return ret; +} + /* * Local variables: * mode: C |