Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
farzonl committed Jun 2, 2019
0 parents commit c4272a9
Show file tree
Hide file tree
Showing 22 changed files with 15,519 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*Images/*.img
*Images/vmlinuz
buildDirARM64/
buildDirX86/
*.log
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[submodule "qemu"]
path = qemu
url = https://github.com/gthparch/qemu.git
branch = feature/qsim_plugins
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apt:
update: true
language: cpp
before_script:
- ./build.sh
script:
- make -C qemu/plugins/qsimPlugin
- make -C qemu/plugins/testPlugin
- make -C debugTool && make -C debugTool/testcases
2 changes: 2 additions & 0 deletions Dependencies.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sudo apt install sshpass

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

example invocation:
python run.py --imgconfig arm64Images/config.json --benchmark simpleBenchmark/ --plugin qemu/plugins/qsimPlugin/qsim-plugin.so

[![Build Status](https://travis-ci.com/farzonl/qsimPlugin.svg?branch=master)](https://travis-ci.com/farzonl/qsimPlugin)
7 changes: 7 additions & 0 deletions arm64Images/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"drive": "arm64disk.img",
"kernel": "vmlinuz",
"initrd": "initrd.img",
"username" : "qsim",
"password" : "qsim12"
}
22 changes: 22 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
if [ ! -d buildDirARM64 ]; then
echo "buildDirARM64 dir created"
mkdir buildDirARM64
fi
if [ ! -d buildDirx86 ]; then
echo "buildDirX86 dir created"
mkdir buildDirX86
fi
git submodule init
git submodule update
#if [ ! -d qemu ]; then
# git clone https://github.com/gthparch/qemu.git
# git checkout feature/qsim_plugin
#fi
cd buildDirARM64
../qemu/configure --target-list=aarch64-softmmu --enable-plugins
make -j 4 &
cd ..
cd buildDirX86
../qemu/configure --target-list=i386-softmmu --enable-plugins
make -j 4

14 changes: 14 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"memory": "4096M",
"emuMachineType": "virt",
"global": "virtio-blk-device.scsi=off",
"devices": ["virtio-scsi-device,id=scsi", "scsi-hd,drive=coreimg",
"virtio-net-device,netdev=unet"],
"netdev": "user,id=unet",
"portNumber": "2851",
"append": "root=/dev/sda2",
"nographic" : true,
"driveParam": "id=coreimg,cache=unsafe,if=none",
"remoteBenchmarkDir": "benchmark",
"remotescriptExec" : "runner.sh"
}
2 changes: 2 additions & 0 deletions debugTool/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.o
*_dynamicLibVerify
53 changes: 53 additions & 0 deletions debugTool/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#_____________STATIC STUFF__________________________________________
OPTIONS = -std=c++11 -D VERBOSE
FILES := main.o $(shell echo src/*.cpp | sed -e 's/cpp/o/g')
UNAME := $(shell uname)
EXE := $(UNAME)_dynamicLibVerify
CC := g++
INCPATH := `pkg-config gmodule-2.0 --cflags`
INCPATH += -I include
LIBPATH := `pkg-config gmodule-2.0 --libs`
CFLAGS := $(INCPATH) $(LIBPATH) $(OPTIONS)
#_____________STATIC STUFF________________________________________________

#Small enough project so lets rebuild everytime
run : build-release
./$(EXE)

run-debug : build-debug
./$(EXE)

run-gdb : build-debug
gdb --args ./$(EXE)

edit0 :
nano -c main.cpp

edit1 :
ifeq ($(UNAME), Linux)
kate *.cpp *.hpp &
endif
ifeq ($(UNAME), Darwin)
@echo 'N/A'
endif

run-valgrind : build-debug
valgrind --leak-check=yes --show-reachable=yes --tool=memcheck ./EXE

build-release : CFLAGS += -O3
build-release : $(EXE)

%.o: %.cpp
$(CC) -c -o $@ $< $(CFLAGS)

$(EXE) : $(FILES)
$(CC) $^ -o $(EXE) $(CFLAGS)

build-debug : CFLAGS += -g -DDEBUG
build-debug : $(EXE)

clean :
rm -rf *.o* $(EXE)*

rebuild : clean build-release

10 changes: 10 additions & 0 deletions debugTool/include/pluginLoad.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#ifndef __PLUGIN__LOAD_HPP__
#define __PLUGIN__LOAD_HPP__
class PluginLoad {
public:
static bool plugin_load(const char *filename);
private:
PluginLoad() = delete;
};
#endif // __PLUGIN__LOAD_HPP__
8 changes: 8 additions & 0 deletions debugTool/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include "pluginLoad.hpp"

int main(int argc, char **argv) {
if(argc == 2) {
PluginLoad::plugin_load(argv[1]);
}
return 0;
}
70 changes: 70 additions & 0 deletions debugTool/src/pluginLoad.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#include <stdio.h>
#include <gmodule.h>
#include "pluginLoad.hpp"


#ifdef VERBOSE
#define DB_PRINTF(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define DB_PRINTF(f_, ...) (void)0
#endif

//#include "/usr/include/glib-2.0/gmodule.h"
typedef bool (*PluginInitFunc)(const char *);
typedef bool (*PluginNeedsBeforeInsnFunc)(u_int64_t, void *);
typedef void (*PluginBeforeInsnFunc)(u_int64_t, void *);
typedef void (*PluginAfterMemFunc)(void *, u_int64_t, int, int);
typedef void (*PluginBeeforeInterupt)(void *, u_int64_t);

PluginInitFunc* init;
PluginNeedsBeforeInsnFunc* needs_before_insn;
PluginBeforeInsnFunc* before_insn;
PluginAfterMemFunc* after_mem;
bool enable_instrumentation = true;

bool PluginLoad::plugin_load(const char *filename)
{
GModule *g_module;
bool retValue = true;
if (!filename) {
DB_PRINTF("plugin name was not specified");
return false;
}
g_module = g_module_open(filename,
G_MODULE_BIND_LAZY);
if (!g_module) {
DB_PRINTF("can't load plugin '%s'", filename);
DB_PRINTF("error: %s",g_module_error ());
return false;
}
DB_PRINTF("plugin '%s' Loaded!", filename);

if (!g_module_symbol(g_module, "plugin_init", (gpointer*)&init) ) {
DB_PRINTF("plugin_init failed to load is: 0x%p !", init);
DB_PRINTF("plugin_init error: %s",g_module_error ());
retValue = false;

}
/* Get the instrumentation callbacks */
if (! g_module_symbol(g_module, "plugin_needs_before_insn", (gpointer*)&needs_before_insn) ) {
DB_PRINTF("needs_before_insn is: 0x%p !", needs_before_insn);
DB_PRINTF("needs_before_insn error: %s",g_module_error ());
retValue = false;
}
if (! g_module_symbol(g_module, "plugin_before_insn",(gpointer*)&before_insn) ) {
DB_PRINTF("before_insn is: 0x%p !", before_insn);
DB_PRINTF("before_insn error: %s",g_module_error ());
retValue = false;
}

if (! g_module_symbol(g_module, "plugin_after_mem",
(gpointer*)&after_mem) ) {

DB_PRINTF("after_mem is: 0x%p !", after_mem);
DB_PRINTF("after_mem error: %s",g_module_error ());
retValue = false;
}

g_module_close (g_module);
return retValue;
}
1 change: 1 addition & 0 deletions debugTool/testcases/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*_TestCases
52 changes: 52 additions & 0 deletions debugTool/testcases/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#_____________STATIC STUFF__________________________________________
OPTIONS = -std=c++11
FILES := test.o $(shell echo ../src/*.cpp | sed -e 's/cpp/o/g')
UNAME := $(shell uname)
EXE := $(UNAME)_TestCases
CC := g++

INCPATH := `pkg-config gmodule-2.0 --cflags` -I include -I ../include
LIBPATH := `pkg-config gmodule-2.0 --libs`
CFLAGS := $(INCPATH) $(LIBPATH) $(OPTIONS)
#_____________STATIC STUFF________________________________________________

#Small enough project so lets rebuild everytime
run : build-release
./$(EXE)

run-debug : build-debug
./$(EXE)

run-gdb : build-debug
gdb --args ./$(EXE)

edit0 :
nano -c main.cpp

edit1 :
ifeq ($(UNAME), Linux)
kate *.cpp *.hpp &
endif
ifeq ($(UNAME), Darwin)
@echo 'N/A'
endif

run-valgrind : build-debug
valgrind --leak-check=yes --show-reachable=yes --tool=memcheck ./EXE

build-release : CFLAGS += -O3
build-release : $(EXE)

%.o: %.cpp
$(CC) -c -o $@ $< $(CFLAGS)

$(EXE) : $(FILES)
$(CC) $^ -o $(EXE) $(CFLAGS)

build-debug : CFLAGS += -g -DDEBUG
build-debug : $(EXE)

clean :
rm -rf *.o* $(EXE)*

rebuild : clean build-release
Loading

0 comments on commit c4272a9

Please sign in to comment.