From patchwork Fri Mar 9 14:33:20 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 145723 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id B8D4EB6F9F for ; Sat, 10 Mar 2012 01:34:15 +1100 (EST) Received: from localhost ([::1]:37920 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S60tZ-000325-I6 for incoming@patchwork.ozlabs.org; Fri, 09 Mar 2012 09:34:13 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54551) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S60t3-00031H-8D for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:34:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S60st-0003HT-0f for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:33:40 -0500 Received: from mnementh.archaic.org.uk ([81.2.115.146]:43330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S60ss-0003GO-Oo for qemu-devel@nongnu.org; Fri, 09 Mar 2012 09:33:30 -0500 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1S60si-0007zq-Q7; Fri, 09 Mar 2012 14:33:20 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 9 Mar 2012 14:33:20 +0000 Message-Id: <1331303600-30715-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: Riku Voipio , Alexander Graf , patches@linaro.org Subject: [Qemu-devel] [PATCH] cpu-all.h: Don't accidentally sign extend in g2h() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Cast the argument of the g2h() macro to a target_ulong so that it isn't accidentally sign-extended if it is a signed 32 bit type and long is a 64 bit type. In particular, this fixes a bug where it would return the wrong value for 32 bit guests on 64 bit hosts when passed in one of the arg* values from do_syscall() [which are all abi_long and thus signed types]. This could result in spurious failure of mlock(), among others. Signed-off-by: Peter Maydell Reviewed-by: Andreas Färber --- This should be committed before Alex's patch to make mmap allocate downwards (http://patchwork.ozlabs.org/patch/144476/) because that hugely increases the chances that g2h will get passed a pointer that has the high bit set. cpu-all.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/cpu-all.h b/cpu-all.h index 80e6d42..a174532 100644 --- a/cpu-all.h +++ b/cpu-all.h @@ -197,7 +197,7 @@ extern unsigned long reserved_va; #endif /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ -#define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) +#define g2h(x) ((void *)((unsigned long)(target_ulong)(x) + GUEST_BASE)) #if HOST_LONG_BITS <= TARGET_VIRT_ADDR_SPACE_BITS #define h2g_valid(x) 1