qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros


From: Lionel Landwerlin
Subject: [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros
Date: Sun, 15 Mar 2009 02:40:11 +0100

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 <stdio.h>
#include <stdlib.h>

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 <address@hidden>

---

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)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]