From patchwork Tue Jun 5 10:39:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Pavel Dovgalyuk X-Patchwork-Id: 10448017 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 309E360284 for ; Tue, 5 Jun 2018 10:42:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1908729036 for ; Tue, 5 Jun 2018 10:42:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B6C629041; Tue, 5 Jun 2018 10:42:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9DA5729036 for ; Tue, 5 Jun 2018 10:42:03 +0000 (UTC) Received: from localhost ([::1]:45576 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fQ9Pe-0007jF-RB for patchwork-qemu-devel@patchwork.kernel.org; Tue, 05 Jun 2018 06:42:02 -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 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Pavel Dovgalyuk This patch adds interface functions that may be called from the loaded plugins. 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 Reviewed-by: Alex Bennée --- 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 += exec.o obj-y += accel/ -obj-$(CONFIG_PLUGINS) += plugins/plugins.o +obj-$(CONFIG_PLUGINS) += plugins/plugins.o plugins/qemulib.o obj-$(CONFIG_TCG) += tcg/tcg.o tcg/tcg-op.o tcg/tcg-op-vec.o tcg/tcg-op-gvec.o obj-$(CONFIG_TCG) += tcg/tcg-common.o tcg/optimize.o obj-$(CONFIG_TCG_INTERPRETER) += 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); +/* 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 = CPU_GET_CLASS(cpu); + + if (reg < cc->gdb_num_core_regs) { + return cc->gdb_read_register(cpu, mem_buf, reg); + } + + return 0; +}