From nobody Sun Nov 2 12:03:11 2025 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; +}