qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <Laurent@vivier.eu>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Riku Voipio <riku.voipio@iki.fi>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket()
Date: Tue, 01 Jan 2013 23:12:34 +0100	[thread overview]
Message-ID: <1357078354.31530.1.camel@Quad> (raw)
In-Reply-To: <CAFEAcA90EDVdsq-BTdj2iH18UHP+ZL5RMP804A8GB=Dhointbw@mail.gmail.com>

Le mardi 01 janvier 2013 à 19:45 +0000, Peter Maydell a écrit :
> On 1 January 2013 18:37, Laurent Vivier <Laurent@vivier.eu> wrote:
> > Le mardi 01 janvier 2013 à 18:27 +0100, Laurent Vivier a écrit :
> >> Le mardi 01 janvier 2013 à 15:03 +0000, Peter Maydell a écrit :
> >> > On 31 December 2012 22:19, Laurent Vivier <Laurent@vivier.eu> wrote:
> >> > > works... sometime. In fact, work if target endianess is network endianess.
> >> > >
> >> > > 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 :
> 
> 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!)
> 
> 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

-- 
"Just play. Have fun. Enjoy the game."
- Michael Jordan

  reply	other threads:[~2013-01-01 22:12 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-12-31 19:37 [Qemu-devel] [PATCH 0/2] linux-user: dhclient support Laurent Vivier
2012-12-31 19:37 ` [Qemu-devel] [PATCH 1/2] linux-user: Add setsockopt(SO_ATTACH_FILTER) Laurent Vivier
2012-12-31 20:56   ` Peter Maydell
2012-12-31 19:38 ` [Qemu-devel] [PATCH 2/2] linux-user: SOCK_PACKET uses network endian to encode protocol in socket() Laurent Vivier
2012-12-31 21:32   ` Peter Maydell
2012-12-31 22:19     ` Laurent Vivier
2013-01-01 15:03       ` Peter Maydell
2013-01-01 17:27         ` Laurent Vivier
2013-01-01 18:37           ` Laurent Vivier
2013-01-01 19:45             ` Peter Maydell
2013-01-01 22:12               ` Laurent Vivier [this message]
2013-01-01 22:50                 ` Peter Maydell

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=1357078354.31530.1.camel@Quad \
    --to=laurent@vivier.eu \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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).