mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-02 04:15:46 +00:00
virhostmem: Get total memory on macOS properly
Problem with HW_PHYSMEM sysctl on 64-bit macOS is that it returns a 32-bit signed value. Thus it overflows. Switching to HW_MEMSIZE is recommended as it's of an uint_64 type [1]. 1: https://github.com/apple-oss-distributions/xnu/blob/xnu-10002.1.13/bsd/sys/sysctl.h Reported-by: Jaroslav Suchanek <jsuchane@redhat.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
bbb2332f7e
commit
69cdb11fba
@ -617,7 +617,10 @@ virHostMemGetTotal(void)
|
||||
unsigned long long physmem = 0;
|
||||
size_t len = sizeof(physmem);
|
||||
|
||||
if (sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) < 0) {
|
||||
/* On macOS hw.physmem is int32_t which doesn't fly with >4GiB of memory.
|
||||
* But hw.memsize is uint64_t. */
|
||||
if (sysctlbyname("hw.memsize", &physmem, &len, NULL, 0) < 0 &&
|
||||
sysctlbyname("hw.physmem", &physmem, &len, NULL, 0) < 0) {
|
||||
virReportSystemError(errno, "%s",
|
||||
_("Unable to query memory total"));
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user