about summary refs log tree commit diff stats
path: root/miasm2
diff options
context:
space:
mode:
Diffstat (limited to 'miasm2')
-rw-r--r--miasm2/analysis/sandbox.py2
-rw-r--r--miasm2/jitter/Jittcc.c319
-rw-r--r--miasm2/jitter/jitcore_tcc.py104
-rw-r--r--miasm2/jitter/jitload.py5
4 files changed, 2 insertions, 428 deletions
diff --git a/miasm2/analysis/sandbox.py b/miasm2/analysis/sandbox.py
index f29d1776..e77b1669 100644
--- a/miasm2/analysis/sandbox.py
+++ b/miasm2/analysis/sandbox.py
@@ -86,7 +86,7 @@ class Sandbox(object):
         parser.add_argument('-g', "--gdbserver", type=int,
                             help="Listen on port @port")
         parser.add_argument("-j", "--jitter",
-                            help="Jitter engine. Possible values are: gcc (default), tcc, llvm, python",
+                            help="Jitter engine. Possible values are: gcc (default), llvm, python",
                             default="gcc")
         parser.add_argument(
             '-q', "--quiet-function-calls", action="store_true",
diff --git a/miasm2/jitter/Jittcc.c b/miasm2/jitter/Jittcc.c
deleted file mode 100644
index 61a6cda4..00000000
--- a/miasm2/jitter/Jittcc.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/*
-** Copyright (C) 2011 EADS France, Fabrice Desclaux <fabrice.desclaux@eads.net>
-**
-** This program is free software; you can redistribute it and/or modify
-** it under the terms of the GNU General Public License as published by
-** the Free Software Foundation; either version 2 of the License, or
-** (at your option) any later version.
-**
-** This program is distributed in the hope that it will be useful,
-** but WITHOUT ANY WARRANTY; without even the implied warranty of
-** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-** GNU General Public License for more details.
-**
-** You should have received a copy of the GNU General Public License along
-** with this program; if not, write to the Free Software Foundation, Inc.,
-** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
-#include <Python.h>
-
-#include <inttypes.h>
-#include <libtcc.h>
-
-#include <stdint.h>
-
-
-
-int include_array_count = 0;
-char **include_array = NULL;
-
-
-int lib_array_count = 0;
-char **lib_array = NULL;
-
-//char *libcodenat_path = NULL;
-
-
-TCCState * tcc_init_state(void)
-{
-	int i;
-	TCCState *tcc_state = NULL;
-	tcc_state = tcc_new();
-	if (!tcc_state) {
-		fprintf(stderr, "Impossible de creer un contexte TCC\n");
-		exit(EXIT_FAILURE);
-	}
-	tcc_set_output_type(tcc_state, TCC_OUTPUT_MEMORY);
-
-	//tcc_add_file(tcc_state, libcodenat_path);
-	for (i=0;i<lib_array_count; i++){
-		tcc_add_file(tcc_state, lib_array[i]);
-	}
-
-	for (i=0;i<include_array_count; i++){
-		tcc_add_include_path(tcc_state, include_array[i]);
-	}
-	return tcc_state;
-}
-
-
-PyObject* tcc_end(PyObject* self, PyObject* args)
-{
-	unsigned long long tmp = 0;
-
-	if (!PyArg_ParseTuple(args, "K", &tmp))
-		return NULL;
-
-	tcc_delete((TCCState *) (intptr_t) tmp);
-
-	Py_INCREF(Py_None);
-	return Py_None;
-}
-
-PyObject* tcc_set_emul_lib_path(PyObject* self, PyObject* args)
-{
-	char* include_arg;
-	char* lib_arg;
-
-	char* str1, * str2, * init_ptr;
-	if (!PyArg_ParseTuple(args, "ss",
-			      &include_arg,
-			      &lib_arg))
-		return NULL;
-
-	init_ptr = str2 = strdup(include_arg);
-	while (str2){
-		str1 = strsep(&str2, ";");
-		if (str1){
-			include_array_count ++;
-			include_array = realloc(include_array,
-						     include_array_count * sizeof(char*));
-			if (include_array == NULL) {
-				fprintf(stderr, "cannot realloc char* include_array\n");
-				exit(EXIT_FAILURE);
-			}
-			include_array[include_array_count-1] = strdup(str1);
-			// fprintf(stderr, "adding include file: %s\n", str1);
-		}
-	}
-	if (init_ptr != NULL)
-		free(init_ptr);
-
-	init_ptr = str2 = strdup(lib_arg);
-	while (str2){
-		str1 = strsep(&str2, ";");
-		if (str1){
-			lib_array_count ++;
-			lib_array = realloc(lib_array,
-						 lib_array_count * sizeof(char*));
-			if (lib_array == NULL) {
-				fprintf(stderr, "cannot realloc char* lib_array\n");
-				exit(EXIT_FAILURE);
-			}
-			lib_array[lib_array_count-1] = strdup(str1);
-			// fprintf(stderr, "adding lib file: %s\n", str1);
-		}
-	}
-	if (init_ptr != NULL)
-		free(init_ptr);
-
-
-	/*
-	libcodenat_path = (char*)malloc(strlen(libcodenat_path_arg)+1);
-	strcpy(libcodenat_path, libcodenat_path_arg);
-	*/
-	Py_INCREF(Py_None);
-
-
-	return Py_None;
-}
-
-
-typedef struct {
-	uint8_t is_local;
-	uint64_t address;
-} block_id;
-
-typedef int (*jitted_func)(block_id*, PyObject*);
-
-
-PyObject* tcc_exec_bloc(PyObject* self, PyObject* args)
-{
-	jitted_func func;
-	PyObject* jitcpu;
-	PyObject* func_py;
-	PyObject* lbl2ptr;
-	PyObject* breakpoints;
-	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|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;
-
-		// Get the expected jitted function address
-		func_py = PyDict_GetItem(lbl2ptr, retaddr);
-		if (func_py)
-			func = (jitted_func) PyLong_AsVoidPtr((PyObject*) func_py);
-		else {
-			if (BlockDst.is_local == 1) {
-				fprintf(stderr, "return on local label!\n");
-				exit(EXIT_FAILURE);
-			}
-			// retaddr is not jitted yet
-			return retaddr;
-		}
-
-		// Execute it
-		status = func(&BlockDst, jitcpu);
-		Py_DECREF(retaddr);
-		retaddr = 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)
-{
-	char* func_name;
-	char* func_code;
-	int (*entry)(void);
-	TCCState *tcc_state = NULL;
-	PyObject* ret;
-
-	tcc_state = tcc_init_state();
-
-	if (!PyArg_ParseTuple(args, "ss", &func_name, &func_code))
-		return NULL;
-
-	if (tcc_compile_string(tcc_state, func_code) != 0) {
-		fprintf(stderr, "Error compiling !\n");
-		fprintf(stderr, "%s\n", func_code);
-		exit(EXIT_FAILURE);
-	}
-	/* XXX configure tinycc install with --disable-static */
-	if (tcc_relocate(tcc_state, TCC_RELOCATE_AUTO) < 0) {
-		fprintf(stderr, "TCC relocate error\n");
-		exit(EXIT_FAILURE);
-	}
-	entry = tcc_get_symbol(tcc_state, func_name);
-	if (!entry){
-		fprintf(stderr, "Error getting symbol %s!\n", func_name);
-		fprintf(stderr, "%s\n", func_name);
-		exit(EXIT_FAILURE);
-	}
-
-	ret = PyTuple_New(2);
-	if (ret == NULL) {
-		fprintf(stderr, "Error alloc %s!\n", func_name);
-		fprintf(stderr, "%s\n", func_name);
-		exit(EXIT_FAILURE);
-	}
-
-	PyTuple_SetItem(ret, 0, PyLong_FromUnsignedLongLong((intptr_t) tcc_state));
-	PyTuple_SetItem(ret, 1, PyLong_FromUnsignedLongLong((intptr_t) entry));
-
-	return ret;
-
-}
-
-
-
-PyObject* tcc_loop_exec(PyObject* self, PyObject* args)
-{
-	//PyObject* (*func)(void*, void*);
-	uint64_t* vm;
-	uint64_t* cpu;
-	PyObject* ret;
-	PyObject* func;
-	PyObject* pArgs;
-
-
-	if (!PyArg_ParseTuple(args, "OKK", &func, &cpu, &vm))
-		return NULL;
-
-	while (1) {
-		if (!PyCallable_Check (func)) {
-			fprintf(stderr, "function not callable!\n");
-			exit(EXIT_FAILURE);
-		}
-
-		pArgs = PyTuple_New(2);
-		PyTuple_SetItem(pArgs, 0, PyLong_FromUnsignedLongLong((intptr_t)cpu));
-		PyTuple_SetItem(pArgs, 1, PyLong_FromUnsignedLongLong((intptr_t)vm));
-		ret = PyObject_CallObject(func, pArgs);
-		Py_DECREF(2);
-
-		if (ret == Py_None) {
-			Py_INCREF(Py_None);
-			return Py_None;
-		}
-		func = ret;
-	}
-
-	return ret;
-}
-
-
-
-static PyObject *TccError;
-
-
-static PyMethodDef TccMethods[] = {
-    {"tcc_set_emul_lib_path",  tcc_set_emul_lib_path, METH_VARARGS,
-     "init tcc path"},
-    {"tcc_exec_bloc",  tcc_exec_bloc, METH_VARARGS,
-     "tcc exec bloc"},
-    {"tcc_compil",  tcc_compil, METH_VARARGS,
-     "tcc compil"},
-    {"tcc_end",  tcc_end, METH_VARARGS,
-     "tcc end"},
-    {NULL, NULL, 0, NULL}        /* Sentinel */
-};
-
-PyMODINIT_FUNC
-initJittcc(void)
-{
-    PyObject *m;
-
-    m = Py_InitModule("Jittcc", TccMethods);
-    if (m == NULL)
-	    return;
-
-    TccError = PyErr_NewException("tcc.error", NULL, NULL);
-    Py_INCREF(TccError);
-    PyModule_AddObject(m, "error", TccError);
-}
-
diff --git a/miasm2/jitter/jitcore_tcc.py b/miasm2/jitter/jitcore_tcc.py
deleted file mode 100644
index 28288400..00000000
--- a/miasm2/jitter/jitcore_tcc.py
+++ /dev/null
@@ -1,104 +0,0 @@
-#-*- coding:utf-8 -*-
-import os
-import tempfile
-from subprocess import Popen, PIPE
-
-from miasm2.jitter import Jittcc
-from miasm2.jitter.jitcore_cc_base import JitCore_Cc_Base, gen_core
-
-
-class JitCore_Tcc(JitCore_Cc_Base):
-
-    "JiT management, using LibTCC as backend"
-
-    def __init__(self, ir_arch, bs=None):
-        super(JitCore_Tcc, self).__init__(ir_arch, bs)
-        self.exec_wrapper = Jittcc.tcc_exec_bloc
-
-    def deleteCB(self, offset):
-        "Free the TCCState corresponding to @offset"
-        if offset in self.states:
-            Jittcc.tcc_end(self.states[offset])
-            del self.states[offset]
-
-    def load(self):
-        super(JitCore_Tcc, self).load()
-        libs = ';'.join(self.libs)
-        jittcc_path = Jittcc.__file__
-        include_dir = os.path.dirname(jittcc_path)
-        include_dir += ";" + os.path.join(include_dir, "arch")
-
-        # XXX HACK
-        # As debian/ubuntu have moved some include files using arch directory,
-        # TCC doesn't know them, so we get the info from CC
-        # For example /usr/include/x86_64-linux-gnu which contains limits.h
-        p = Popen(["cc", "-Wp,-v", "-E", "-"],
-                  stdout=PIPE, stderr=PIPE, stdin=PIPE)
-        p.stdin.close()
-        include_files = p.stderr.read().split('\n')
-        include_files = [x[1:]
-                         for x in include_files if x.startswith(' /usr/include')]
-        include_files += self.include_files
-        include_files = ";".join(include_files)
-        Jittcc.tcc_set_emul_lib_path(include_files, libs)
-
-    def __del__(self):
-        for tcc_state in self.states.values():
-            Jittcc.tcc_end(tcc_state)
-
-    def jit_tcc_compil(self, func_name, func_code):
-        return Jittcc.tcc_compil(func_name, func_code)
-
-    def compil_code(self, block, func_code):
-        """
-        Compil the C code of @func_code from @block
-        @block: original asm_block
-        @func_code: C code of the block
-        """
-        label = block.label
-        self.jitcount += 1
-        tcc_state, mcode = self.jit_tcc_compil(self.label2fname(label), func_code)
-        self.lbl2jitbloc[label.offset] = mcode
-        self.states[label.offset] = tcc_state
-
-    def add_bloc(self, block):
-        """Add a bloc to JiT and JiT it.
-        @block: block to jit
-        """
-        block_hash = self.hash_block(block)
-        fname_out = os.path.join(self.tempdir, "%s.c" % block_hash)
-
-        if os.access(fname_out, os.R_OK):
-            func_code = open(fname_out, "rb").read()
-        else:
-            func_code = self.gen_c_code(block.label, block)
-
-            # Create unique C file
-            fdesc, fname_tmp = tempfile.mkstemp(suffix=".c")
-            os.write(fdesc, func_code)
-            os.close(fdesc)
-            os.rename(fname_tmp, fname_out)
-
-        self.compil_code(block, func_code)
-
-    @staticmethod
-    def gen_C_source(ir_arch, func_code):
-        c_source = ""
-        c_source += "\n".join(func_code)
-
-        c_source = gen_core(ir_arch.arch, ir_arch.attrib) + c_source
-
-        c_source = """
-     #ifdef __x86_64__
-     #ifndef __LP64__
-     /*
-      for ubuntu ?!? XXX TODO
-      /!\ force 64 bit system using 64 bits libc
-      change this to __ILP32__ to do so.
-     */
-     #define __LP64__
-     #endif
-     #endif
-     """ + "#include <Python.h>\n" + c_source
-
-        return c_source
diff --git a/miasm2/jitter/jitload.py b/miasm2/jitter/jitload.py
index b2e16c1d..db486b4f 100644
--- a/miasm2/jitter/jitload.py
+++ b/miasm2/jitter/jitload.py
@@ -171,7 +171,6 @@ class jitter(object):
         @ir_arch: ir instance for this architecture
         @jit_type: JiT backend to use. Available options are:
             - "gcc"
-            - "tcc"
             - "llvm"
             - "python"
         """
@@ -210,9 +209,7 @@ class jitter(object):
         self.symbexec.reset_regs()
 
         try:
-            if jit_type == "tcc":
-                from miasm2.jitter.jitcore_tcc import JitCore_Tcc as JitCore
-            elif jit_type == "llvm":
+            if jit_type == "llvm":
                 from miasm2.jitter.jitcore_llvm import JitCore_LLVM as JitCore
             elif jit_type == "python":
                 from miasm2.jitter.jitcore_python import JitCore_Python as JitCore