summaryrefslogtreecommitdiff
path: root/libiberty/physmem.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@delorie.com>2003-02-22 17:08:34 +0000
committerDJ Delorie <dj@delorie.com>2003-02-22 17:08:34 +0000
commit93d3100926f21a01c5eeec84f8de2a54bc65cb6b (patch)
treee325ea0f1477f9d43d968121787a2878064725d0 /libiberty/physmem.c
parent09277b1bb09e0a9a6a29ef097d05fe949e79a92b (diff)
downloadgdb-93d3100926f21a01c5eeec84f8de2a54bc65cb6b.tar.gz
merge from gcc
Diffstat (limited to 'libiberty/physmem.c')
-rw-r--r--libiberty/physmem.c57
1 files changed, 50 insertions, 7 deletions
diff --git a/libiberty/physmem.c b/libiberty/physmem.c
index 2011f0251bd..80fdd7975e9 100644
--- a/libiberty/physmem.c
+++ b/libiberty/physmem.c
@@ -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>
@@ -30,16 +30,30 @@
#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;
}