about summary refs log tree commit diff stats
path: root/miasm2/jitter/Jitllvm.c
blob: c176a4b23240b5b1cccdbba8e0a3aaf57ffb82a9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <Python.h>

#include <inttypes.h>

#include <stdint.h>
#include "queue.h"
#include "vm_mngr.h"
#include "vm_mngr_py.h"
#include "JitCore.h"
// Needed to get the JitCpu.cpu offset, arch independent
#include "arch/JitCore_x86.h"

PyObject* llvm_exec_bloc(PyObject* self, PyObject* args)
{
	uint64_t func_addr;
	uint64_t (*func)(void*, void*, void*, uint8_t*);
	uint64_t vm;
	uint64_t ret;
	JitCpu* jitcpu;
	uint8_t status;
	
	if (!PyArg_ParseTuple(args, "KOK", &func_addr, &jitcpu, &vm))
		return NULL;
	vm_cpu_t* cpu = jitcpu->cpu;
	func = (void *) (intptr_t) func_addr;
	ret = func((void*) jitcpu, (void*)(intptr_t) cpu, (void*)(intptr_t) vm, &status);
	return PyLong_FromUnsignedLongLong(ret);
}


static PyMethodDef LLVMMethods[] = {
    {"llvm_exec_bloc",  llvm_exec_bloc, METH_VARARGS,
     "llvm exec bloc"},
    {NULL, NULL, 0, NULL}        /* Sentinel */
};

PyMODINIT_FUNC
initJitllvm(void)
{
    PyObject *m;

    m = Py_InitModule("Jitllvm", LLVMMethods);
    if (m == NULL)
	    return;

}