diff options
| author | Camille Mougey <camille.mougey@cea.fr> | 2015-10-23 11:26:37 +0200 |
|---|---|---|
| committer | Camille Mougey <camille.mougey@cea.fr> | 2015-10-23 13:29:06 +0200 |
| commit | dcf8369b123ec2fdfc3a0120b46d0770b8fba7c0 (patch) | |
| tree | d1a7c3d20e50f259013ef94da0d73f8f0b3077be | |
| parent | 2b2858a975031aad5abdfaf6dcb123f7edee5ba1 (diff) | |
| download | miasm-dcf8369b123ec2fdfc3a0120b46d0770b8fba7c0.tar.gz miasm-dcf8369b123ec2fdfc3a0120b46d0770b8fba7c0.zip | |
JitTCC: loop in C while future basic blocks are known
| -rw-r--r-- | miasm2/jitter/Jittcc.c | 50 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore.py | 11 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore_tcc.py | 2 | ||||
| -rw-r--r-- | miasm2/jitter/jitload.py | 2 |
4 files changed, 47 insertions, 18 deletions
diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c index d146aaf4..a2102609 100644 --- a/miasm2/jitter/Jittcc.c +++ b/miasm2/jitter/Jittcc.c @@ -124,23 +124,53 @@ typedef struct { uint64_t address; } block_id; +typedef int (*jitted_func)(block_id*, PyObject*); + PyObject* tcc_exec_bloc(PyObject* self, PyObject* args) { - void (*func)(block_id*, PyObject*); + jitted_func func; PyObject* jitcpu; - block_id BlockDst = {0, 0}; - - if (!PyArg_ParseTuple(args, "KO", &func, &jitcpu)) + PyObject* func_py; + PyObject* lbl2ptr; + PyObject* breakpoints; + PyObject* retaddr = NULL; + int status; + block_id BlockDst; + + if (!PyArg_ParseTuple(args, "OOOO", &retaddr, &jitcpu, &lbl2ptr, &breakpoints)) return NULL; - func(&BlockDst, jitcpu); - if (BlockDst.is_local == 1) { - fprintf(stderr, "return on local label!\n"); - exit(1); - } + for (;;) { + // Init + BlockDst.is_local = 0; + BlockDst.address = 0; + + // Get the expected jitted function address + func_py = PyDict_GetItem(lbl2ptr, retaddr); + if (func_py) + func = (jitted_func) PyInt_AsLong((PyObject*) func_py); + else { + if (BlockDst.is_local == 1) { + fprintf(stderr, "return on local label!\n"); + exit(1); + } + // retaddr is not jitted yet + return retaddr; + } + + // Execute it + status = func(&BlockDst, jitcpu); + retaddr = PyLong_FromUnsignedLongLong(BlockDst.address); - return PyLong_FromUnsignedLongLong(BlockDst.address); + // Check exception + if (status) + return retaddr; + + // Check breakpoint + if (PyDict_Contains(breakpoints, retaddr)) + return retaddr; + } } PyObject* tcc_compil(PyObject* self, PyObject* args) diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index a3a91d76..afd80149 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -153,17 +153,16 @@ class JitCore(object): # Update jitcode mem range self.add_bloc_to_mem_interval(vm, cur_bloc) - def jit_call(self, label, cpu, vmmngr): + def jit_call(self, label, cpu, vmmngr, breakpoints): """Call the function label with cpu and vmmngr states @label: function's label @cpu: JitCpu instance @vm: VmMngr instance """ + # TODO useless vmmngr + return self.exec_wrapper(label, cpu, self.lbl2jitbloc._data, breakpoints) - fc_ptr = self.lbl2jitbloc[label] - return self.exec_wrapper(fc_ptr, cpu) - - def runbloc(self, cpu, vm, lbl): + def runbloc(self, cpu, vm, lbl, breakpoints): """Run the bloc starting at lbl. @cpu: JitCpu instance @vm: VmMngr instance @@ -178,7 +177,7 @@ class JitCore(object): self.disbloc(lbl, cpu, vm) # Run the bloc and update cpu/vmmngr state - ret = self.jit_call(lbl, cpu, vm) + ret = self.jit_call(lbl, cpu, vm, breakpoints) return ret diff --git a/miasm2/jitter/jitcore_tcc.py b/miasm2/jitter/jitcore_tcc.py index 20f10339..304a5bca 100644 --- a/miasm2/jitter/jitcore_tcc.py +++ b/miasm2/jitter/jitcore_tcc.py @@ -138,7 +138,7 @@ class JitCore_Tcc(jitcore.JitCore): def jitirblocs(self, label, irblocs): f_name = "bloc_%s" % label.name - f_declaration = 'void %s(block_id * BlockDst, JitCpu* jitcpu)' % f_name + f_declaration = 'int %s(block_id * BlockDst, JitCpu* jitcpu)' % f_name out = irblocs2C(self.ir_arch, self.resolver, label, irblocs, gen_exception_code=True, log_mn=self.log_mn, diff --git a/miasm2/jitter/jitload.py b/miasm2/jitter/jitload.py index 112920a1..68061c75 100644 --- a/miasm2/jitter/jitload.py +++ b/miasm2/jitter/jitload.py @@ -292,7 +292,7 @@ class jitter: """Wrapper on JiT backend. Run the code at PC and return the next PC. @pc: address of code to run""" - return self.jit.runbloc(self.cpu, self.vm, pc) + return self.jit.runbloc(self.cpu, self.vm, pc, self.breakpoints_handler.callbacks) def runiter_once(self, pc): """Iterator on callbacks results on code running from PC. |