From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:40771) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqA4l-0004lr-OI for qemu-devel@nongnu.org; Tue, 01 Jan 2013 17:12:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TqA4h-0001fm-HB for qemu-devel@nongnu.org; Tue, 01 Jan 2013 17:12:47 -0500 Received: from moutng.kundenserver.de ([212.227.17.10]:56026) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TqA4h-0001fI-7k for qemu-devel@nongnu.org; Tue, 01 Jan 2013 17:12:43 -0500 Message-ID: <1357078354.31530.1.camel@Quad> From: Laurent Vivier Date: Tue, 01 Jan 2013 23:12:34 +0100 In-Reply-To: References: <1356982680-12436-1-git-send-email-laurent@vivier.eu> <1356982680-12436-3-git-send-email-laurent@vivier.eu> <1356992395.3199.25.camel@Quad> <1357061254.3025.9.camel@Quad> <1357065466.3025.14.camel@Quad> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: Riku Voipio , qemu-devel@nongnu.org Le mardi 01 janvier 2013 =C3=A0 19:45 +0000, Peter Maydell a =C3=A9crit : > On 1 January 2013 18:37, Laurent Vivier wrote: > > Le mardi 01 janvier 2013 =C3=A0 18:27 +0100, Laurent Vivier a =C3=A9cri= t : > >> Le mardi 01 janvier 2013 =C3=A0 15:03 +0000, Peter Maydell a =C3=A9cri= t : > >> > On 31 December 2012 22:19, Laurent Vivier wrote: > >> > > works... sometime. In fact, work if target endianess is network en= dianess. > >> > > > >> > > Correct me if I'm wrong. > >> > > > >> > > target host > >> > > little endian / big endian > >> > > > >> > > memory 00 00 00 03 > >> > > >> > Syscall arguments aren't generally passed in memory, they're > >> > in registers (and if they were pased in memory for some architecture > >> > then that arch would do a load-and-swap-from-memory in main.c). > >> > So the value you see in do_socket() is always "the integer passed > >> > as a syscall parameter, as a host-order integer". > >> > >> Yes, I missed that. > > > > But, in fact, for socketcall(), they are read from memory : >=20 > Yes, this is because socketcall is weird. The actual kernel > implementation also reads them from memory: > http://lxr.linux.no/#linux+v3.7.1/net/socket.c#L2443 > as an array of unsigned longs. So as long as qemu also reads > them out of memory as an array of target abi_ulongs (which as > you can see we do) then we'll retrieve the same value (0x3 or > 0x300) to pass to do_socket() as the guest program wrote into > its guest view of memory (since it should have written an > unsigned long). (What is happening here is that the guest > binary writes the protocol value to memory as an unsigned > long, so it goes in as 4 bytes in whichever order the guest uses; > qemu's get_user_ual() then rereads those 4 bytes, swapping > the value back so we get the same integer value the guest > program stored. Note that the guest doesn't write the protocol > argument as a 2 byte value!) >=20 > I would encourage you to write some simple test programs > and check them using strace (both of the native program and > of qemu running the program). OK, I will... but I think we will fall back to my original patch ;-) Regards, Laurent --=20 "Just play. Have fun. Enjoy the game." - Michael Jordan