From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152819530485842.18419673306971; Tue, 5 Jun 2018 03:41:44 -0700 (PDT) Received: from localhost ([::1]:45574 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9P3-0006lm-9T for importer@patchew.org; Tue, 05 Jun 2018 06:41:25 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9N5-0005OK-Su for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9N4-00068B-Nv for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:23 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55888) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9N4-00067i-B9 for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:22 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 8455054015E; Tue, 5 Jun 2018 13:39:21 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:21 +0300 Message-ID: <152819516132.30857.1700667353240369481.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 1/7] tcg: add headers for non-target helpers X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch adds functions and headers for adding the helpers from the modules other than the target translators. Signed-off-by: Pavel Dovgalyuk --- include/exec/helper-register.h | 53 ++++++++++++++++++++++++++++++++++++= ++++ tcg/tcg.c | 12 +++++++++ tcg/tcg.h | 3 ++ 3 files changed, 68 insertions(+) create mode 100644 include/exec/helper-register.h diff --git a/include/exec/helper-register.h b/include/exec/helper-register.h new file mode 100644 index 0000000..aeface9 --- /dev/null +++ b/include/exec/helper-register.h @@ -0,0 +1,53 @@ +#ifndef HELPER_REGISTER_H +#define HELPER_REGISTER_H + +#include "exec/helper-head.h" + +/* Need one more level of indirection before stringification + to get all the macros expanded first. */ +#define str(s) #s + +#define DEF_HELPER_FLAGS_0(NAME, FLAGS, ret) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, dh_sizemask(ret, 0= )); + +#define DEF_HELPER_FLAGS_1(NAME, FLAGS, ret, t1) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1)); + +#define DEF_HELPER_FLAGS_2(NAME, FLAGS, ret, t1, t2) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1) | dh_sizemask(t2, 2)); + +#define DEF_HELPER_FLAGS_3(NAME, FLAGS, ret, t1, t2, t3) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1) | dh_sizemask(t2, 2) \ + | dh_sizemask(t3, 3)); + +#define DEF_HELPER_FLAGS_4(NAME, FLAGS, ret, t1, t2, t3, t4) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1) | dh_sizemask(t2, 2) \ + | dh_sizemask(t3, 3) | dh_sizemask(t4, 4)); + +#define DEF_HELPER_FLAGS_5(NAME, FLAGS, ret, t1, t2, t3, t4, t5) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1) | dh_sizemask(t2, 2) \ + | dh_sizemask(t3, 3) | dh_sizemask(t4, 4) | dh_sizemask(t5, 5)); + +#define DEF_HELPER_FLAGS_6(NAME, FLAGS, ret, t1, t2, t3, t4, t5, t6) \ + tcg_register_helper(HELPER(NAME), str(NAME), FLAGS, \ + dh_sizemask(ret, 0) | dh_sizemask(t1, 1) | dh_sizemask(t2, 2) \ + | dh_sizemask(t3, 3) | dh_sizemask(t4, 4) | dh_sizemask(t5, 5) \ + | dh_sizemask(t6, 6)); + +#include "helper.h" + +#undef str +#undef DEF_HELPER_FLAGS_0 +#undef DEF_HELPER_FLAGS_1 +#undef DEF_HELPER_FLAGS_2 +#undef DEF_HELPER_FLAGS_3 +#undef DEF_HELPER_FLAGS_4 +#undef DEF_HELPER_FLAGS_5 +#undef DEF_HELPER_FLAGS_6 + +#endif /* HELPER_REGISTER_H */ diff --git a/tcg/tcg.c b/tcg/tcg.c index 6eeebe0..8191381 100644 --- a/tcg/tcg.c +++ b/tcg/tcg.c @@ -1623,6 +1623,18 @@ static inline const char *tcg_find_helper(TCGContext= *s, uintptr_t val) return ret; } =20 +void tcg_register_helper(void *func, const char *name, + unsigned flags, unsigned sizemask) +{ + TCGHelperInfo *info =3D g_new0(TCGHelperInfo, 1); + info->func =3D func; + info->name =3D name; + info->flags =3D flags; + info->sizemask =3D sizemask; + + g_hash_table_insert(helper_table, func, info); +} + static const char * const cond_name[] =3D { [TCG_COND_NEVER] =3D "never", diff --git a/tcg/tcg.h b/tcg/tcg.h index 08f8bbf..7a4b750 100644 --- a/tcg/tcg.h +++ b/tcg/tcg.h @@ -890,6 +890,9 @@ void tcg_register_thread(void); void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); =20 +void tcg_register_helper(void *func, const char *name, + unsigned flags, unsigned sizemask); + int tcg_gen_code(TCGContext *s, TranslationBlock *tb); =20 void tcg_set_frame(TCGContext *s, TCGReg reg, intptr_t start, intptr_t siz= e); From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528195305574521.8492779961781; Tue, 5 Jun 2018 03:41:45 -0700 (PDT) Received: from localhost ([::1]:45575 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9P9-0006ru-OF for importer@patchew.org; Tue, 05 Jun 2018 06:41:31 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45637) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9ND-0005Za-BJ for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9NA-0006D0-4v for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:31 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9N9-0006Bi-P0 for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:28 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id ED3695401D2; Tue, 5 Jun 2018 13:39:26 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:26 +0300 Message-ID: <152819516675.30857.9162557650483931182.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 2/7] Add plugin support X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This patch adds support for dynamically loaded plugins. Every plugin is a dynamic library with a set of optional exported functions that will be called from QEMU. Signed-off-by: Pavel Dovgalyuk --- Makefile.target | 1=20 configure | 14 ++++++- include/qemu/plugins.h | 8 ++++ plugins/include/plugins.h | 12 ++++++ plugins/plugins.c | 91 +++++++++++++++++++++++++++++++++++++++++= ++++ qemu-options.hx | 10 +++++ vl.c | 8 ++++ 7 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 include/qemu/plugins.h create mode 100644 plugins/include/plugins.h create mode 100644 plugins/plugins.c diff --git a/Makefile.target b/Makefile.target index dad2cf8..4cffd96 100644 --- a/Makefile.target +++ b/Makefile.target @@ -93,6 +93,7 @@ all: $(PROGS) stap # cpu emulator library obj-y +=3D exec.o obj-y +=3D accel/ +obj-$(CONFIG_PLUGINS) +=3D plugins/plugins.o obj-$(CONFIG_TCG) +=3D tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-= gvec.o obj-$(CONFIG_TCG) +=3D tcg/tcg-common.o tcg/optimize.o obj-$(CONFIG_TCG_INTERPRETER) +=3D tcg/tci.o diff --git a/configure b/configure index a71bf9b..34e6f00 100755 --- a/configure +++ b/configure @@ -373,6 +373,7 @@ EXESUF=3D"" DSOSUF=3D".so" LDFLAGS_SHARED=3D"-shared" modules=3D"no" +plugins=3D"no" prefix=3D"/usr/local" mandir=3D"\${prefix}/share/man" datadir=3D"\${prefix}/share" @@ -922,6 +923,12 @@ for opt do --disable-modules) modules=3D"no" ;; + --enable-plugins) + plugins=3D"yes" + ;; + --disable-plugins) + plugins=3D"no" + ;; --cpu=3D*) ;; --target-list=3D*) target_list=3D"$optarg" @@ -1567,6 +1574,7 @@ disabled with --disable-FEATURE, default is enabled i= f available: guest-agent-msi build guest agent Windows MSI installation package pie Position Independent Executables modules modules support + plugins plugins support debug-tcg TCG debugging (default is disabled) debug-info debugging information sparse sparse checker @@ -3392,7 +3400,7 @@ else glib_req_ver=3D2.22 fi glib_modules=3Dgthread-2.0 -if test "$modules" =3D yes; then +if test "$modules" =3D yes || test "$plugins" =3D yes; then glib_modules=3D"$glib_modules gmodule-export-2.0" fi =20 @@ -5777,6 +5785,7 @@ if test "$slirp" =3D "yes" ; then echo "smbd $smbd" fi echo "module support $modules" +echo "plugin support $plugins" echo "host CPU $cpu" echo "host big endian $bigendian" echo "target list $target_list" @@ -6111,6 +6120,9 @@ if test "$modules" =3D "yes"; then echo "CONFIG_STAMP=3D_$( (echo $qemu_version; echo $pkgversion; cat $0) = | $shacmd - | cut -f1 -d\ )" >> $config_host_mak echo "CONFIG_MODULES=3Dy" >> $config_host_mak fi +if test "$plugins" =3D "yes"; then + echo "CONFIG_PLUGINS=3Dy" >> $config_host_mak +fi if test "$have_x11" =3D "yes" -a "$need_x11" =3D "yes"; then echo "CONFIG_X11=3Dy" >> $config_host_mak echo "X11_CFLAGS=3D$x11_cflags" >> $config_host_mak diff --git a/include/qemu/plugins.h b/include/qemu/plugins.h new file mode 100644 index 0000000..4464822 --- /dev/null +++ b/include/qemu/plugins.h @@ -0,0 +1,8 @@ +#ifndef PLUGINS_H +#define PLUGINS_H + +void qemu_plugin_parse_cmd_args(const char *optarg); +void qemu_plugin_load(const char *filename, const char *args); +void qemu_plugins_init(void); + +#endif /* PLUGINS_H */ diff --git a/plugins/include/plugins.h b/plugins/include/plugins.h new file mode 100644 index 0000000..100a786 --- /dev/null +++ b/plugins/include/plugins.h @@ -0,0 +1,12 @@ +#ifndef PLUGINS_INTERFACE_H +#define PLUGINS_INTERFACE_H + +#include + +/* Plugin interface */ + +bool plugin_init(const char *args); +bool plugin_needs_before_insn(uint64_t pc, void *cpu); +void plugin_before_insn(uint64_t pc, void *cpu); + +#endif /* PLUGINS_INTERFACE_H */ diff --git a/plugins/plugins.c b/plugins/plugins.c new file mode 100644 index 0000000..eabc931 --- /dev/null +++ b/plugins/plugins.c @@ -0,0 +1,91 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "qemu/error-report.h" +#include "qemu/plugins.h" +#include "qemu/queue.h" +#include + +typedef bool (*PluginInitFunc)(const char *); +typedef bool (*PluginNeedsBeforeInsnFunc)(uint64_t, void *); +typedef void (*PluginBeforeInsnFunc)(uint64_t, void *); + +typedef struct QemuPluginInfo { + const char *filename; + const char *args; + GModule *g_module; + + PluginInitFunc init; + PluginNeedsBeforeInsnFunc needs_before_insn; + PluginBeforeInsnFunc before_insn; + + QLIST_ENTRY(QemuPluginInfo) next; +} QemuPluginInfo; + +static QLIST_HEAD(, QemuPluginInfo) qemu_plugins + =3D QLIST_HEAD_INITIALIZER(qemu_plugins); + +static QemuOptsList qemu_plugin_opts =3D { + .name =3D "plugin", + .head =3D QTAILQ_HEAD_INITIALIZER(qemu_plugin_opts.head), + .desc =3D { + { + .name =3D "file", + .type =3D QEMU_OPT_STRING, + },{ + .name =3D "args", + .type =3D QEMU_OPT_STRING, + }, + { /* end of list */ } + }, +}; + +void qemu_plugin_parse_cmd_args(const char *optarg) +{ + QemuOpts *opts =3D qemu_opts_parse_noisily(&qemu_plugin_opts, optarg, = false); + qemu_plugin_load(qemu_opt_get(opts, "file"), + qemu_opt_get(opts, "args")); +} + +void qemu_plugin_load(const char *filename, const char *args) +{ + GModule *g_module; + QemuPluginInfo *info =3D NULL; + if (!filename) { + error_report("plugin name was not specified"); + return; + } + g_module =3D g_module_open(filename, + G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL); + if (!g_module) { + error_report("can't load plugin '%s'", filename); + return; + } + info =3D g_new0(QemuPluginInfo, 1); + info->filename =3D g_strdup(filename); + info->g_module =3D g_module; + if (args) { + info->args =3D g_strdup(args); + } + + g_module_symbol(g_module, "plugin_init", (gpointer*)&info->init); + + /* Get the instrumentation callbacks */ + g_module_symbol(g_module, "plugin_needs_before_insn", + (gpointer*)&info->needs_before_insn); + g_module_symbol(g_module, "plugin_before_insn", + (gpointer*)&info->before_insn); + + QLIST_INSERT_HEAD(&qemu_plugins, info, next); + + return; +} + +void qemu_plugins_init(void) +{ + QemuPluginInfo *info; + QLIST_FOREACH(info, &qemu_plugins, next) { + if (info->init) { + info->init(info->args); + } + } +} diff --git a/qemu-options.hx b/qemu-options.hx index c0d3951..d171544 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -3950,6 +3950,16 @@ Dump json-encoded vmstate information for current ma= chine type to file in @var{file} ETEXI =20 +#ifdef CONFIG_PLUGINS +DEF("plugin", HAS_ARG, QEMU_OPTION_plugin, \ + "-plugin file=3D[,args=3D] load plugin with <= args>\n", QEMU_ARCH_ALL) +STEXI +@item -plugin file=3D@var{file}[,args=3D@var{args}] +@findex -plugin +Load @var{file} plugin passing @var{args} arguments. +ETEXI +#endif + STEXI @end table ETEXI diff --git a/vl.c b/vl.c index 0603171..05420bf 100644 --- a/vl.c +++ b/vl.c @@ -129,6 +129,7 @@ int main(int argc, char **argv) #include "qapi/qapi-commands-run-state.h" #include "qapi/qmp/qerror.h" #include "sysemu/iothread.h" +#include "qemu/plugins.h" =20 #define MAX_VIRTIO_CONSOLES 1 =20 @@ -3925,6 +3926,11 @@ int main(int argc, char **argv, char **envp) exit(1); } break; +#ifdef CONFIG_PLUGINS + case QEMU_OPTION_plugin: + qemu_plugin_parse_cmd_args(optarg); + break; +#endif case QEMU_OPTION_nodefconfig: case QEMU_OPTION_nouserconfig: /* Nothing to be parsed here. Especially, do not error out= below. */ @@ -4470,6 +4476,8 @@ int main(int argc, char **argv, char **envp) } parse_numa_opts(current_machine); =20 + qemu_plugins_init(); + /* do monitor/qmp handling at preconfig state if requested */ main_loop(); =20 From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152819535301311.27222280480612; Tue, 5 Jun 2018 03:42:33 -0700 (PDT) Received: from localhost ([::1]:45576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9Q8-0007jF-5r for importer@patchew.org; Tue, 05 Jun 2018 06:42:32 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45653) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NG-0005cA-CQ for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9NF-0006Gz-EU for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:34 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55928) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NF-0006Gc-5u for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:33 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 5A56F540218; Tue, 5 Jun 2018 13:39:32 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:32 +0300 Message-ID: <152819517217.30857.1806942753626059939.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 3/7] plugins: provide helper functions for plugins X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch adds interface functions that may be called from the loaded plug= ins. Such functions are needed to inspect the VM state and to pass data to the QEMU (e.g., QEMU-side logging). Signed-off-by: Pavel Dovgalyuk --- Makefile.target | 2 +- plugins/include/plugins.h | 6 ++++++ plugins/qemulib.c | 31 +++++++++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 plugins/qemulib.c diff --git a/Makefile.target b/Makefile.target index 4cffd96..5648c9c 100644 --- a/Makefile.target +++ b/Makefile.target @@ -93,7 +93,7 @@ all: $(PROGS) stap # cpu emulator library obj-y +=3D exec.o obj-y +=3D accel/ -obj-$(CONFIG_PLUGINS) +=3D plugins/plugins.o +obj-$(CONFIG_PLUGINS) +=3D plugins/plugins.o plugins/qemulib.o obj-$(CONFIG_TCG) +=3D tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-= gvec.o obj-$(CONFIG_TCG) +=3D tcg/tcg-common.o tcg/optimize.o obj-$(CONFIG_TCG_INTERPRETER) +=3D tcg/tci.o diff --git a/plugins/include/plugins.h b/plugins/include/plugins.h index 100a786..fa624ea 100644 --- a/plugins/include/plugins.h +++ b/plugins/include/plugins.h @@ -9,4 +9,10 @@ bool plugin_init(const char *args); bool plugin_needs_before_insn(uint64_t pc, void *cpu); void plugin_before_insn(uint64_t pc, void *cpu); =20 +/* QEMU interface */ + +void qemulib_log(const char *fmt, ...) /*GCC_FMT_ATTR(1, 2)*/; +int qemulib_read_memory(void *cpu, uint64_t addr, uint8_t *buf, int len); +int qemulib_read_register(void *cpu, uint8_t *mem_buf, int reg); + #endif /* PLUGINS_INTERFACE_H */ diff --git a/plugins/qemulib.c b/plugins/qemulib.c new file mode 100644 index 0000000..eb812c1 --- /dev/null +++ b/plugins/qemulib.c @@ -0,0 +1,31 @@ +#include "qemu/osdep.h" +#include "qemu-common.h" +#include "cpu.h" +#include "qemu/error-report.h" +#include "qemu/plugins.h" +#include "qemu/log.h" +#include "include/plugins.h" + +void qemulib_log(const char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + qemu_log_vprintf(fmt, args); + va_end(args); +} + +int qemulib_read_memory(void *cpu, uint64_t addr, uint8_t *buf, int len) +{ + return cpu_memory_rw_debug(cpu, addr, buf, len, false); +} + +int qemulib_read_register(void *cpu, uint8_t *mem_buf, int reg) +{ + CPUClass *cc =3D CPU_GET_CLASS(cpu); + + if (reg < cc->gdb_num_core_regs) { + return cc->gdb_read_register(cpu, mem_buf, reg); + } + + return 0; +} From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528195433736361.3943230978872; Tue, 5 Jun 2018 03:43:53 -0700 (PDT) Received: from localhost ([::1]:45585 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9RR-0000mQ-2T for importer@patchew.org; Tue, 05 Jun 2018 06:43:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NO-0005jT-5z for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9NL-0006LZ-10 for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:42 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55946) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NK-0006Kt-IG for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:38 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id BBD1054021C; Tue, 5 Jun 2018 13:39:37 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:37 +0300 Message-ID: <152819517756.30857.1862569750260837574.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 4/7] tcg: add instrumenting module X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This is a samples of the instrumenting interface and implementation of some instruction tracing tasks. Signed-off-by: Pavel Dovgalyuk --- accel/tcg/translator.c | 5 +++++ include/qemu/instrument.h | 7 +++++++ plugins/helper.h | 1 + plugins/plugins.c | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 include/qemu/instrument.h create mode 100644 plugins/helper.h diff --git a/accel/tcg/translator.c b/accel/tcg/translator.c index 0f9dca9..48773ac 100644 --- a/accel/tcg/translator.c +++ b/accel/tcg/translator.c @@ -17,6 +17,7 @@ #include "exec/gen-icount.h" #include "exec/log.h" #include "exec/translator.h" +#include "qemu/instrument.h" =20 /* Pairs with tcg_clear_temp_count. To be called by #TranslatorOps.{translate_insn,tb_stop} if @@ -89,6 +90,10 @@ void translator_loop(const TranslatorOps *ops, DisasCont= extBase *db, } } =20 + if (plugins_need_before_insn(db->pc_next, cpu)) { + plugins_instrument_before_insn(db->pc_next, cpu); + } + /* Disassemble one instruction. The translate_insn hook should update db->pc_next and db->is_jmp to indicate what should be done next -- either exiting this loop or locate the start of diff --git a/include/qemu/instrument.h b/include/qemu/instrument.h new file mode 100644 index 0000000..e8f279f --- /dev/null +++ b/include/qemu/instrument.h @@ -0,0 +1,7 @@ +#ifndef INSTRUMENT_H +#define INSTRUMENT_H + +bool plugins_need_before_insn(target_ulong pc, CPUState *cpu); +void plugins_instrument_before_insn(target_ulong pc, CPUState *cpu); + +#endif /* INSTRUMENT_H */ diff --git a/plugins/helper.h b/plugins/helper.h new file mode 100644 index 0000000..007b395 --- /dev/null +++ b/plugins/helper.h @@ -0,0 +1 @@ +DEF_HELPER_2(before_insn, void, tl, ptr) diff --git a/plugins/plugins.c b/plugins/plugins.c index eabc931..5a08e71 100644 --- a/plugins/plugins.c +++ b/plugins/plugins.c @@ -1,8 +1,13 @@ #include "qemu/osdep.h" #include "qemu-common.h" +#include "cpu.h" #include "qemu/error-report.h" #include "qemu/plugins.h" +#include "qemu/instrument.h" +#include "tcg/tcg.h" +#include "tcg/tcg-op.h" #include "qemu/queue.h" +#include "qemu/option.h" #include =20 typedef bool (*PluginInitFunc)(const char *); @@ -80,6 +85,40 @@ void qemu_plugin_load(const char *filename, const char *= args) return; } =20 +bool plugins_need_before_insn(target_ulong pc, CPUState *cpu) +{ + QemuPluginInfo *info; + QLIST_FOREACH(info, &qemu_plugins, next) { + if (info->needs_before_insn && info->needs_before_insn(pc, cpu)) { + return true; + } + } + + return false; +} + +void plugins_instrument_before_insn(target_ulong pc, CPUState *cpu) +{ + TCGv t_pc =3D tcg_const_tl(pc); + TCGv_ptr t_cpu =3D tcg_const_ptr(cpu); + /* We will dispatch plugins' callbacks in our own helper below */ + gen_helper_before_insn(t_pc, t_cpu); + tcg_temp_free(t_pc); + tcg_temp_free_ptr(t_cpu); +} + +void helper_before_insn(target_ulong pc, void *cpu) +{ + QemuPluginInfo *info; + QLIST_FOREACH(info, &qemu_plugins, next) { + if (info->needs_before_insn && info->needs_before_insn(pc, cpu)) { + if (info->before_insn) { + info->before_insn(pc, cpu); + } + } + } +} + void qemu_plugins_init(void) { QemuPluginInfo *info; @@ -88,4 +127,6 @@ void qemu_plugins_init(void) info->init(info->args); } } + +#include "exec/helper-register.h" } From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528195431156652.2666322039333; Tue, 5 Jun 2018 03:43:51 -0700 (PDT) Received: from localhost ([::1]:45584 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9RO-0000kQ-6d for importer@patchew.org; Tue, 05 Jun 2018 06:43:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45706) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NR-0005m8-30 for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9NQ-0006Qd-7d for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:45 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55966) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NP-0006QC-VH for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:44 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 25878540222; Tue, 5 Jun 2018 13:39:43 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:42 +0300 Message-ID: <152819518295.30857.8519946393746431063.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 5/7] plugins: add plugin template X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This is a template of the QEMU plugin. It includes empty functions that plugins may implement. Signed-off-by: Pavel Dovgalyuk --- plugins/template/Makefile | 19 +++++++++++++++++++ plugins/template/template.c | 19 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 plugins/template/Makefile create mode 100644 plugins/template/template.c diff --git a/plugins/template/Makefile b/plugins/template/Makefile new file mode 100644 index 0000000..b9d10da --- /dev/null +++ b/plugins/template/Makefile @@ -0,0 +1,19 @@ +CFLAGS +=3D -I../include -fno-PIE -fPIC -O3 +LDFLAGS +=3D -shared +# TODO: Windows +DSOSUF :=3D .so + +NAME:=3D template +BIN :=3D $(NAME)$(DSOSUF) + +FILES :=3D template.o + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +all: $(FILES) + $(CC) $(LDFLAGS) -o $(BIN) $(FILES) + +clean: + rm $(FILES) + rm $(BIN) diff --git a/plugins/template/template.c b/plugins/template/template.c new file mode 100644 index 0000000..fed1053 --- /dev/null +++ b/plugins/template/template.c @@ -0,0 +1,19 @@ +#include +#include +#include "plugins.h" + +bool plugin_init(const char *args) +{ + printf("template plugin loaded successfully\n"); + return true; +} + +bool plugin_needs_before_insn(uint64_t pc, void *cpu) +{ + return true; +} + +void plugin_before_insn(uint64_t pc, void *cpu) +{ + printf("executing instruction at %lx\n", pc); +} From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528195540784501.97064599998794; Tue, 5 Jun 2018 03:45:40 -0700 (PDT) Received: from localhost ([::1]:45600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9T4-0002pe-QJ for importer@patchew.org; Tue, 05 Jun 2018 06:45:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45804) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NY-0005tu-Pd for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9NV-0006W9-Kz for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:52 -0400 Received: from mail.ispras.ru ([83.149.199.45]:55980) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9NV-0006VU-CZ for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:49 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id 8F5D3540226; Tue, 5 Jun 2018 13:39:48 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:48 +0300 Message-ID: <152819518838.30857.7489579122481731984.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 6/7] plugin: add instruction execution logger X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Pavel Dovgalyuk This patch adds a plugin for logging addresses of all executed instructions, making a complete instruction-level trace. Signed-off-by: Pavel Dovgalyuk --- plugins/exec-log/Makefile | 19 +++++++++++++++++++ plugins/exec-log/exec-log.c | 18 ++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 plugins/exec-log/Makefile create mode 100644 plugins/exec-log/exec-log.c diff --git a/plugins/exec-log/Makefile b/plugins/exec-log/Makefile new file mode 100644 index 0000000..86374f4 --- /dev/null +++ b/plugins/exec-log/Makefile @@ -0,0 +1,19 @@ +CFLAGS +=3D -I../include -fno-PIE -fPIC -O3 +LDFLAGS +=3D -shared +# TODO: Windows +DSOSUF :=3D .so + +NAME:=3D exec-log +BIN :=3D $(NAME)$(DSOSUF) + +FILES :=3D exec-log.o + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +all: $(FILES) + $(CC) $(LDFLAGS) -o $(BIN) $(FILES) + +clean: + rm $(FILES) + rm $(BIN) diff --git a/plugins/exec-log/exec-log.c b/plugins/exec-log/exec-log.c new file mode 100644 index 0000000..7fc7975 --- /dev/null +++ b/plugins/exec-log/exec-log.c @@ -0,0 +1,18 @@ +#include +#include +#include "plugins.h" + +bool plugin_init(const char *args) +{ + return true; +} + +bool plugin_needs_before_insn(uint64_t pc, void *cpu) +{ + return true; +} + +void plugin_before_insn(uint64_t pc, void *cpu) +{ + qemulib_log("executing instruction at %lx\n", pc); +} From nobody Wed May 1 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1528195480854461.8276407152705; Tue, 5 Jun 2018 03:44:40 -0700 (PDT) Received: from localhost ([::1]:45586 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9SC-0001Tx-7H for importer@patchew.org; Tue, 05 Jun 2018 06:44:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9Nb-0005xU-TY for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fQ9Na-0006ay-VQ for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:55 -0400 Received: from mail.ispras.ru ([83.149.199.45]:56000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9Na-0006aS-Ng for qemu-devel@nongnu.org; Tue, 05 Jun 2018 06:39:54 -0400 Received: from [127.0.1.1] (unknown [85.142.117.226]) by mail.ispras.ru (Postfix) with ESMTPSA id EBF0B540232; Tue, 5 Jun 2018 13:39:53 +0300 (MSK) From: Pavel Dovgalyuk To: qemu-devel@nongnu.org Date: Tue, 05 Jun 2018 13:39:53 +0300 Message-ID: <152819519376.30857.17032517857304957536.stgit@pasha-ThinkPad-T60> In-Reply-To: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> References: <152819515565.30857.16834004920507717324.stgit@pasha-ThinkPad-T60> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 83.149.199.45 Subject: [Qemu-devel] [RFC PATCH v2 7/7] plugins: add syscall logging plugin sample X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, maria.klimushenkova@ispras.ru, dovgaluk@ispras.ru, pavel.dovgaluk@ispras.ru, pbonzini@redhat.com, vilanova@ac.upc.edu Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 This is an example of plugin which instruments only specific instructions: sysenter and sysexit. When executing them, it prints system call id and return code to the QEMU log. Signed-off-by: Pavel Dovgalyuk --- plugins/syscall-log/Makefile | 19 ++++++++++++++++ plugins/syscall-log/syscall-log.c | 44 +++++++++++++++++++++++++++++++++= ++++ 2 files changed, 63 insertions(+) create mode 100644 plugins/syscall-log/Makefile create mode 100644 plugins/syscall-log/syscall-log.c diff --git a/plugins/syscall-log/Makefile b/plugins/syscall-log/Makefile new file mode 100644 index 0000000..1bbdf04 --- /dev/null +++ b/plugins/syscall-log/Makefile @@ -0,0 +1,19 @@ +CFLAGS +=3D -I../include -fno-PIE -fPIC -O3 +LDFLAGS +=3D -shared +# TODO: Windows +DSOSUF :=3D .so + +NAME:=3D syscall-log +BIN :=3D $(NAME)$(DSOSUF) + +FILES :=3D syscall-log.o + +%.o: %.c + $(CC) -c -o $@ $< $(CFLAGS) + +all: $(FILES) + $(CC) $(LDFLAGS) -o $(BIN) $(FILES) + +clean: + rm $(FILES) + rm $(BIN) diff --git a/plugins/syscall-log/syscall-log.c b/plugins/syscall-log/syscal= l-log.c new file mode 100644 index 0000000..1f5d55f --- /dev/null +++ b/plugins/syscall-log/syscall-log.c @@ -0,0 +1,44 @@ +#include +#include +#include "plugins.h" + +bool plugin_init(const char *args) +{ + return true; +} + +bool plugin_needs_before_insn(uint64_t pc, void *cpu) +{ + uint8_t code =3D 0; + if (!qemulib_read_memory(cpu, pc, &code, 1) + && code =3D=3D 0x0f) { + if (qemulib_read_memory(cpu, pc + 1, &code, 1)) { + return false; + } + if (code =3D=3D 0x34) { + /* sysenter */ + return true; + } + if (code =3D=3D 0x35) { + /* sysexit */ + return true; + } + } + return false; +} + +void plugin_before_insn(uint64_t pc, void *cpu) +{ + uint8_t code =3D 0; + uint32_t reg; + qemulib_read_memory(cpu, pc + 1, &code, 1); + /* Read EAX. There should be a header with register ids + or a function for reading the register by the name */ + qemulib_read_register(cpu, (uint8_t*)®, 0); + /* log system calls */ + if (code =3D=3D 0x34) { + qemulib_log("sysenter %x\n", reg); + } else if (code =3D=3D 0x35) { + qemulib_log("sysexit %x\n", reg); + } +}