File 0148-exec-add-wrapper-for-host-pointer-a.patch of Package qemu.6354
From 132f851c0d338b8033beb509e62ed1cbc95e0e24 Mon Sep 17 00:00:00 2001
From: "Michael S. Tsirkin" <mst@redhat.com>
Date: Wed, 12 Nov 2014 11:44:41 +0200
Subject: [PATCH] exec: add wrapper for host pointer access
host pointer accesses force pointer math, let's
add a wrapper to make them safer.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Reviewed-by: Amos Kong <akong@redhat.com>
Signed-off-by: Amit Shah <amit.shah@redhat.com>
(cherry picked from commit 1240be24357ee292f8d05aa2abfdba75dd0ca25d)
Signed-off-by: Alexander Graf <agraf@suse.de>
---
exec.c | 8 ++++----
include/exec/cpu-all.h | 5 +++++
2 files changed, 9 insertions(+), 4 deletions(-)
diff --git a/exec.c b/exec.c
index 76d4755f31..7d74973604 100644
--- a/exec.c
+++ b/exec.c
@@ -773,7 +773,7 @@ static void tlb_reset_dirty_range_all(ram_addr_t start, ram_addr_t length)
block = qemu_get_ram_block(start);
assert(block == qemu_get_ram_block(end - 1));
- start1 = (uintptr_t)block->host + (start - block->offset);
+ start1 = (uintptr_t)ramblock_ptr(block, start - block->offset);
cpu_tlb_reset_dirty_all(start1, length);
}
@@ -1403,7 +1403,7 @@ void qemu_ram_remap(ram_addr_t addr, ram_addr_t length)
QTAILQ_FOREACH(block, &ram_list.blocks, next) {
offset = addr - block->offset;
if (offset < block->length) {
- vaddr = block->host + offset;
+ vaddr = ramblock_ptr(block, offset);
if (block->flags & RAM_PREALLOC_MASK) {
;
} else if (xen_enabled()) {
@@ -1471,7 +1471,7 @@ void *qemu_get_ram_ptr(ram_addr_t addr)
xen_map_cache(block->offset, block->length, 1);
}
}
- return block->host + (addr - block->offset);
+ return ramblock_ptr(block, addr - block->offset);
}
/* Return a host pointer to guest's ram. Similar to qemu_get_ram_ptr
@@ -1490,7 +1490,7 @@ static void *qemu_ram_ptr_length(ram_addr_t addr, hwaddr *size)
if (addr - block->offset < block->length) {
if (addr - block->offset + *size > block->length)
*size = block->length - addr + block->offset;
- return block->host + (addr - block->offset);
+ return ramblock_ptr(block, addr - block->offset);
}
}
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index fb649a4029..8097763e5f 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -433,6 +433,11 @@ typedef struct RAMBlock {
int fd;
} RAMBlock;
+static inline void *ramblock_ptr(RAMBlock *block, ram_addr_t offset)
+{
+ return (char *)block->host + offset;
+}
+
typedef struct RAMList {
QemuMutex mutex;
/* Protected by the iothread lock. */