Skip to contentSkip to conversation

RFC: linux user problems

Qemu-devel J. Mayer 2 participants 3 messages Sep 17, 2007

lore
Share & tools
lore

J. Mayer

author
#0 lore raw

It seems to me that there are many problems in linux-user/syscall.c
- minor fixes, just to avoid compilation warnings:
do_socketcall should be inside a #ifdef TARGET_NR_socketcall block do_ipc should be inside a #ifdef TARGET_NR_ipc block
- problems for 64 bits targets:
it seems that do_syscall and child functions should take target_long / target_ulong arguments 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 than target_long on 64 bits targets. unsigned short is never the same size than target_ulong (am I wrong ?) there should be a target_short definition: are we sure short on the host is always the same size than target_short ?
I also don't understand the padding logic here (does the original target_ipc_perm structure relies on alignments generated by the compiler ?).
I found the same kind of problems for the target_msqid_ds and target_msgbuf structure.
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
#1 lore raw
Quoted 6 lines · J. Mayer

It seems to me that there are many problems in linux-user/syscall.c
- problems for 64 bits targets:
it seems that do_syscall and child functions should take target_long / target_ulong arguments 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...).

IIRC most of code predates target_long. I'm surprised 64-bit targets work at all.

Quoted 2 lines

there should be a target_short definition: are we sure short on the host is always the same size than target_short ?

Short is the same 16-bit type on every host or target we're even vaguely likely to care about.

I can only think of one system (a weird and fairly obscure DSP) where this is not true. You'd definitely not be running linux, and almost certainly not be running qemu on it.

Paul

author
#2 lore raw
Quoted 10 lines · Paul Brook
Quoted 6 lines · J. Mayer

It seems to me that there are many problems in linux-user/syscall.c
- problems for 64 bits targets:
it seems that do_syscall and child functions should take target_long / target_ulong arguments 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...).

IIRC most of code predates target_long. I'm surprised 64-bit targets work at all.

Well, in fact I already did this (mostly alpha emulation). But running on a 64 bits host platform, which may explain I've been able to start running anything !...
I'd like to make this more reliable in order to test some PowerPC 64 code without the need of the full MMU emulation (which is not complete and far from being debugged...) and any firmware.

Quoted 9 lines
Quoted 2 lines

there should be a target_short definition: are we sure short on the host is always the same size than target_short ?

Short is the same 16-bit type on every host or target we're even vaguely likely to care about.

I can only think of one system (a weird and fairly obscure DSP) where this is not true. You'd definitely not be running linux, and almost certainly not be running qemu on it.

OK, so there's no issue with this. But there always seem to be an issue confusing short with long or target_long...

I go on checking the syscall.c code, converting long to target_long when it seems correct and preparing remarks and/or questions for all other cases.

Regards.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized