[kaffe] CVS kaffe (guilhem): Readded memory protection handling in the GC.
Kaffe CVS
cvs-commits at kaffe.org
Sun May 30 03:40:04 PDT 2004
PatchSet 4794
Date: 2004/05/30 10:35:15
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
Readded memory protection handling in the GC.
* configure.ac: Check for mprotect. If the host is an HPUX disable
the use of it for some code.
* config/config.h.in, configure: Regenerated.
* kaffe/kaffevm/mem/gc-mem.c: Added memory protection handling for
the heap.
Members:
ChangeLog:1.2363->1.2364
configure:1.324->1.325
configure.ac:1.23->1.24
config/config.h.in:1.100->1.101
kaffe/kaffevm/mem/gc-mem.c:1.57->1.58
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2363 kaffe/ChangeLog:1.2364
--- kaffe/ChangeLog:1.2363 Sat May 29 17:01:16 2004
+++ kaffe/ChangeLog Sun May 30 10:35:15 2004
@@ -1,5 +1,15 @@
2004-05-29 Guilhem Lavaux <guilhem at kaffe.org>
+ * configure.ac: Check for mprotect. If the host is an HPUX disable
+ the use of it for some code.
+
+ * config/config.h.in, configure: Regenerated.
+
+ * kaffe/kaffevm/mem/gc-mem.c: Added memory protection handling for
+ the heap.
+
+2004-05-29 Guilhem Lavaux <guilhem at kaffe.org>
+
* kaffe/kaffevm/systems/unix-jthreads/signal.c
(nullException): Check whether currentJThread exists.
Index: kaffe/configure
diff -u kaffe/configure:1.324 kaffe/configure:1.325
--- kaffe/configure:1.324 Wed May 26 20:15:18 2004
+++ kaffe/configure Sun May 30 10:35:16 2004
@@ -42415,6 +42415,121 @@
fi
+for ac_func in mprotect
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6
+if eval "test \"\${$as_ac_var+set}\" = set"; then
+ echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+ cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h. */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h. */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+ For example, HP-UX 11i <limits.h> declares gettimeofday. */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+ which can conflict with char $ac_func (); below.
+ Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+ <limits.h> exists even on freestanding compilers. */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any gcc2 internal prototype to avoid an error. */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+/* We use char because int might match the return type of a gcc2
+ builtin and then its argument prototype would still apply. */
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+ to always fail with ENOSYS. Some functions are actually named
+ something starting with __ and the normal name is an alias. */
+#if defined (__stub_$ac_func) || defined (__stub___$ac_func)
+choke me
+#else
+char (*f) () = $ac_func;
+#endif
+#ifdef __cplusplus
+}
+#endif
+
+int
+main ()
+{
+return f != $ac_func;
+ ;
+ return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (eval echo "$as_me:$LINENO: \"$ac_link\"") >&5
+ (eval $ac_link) 2>conftest.er1
+ ac_status=$?
+ grep -v '^ *+' conftest.er1 >conftest.err
+ rm -f conftest.er1
+ cat conftest.err >&5
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); } &&
+ { ac_try='test -z "$ac_c_werror_flag"
+ || test ! -s conftest.err'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; } &&
+ { ac_try='test -s conftest$ac_exeext'
+ { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+ (eval $ac_try) 2>&5
+ ac_status=$?
+ echo "$as_me:$LINENO: \$? = $ac_status" >&5
+ (exit $ac_status); }; }; then
+ eval "$as_ac_var=yes"
+else
+ echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+eval "$as_ac_var=no"
+fi
+rm -f conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+fi
+echo "$as_me:$LINENO: result: `eval echo '${'$as_ac_var'}'`" >&5
+echo "${ECHO_T}`eval echo '${'$as_ac_var'}'`" >&6
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+ cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+
+fi
+done
+
+if test x"$ac_cv_func_mprotect" = x"yes"; then
+ case "$Khost_os" in
+ hpux*)
+ ;;
+ *)
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_COMPATIBLE_MPROTECT 1
+_ACEOF
+
+ ;;
+ esac
+fi
+
+
for ac_header in valgrind/memcheck.h
do
as_ac_Header=`echo "ac_cv_header_$ac_header" | $as_tr_sh`
Index: kaffe/configure.ac
diff -u kaffe/configure.ac:1.23 kaffe/configure.ac:1.24
--- kaffe/configure.ac:1.23 Wed May 26 20:15:23 2004
+++ kaffe/configure.ac Sun May 30 10:35:21 2004
@@ -1051,6 +1051,19 @@
AC_CHECK_FUNCS(getrusage, have_rusage=yes)
fi
+dnl Check whether there exists mprotect. If it exists and we are
+dnl on HPUX, then prevent kaffe from using it when the pointer does not
+dnl come from mmap.
+AC_CHECK_FUNCS(mprotect)
+if test x"$ac_cv_func_mprotect" = x"yes"; then
+ case "$Khost_os" in
+ hpux*)
+ ;;
+ *) AC_DEFINE(HAVE_COMPATIBLE_MPROTECT, 1, [Does mprotect support protecting region not covered by mmap ?])
+ ;;
+ esac
+fi
+
dnl needed for valgrind
AC_CHECK_HEADERS([valgrind/memcheck.h])
Index: kaffe/config/config.h.in
diff -u kaffe/config/config.h.in:1.100 kaffe/config/config.h.in:1.101
--- kaffe/config/config.h.in:1.100 Sun May 9 14:57:31 2004
+++ kaffe/config/config.h.in Sun May 30 10:35:22 2004
@@ -49,6 +49,9 @@
/* Define to 1 if you have the `chdir' function. */
#undef HAVE_CHDIR
+/* Does mprotect support protecting region not covered by mmap ? */
+#undef HAVE_COMPATIBLE_MPROTECT
+
/* Define if the GNU dcgettext() function is already present or preinstalled.
*/
#undef HAVE_DCGETTEXT
@@ -335,6 +338,9 @@
/* Define to 1 if you have a working `mmap' system call. */
#undef HAVE_MMAP
+
+/* Define to 1 if you have the `mprotect' function. */
+#undef HAVE_MPROTECT
/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */
#undef HAVE_NDIR_H
Index: kaffe/kaffe/kaffevm/mem/gc-mem.c
diff -u kaffe/kaffe/kaffevm/mem/gc-mem.c:1.57 kaffe/kaffe/kaffevm/mem/gc-mem.c:1.58
--- kaffe/kaffe/kaffevm/mem/gc-mem.c:1.57 Wed Apr 21 10:15:07 2004
+++ kaffe/kaffe/kaffevm/mem/gc-mem.c Sun May 30 10:35:22 2004
@@ -625,11 +625,28 @@
static gc_block *gc_last_block;
static gc_block *gc_prim_freelist[GC_PRIM_LIST_COUNT+1];
+#ifndef PROT_NONE
+#define PROT_NONE 0
+#endif
+
+#if !defined(HAVE_MPROTECT) || !defined(HAVE_COMPATIBLE_MPROTECT)
+#define mprotect(A,L,P)
+#define ALL_PROT
+#define NO_PROT
+#else
+/* In a sense, this is backwards. */
+#define ALL_PROT PROT_READ|PROT_WRITE|PROT_EXEC
+#define NO_PROT PROT_NONE
+#endif
+
/* Mark a primitive block as used */
static inline void
gc_block_add(gc_block *b)
{
b->nr = 1;
+#if defined(KAFFE_VMDEBUG)
+ mprotect(GCBLOCK2BASE(b), b->size, ALL_PROT);
+#endif
}
/* Mark a primitive block as unused */
@@ -637,6 +654,9 @@
gc_block_rm(gc_block *b)
{
b->nr = 0;
+#if defined(KAFFE_VMDEBUG)
+ mprotect(GCBLOCK2BASE(b), b->size, NO_PROT);
+#endif
}
/* Get the end a gc block
@@ -945,6 +965,8 @@
ptr = (void*)((((uintp)ptr) + gc_pgsize - 1) & -gc_pgsize);
#endif
+ mprotect(ptr, size, ALL_PROT);
+
addToCounter(&gcpages, "gcmem-system pages", 1, size);
return ((uintp) ptr);
}
@@ -1071,6 +1093,9 @@
gc_heap_range = last_addr - gc_heap_base;
DBG(GCSYSALLOC, dprintf("%ld unused bytes in heap addr range\n",
(long) (gc_heap_range - gc_heap_total)));
+#if defined(KAFFE_VMDEBUG)
+ mprotect((void *) heap_addr, size, NO_PROT);
+#endif
return GCMEM2BLOCK(heap_addr);
}
More information about the kaffe
mailing list