aboutsummaryrefslogtreecommitdiff
path: root/libiberty/physmem.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2003-02-22 17:08:34 +0000
committerDJ Delorie <dj@redhat.com>2003-02-22 17:08:34 +0000
commitcc529274241cd4e72f7d03479b34f3779df479f1 (patch)
treecb29b6c945ccc680414d46c9ee7128aaf8b3923d /libiberty/physmem.c
parentb631436bb9381026916d8f10ba0e115a189502c0 (diff)
downloadgdb-cc529274241cd4e72f7d03479b34f3779df479f1.zip
gdb-cc529274241cd4e72f7d03479b34f3779df479f1.tar.gz
gdb-cc529274241cd4e72f7d03479b34f3779df479f1.tar.bz2
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 2011f02..80fdd79 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;
}