Skip to content

Commit

Permalink
initial plugins commit; including basic functionality and contexts+sy…
Browse files Browse the repository at this point in the history
…scalls plugins
  • Loading branch information
Vasiliev Ivan committed Apr 6, 2017
1 parent ad584d3 commit 0954ce5
Show file tree
Hide file tree
Showing 40 changed files with 5,749 additions and 28 deletions.
27 changes: 25 additions & 2 deletions Makefile.target
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,17 @@ $(QEMU_PROG)-simpletrace.stp: $(BUILD_DIR)/trace-events-all
else
stap:
endif
.PHONY: stap
.PHONY: stap plugins

all: $(PROGS) stap
all: $(PROGS) stap plugins

# Dummy command so that make thinks it has done something
@true

#########################################################
# cpu emulator library
obj-y = exec.o translate-all.o cpu-exec.o
obj-$(CONFIG_PLUGIN) += plugins/plugin.o plugins/plugin-qemu.o
obj-y += translate-common.o
obj-y += cpu-exec-common.o
obj-y += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o
Expand Down Expand Up @@ -166,6 +167,17 @@ GENERATED_HEADERS += hmp-commands.h hmp-commands-info.h

endif # CONFIG_SOFTMMU

#########################################################
# plugin targets

ifdef CONFIG_PLUGIN
plugins:
$(call quiet-command,$(MAKE) -C . V="$(V)" -f $(SRC_PATH)/plugins/plugins_src/Makefile all,)
else
plugins:
@true
endif # CONFIG_PLUGIN

# Workaround for http://gcc.gnu.org/PR55489, see configure.
%/translate.o: QEMU_CFLAGS += $(TRANSLATE_OPT_CFLAGS)

Expand Down Expand Up @@ -204,6 +216,11 @@ $(QEMU_PROG_BUILD): config-devices.mak
COMMON_LDADDS = $(trace-obj-y) ../libqemuutil.a ../libqemustub.a

# build either PROG or PROGW
TEMPLDFLAGS :=
ifeq ($(CONFIG_WIN32), y)
TEMPLDFLAGS += -Wl,--out-implib,libqemuplugins.dll.a
endif
$(QEMU_PROG_BUILD): LDFLAGS += $(TEMPLDFLAGS)
$(QEMU_PROG_BUILD): $(all-obj-y) $(COMMON_LDADDS)
$(call LINK, $(filter-out %.mak, $^))
ifdef CONFIG_DARWIN
Expand All @@ -227,6 +244,9 @@ clean: clean-target
ifdef CONFIG_TRACE_SYSTEMTAP
rm -f *.stp
endif
ifdef CONFIG_PLUGIN
$(call quiet-command,$(MAKE) -C . V="$(V)" -f $(SRC_PATH)/plugins/plugins_src/Makefile clean,)
endif

install: all
ifneq ($(PROGS),)
Expand All @@ -237,6 +257,9 @@ ifdef CONFIG_TRACE_SYSTEMTAP
$(INSTALL_DATA) $(QEMU_PROG).stp-installed "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG).stp"
$(INSTALL_DATA) $(QEMU_PROG)-simpletrace.stp "$(DESTDIR)$(qemu_datadir)/../systemtap/tapset/$(QEMU_PROG)-simpletrace.stp"
endif
ifdef CONFIG_PLUGIN
$(call quiet-command,$(MAKE) -C . V="$(V)" -f $(SRC_PATH)/plugins/plugins_src/Makefile install,)
endif

GENERATED_HEADERS += config-target.h
Makefile: $(GENERATED_HEADERS)
20 changes: 20 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ kvm="no"
hax="no"
rdma=""
gprof="no"
plugin="no"
debug_tcg="no"
debug="no"
fortify_source=""
Expand Down Expand Up @@ -859,6 +860,10 @@ for opt do
;;
--block-drv-ro-whitelist=*) block_drv_ro_whitelist=$(echo "$optarg" | sed -e 's/,/ /g')
;;
--enable-plugin) plugin="yes"
;;
--disable-plugin) plugin="no"
;;
--enable-debug-tcg) debug_tcg="yes"
;;
--disable-debug-tcg) debug_tcg="no"
Expand Down Expand Up @@ -1304,6 +1309,9 @@ Advanced options (experts only):
--bindir=PATH install binaries in PATH
--libdir=PATH install libraries in PATH
--sysconfdir=PATH install config in PATH$confsuffix
--libexecdir=PATH install TCG plugins in PATH"
--enable-plugin enable plugin support"
--disable-plugin disable plugin support (default)"
--localstatedir=PATH install local state in PATH (set at runtime on win32)
--with-confsuffix=SUFFIX suffix for QEMU data inside datadir/libdir/sysconfdir [$confsuffix]
--enable-debug enable common debug build options
Expand Down Expand Up @@ -5010,6 +5018,7 @@ echo "module support $modules"
echo "host CPU $cpu"
echo "host big endian $bigendian"
echo "target list $target_list"
echo "plugin support $plugin"
echo "tcg debug enabled $debug_tcg"
echo "gprof enabled $gprof"
echo "sparse enabled $sparse"
Expand Down Expand Up @@ -5149,6 +5158,17 @@ echo "libs_softmmu=$libs_softmmu" >> $config_host_mak

echo "ARCH=$ARCH" >> $config_host_mak

if test "$plugin" = "yes" ; then
echo "CONFIG_PLUGIN=y" >> $config_host_mak
if test "$mingw32" = "yes" ; then
LIBS="-lpsapi -ldl -lregex $LIBS"
LDFLAGS="-Wl,--export-all-symbols $LDFLAGS"
else
LIBS="-ldl $LIBS"
LDFLAGS="-rdynamic $LDFLAGS"
fi
fi

if test "$debug_tcg" = "yes" ; then
echo "CONFIG_DEBUG_TCG=y" >> $config_host_mak
fi
Expand Down
5 changes: 5 additions & 0 deletions cpu-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "qemu/atomic.h"
#include "sysemu/qtest.h"
#include "qemu/timer.h"
#include "plugins/plugin.h"
#include "exec/address-spaces.h"
#include "qemu/rcu.h"
#include "exec/tb-hash.h"
Expand Down Expand Up @@ -425,13 +426,15 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
cpu->exception_index = -1;
return true;
} else {
plugin_exception(cpu);
#if defined(CONFIG_USER_ONLY)
/* if user mode only, we simulate a fake exception
which will be handled outside the cpu execution
loop */
#if defined(TARGET_I386)
CPUClass *cc = CPU_GET_CLASS(cpu);
cc->do_interrupt(cpu);
plugin_exception_handler(cpu);
#endif
*ret = cpu->exception_index;
cpu->exception_index = -1;
Expand All @@ -440,6 +443,7 @@ static inline bool cpu_handle_exception(CPUState *cpu, int *ret)
if (replay_exception()) {
CPUClass *cc = CPU_GET_CLASS(cpu);
cc->do_interrupt(cpu);
plugin_exception_handler(cpu);
cpu->exception_index = -1;
} else if (!replay_has_interrupt()) {
/* give a chance to iothread in replay mode */
Expand Down Expand Up @@ -510,6 +514,7 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
else {
if (cc->cpu_exec_interrupt(cpu, interrupt_request)) {
replay_interrupt();
plugin_interrupt(cpu);
*last_tb = NULL;
}
/* The target hook may have updated the 'cpu->interrupt_request';
Expand Down
6 changes: 6 additions & 0 deletions cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "sysemu/kvm.h"
#include "sysemu/hax.h"
#include "qmp-commands.h"
#include "plugins/plugin.h"
#include "exec/exec-all.h"

#include "qemu/thread.h"
Expand Down Expand Up @@ -1407,6 +1408,11 @@ void pause_all_vcpus(void)
qemu_cpu_kick(cpu);
}
}
#ifdef CONFIG_PLUGIN
CPU_FOREACH(cpu) {
plugin_cpu_paused(cpu);
}
#endif
}

void cpu_resume(CPUState *cpu)
Expand Down
4 changes: 4 additions & 0 deletions cputlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "exec/memory-internal.h"
#include "exec/ram_addr.h"
#include "tcg/tcg.h"
#include "plugins/plugin.h"
#include "qemu/error-report.h"
#include "exec/log.h"
#include "exec/helper-proto.h"
Expand Down Expand Up @@ -406,6 +407,9 @@ void tlb_set_page_with_attrs(CPUState *cpu, target_ulong vaddr,
} else {
te->addr_write = -1;
}
#ifdef CONFIG_PLUGIN
plugin_tlb_set_page(cpu, vaddr, paddr, prot, mmu_idx, size);
#endif
}

/* Add a new TLB entry, but without specifying the memory
Expand Down
9 changes: 7 additions & 2 deletions gdbstub.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "qemu/error-report.h"
#include "qemu/cutils.h"
#include "cpu.h"
#include "plugins/plugin.h"
#ifdef CONFIG_USER_ONLY
#include "qemu.h"
#else
Expand Down Expand Up @@ -1590,7 +1591,9 @@ void gdb_exit(CPUArchState *env, int code)
#ifndef CONFIG_USER_ONLY
Chardev *chr;
#endif

#ifdef CONFIG_PLUGIN
plugin_cpus_stopped();
#endif
s = gdbserver_state;
if (!s) {
return;
Expand Down Expand Up @@ -1673,7 +1676,9 @@ void gdb_signalled(CPUArchState *env, int sig)
{
GDBState *s;
char buf[4];

#ifdef CONFIG_PLUGIN
plugin_cpus_stopped();
#endif
s = gdbserver_state;
if (gdbserver_fd < 0 || s->fd < 0) {
return;
Expand Down
40 changes: 40 additions & 0 deletions hmp-commands.hx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,47 @@ STEXI
@findex quit
Quit the emulator.
ETEXI
{
.name = "load_plugin",
.args_type = "name:s",
.params = "name",
.help = "start instrumenting",
.cmd = do_load_plugin,
},

STEXI
@item load_plugin
@findex load_plugin
Start instrumenting process. To stop it use unload_plugin.
ETEXI

{
.name = "unload_plugin",
.args_type = "name:s?",
.params = "[name]",
.help = "stop instrumenting",
.cmd = do_unload_plugin,
},

STEXI
@item unload_plugin
@findex unload_plugin
Stop instrumenting process.
ETEXI

{
.name = "list_plugins",
.args_type = "",
.params = "",
.help = "show list of loaded plugins",
.cmd = do_list_plugins,
},

STEXI
@item list_plugins
@findex list_plugins
Show list of loaded plugins.
ETEXI
{
.name = "block_resize",
.args_type = "device:B,size:o",
Expand Down
19 changes: 19 additions & 0 deletions include/monitor/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

extern Monitor *cur_mon;

typedef struct mon_cmd_t mon_cmd_t;

/* flags for monitor_init */
/* 0x01 unused */
#define MONITOR_USE_READLINE 0x02
Expand Down Expand Up @@ -52,4 +54,21 @@ int monitor_fdset_dup_fd_add(int64_t fdset_id, int dup_fd);
void monitor_fdset_dup_fd_remove(int dup_fd);
int monitor_fdset_dup_fd_find(int dup_fd);

const mon_cmd_t *monitor_parse_command(Monitor *mon, const char **cmdp, mon_cmd_t *table);
void help_cmd_dump(Monitor *mon, const mon_cmd_t *cmds, char **args, int nb_args, int arg_index);
void monitor_find_completion_by_table(Monitor *mon, const mon_cmd_t *cmd_table, char **args, int nb_args);

typedef struct mon_cmd_t {
const char *name;
const char *args_type;
const char *params;
const char *help;
void (*cmd)(Monitor *mon, const QDict *qdict);
/* @sub_table is a list of 2nd level of commands. If it do not exist,
* mhandler should be used. If it exist, sub_table[?].mhandler should be
* used, and mhandler of 1st level plays the role of help function.
*/
struct mon_cmd_t *sub_table;
void (*command_completion)(ReadLineState *rs, int nb_args, const char *str);
} mon_cmd_t;
#endif /* MONITOR_H */
Loading

0 comments on commit 0954ce5

Please sign in to comment.