qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Lionel Landwerlin <lionel.landwerlin@openwide.fr>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros
Date: Sun, 15 Mar 2009 02:40:11 +0100	[thread overview]
Message-ID: <1237081212.589.23.camel@coalu.atr> (raw)

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 <lionel.landwerlin@openwide.fr>

---

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	other threads:[~2009-03-15  1:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-15  1:40 Lionel Landwerlin [this message]
2009-03-15  9:45 ` [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros Stuart Brady

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1237081212.589.23.camel@coalu.atr \
    --to=lionel.landwerlin@openwide.fr \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).