The ecj compiler generates a 'pop' instruction when exception handler
is empty. This causes that exception object reference is not popped
from native stack when exception handler is executed and that leads to
native stack corruption. The solution is to always emit native pop
instruction at exception handler entry which saves the exception
object reference in ecx register.

Signed-off-by: Tomek Grabiec <[email protected]>
---
 arch/x86/emit-code_32.c       |    4 ++++
 arch/x86/insn-selector_32.brg |    7 +------
 2 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/arch/x86/emit-code_32.c b/arch/x86/emit-code_32.c
index 43ae427..8dd5ecd 100644
--- a/arch/x86/emit-code_32.c
+++ b/arch/x86/emit-code_32.c
@@ -971,6 +971,10 @@ void emit_body(struct basic_block *bb, struct buffer *buf)
        bb->mach_offset = buffer_offset(buf);
        backpatch_branches(buf, &bb->backpatch_insns, bb->mach_offset);
 
+       if (bb->is_eh)
+               /* We must always pop the exception object */
+               __emit_pop_reg(buf, REG_ECX);
+
        for_each_insn(insn, &bb->insn_list) {
                emit_insn(buf, insn);
        }
diff --git a/arch/x86/insn-selector_32.brg b/arch/x86/insn-selector_32.brg
index 3bf0b6d..879f4a5 100644
--- a/arch/x86/insn-selector_32.brg
+++ b/arch/x86/insn-selector_32.brg
@@ -883,12 +883,7 @@ arg:       EXPR_ARGS_LIST(arg, arg)
 
 reg:   EXPR_EXCEPTION_REF
 {
-       struct var_info *result;
-
-       result = get_var(s->b_parent);
-       state->reg1 = result;
-
-       select_insn(s, tree, reg_insn(INSN_POP_REG, result));
+       state->reg1 = get_fixed_var(s->b_parent, REG_ECX);
 }
 
 stmt:  STMT_RETURN(reg)
-- 
1.6.0.6


------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Jatovm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jatovm-devel

Reply via email to