diff options
author | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-22 15:17:36 +0000 |
---|---|---|
committer | ghazi <ghazi@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-02-22 15:17:36 +0000 |
commit | 0991d38e7beb2f0729589412b1712ac4805a4aee (patch) | |
tree | 0c5bc9ab05e32a306318e93a583171ce6303b5a0 /libiberty/physmem.c | |
parent | d98e17aef7ed7b81210fdb717fc793313ce852cf (diff) | |
download | gcc-0991d38e7beb2f0729589412b1712ac4805a4aee.tar.gz |
* configure.in: Check for sys/sysctl.h and sysctl.
* physmem.c: Add support for *bsd and darwin.
* Makefile.in: Generate depedency for physmem.o.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@63285 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libiberty/physmem.c')
-rw-r--r-- | libiberty/physmem.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libiberty/physmem.c b/libiberty/physmem.c index 2011f0251bd..c502a86c118 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; } |