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