diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2009-06-24 20:14:10 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2009-06-24 20:14:10 +0300 |
commit | b317b218e2d383dd27a700094c0de4510540ea18 (patch) | |
tree | 1959c0771ea3da312d9956981d1af808b1af3fcc | |
parent | Cast a char argument to isspace() to unsigned char. (diff) | |
download | xz-b317b218e2d383dd27a700094c0de4510540ea18.tar.xz |
Support HW_PHYSMEM64
Diffstat (limited to '')
-rw-r--r-- | src/common/physmem.h | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/common/physmem.h b/src/common/physmem.h index d002d9df..25806512 100644 --- a/src/common/physmem.h +++ b/src/common/physmem.h @@ -59,19 +59,27 @@ physmem(void) ret = (uint64_t)(pagesize) * (uint64_t)(pages); #elif defined(HAVE_PHYSMEM_SYSCTL) - int name[2] = { CTL_HW, HW_PHYSMEM }; + int name[2] = { + CTL_HW, +#ifdef HW_PHYSMEM64 + HW_PHYSMEM64 +#else + HW_PHYSMEM +#endif + }; union { - unsigned long ul; - unsigned int ui; + uint32_t u32; + uint64_t u64; } mem; - size_t mem_ptr_size = sizeof(mem.ul); - if (!sysctl(name, 2, &mem.ul, &mem_ptr_size, NULL, NULL)) { - // Some systems use unsigned int as the "return value". - // This makes a difference on 64-bit boxes. - if (mem_ptr_size == sizeof(mem.ul)) - ret = mem.ul; - else if (mem_ptr_size == sizeof(mem.ui)) - ret = mem.ui; + size_t mem_ptr_size = sizeof(mem.u64); + if (!sysctl(name, 2, &mem.u64, &mem_ptr_size, NULL, NULL)) { + // IIRC, 64-bit "return value" is possible on some 64-bit + // BSD systems even with HW_PHYSMEM (instead of HW_PHYSMEM64), + // so support both. + if (mem_ptr_size == sizeof(mem.u64)) + ret = mem.u64; + else if (mem_ptr_size == sizeof(mem.u32)) + ret = mem.u32; } #elif defined(HAVE_PHYSMEM_SYSINFO) |