about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--miasm2/jitter/Jitgcc.c22
-rw-r--r--miasm2/jitter/Jittcc.c20
-rw-r--r--miasm2/jitter/jitcore.py6
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.