This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch: *bsd & darwin support in libiberty/physmem.c
Aargh! That version works, but right after I sent it I saw I'd done
the error-checking wrong.
This is better.
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/configure.in,v
retrieving revision 1.61
diff -u -p -u -p -r1.61 configure.in
--- configure.in 21 Feb 2003 20:33:50 -0000 1.61
+++ configure.in 22 Feb 2003 09:37:05 -0000
@@ -142,7 +142,7 @@ AC_SUBST_FILE(host_makefile_frag)
# It's OK to check for header files. Although the compiler may not be
# able to link anything, it had better be able to at least compile
# something.
-AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h)
+AC_CHECK_HEADERS(sys/file.h sys/param.h limits.h stdlib.h string.h unistd.h strings.h sys/time.h time.h sys/resource.h sys/stat.h sys/mman.h fcntl.h alloca.h sys/pstat.h sys/sysmp.h sys/sysinfo.h machine/hal_sysinfo.h sys/table.h sys/sysctl.h)
AC_HEADER_SYS_WAIT
AC_HEADER_TIME
@@ -208,7 +208,7 @@ vars="sys_errlist sys_nerr sys_siglist"
checkfuncs="getrusage on_exit psignal strerror strsignal sysconf times sbrk gettimeofday"
checkfuncs="$checkfuncs realpath canonicalize_file_name pstat_getstatic pstat_getdynamic sysmp"
-checkfuncs="$checkfuncs getsysinfo table"
+checkfuncs="$checkfuncs getsysinfo table sysctl"
# These are neither executed nor required, but they help keep
# autoheader happy without adding a bunch of text to acconfig.h.
@@ -220,7 +220,7 @@ if test "x" = "y"; then
AC_CHECK_FUNCS(strtod strtol strtoul tmpnam vasprintf vfprintf vprintf)
AC_CHECK_FUNCS(vsprintf waitpid getrusage on_exit psignal strerror strsignal)
AC_CHECK_FUNCS(sysconf times sbrk gettimeofday ffs)
- AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table)
+ AC_CHECK_FUNCS(pstat_getstatic pstat_getdynamic sysmp getsysinfo table sysctl)
AC_CHECK_FUNCS(realpath canonicalize_file_name)
AC_DEFINE(HAVE_SYS_ERRLIST, 1, [Define if you have the sys_errlist variable.])
AC_DEFINE(HAVE_SYS_NERR, 1, [Define if you have the sys_nerr variable.])
Index: physmem.c
===================================================================
RCS file: /cvs/gcc/gcc/libiberty/physmem.c,v
retrieving revision 1.5
diff -u -p -u -p -r1.5 physmem.c
--- physmem.c 21 Feb 2003 20:33:50 -0000 1.5
+++ physmem.c 22 Feb 2003 09:37:05 -0000
@@ -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. */
+ size_t physmem;
+ size_t len = sizeof (physmem);
+ 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;
}
@@ -155,6 +177,18 @@ physmem_available ()
if (0 <= pages && 0 <= pagesize)
return pages * pagesize;
}
+ }
+#endif
+
+#if HAVE_SYSCTL && defined HW_USERMEM
+ { /* This works on *bsd and darwin. */
+ unsigned int usermem;
+ size_t len = sizeof (usermem);
+ 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
--
- Geoffrey Keating <geoffk at geoffk dot org>