about summary refs log tree commit diff stats
path: root/miasm2/jitter/Jittcc.c
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2/jitter/Jittcc.c')
-rw-r--r--miasm2/jitter/Jittcc.c50
1 files changed, 40 insertions, 10 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)