* [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros
@ 2009-03-15 1:40 Lionel Landwerlin
2009-03-15 9:45 ` Stuart Brady
0 siblings, 1 reply; 2+ messages in thread
From: Lionel Landwerlin @ 2009-03-15 1:40 UTC (permalink / raw)
To: qemu-devel
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)
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros
2009-03-15 1:40 [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros Lionel Landwerlin
@ 2009-03-15 9:45 ` Stuart Brady
0 siblings, 0 replies; 2+ messages in thread
From: Stuart Brady @ 2009-03-15 9:45 UTC (permalink / raw)
To: qemu-devel
On Sun, Mar 15, 2009 at 02:40:11AM +0100, Lionel Landwerlin wrote:
> 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.
Surely the value currently produced by TARGET_IOC() *is* an unsigned int
(provided you use the direction macros)? I'm not sure if any arch will
ever need more than 32 bits here, but even with the cast to abi_long,
the high bits would be truncated before the cast.
target_cmd in IOCTLEntry is an unsigned int, but the command is also
passed around as an abi_long is some places... I couldn't see any code
that's currently affected by this, though -- did I miss something?
Cheers,
--
Stuart Brady
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-03-15 9:45 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-03-15 1:40 [Qemu-devel] [PATCH] [linux-user] Fix ioctl code generation macros Lionel Landwerlin
2009-03-15 9:45 ` Stuart Brady
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).