All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Pavel Dovgalyuk" <dovgaluk@ispras.ru>
To: "'Alex Bennée'" <alex.bennee@linaro.org>,
	"'Pavel Dovgalyuk'" <Pavel.Dovgaluk@ispras.ru>
Cc: qemu-devel@nongnu.org, peter.maydell@linaro.org,
	maria.klimushenkova@ispras.ru, pbonzini@redhat.com,
	vilanova@ac.upc.edu
Subject: Re: [Qemu-devel] [RFC PATCH v2 7/7] plugins: add syscall logging plugin sample
Date: Mon, 10 Sep 2018 12:18:19 +0300	[thread overview]
Message-ID: <001501d448e7$37421570$a5c64050$@ru> (raw)
In-Reply-To: <87pnxpz9jf.fsf@linaro.org>

> From: Alex Bennée [mailto:alex.bennee@linaro.org]
> Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru> writes:
> 
> > 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.
> 
> Again I'm not sure this is a very useful example either. It doesn't
> achieve anything we can't already do with the existing logging/strace
> stuff and it is quite ugly in it's knowledge of a single architecture to
> try and figure out what's going on.

Not exactly. strace is intrusive, when running within the VM.
And this plugin does not affect the emulated system at all (except the slowdown).

Pavel Dovgalyuk
> 
> >
> > Signed-off-by: Pavel Dovgalyuk <Pavel.Dovgaluk@ispras.ru>
> > ---
> >  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 += -I../include -fno-PIE -fPIC -O3
> > +LDFLAGS += -shared
> > +# TODO: Windows
> > +DSOSUF := .so
> > +
> > +NAME:= syscall-log
> > +BIN := $(NAME)$(DSOSUF)
> > +
> > +FILES := 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/syscall-log.c
> > new file mode 100644
> > index 0000000..1f5d55f
> > --- /dev/null
> > +++ b/plugins/syscall-log/syscall-log.c
> > @@ -0,0 +1,44 @@
> > +#include <stdint.h>
> > +#include <stdio.h>
> > +#include "plugins.h"
> > +
> > +bool plugin_init(const char *args)
> > +{
> > +    return true;
> > +}
> > +
> > +bool plugin_needs_before_insn(uint64_t pc, void *cpu)
> > +{
> > +    uint8_t code = 0;
> > +    if (!qemulib_read_memory(cpu, pc, &code, 1)
> > +        && code == 0x0f) {
> > +        if (qemulib_read_memory(cpu, pc + 1, &code, 1)) {
> > +            return false;
> > +        }
> > +        if (code == 0x34) {
> > +            /* sysenter */
> > +            return true;
> > +        }
> > +        if (code == 0x35) {
> > +            /* sysexit */
> > +            return true;
> > +        }
> > +    }
> > +    return false;
> > +}
> > +
> > +void plugin_before_insn(uint64_t pc, void *cpu)
> > +{
> > +    uint8_t code = 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*)&reg, 0);
> > +    /* log system calls */
> > +    if (code == 0x34) {
> > +        qemulib_log("sysenter %x\n", reg);
> > +    } else if (code == 0x35) {
> > +        qemulib_log("sysexit %x\n", reg);
> > +    }
> > +}
> 
> 
> --
> Alex Bennée

  reply	other threads:[~2018-09-10  9:18 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-05 10:39 [Qemu-devel] [RFC PATCH v2 0/7] QEMU binary instrumentation prototype Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 1/7] tcg: add headers for non-target helpers Pavel Dovgalyuk
2018-06-05 13:07   ` Thomas Huth
2018-06-06  7:30     ` Pavel Dovgalyuk
2018-09-07 12:16   ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 2/7] Add plugin support Pavel Dovgalyuk
2018-09-07 10:11   ` Alex Bennée
2018-09-13  6:40     ` Pavel Dovgalyuk
2018-09-07 12:34   ` Alex Bennée
2018-09-10  8:30     ` Pavel Dovgalyuk
2018-09-07 14:14   ` Alex Bennée
2018-09-10 11:41     ` Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 3/7] plugins: provide helper functions for plugins Pavel Dovgalyuk
2018-09-07 13:06   ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 4/7] tcg: add instrumenting module Pavel Dovgalyuk
2018-09-07 13:36   ` Alex Bennée
2018-09-13  6:55     ` Pavel Dovgalyuk
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 5/7] plugins: add plugin template Pavel Dovgalyuk
2018-09-07 13:41   ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 6/7] plugin: add instruction execution logger Pavel Dovgalyuk
2018-09-07 13:59   ` Alex Bennée
2018-06-05 10:39 ` [Qemu-devel] [RFC PATCH v2 7/7] plugins: add syscall logging plugin sample Pavel Dovgalyuk
2018-09-07 14:06   ` Alex Bennée
2018-09-10  9:18     ` Pavel Dovgalyuk [this message]
2018-09-10 13:58       ` Alex Bennée
2018-06-05 10:49 ` [Qemu-devel] [RFC PATCH v2 0/7] QEMU binary instrumentation prototype Peter Maydell
2018-06-05 11:56   ` Pavel Dovgalyuk
2018-06-25  5:46     ` Pavel Dovgalyuk
2018-06-25  9:06       ` Peter Maydell
2018-09-07 14:10       ` Alex Bennée
2018-07-10 13:06     ` Stefan Hajnoczi
2018-07-11  6:02       ` Pavel Dovgalyuk
2018-07-30 13:26         ` Pavel Dovgalyuk
2018-08-29  5:39       ` Pavel Dovgalyuk
2018-08-29 19:57         ` Peter Maydell
2018-08-30  4:03           ` Alex Bennée
2018-06-06  8:52 ` no-reply
2018-06-06  9:21 ` no-reply
2018-06-06 10:45 ` no-reply
2018-09-07 14:39 ` Alex Bennée
2018-09-08  0:57   ` Peter Maydell
2018-09-10  9:01     ` Alex Bennée
2018-09-10 11:44       ` Pavel Dovgalyuk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='001501d448e7$37421570$a5c64050$@ru' \
    --to=dovgaluk@ispras.ru \
    --cc=Pavel.Dovgaluk@ispras.ru \
    --cc=alex.bennee@linaro.org \
    --cc=maria.klimushenkova@ispras.ru \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vilanova@ac.upc.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.