]> granicus.if.org Git - xz/commitdiff
Support HW_PHYSMEM64
authorLasse Collin <lasse.collin@tukaani.org>
Wed, 24 Jun 2009 17:14:10 +0000 (20:14 +0300)
committerLasse Collin <lasse.collin@tukaani.org>
Wed, 24 Jun 2009 17:14:10 +0000 (20:14 +0300)
src/common/physmem.h

index d002d9df39e77b29bbd355e56e899a9cca0ea8fd..258065124aa8ddc13653b09ca9868e232d08135d 100644 (file)
@@ -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)