[Spice-devel] [PATCH] Do endian swapping.

Christophe Fergeau cfergeau at redhat.com
Wed Dec 14 14:32:11 UTC 2016


Hey,

On Mon, Nov 28, 2016 at 03:08:34PM +0100, Michal Suchanek wrote:
> This allows running big endian and little endian guest side by side using
> cut&paste between them.
> 
> There is some general design idea that swapping should come as cloce 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>
> ---
>  src/vdagentd/uinput.c      |  4 +++
>  src/vdagentd/vdagentd.c    | 68 ++++++++++++++++++++++++++++++++++------------
>  src/vdagentd/virtio-port.c | 35 +++++++++++++++---------
>  3 files changed, 76 insertions(+), 31 deletions(-)
> 
> diff --git a/src/vdagentd/uinput.c b/src/vdagentd/uinput.c
> index e2966c4..21292cb 100644
> --- a/src/vdagentd/uinput.c
> +++ b/src/vdagentd/uinput.c
> @@ -200,6 +200,10 @@ void vdagentd_uinput_do_mouse(struct vdagentd_uinput **uinputp,
>      };
>      int i, down;
>  
> +    mouse->x = le32toh(mouse->x);
> +    mouse->y = le32toh(mouse->y);
> +    mouse->buttons = le32toh(mouse->buttons);
> +
>      if (*uinputp) {
>          if (mouse->display_id >= uinput->screen_count) {

No swapping of mouse->display_id?

> diff --git a/src/vdagentd/vdagentd.c b/src/vdagentd/vdagentd.c
> index a1faf23..f91434d 100644
> --- a/src/vdagentd/vdagentd.c
> +++ b/src/vdagentd/vdagentd.c
> @@ -399,15 +422,18 @@ static int virtio_port_read_complete(
>          if (message_header->size != sizeof(VDAgentMaxClipboard))
>              goto size_error;
>          VDAgentMaxClipboard *msg = (VDAgentMaxClipboard *)data;
> -        syslog(LOG_DEBUG, "Set max clipboard: %d", msg->max);
> -        max_clipboard = msg->max;
> +        syslog(LOG_DEBUG, "Set max clipboard: %d", le32toh(msg->max));
> +        max_clipboard = le32toh(msg->max);
>          break;
>      case VD_AGENT_AUDIO_VOLUME_SYNC:
>          if (message_header->size < sizeof(VDAgentAudioVolumeSync))
>              goto size_error;
> +        VDAgentAudioVolumeSync *vdata = (VDAgentAudioVolumeSync *)data;
> +        if (message_header->size < sizeof(VDAgentAudioVolumeSync) +
> +                vdata->nchannels * sizeof(vdata->volume[0]))
> +            goto size_error;

This last change seems unrelated, and would be missing a vdata->nchannels
byteswap if I'm not mistaken.

Christophe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20161214/20b21984/attachment.sig>


More information about the Spice-devel mailing list