From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LifJv-0000lq-P1 for qemu-devel@nongnu.org; Sat, 14 Mar 2009 21:39:19 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LifJr-0000i7-WD for qemu-devel@nongnu.org; Sat, 14 Mar 2009 21:39:19 -0400 Received: from [199.232.76.173] (port=36731 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LifJr-0000i4-P9 for qemu-devel@nongnu.org; Sat, 14 Mar 2009 21:39:15 -0400 Received: from mail.corp.accelance.fr ([213.162.48.15]:57660) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LifJr-0001cR-CJ for qemu-devel@nongnu.org; Sat, 14 Mar 2009 21:39:15 -0400 Received: from [192.168.0.5] (potipota.net [88.168.176.51]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.corp.accelance.fr (Postfix) with ESMTP id C38235ADAE4 for ; Sun, 15 Mar 2009 02:38:55 +0100 (CET) From: Lionel Landwerlin Content-Type: text/plain Date: Sun, 15 Mar 2009 02:40:11 +0100 Message-Id: <1237081212.589.23.camel@coalu.atr> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros 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 On 64bits hosts, the current TARGET_IO* macros generate 64 bits signed integers that do not always match the 32bits signed integers from emulated program (when emulating a 32bits user space program). This makes problems if you're comparing the ioctl command value from the emulated program directly with the result of a TARGET_IO* macros. Here a little example of the problem : >>>>>>>> #include #include int main (int argc, char *argv[]) { int a = 3222335234; long b = 3222335234; printf ("a = %i/%x, b = %i/%x\n", a, a, b, b); if (a == b) printf ("Fine !\n"); else printf ("Ohoh ??\n"); return EXIT_FAILURE; } <<<<<<<<< Of course, the problem is solved if you're saving the result of the TARGET_IO* macros in an unsigned integer. So here is a little patch that forces TARGET_IO* macros to output abi_long sized integers. Signed-off-by: Lionel Landwerlin --- diff --git a/linux-user/syscall_defs.h b/linux-user/syscall_defs.h index 8abe08b..89926f9 100644 --- a/linux-user/syscall_defs.h +++ b/linux-user/syscall_defs.h @@ -83,10 +83,10 @@ #define TARGET_IOC_DIRSHIFT (TARGET_IOC_SIZESHIFT+TARGET_IOC_SIZEBITS) #define TARGET_IOC(dir,type,nr,size) \ - (((dir) << TARGET_IOC_DIRSHIFT) | \ - ((type) << TARGET_IOC_TYPESHIFT) | \ - ((nr) << TARGET_IOC_NRSHIFT) | \ - ((size) << TARGET_IOC_SIZESHIFT)) + ((abi_long) (((dir) << TARGET_IOC_DIRSHIFT) | \ + ((type) << TARGET_IOC_TYPESHIFT) | \ + ((nr) << TARGET_IOC_NRSHIFT) | \ + ((size) << TARGET_IOC_SIZESHIFT))) /* used to create numbers */ #define TARGET_IO(type,nr) TARGET_IOC(TARGET_IOC_NONE,(type),(nr),0)