RFC: linux user problems]
Following my previous message, I did a patch that makes syscalls take target_long/target_ulong argument and return target_long value instead of long/unsigned long.
I also included the #ifdef protection for do_socketcall and do_ipc to avoid compilation warnings.
And I also converted the fd given to do_ioctl to be an int.
In addition to my previous remarks, I noticed some other things while reading the code:
- the do_msgctl function seems very strange to me. It looks like half of the code is missing in the switch...
- do_ipc directly uses pointers from the emulated environment without using lock_user related functions like it seems to be done everywhere else.
- there are at least two problems in IPCOP_shmat:
* the returned address could not fit in the target address space when
emulating a 32 bits
target on a 64 bits host
* the returned address is always casted into a 32 bits value. I changed this to be target_ulong.
- I also noticed some suspicious warnings (cast between pointer and integer of different size) that may hide other problems:
* target_to_host_cmsg:567
* host_to_target_cmsg:612
* do_ipc:1609
* do_ipc: 1621
* do_ipc: 1645
* do_ipc: 1655
* do_ipc: 1677 (multiple times)
* do_ipc: 1687
* do_ipc: 1711
* do_syscall:2686
* do_syscall: 3903
* do_syscall: 4671
May someone take a look at my patch and say if it seems reasonable to include this in the repository ?
I did not notice any regression, launching 32 bits programs on a 64 bits host, but I did not do any unitary tests to trigger specific bugs, just launched command lines programs like bash, make, ... and used them. Then other looks to the patch would be welcome !
-------- Forwarded Message --------
Quoted 61 lines
From: J. Mayer <[email protected]>
Reply-To: [email protected]
To: [email protected]
Subject: [Qemu-devel] RFC: linux user problems
Date: Mon, 17 Sep 2007 23:04:00 +0200It seems to me that there are many problems in
linux-user/syscall.c
- minor fixes, just to avoid compilation warnings:do_socketcallshould be inside a #ifdefTARGET_NR_socketcallblockdo_ipcshould be inside a #ifdefTARGET_NR_ipcblock
- problems for 64 bits targets:
it seems thatdo_syscalland child functions should taketarget_long/target_ulongarguments instead of long / unsigned long. This would make a chance for 64 bits targets to be ran on 32 bits hosts (even if, yes, there would also be other problems to fix elsewhere...).
- ipc specific problems:
some structure used for IPC definitions have been merged. They used to be target specific and now are generic. But it seems to me that many mistakes have been done here, while comparing with the PowerPC 64 target definition, which has not been merged:struct target_ipc_perm { int __key; unsigned short uid; unsigned short gid; unsigned short cuid; unsigned short cgid; unsigned short mode; unsigned short seq; }; in PowerPC 64 becomes: struct target_ipc_perm { target_long __key; target_ulong uid; target_ulong gid; target_ulong cuid; target_ulong cgid; unsigned short int mode; unsigned short int __pad1; unsigned short int __seq; unsigned short int __pad2; target_ulong __unused1; target_ulong __unused2; };in generic code.
Problems are, imho:
int is not the same size thantarget_longon 64 bits targets. unsigned short is never the same size thantarget_ulong(am I wrong ?) there should be atarget_shortdefinition: are we sure short on the host is always the same size thantarget_short?
I also don't understand the padding logic here (does the originaltarget_ipc_permstructure relies on alignments generated by the compiler ?).
I found the same kind of problems for thetarget_msqid_dsandtarget_msgbufstructure.
I may be wrong, but it seems to me that those problems are not PowerPC 64 specific and that there are some serious bugs to be fixed here. Can someone confirm this or tell me what I missed ?Regards.
Signature · 2 lines
J. Mayer <[email protected]> Never organized
Index: linux-user/qemu.h
===================================================================
RCS file: /sources/qemu/qemu/linux-user/qemu.h,v
retrieving revision 1.33
qemu.h +4 -3
@@ -126,10 +127,11 @@ int load_flt_binary(struct linux_binprmvoid memcpy_to_target (target_ulong dest,const void *src,unsigned long len);void target_set_brk (target_ulong new_brk); -long do_brk (target_ulong new_brk); +target_long do_brk (target_ulong new_brk);void syscall_init (void ); -long do_syscall (void *cpu_env,int num,long arg1,long arg2,long arg3, -long arg4,long arg5,long arg6); +target_long do_syscall (void *cpu_env,int num,target_long arg1, +target_long arg2,target_long arg3,target_long arg4, +target_long arg5,target_long arg6);void gemu_log (const char *fmt, ...) __attribute__((format (printf,1 ,2 )));extern CPUState *global_env;void cpu_loop (CPUState *env);
Index: linux-user/syscall.c
===================================================================
RCS file: /sources/qemu/qemu/linux-user/syscall.c,v retrieving revision 1.121
syscall.c +102 -75
472 lines not on this page · raw message
Quoted 35 lines · J. Mayer
Following my previous message, I did a patch that makes syscalls take target_long/target_ulong argument and return
target_longvalue instead of long/unsigned long.
I also included the #ifdef protection fordo_socketcallanddo_ipcto avoid compilation warnings.
And I also converted the fd given todo_ioctlto be an int.In addition to my previous remarks, I noticed some other things while reading the code:
- thedo_msgctlfunction seems very strange to me. It looks like half of the code is missing in the switch...
-do_ipcdirectly uses pointers from the emulated environment without usinglock_userrelated functions like it seems to be done everywhere else.
- there are at least two problems inIPCOP_shmat:
* the returned address could not fit in the target address space when
emulating a 32 bits
target on a 64 bits host
* the returned address is always casted into a 32 bits value. I changed this to betarget_ulong.
- I also noticed some suspicious warnings (cast between pointer and integer of different size) that may hide other problems:
* target_to_host_cmsg:567
* host_to_target_cmsg:612
* do_ipc:1609
*do_ipc: 1621
*do_ipc: 1645
*do_ipc: 1655
*do_ipc: 1677 (multiple times)
*do_ipc: 1687
*do_ipc: 1711
* do_syscall:2686
*do_syscall: 3903
*do_syscall: 4671
Quoted 2 lines
May someone take a look at my patch and say if it seems reasonable to include this in the repository ?
Looks reasonable, but introduces new compiler warnings (on a ppc32/Linux host):
Most (all?) targets show:
/home/ths/qemu/qemu-work/linux-user/syscall.c: In function do_ipc':/home/ths/qemu/qemu-work/linux-user/syscall.c:1612: warning: long int format, target_long arg (arg 2)
There's also one instance of:
/home/ths/qemu/qemu-work/linux-user/syscall.c: At top level:/home/ths/qemu/qemu-work/linux-user/syscall.c:1258: warning: 'shm_regions' defined but not used
which looks like a missing #ifdef TARGET_NR_ipc.
Thiemo
Quoted 39 lines · Thiemo Seufer
Quoted 35 lines · J. Mayer
Following my previous message, I did a patch that makes syscalls take target_long/target_ulong argument and return
target_longvalue instead of long/unsigned long.
I also included the #ifdef protection fordo_socketcallanddo_ipcto avoid compilation warnings.
And I also converted the fd given todo_ioctlto be an int.In addition to my previous remarks, I noticed some other things while reading the code:
- thedo_msgctlfunction seems very strange to me. It looks like half of the code is missing in the switch...
-do_ipcdirectly uses pointers from the emulated environment without usinglock_userrelated functions like it seems to be done everywhere else.
- there are at least two problems inIPCOP_shmat:
* the returned address could not fit in the target address space when
emulating a 32 bits
target on a 64 bits host
* the returned address is always casted into a 32 bits value. I changed this to betarget_ulong.
- I also noticed some suspicious warnings (cast between pointer and integer of different size) that may hide other problems:
* target_to_host_cmsg:567
* host_to_target_cmsg:612
* do_ipc:1609
*do_ipc: 1621
*do_ipc: 1645
*do_ipc: 1655
*do_ipc: 1677 (multiple times)
*do_ipc: 1687
*do_ipc: 1711
* do_syscall:2686
*do_syscall: 3903
*do_syscall: 4671Quoted 2 lines
May someone take a look at my patch and say if it seems reasonable to include this in the repository ?
Quoted 7 lines
Looks reasonable, but introduces new compiler warnings (on a ppc32/Linux host):
Most (all?) targets show:
/home/ths/qemu/qemu-work/linux-user/syscall.c: In functiondo_ipc':/home/ths/qemu/qemu-work/linux-user/syscall.c:1612: warning: long int format,target_longarg (arg 2)
My fault, I did only compile on x86_64, forgot to check in 32 bits mode, and did not see this warning (I may have missed it...), sorry.
Quoted 7 lines
There's also one instance of:
/home/ths/qemu/qemu-work/linux-user/syscall.c: At top level:/home/ths/qemu/qemu-work/linux-user/syscall.c:1258: warning: 'shm_regions' defined but not usedwhich looks like a missing #ifdef
TARGET_NR_ipc.
I will check more closely as there are also a lot of inline functions (then not generating compilation warnings) that are used only from do_ipc. Putting them in the #ifdef TARGET_NR_ipc may show other unused variables or functions.
Thanks for the report.