From patchwork Mon Apr 5 17:24:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 49414 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 09302B7CF0 for ; Tue, 6 Apr 2010 04:02:25 +1000 (EST) Received: from localhost ([127.0.0.1]:35926 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nyqcw-0004nw-RX for incoming@patchwork.ozlabs.org; Mon, 05 Apr 2010 14:02:22 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NyqEq-0003FV-8o for qemu-devel@nongnu.org; Mon, 05 Apr 2010 13:37:28 -0400 Received: from [140.186.70.92] (port=47515 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NyqEn-0003E0-T7 for qemu-devel@nongnu.org; Mon, 05 Apr 2010 13:37:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1NyqEk-0001CB-Q8 for qemu-devel@nongnu.org; Mon, 05 Apr 2010 13:37:25 -0400 Received: from are.twiddle.net ([75.149.56.221]:60858) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1NyqEk-0001BX-FR for qemu-devel@nongnu.org; Mon, 05 Apr 2010 13:37:22 -0400 Received: by are.twiddle.net (Postfix, from userid 5000) id 6B79DC66; Mon, 5 Apr 2010 10:37:21 -0700 (PDT) Message-Id: <8fab352a4e45a8412daed0adb442dc4457279ca0.1270488612.git.rth@twiddle.net> In-Reply-To: References: From: Richard Henderson Date: Mon, 5 Apr 2010 10:24:51 -0700 To: qemu-devel@nongnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 2/7] Add guest_start_len_valid function. 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 To be used by userspace emulation to verify that the memory range defined by [start, start+len) is valid for the guest, taking into account TARGET_VIRT_ADDR_SPACE_BITS. Signed-off-by: Richard Henderson --- cpu-all.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 927445c..7d31b16 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -637,11 +637,21 @@ extern int have_guest_base; #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS #define h2g_valid(x) 1 +#define guest_start_len_valid(s,l) ({ \ + unsigned long __s = (unsigned long)(s); \ + unsigned long __e = __s + (l) - 1; \ + __e >= __s; \ +}) #else #define h2g_valid(x) ({ \ unsigned long __guest = (unsigned long)(x) - GUEST_BASE; \ __guest < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \ }) +#define guest_start_len_valid(s,l) ({ \ + unsigned long __s = (unsigned long)(s); \ + unsigned long __e = __s + (l) - 1; \ + __e >= __s && __e < (1ul << TARGET_VIRT_ADDR_SPACE_BITS); \ +}) #endif #define h2g(x) ({ \