From: "Oleinik, Alexander" <alxndr@bu.edu>
To: "qemu-devel@nongnu.org" <qemu-devel@nongnu.org>
Cc: Juan Quintela <quintela@redhat.com>,
"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
"Oleinik, Alexander" <alxndr@bu.edu>,
"bsd@redhat.com" <bsd@redhat.com>,
"stefanha@redhat.com" <stefanha@redhat.com>,
"pbonzini@redhat.com" <pbonzini@redhat.com>
Subject: [Qemu-devel] [RFC PATCH v2 07/17] fuzz: Add ramfile qemu-file type
Date: Mon, 5 Aug 2019 07:11:08 +0000 [thread overview]
Message-ID: <20190805071038.32146-8-alxndr@bu.edu> (raw)
In-Reply-To: <20190805071038.32146-1-alxndr@bu.edu>
Signed-off-by: Alexander Oleinik <alxndr@bu.edu>
---
migration/qemu-file.c | 84 +++++++++++++++++++++++++++++++++++++++++++
migration/qemu-file.h | 11 ++++++
2 files changed, 95 insertions(+)
diff --git a/migration/qemu-file.c b/migration/qemu-file.c
index 0431585502..453e2897d5 100644
--- a/migration/qemu-file.c
+++ b/migration/qemu-file.c
@@ -786,3 +786,87 @@ void qemu_file_set_blocking(QEMUFile *f, bool block)
f->ops->set_blocking(f->opaque, block);
}
}
+
+#ifdef CONFIG_FUZZ
+#define INCREMENT 10240
+static ssize_t ram_writev_buffer(void *opaque, struct iovec *iov, int iovcnt,
+ int64_t pos)
+{
+ ram_disk *rd = (ram_disk *)opaque;
+ gsize newsize;
+ ssize_t total_size = 0;
+ int i;
+ if (!rd->base) {
+ rd->base = g_malloc(INCREMENT);
+ rd->len = INCREMENT;
+ }
+ for (i = 0; i < iovcnt; i++) {
+ if (pos + iov[i].iov_len >= rd->len) {
+ newsize = ((pos + iov[i].iov_len) / INCREMENT + 1) * INCREMENT;
+ rd->base = g_realloc(rd->base, newsize);
+ rd->len = newsize;
+ }
+ memcpy(rd->base + pos, iov[i].iov_base, iov[i].iov_len);
+ pos += iov[i].iov_len;
+ total_size += iov[i].iov_len;
+ }
+ return total_size;
+}
+
+static ssize_t ram_get_buffer(void *opaque, uint8_t *buf, int64_t pos,
+ size_t size)
+{
+ ram_disk *rd = (ram_disk *)opaque;
+ if (pos + size > rd->len) {
+ if (rd->len - pos >= 0) {
+ memcpy(buf, rd->base + pos, rd->len - pos);
+ size = rd->len - pos;
+ }
+ } else {
+ memcpy(buf, rd->base + pos, size);
+ }
+ return size;
+}
+
+static int ram_fclose(void *opaque)
+{
+ return 0;
+}
+
+static const QEMUFileOps ram_read_ops = {
+ .get_buffer = ram_get_buffer,
+ .close = ram_fclose
+};
+
+static const QEMUFileOps ram_write_ops = {
+ .writev_buffer = ram_writev_buffer,
+ .close = ram_fclose
+};
+
+QEMUFile *qemu_fopen_ram(ram_disk **return_rd)
+{
+ ram_disk *rd = g_new0(ram_disk, 1);
+ *return_rd = rd;
+ return qemu_fopen_ops(rd, &ram_write_ops);
+}
+
+QEMUFile *qemu_fopen_ro_ram(ram_disk* rd)
+{
+ return qemu_fopen_ops(rd, &ram_read_ops);
+}
+
+void qemu_freopen_ro_ram(QEMUFile *f)
+{
+ void *rd = f->opaque;
+ f->bytes_xfer = 0;
+ f->xfer_limit = 0;
+ f->last_error = 0;
+ f->iovcnt = 0;
+ f->buf_index = 0;
+ f->buf_size = 0;
+ f->pos = 0;
+ f->ops = &ram_read_ops;
+ f->opaque = rd;
+ return;
+}
+#endif
diff --git a/migration/qemu-file.h b/migration/qemu-file.h
index 13baf896bd..7048674f1b 100644
--- a/migration/qemu-file.h
+++ b/migration/qemu-file.h
@@ -177,4 +177,15 @@ size_t ram_control_save_page(QEMUFile *f, ram_addr_t block_offset,
void qemu_put_counted_string(QEMUFile *f, const char *name);
+#ifdef CONFIG_FUZZ
+typedef struct ram_disk {
+ void *base;
+ gsize len;
+} ram_disk;
+
+QEMUFile *qemu_fopen_ram(ram_disk **rd);
+QEMUFile *qemu_fopen_ro_ram(ram_disk* rd);
+void qemu_freopen_ro_ram(QEMUFile *f);
+#endif
+
#endif
--
2.20.1
next prev parent reply other threads:[~2019-08-05 7:13 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-05 7:11 [Qemu-devel] [RFC PATCH v2 00/17] Add virtual device fuzzing support Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 01/17] fuzz: Move initialization from main to qemu_init Oleinik, Alexander
2019-08-05 7:43 ` Paolo Bonzini
2019-08-15 12:41 ` Darren Kenny
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 02/17] fuzz: Add fuzzer configure options Oleinik, Alexander
2019-08-05 7:44 ` Paolo Bonzini
2019-08-12 22:39 ` Bandan Das
2019-08-13 18:46 ` Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 03/17] fuzz: Keep memory mapped for fork-based fuzzer Oleinik, Alexander
2019-08-09 9:01 ` Stefan Hajnoczi
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 04/17] fuzz: Skip modules that were already initialized Oleinik, Alexander
2019-08-05 7:44 ` Paolo Bonzini
2019-08-09 9:04 ` Stefan Hajnoczi
2019-08-13 18:53 ` Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 05/17] fuzz: Add direct receive function for qtest server Oleinik, Alexander
2019-08-09 9:23 ` Stefan Hajnoczi
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 06/17] fuzz: Add FUZZ_TARGET module type Oleinik, Alexander
2019-08-09 9:07 ` Stefan Hajnoczi
2019-08-05 7:11 ` Oleinik, Alexander [this message]
2019-08-05 7:50 ` [Qemu-devel] [RFC PATCH v2 07/17] fuzz: Add ramfile qemu-file type Paolo Bonzini
2019-08-05 10:46 ` Dr. David Alan Gilbert
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 08/17] fuzz: Export the qemu_savevm_live_state function Oleinik, Alexander
2019-08-05 10:54 ` Dr. David Alan Gilbert
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 09/17] fuzz: hardcode needed objects into i386 target Oleinik, Alexander
2019-08-09 9:33 ` Stefan Hajnoczi
2019-08-16 12:51 ` Darren Kenny
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 10/17] fuzz: qtest client directly interacts with server Oleinik, Alexander
2019-08-09 9:37 ` Stefan Hajnoczi
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 11/17] fuzz: Move useful qos functions to separate object Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 12/17] fuzz: Add fuzzer skeleton Oleinik, Alexander
2019-08-09 9:43 ` Stefan Hajnoczi
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 13/17] fuzz: Add libqos support to the fuzzer Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 14/17] fuzz: Add forking " Oleinik, Alexander
2019-08-09 9:46 ` Stefan Hajnoczi
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 15/17] fuzz: Add general qtest fuzz-target Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 16/17] fuzz: Add virtio-net fuzz targets Oleinik, Alexander
2019-08-05 7:11 ` [Qemu-devel] [RFC PATCH v2 17/17] fuzz: Add fuzz accelerator type Oleinik, Alexander
2019-08-05 8:19 ` [Qemu-devel] [RFC PATCH v2 00/17] Add virtual device fuzzing support no-reply
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=20190805071038.32146-8-alxndr@bu.edu \
--to=alxndr@bu.edu \
--cc=bsd@redhat.com \
--cc=dgilbert@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.com \
--cc=stefanha@redhat.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).