diff options
| author | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2016-11-10 11:14:13 +0100 |
|---|---|---|
| committer | Fabrice Desclaux <fabrice.desclaux@cea.fr> | 2016-11-10 11:14:13 +0100 |
| commit | 0aa399dd85f33de8334e2ebc579cc336acf9a7d3 (patch) | |
| tree | 43f5d8678b8c664649db42ce2b1c983ae0d02e26 | |
| parent | 9821e83e79a45e45a99ed89eb8951bd278cc83d8 (diff) | |
| download | miasm-0aa399dd85f33de8334e2ebc579cc336acf9a7d3.tar.gz miasm-0aa399dd85f33de8334e2ebc579cc336acf9a7d3.zip | |
Jitter: Add max exec per jit call option
| -rw-r--r-- | miasm2/jitter/Jitgcc.c | 22 | ||||
| -rw-r--r-- | miasm2/jitter/Jittcc.c | 20 | ||||
| -rw-r--r-- | miasm2/jitter/jitcore.py | 6 |
3 files changed, 44 insertions, 4 deletions
diff --git a/miasm2/jitter/Jitgcc.c b/miasm2/jitter/Jitgcc.c index 8b789f70..71023902 100644 --- a/miasm2/jitter/Jitgcc.c +++ b/miasm2/jitter/Jitgcc.c @@ -20,14 +20,34 @@ PyObject* gcc_exec_bloc(PyObject* self, PyObject* args) PyObject* retaddr = NULL; int status; block_id BlockDst; + uint64_t max_exec_per_call = 0; + uint64_t cpt; + int do_cpt; - if (!PyArg_ParseTuple(args, "OOOO", &retaddr, &jitcpu, &lbl2ptr, &breakpoints)) + + if (!PyArg_ParseTuple(args, "OOOO|K", + &retaddr, &jitcpu, &lbl2ptr, &breakpoints, + &max_exec_per_call)) return NULL; /* The loop will decref retaddr always once */ Py_INCREF(retaddr); + if (max_exec_per_call == 0) { + do_cpt = 0; + cpt = 1; + } else { + do_cpt = 1; + cpt = max_exec_per_call; + } + + + for (;;) { + if (cpt == 0) + return retaddr; + if (do_cpt) + cpt --; // Init BlockDst.is_local = 0; BlockDst.address = 0; diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c index 1acbd56f..1297336d 100644 --- a/miasm2/jitter/Jittcc.c +++ b/miasm2/jitter/Jittcc.c @@ -139,14 +139,32 @@ PyObject* tcc_exec_bloc(PyObject* self, PyObject* args) PyObject* retaddr = NULL; int status; block_id BlockDst; + uint64_t max_exec_per_call = 0; + uint64_t cpt; + int do_cpt; - if (!PyArg_ParseTuple(args, "OOOO", &retaddr, &jitcpu, &lbl2ptr, &breakpoints)) + if (!PyArg_ParseTuple(args, "OOOO|K", + &retaddr, &jitcpu, &lbl2ptr, &breakpoints, + &max_exec_per_call)) return NULL; /* The loop will decref retaddr always once */ Py_INCREF(retaddr); + if (max_exec_per_call == 0) { + do_cpt = 0; + cpt = 1; + } else { + do_cpt = 1; + cpt = max_exec_per_call; + } + + for (;;) { + if (cpt == 0) + return retaddr; + if (do_cpt) + cpt --; // Init BlockDst.is_local = 0; BlockDst.address = 0; diff --git a/miasm2/jitter/jitcore.py b/miasm2/jitter/jitcore.py index 04bd707a..f3a79bee 100644 --- a/miasm2/jitter/jitcore.py +++ b/miasm2/jitter/jitcore.py @@ -51,7 +51,8 @@ class JitCore(object): self.blocs_mem_interval = interval() self.disasm_cb = None self.split_dis = set() - self.options = {"jit_maxline": 50 # Maximum number of line jitted + self.options = {"jit_maxline": 50, # Maximum number of line jitted + "max_exec_per_call": 0 # 0 means no limit } self.mdis = asmbloc.disasmEngine(ir_arch.arch, ir_arch.attrib, bs, @@ -170,7 +171,8 @@ class JitCore(object): @cpu: JitCpu instance @breakpoints: Dict instance of used breakpoints """ - return self.exec_wrapper(label, cpu, self.lbl2jitbloc.data, breakpoints) + return self.exec_wrapper(label, cpu, self.lbl2jitbloc.data, breakpoints, + self.options["max_exec_per_call"]) def runbloc(self, cpu, vm, lbl, breakpoints): """Run the bloc starting at lbl. |