merge from gcc
[deliverable/binutils-gdb.git] / libiberty / physmem.c
index 2011f0251bd1a3df3667909ac8854e8a03260722..80fdd7975e929acc27e446b8cffabb7ae0209875 100644 (file)
@@ -15,7 +15,7 @@
    along with this program; if not, write to the Free Software Foundation,
    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
-/* Written by Paul Eggert and Jim Meyering.  */
+/* Written by Paul Eggert.  */
 
 #if HAVE_CONFIG_H
 # include <config.h>
 #endif
 
 #if HAVE_SYS_SYSMP_H
-#include <sys/sysmp.h>
+# include <sys/sysmp.h>
 #endif
 
 #if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H
-#  include <sys/sysinfo.h>
-#  include <machine/hal_sysinfo.h>
+# include <sys/sysinfo.h>
+# include <machine/hal_sysinfo.h>
 #endif
 
 #if HAVE_SYS_TABLE_H
-#  include <sys/table.h>
+# include <sys/table.h>
+#endif
+
+#include <sys/types.h>
+
+#if HAVE_SYS_PARAM_H
+# include <sys/param.h>
+#endif
+
+#if HAVE_SYS_SYSCTL_H
+# include <sys/sysctl.h>
+#endif
+
+#if HAVE_SYS_SYSTEMCFG_H
+# include <sys/systemcfg.h>
 #endif
 
 #include "libiberty.h"
@@ -73,7 +87,7 @@ physmem_total ()
 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
   { /* This works on irix6. */
     struct rminfo realmem;
-    if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == 0)
+    if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
       {
        double pagesize = sysconf (_SC_PAGESIZE);
        double pages = realmem.physmem;
@@ -98,6 +112,23 @@ physmem_total ()
   }
 #endif
 
+#if HAVE_SYSCTL && defined HW_PHYSMEM
+  { /* This works on *bsd and darwin.  */
+    unsigned int physmem;
+    size_t len = sizeof(physmem);
+    static int mib[2] = {CTL_HW, HW_PHYSMEM};
+
+    if (sysctl(mib, ARRAY_SIZE(mib), &physmem, &len, NULL, 0) == 0
+       && len == sizeof (physmem))
+      return (double)physmem;
+  }
+#endif
+
+#if HAVE__SYSTEM_CONFIGURATION
+  /* This works on AIX.  */
+  return _system_configuration.physmem;
+#endif
+
   /* Return 0 if we can't determine the value.  */
   return 0;
 }
@@ -133,7 +164,7 @@ physmem_available ()
 #if HAVE_SYSMP && defined MP_SAGET && defined MPSA_RMINFO && defined _SC_PAGESIZE
   { /* This works on irix6. */
     struct rminfo realmem;
-    if (sysmp(MP_SAGET, MPSA_RMINFO, &realmem, sizeof(realmem)) == 0)
+    if (sysmp (MP_SAGET, MPSA_RMINFO, &realmem, sizeof realmem) == 0)
       {
        double pagesize = sysconf (_SC_PAGESIZE);
        double pages = realmem.availrmem;
@@ -158,6 +189,18 @@ physmem_available ()
   }
 #endif
 
+#if HAVE_SYSCTL && defined HW_USERMEM
+  { /* This works on *bsd and darwin.  */
+    unsigned int usermem;
+    size_t len = sizeof(usermem);
+    static int mib[2] = {CTL_HW, HW_USERMEM};
+
+    if (sysctl(mib, ARRAY_SIZE(mib), &usermem, &len, NULL, 0) == 0
+       && len == sizeof (usermem))
+      return (double)usermem;
+  }
+#endif
+
   /* Guess 25% of physical memory.  */
   return physmem_total () / 4;
 }
This page took 0.042255 seconds and 4 git commands to generate.