The is_jit_method() function does not perform the check which it's name suggests. It checks whether address is above text segment which is wrong because it clasifies as JIT methods functions which are not JIT: trampolines, linked library functions, kernel functions.
In place of is_jit_method() a new function is introduced - is_native(). It checks whether given address is located outside the _heap_. It returns true to all functions but JIT methods and trampolines. It can be used in place of is_jit_method() where it is reasonable to assume that the address can not be in a trampoline. Signed-off-by: Tomek Grabiec <tgrab...@gmail.com> --- arch/x86/exception.c | 2 +- arch/x86/signal.c | 2 +- include/jit/compiler.h | 2 +- include/jit/exception.h | 2 +- jit/exception.c | 2 +- jit/method.c | 28 +++++++++++++++++----------- test/arch-mmix/stack-frame.c | 5 ----- test/jit/Makefile | 1 + 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/arch/x86/exception.c b/arch/x86/exception.c index 217e7a3..c668660 100644 --- a/arch/x86/exception.c +++ b/arch/x86/exception.c @@ -82,7 +82,7 @@ void throw_exception_from_trampoline(void *ctx, struct object *exception) signal_exception(exception); - if (!is_jit_method(return_address)) + if (is_native(return_address)) /* Return to caller. */ uc->uc_mcontext.gregs[REG_IP] = return_address; else diff --git a/arch/x86/signal.c b/arch/x86/signal.c index dccf4aa..6b59881 100644 --- a/arch/x86/signal.c +++ b/arch/x86/signal.c @@ -38,7 +38,7 @@ bool signal_from_jit_method(void *ctx) uc = ctx; ip = uc->uc_mcontext.gregs[REG_IP]; - if (!is_jit_method(ip)) + if (is_native(ip)) return false; return true; diff --git a/include/jit/compiler.h b/include/jit/compiler.h index f293c0a..b29ff88 100644 --- a/include/jit/compiler.h +++ b/include/jit/compiler.h @@ -93,7 +93,7 @@ static inline void *method_trampoline_ptr(struct methodblock *method) return buffer_ptr(method->trampoline->objcode); } -bool is_jit_method(unsigned long eip); +bool is_native(unsigned long eip); void fixup_direct_calls(struct jit_trampoline *trampoline, unsigned long target); diff --git a/include/jit/exception.h b/include/jit/exception.h index bd9b63e..6ee6d5f 100644 --- a/include/jit/exception.h +++ b/include/jit/exception.h @@ -82,7 +82,7 @@ static inline struct object *exception_occurred(void) void *eh; \ \ native_ptr = __builtin_return_address(0) - 1; \ - if (!is_jit_method((unsigned long)native_ptr)) \ + if (is_native((unsigned long)native_ptr)) \ die("%s: must not be called from not-JIT code", \ __func__); \ \ diff --git a/jit/exception.c b/jit/exception.c index 67712c1..bf96885 100644 --- a/jit/exception.c +++ b/jit/exception.c @@ -223,7 +223,7 @@ throw_exception_from(struct compilation_unit *cu, struct jit_stack_frame *frame, signal_exception(exception); - if (!is_jit_method(frame->return_address)) { + if (is_native(frame->return_address)) { /* * No handler found within jitted method call chain. * Return to previous (not jit) method. diff --git a/jit/method.c b/jit/method.c index 90970d1..d0e0cb1 100644 --- a/jit/method.c +++ b/jit/method.c @@ -24,25 +24,31 @@ * Please refer to the file LICENSE for details. */ +#include <arch/stack-frame.h> #include <jit/compiler.h> +#include <vm/natives.h> #include <stdbool.h> +#include <unistd.h> -/* Points to the first address past text segment */ -extern char etext; +/* This is located on the first address past the end of the + uninitialized data segment */ +extern char end; /* - * Checks whether address belongs to jitted or JATO method. - * This is used in deciding when to stop the unwind process upon - * exception throwing. - * - * It utilises the fact, that jitted code is allocated on heap. So by - * comparing return address with text segment end we can tell whether - * the caller is on heap or in text. + * Checks whether address is located above data segments and below heap end. + */ +static bool address_on_heap(unsigned long addr) +{ + return addr >= (unsigned long)&end && addr < (unsigned long)sbrk(0); +} + +/* + * Checks whether given address belongs to a native function. */ -bool is_jit_method(unsigned long eip) +bool is_native(unsigned long eip) { - return eip >= (unsigned long)&etext; + return !address_on_heap(eip); } const char *method_symbol(struct methodblock *method, char *symbol, size_t size) diff --git a/test/arch-mmix/stack-frame.c b/test/arch-mmix/stack-frame.c index 78021db..6be9ead 100644 --- a/test/arch-mmix/stack-frame.c +++ b/test/arch-mmix/stack-frame.c @@ -25,8 +25,3 @@ */ #include <arch/stack-frame.h> - -bool is_jit_method(unsigned long eip) -{ - return false; -} diff --git a/test/jit/Makefile b/test/jit/Makefile index 7f35a33..2e0409d 100644 --- a/test/jit/Makefile +++ b/test/jit/Makefile @@ -42,6 +42,7 @@ OBJS = \ ../../jit/cu-mapping.o \ ../../jit/nop-bc.o \ ../../jit/tree-node.o \ + ../../jit/method.o \ ../libharness/libharness.o \ ../jamvm/alloc-stub.o \ ../jamvm/resolve-stub.o \ -- 1.6.0.6 ------------------------------------------------------------------------------ Are you an open source citizen? Join us for the Open Source Bridge conference! Portland, OR, June 17-19. Two days of sessions, one day of unconference: $250. Need another reason to go? 24-hour hacker lounge. Register today! http://ad.doubleclick.net/clk;215844324;13503038;v?http://opensourcebridge.org _______________________________________________ Jatovm-devel mailing list Jatovm-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jatovm-devel