about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAjax <commial@gmail.com>2017-01-05 17:14:50 +0100
committerAjax <commial@gmail.com>2017-01-05 17:14:50 +0100
commit776c25a65eec254b057ea7eddf39431c4e5d1916 (patch)
tree7192c863354352be60f092ad3f357c2b9044f4db
parenta96b8db7df51a05081f6b8597f3c07f534494a78 (diff)
downloadmiasm-776c25a65eec254b057ea7eddf39431c4e5d1916.tar.gz
miasm-776c25a65eec254b057ea7eddf39431c4e5d1916.zip
LLVM: handle max_exec_per_call option
-rw-r--r--miasm2/jitter/Jitllvm.c23
-rw-r--r--miasm2/jitter/jitcore_llvm.py9
2 files changed, 21 insertions, 11 deletions
diff --git a/miasm2/jitter/Jitllvm.c b/miasm2/jitter/Jitllvm.c
index cf2e1324..b46f88e3 100644
--- a/miasm2/jitter/Jitllvm.c
+++ b/miasm2/jitter/Jitllvm.c
@@ -22,16 +22,35 @@ PyObject* llvm_exec_bloc(PyObject* self, PyObject* args)
 	PyObject* lbl2ptr;
 	PyObject* breakpoints;
 	PyObject* retaddr = NULL;
+	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;
+
 	cpu = jitcpu->cpu;
 	vm = &(jitcpu->pyvm->vm_mngr);
 	/* 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 (;;) {
+		// Handle cpt
+		if (cpt == 0)
+			return retaddr;
+		if (do_cpt)
+			cpt --;
+
 		// Get the expected jitted function address
 		func_py = PyDict_GetItem(lbl2ptr, retaddr);
 		if (func_py)
diff --git a/miasm2/jitter/jitcore_llvm.py b/miasm2/jitter/jitcore_llvm.py
index 66e835ef..8f58f1da 100644
--- a/miasm2/jitter/jitcore_llvm.py
+++ b/miasm2/jitter/jitcore_llvm.py
@@ -129,12 +129,3 @@ class JitCore_LLVM(jitcore.JitCore):
                                           self.log_regs,
                                           block_raw)).hexdigest()
         return block_hash
-
-    def jit_call(self, label, cpu, _vmmngr, breakpoints):
-        """Call the function label with cpu and vmmngr states
-        @label: function's label
-        @cpu: JitCpu instance
-        @breakpoints: Dict instance of used breakpoints
-        """
-        return self.exec_wrapper(label, cpu,
-                                 self.lbl2jitbloc.data, breakpoints)