From patchwork Thu Feb 11 22:47:42 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 45432 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EAA68B7C09 for ; Tue, 16 Feb 2010 08:11:15 +1100 (EST) Received: from localhost ([127.0.0.1]:41702 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nh8Dp-0005U1-0N for incoming@patchwork.ozlabs.org; Mon, 15 Feb 2010 16:11:13 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nh87M-0003mB-My for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:32 -0500 Received: from [199.232.76.173] (port=59650 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nh87K-0003kz-I7 for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:30 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nh87I-0000rJ-9O for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:28 -0500 Received: from are.twiddle.net ([75.149.56.221]:51072) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nh87G-0000qo-UO for qemu-devel@nongnu.org; Mon, 15 Feb 2010 16:04:27 -0500 Received: by are.twiddle.net (Postfix, from userid 5000) id 244F3E85; Mon, 15 Feb 2010 13:04:24 -0800 (PST) Message-Id: <61c1b83df6256642fb1b23f1e0a7a070bf0dfcfb.1266267595.git.rth@twiddle.net> In-Reply-To: References: From: Richard Henderson Date: Thu, 11 Feb 2010 14:47:42 -0800 To: qemu-devel@nongnu.org X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 2/7] Use TARGET_VIRT_ADDR_SPACE_BITS in h2g_valid. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Previously, only 32-bit guests had a proper check for the validity of the virtual address. Extend that check to 64-bit guests with a restricted virtual address space. --- cpu-all.h | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 1ccc9a8..b81641f 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -634,16 +634,22 @@ extern int have_guest_base; /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) + +#if HOST_LONG_BITS == TARGET_VIRT_ADDR_SPACE_BITS +#define h2g_valid(x) 1 +#else +#define h2g_valid(x) ({ \ + unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \ + __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \ +}) +#endif + #define h2g(x) ({ \ unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \ /* Check if given address fits target address space */ \ - assert(__ret == (abi_ulong)__ret); \ + assert(h2g_valid(x)); \ (abi_ulong)__ret; \ }) -#define h2g_valid(x) ({ \ - unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \ - (__guest == (abi_ulong)__guest); \ -}) #define saddr(x) g2h(x) #define laddr(x) g2h(x)