Guard pages are memory pages which can be access protected (hidden) in order to trigger SIGSEGV when accessed. This mechanism will be used by GC safepoints and exception occurance detection.
Signed-off-by: Tomek Grabiec <[email protected]> --- Makefile | 3 +- include/vm/alloc.h | 1 + include/vm/guard-page.h | 8 ++++++ jit/alloc.c | 13 +++++++++++ vm/guard-page.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 79 insertions(+), 1 deletions(-) create mode 100644 include/vm/guard-page.h create mode 100644 vm/guard-page.c diff --git a/Makefile b/Makefile index 506a74c..d8c9e87 100644 --- a/Makefile +++ b/Makefile @@ -99,7 +99,8 @@ VM_OBJS = \ vm/zalloc.o \ vm/class.o \ vm/list.o \ - vm/radix-tree.o + vm/radix-tree.o \ + vm/guard-page.o JAMVM_OBJS = \ vm/jato.o \ diff --git a/include/vm/alloc.h b/include/vm/alloc.h index 9b2224e..8eee805 100644 --- a/include/vm/alloc.h +++ b/include/vm/alloc.h @@ -5,6 +5,7 @@ struct buffer; +void *alloc_page(); int get_buffer_align_bits(void); void *alloc_exec(size_t); int expand_buffer_exec(struct buffer *); diff --git a/include/vm/guard-page.h b/include/vm/guard-page.h new file mode 100644 index 0000000..bb28f8e --- /dev/null +++ b/include/vm/guard-page.h @@ -0,0 +1,8 @@ +#ifndef _VM_GUARD_PAGE_ +#define _VM_GUARD_PAGE_ + +void *alloc_guard_page(); +int hide_guard_page(void *page_ptr); +int unhide_guard_page(void *page_ptr); + +#endif /* _VM_GUARD_PAGE_ */ diff --git a/jit/alloc.c b/jit/alloc.c index 02092a2..ce72f75 100644 --- a/jit/alloc.c +++ b/jit/alloc.c @@ -92,3 +92,16 @@ int expand_buffer_exec(struct buffer *buf) return 0; } + +void *alloc_page() +{ + void *p; + int page_size; + + page_size = getpagesize(); + + if (posix_memalign(&p, page_size, page_size)) + return NULL; + + return p; +} diff --git a/vm/guard-page.c b/vm/guard-page.c new file mode 100644 index 0000000..1b51eed --- /dev/null +++ b/vm/guard-page.c @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2009 Tomasz Grabiec + * + * This file is released under the GPL version 2 with the following + * clarification and special exception: + * + * Linking this library statically or dynamically with other modules is + * making a combined work based on this library. Thus, the terms and + * conditions of the GNU General Public License cover the whole + * combination. + * + * As a special exception, the copyright holders of this library give you + * permission to link this library with independent modules to produce an + * executable, regardless of the license terms of these independent + * modules, and to copy and distribute the resulting executable under terms + * of your choice, provided that you also meet, for each linked independent + * module, the terms and conditions of the license of that module. An + * independent module is a module which is not derived from or based on + * this library. If you modify this library, you may extend this exception + * to your version of the library, but you are not obligated to do so. If + * you do not wish to do so, delete this exception statement from your + * version. + * + * Please refer to the file LICENSE for details. + */ + +#include <vm/guard-page.h> +#include <vm/alloc.h> +#include <vm/die.h> + +#include <sys/mman.h> +#include <unistd.h> + +void *alloc_guard_page() +{ + void *p = alloc_page(); + + if (p == NULL) + return NULL; + + if (hide_guard_page(p)) + return NULL; + + return p; +} + +int hide_guard_page(void *page_ptr) +{ + return mprotect(page_ptr, sysconf(_SC_PAGESIZE), PROT_NONE); +} + +int unhide_guard_page(void *page_ptr) +{ + return mprotect(page_ptr, sysconf(_SC_PAGESIZE), PROT_READ|PROT_WRITE); +} -- 1.6.0.6 ------------------------------------------------------------------------------ OpenSolaris 2009.06 is a cutting edge operating system for enterprises looking to deploy the next generation of Solaris that includes the latest innovations from Sun and the OpenSource community. Download a copy and enjoy capabilities such as Networking, Storage and Virtualization. Go to: http://p.sf.net/sfu/opensolaris-get _______________________________________________ Jatovm-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/jatovm-devel
