From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KI8AZ-00013m-Re for qemu-devel@nongnu.org; Sun, 13 Jul 2008 16:27:43 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KI8AY-000126-2I for qemu-devel@nongnu.org; Sun, 13 Jul 2008 16:27:43 -0400 Received: from [199.232.76.173] (port=40883 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KI8AX-000120-SV for qemu-devel@nongnu.org; Sun, 13 Jul 2008 16:27:41 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:42243) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KI8AW-0006qc-8o for qemu-devel@nongnu.org; Sun, 13 Jul 2008 16:27:41 -0400 Received: from smtp07.web.de (fmsmtp07.dlan.cinetic.de [172.20.5.215]) by fmmailgate03.web.de (Postfix) with ESMTP id 953A3E3A5ED1 for ; Sun, 13 Jul 2008 22:27:33 +0200 (CEST) Received: from [88.64.30.223] (helo=[192.168.1.198]) by smtp07.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.109 #226) id 1KI8AP-0004Sm-00 for qemu-devel@nongnu.org; Sun, 13 Jul 2008 22:27:33 +0200 Message-ID: <487A6534.4080104@web.de> Date: Sun, 13 Jul 2008 22:27:32 +0200 From: Jan Kiszka MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Sender: jan.kiszka@web.de Subject: [Qemu-devel] [PATCH] linux-user: Safety belt for h2g Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org h2g can only work on 64-bit hosts if the provided address is mappable to the guest range. Neglecting this was already the source for several bugs. Instrument the macro so that it will trigger earlier in the future (at least as long as we have this kind of mapping mechanism). Signed-off-by: Jan Kiszka --- cpu-all.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) Index: b/cpu-all.h =================================================================== --- a/cpu-all.h +++ b/cpu-all.h @@ -659,6 +659,8 @@ static inline void stfq_be_p(void *ptr, /* MMU memory access macros */ #if defined(CONFIG_USER_ONLY) +#include + /* On some host systems the guest address space is reserved on the host. * This allows the guest address space to be offset to a convenient location. */ @@ -667,7 +669,11 @@ static inline void stfq_be_p(void *ptr, /* All direct uses of g2h and h2g need to go away for usermode softmmu. */ #define g2h(x) ((void *)((unsigned long)(x) + GUEST_BASE)) -#define h2g(x) ((target_ulong)((unsigned long)(x) - GUEST_BASE)) +#define h2g(x) ({ \ + unsigned long __ret = (unsigned long)(x) - GUEST_BASE; \ + assert(__ret == (target_ulong)__ret); \ + __ret; \ +}) #define saddr(x) g2h(x) #define laddr(x) g2h(x)