[Spice-devel] [PATCH v6 5/5] Do endian swapping.

Michal Suchánek msuchanek at suse.de
Tue Jan 24 17:34:20 UTC 2017


On Mon, 23 Jan 2017 16:58:14 +0100
Michal Suchánek <msuchanek at suse.de> wrote:

> On Mon, 23 Jan 2017 15:40:57 +0100
> Christophe de Dinechin <dinechin at redhat.com> wrote:
> 
> > On 23/01/2017 14:53, Michal Suchanek wrote:  
> > > This allows running big endian and little endian guest side by
> > > side using cut & paste between them.
> > >
> > > There is a general design idea that swapping should come as close
> > > to virtio_read/virtio_write as possible. In particular, the
> > > protocol between vdagent and vdagentd is guest-specific and in
> > > native endian. With muliple layers of headers this is a bit
> > > tricky. A few message types have to be swapped fully before
> > > passing through vdagentd.
> > >
> > > Signed-off-by: Michal Suchanek <msuchanek at suse.de>
> > > Signed-off-by: Victor Toso <me at victortoso.com>
> > > ---
> > > v2:
> > >   - introduce helper functions to swap (a portion of) a message
> > > wholesale
> > >   - pollute fewer places with swapping sometimes at the cost of
> > > slightly more verbose code
> > > v3:
> > >   - use glib byteswap macros in place of endian.h byteswap macros
> > >   - move variable declaration out of case statement
> > >   - reuse more of existing clipboard code
> > > v4:
> > >   - also use glib byteswap for 64bit swaps
> > >   - use file xfer message structure for swapping size
> > > v5:
> > >   - rebase on top of vdagentd: early return on bad message size
> > > ---
> > >   src/vdagentd/vdagentd.c    | 125
> > > +++++++++++++++++++++++++++++++++++----------
> > > src/vdagentd/virtio-port.c |  36 ++++++++----- 2 files changed,
> > > 121 insertions(+), 40 deletions(-)
> > >
> > > diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> > > index 7e16cd2..f8de1e7 100644
> > > --- a/src/vdagentd/vdagentd.c
> > > +++ b/src/vdagentd/vdagentd.c
> > > @@ -78,6 +78,34 @@ static int client_connected = 0;
> > >   static int max_clipboard = -1;
> > >   
> > >   /* utility functions */
> > > +static void virtio_msg_uint32_to_le(uint8_t *_msg, uint32_t size,
> > > uint32_t offset)    
> > If we are converting uint32 messages, shouln't this take a uint32_t
> > *msg as input? See [1] below  
> 
> Technically we can. The to_le message swap will likely get the native
> pointer width, unlike the from_le message swaps.

Actually, the function is used twice, once with uint32_t pointer and
once with uint8_t pointer. So it does not matter either way.

Thanks

Michal


More information about the Spice-devel mailing list