diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-10-23 11:24:12 +0200 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-10-23 11:24:12 +0200 |
| commit | 2b2858a975031aad5abdfaf6dcb123f7edee5ba1 (patch) | |
| tree | 18670b8aeb7fcd2554df5fabd1857b377a0de9ac | |
| parent | bcd4822ab014156c4977667b165072ba396d1f17 (diff) | |
| download | miasm-2b2858a975031aad5abdfaf6dcb123f7edee5ba1.tar.gz miasm-2b2858a975031aad5abdfaf6dcb123f7edee5ba1.zip | |
JitTCC: jitted functions return a status code
| -rw-r--r-- | miasm2/ir/ir2C.py | 24 | ||||
| -rw-r--r-- | miasm2/jitter/JitCore.h | 3 |
2 files changed, 15 insertions, 12 deletions
diff --git a/miasm2/ir/ir2C.py b/miasm2/ir/ir2C.py index 6cf3b4e6..0161c391 100644 --- a/miasm2/ir/ir2C.py +++ b/miasm2/ir/ir2C.py @@ -51,7 +51,7 @@ pre_instr_test_exception = r""" // pre instruction test exception if (VM_exception_flag) { %s; - return; + return JIT_RET_EXCEPTION; } """ @@ -60,14 +60,14 @@ code_exception_fetch_mem_at_instr = r""" // except fetch mem at instr if (VM_exception_flag & EXCEPT_DO_NOT_UPDATE_PC) { %s; - return; + return JIT_RET_EXCEPTION; } """ code_exception_fetch_mem_post_instr = r""" // except fetch mem post instr if (VM_exception_flag) { %s; - return; + return JIT_RET_EXCEPTION; } """ @@ -76,14 +76,14 @@ code_exception_fetch_mem_at_instr_noautomod = r""" // except fetch mem at instr noauto if ((VM_exception_flag & ~EXCEPT_CODE_AUTOMOD) & EXCEPT_DO_NOT_UPDATE_PC) { %s; - return; + return JIT_RET_EXCEPTION; } """ code_exception_fetch_mem_post_instr_noautomod = r""" // except post instr noauto if (VM_exception_flag & ~EXCEPT_CODE_AUTOMOD) { %s; - return; + return JIT_RET_EXCEPTION; } """ @@ -92,7 +92,7 @@ code_exception_at_instr = r""" // except at instr if (CPU_exception_flag && CPU_exception_flag > EXCEPT_NUM_UPDT_EIP) { %s; - return; + return JIT_RET_EXCEPTION; } """ @@ -105,7 +105,7 @@ if (CPU_exception_flag) { else { %s; } - return; + return JIT_RET_EXCEPTION; } """ @@ -113,7 +113,7 @@ if (CPU_exception_flag) { code_exception_at_instr_noautomod = r""" if ((CPU_exception_flag & ~EXCEPT_CODE_AUTOMOD) && (CPU_exception_flag > EXCEPT_NUM_UPDT_EIP)) { %s; - return; + return JIT_RET_EXCEPTION; } """ @@ -125,7 +125,7 @@ if (CPU_exception_flag & ~EXCEPT_CODE_AUTOMOD) { else { %s; } - return; + return JIT_RET_EXCEPTION; } """ @@ -134,7 +134,7 @@ if (BlockDst->is_local) { goto *local_labels[BlockDst->address]; } else { - return; + return JIT_RET_NO_EXCEPTION; } """ @@ -296,7 +296,7 @@ def Expr2C(ir_arch, l, exprs, gen_exception_code=False): if e.dst == ir_arch.arch.pc[ir_arch.attrib]: pc_is_dst = True - out_pc += ["return;"] + out_pc += ["return JIT_RET_NO_EXCEPTION;"] # if len(id_to_update) != len(set(id_to_update)): # raise ValueError('Not implemented: multi dst to same id!', str([str(x) @@ -327,7 +327,7 @@ def Expr2C(ir_arch, l, exprs, gen_exception_code=False): if set_exception_flags: if pc_is_dst: post_instr.append("if (VM_exception_flag) { " + - "/*pc = 0x%X; */return; }" % (l.offset)) + "/*pc = 0x%X; */return JIT_RET_EXCEPTION; }" % (l.offset)) else: e = set_pc(ir_arch, l.offset & mask_int) s1 = "%s" % translator.from_expr(patch_c_id(ir_arch.arch, e)) diff --git a/miasm2/jitter/JitCore.h b/miasm2/jitter/JitCore.h index af87a9cb..c8400701 100644 --- a/miasm2/jitter/JitCore.h +++ b/miasm2/jitter/JitCore.h @@ -131,4 +131,7 @@ PyObject* vm_get_mem(JitCpu *self, PyObject* args); #define VM_exception_flag (((VmMngr*)jitcpu->pyvm)->vm_mngr.exception_flags) #define CPU_exception_flag (((vm_cpu_t*)jitcpu->cpu)->exception_flags) +#define JIT_RET_EXCEPTION 1 +#define JIT_RET_NO_EXCEPTION 0 + #endif |