aboutsummaryrefslogtreecommitdiff
path: root/libiberty/physmem.c
diff options
context:
space:
mode:
authorKaveh R. Ghazi <ghazi@caip.rutgers.edu>2003-02-22 15:17:36 +0000
committerKaveh Ghazi <ghazi@gcc.gnu.org>2003-02-22 15:17:36 +0000
commit170230b7235a9ed4345a770c2d9d2ec1ffed94b2 (patch)
tree0c5bc9ab05e32a306318e93a583171ce6303b5a0 /libiberty/physmem.c
parent514e19c9fb0aaa8d4c5a78b4b357b4c19bc8c7b4 (diff)
downloadgcc-170230b7235a9ed4345a770c2d9d2ec1ffed94b2.zip
gcc-170230b7235a9ed4345a770c2d9d2ec1ffed94b2.tar.gz
gcc-170230b7235a9ed4345a770c2d9d2ec1ffed94b2.tar.bz2
configure.in: Check for sys/sysctl.h and sysctl.
* configure.in: Check for sys/sysctl.h and sysctl. * physmem.c: Add support for *bsd and darwin. * Makefile.in: Generate depedency for physmem.o. Co-Authored-By: Geoffrey Keating <geoffk@apple.com> Co-Authored-By: Richard Earnshaw <rearnsha@arm.com> From-SVN: r63285
Diffstat (limited to 'libiberty/physmem.c')
-rw-r--r--libiberty/physmem.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/libiberty/physmem.c b/libiberty/physmem.c
index 2011f02..c502a86 100644
--- a/libiberty/physmem.c
+++ b/libiberty/physmem.c
@@ -42,6 +42,16 @@
# 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
+
#include "libiberty.h"
/* Return the total amount of physical memory. */
@@ -98,6 +108,18 @@ 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
+
/* Return 0 if we can't determine the value. */
return 0;
}
@@ -158,6 +180,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;
}