From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34691) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoUTr-0007Ea-Uz for qemu-devel@nongnu.org; Wed, 12 Nov 2014 04:44:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XoUTl-00086L-5q for qemu-devel@nongnu.org; Wed, 12 Nov 2014 04:44:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43893) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XoUTk-000866-TN for qemu-devel@nongnu.org; Wed, 12 Nov 2014 04:44:45 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAC9iiEB007554 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 12 Nov 2014 04:44:44 -0500 Date: Wed, 12 Nov 2014 11:44:41 +0200 From: "Michael S. Tsirkin" Message-ID: <1415785203-26938-3-git-send-email-mst@redhat.com> References: <1415785203-26938-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1415785203-26938-1-git-send-email-mst@redhat.com> Subject: [Qemu-devel] [PATCH 2/4] exec: add wrapper for host pointer access List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , dgilbert@redhat.com, quintela@redhat.com host pointer accesses force pointer math, let's add a wrapper to make them safer. Signed-off-by: Michael S. Tsirkin --- include/exec/cpu-all.h | 5 +++++ exec.c | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h index c085804..9d8d408 100644 --- a/include/exec/cpu-all.h +++ b/include/exec/cpu-all.h @@ -313,6 +313,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. */ diff --git a/exec.c b/exec.c index ad5cf12..9648669 100644 --- a/exec.c +++ b/exec.c @@ -840,7 +840,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); } @@ -1500,7 +1500,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) { ; } else if (xen_enabled()) { @@ -1551,7 +1551,7 @@ void *qemu_get_ram_block_host_ptr(ram_addr_t addr) { RAMBlock *block = qemu_get_ram_block(addr); - return block->host; + return ramblock_ptr(block, 0); } /* Return a host pointer to ram allocated with qemu_ram_alloc. @@ -1578,7 +1578,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 @@ -1597,7 +1597,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); } } -- MST