From patchwork Thu Apr 5 10:47:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [v8,04/10] Add host_from_stream_offset_versioned function Date: Thu, 05 Apr 2012 00:47:53 -0000 From: Orit Wasserman X-Patchwork-Id: 151011 Message-Id: <1333622879-12055-5-git-send-email-owasserm@redhat.com> To: qemu-devel@nongnu.org Cc: aliguori@us.ibm.com, quintela@redhat.com, stefanha@gmail.com, blauwirbel@gmail.com, Orit Wasserman , avi@redhat.com Signed-off-by: Orit Wasserman --- arch_init.c | 26 +++++++++++++++++++++++--- 1 files changed, 23 insertions(+), 3 deletions(-) diff --git a/arch_init.c b/arch_init.c index 5f60fa9..cef5d6f 100644 --- a/arch_init.c +++ b/arch_init.c @@ -552,6 +552,18 @@ static inline void *host_from_stream_offset(QEMUFile *f, return NULL; } +static inline void *host_from_stream_offset_versioned(int version_id, + QEMUFile *f, ram_addr_t offset, int flags) +{ + void *host; + if (version_id == 3) { + host = qemu_get_ram_ptr(offset); + } else { + host = host_from_stream_offset(f, offset, flags); + } + return host; +} + int ram_load(QEMUFile *f, void *opaque, int version_id) { ram_addr_t addr; @@ -607,8 +619,11 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) void *host; uint8_t ch; - host = host_from_stream_offset(f, addr, flags); + host = host_from_stream_offset_versioned(version_id, + f, addr, flags); if (!host) { + fprintf(stderr, "Failed to convert RAM address to host" + " for offset " RAM_ADDR_FMT "\n", addr); return -EINVAL; } @@ -623,8 +638,13 @@ int ram_load(QEMUFile *f, void *opaque, int version_id) } else if (flags & RAM_SAVE_FLAG_PAGE) { void *host; - host = host_from_stream_offset(f, addr, flags); - + host = host_from_stream_offset_versioned(version_id, + f, addr, flags); + if (!host) { + fprintf(stderr, "Failed to convert RAM address to host" + " for offset " RAM_ADDR_FMT "\n", addr); + return -EINVAL; + } qemu_get_buffer(f, host, TARGET_PAGE_SIZE); } error = qemu_file_get_error(f);