[Spice-devel] [PATCH spice-protocol v4] stats: Avoid holes in SpiceStat structure

Christophe Fergeau cfergeau at redhat.com
Thu Jan 17 16:42:02 UTC 2019


On Mon, Jan 14, 2019 at 04:17:49PM +0000, Frediano Ziglio wrote:
> The SpiceStat structure can be 20 or 24 bytes depending on alignment.
> Being a memory mapped structure potentially used with lockless access,
> it is not good to have it unaligned.
> The only tool that we know of that reads this memory mapped file
> (reds_stats) is able to detect if the structure is either 20 or 24
> bytes and act accordingly so changing this structure won't affect the
> behaviour (unless you have an old tool but as they are usually
> packaged together this is quite improbable).
> This will also help on Windows as in that system it is not possible

This is the main reason for the change, no? I would have started with
that.

Acked-by: Christophe Fergeau <cfergeau at redhat.com>



> for reds_stats to implement the same discovery trick implemented on
> Linux.  On Windows it is not possible to read the size of the file
> mapping (on Windows to implement shared memory you can use a file
> mapping not associated to a file).
> The structure will change layout only on 32-bit architectures which is
> not recommended nowadays (the 64-bit platforms that we support align
> 64-bit integers to 64 bits).
> 
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
>  spice/stats.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> Changes since v3:
> - update commit message.
> 
> Changes since v2:
> - typos and grammar.
> 
> Changes since v1:
> - update commit message and comment.
> 
> diff --git a/spice/stats.h b/spice/stats.h
> index d4c45ab..44c6482 100644
> --- a/spice/stats.h
> +++ b/spice/stats.h
> @@ -66,6 +66,8 @@ typedef struct SpiceStat {
>      uint32_t generation;
>      uint32_t num_of_nodes;
>      uint32_t root_index;
> +    /* to avoid holes in the structure on some platforms */
> +    uint32_t padding;
>      SpiceStatNode nodes[];
>  } SpiceStat;
>  
> -- 
> 2.20.1
> 
> _______________________________________________
> Spice-devel mailing list
> Spice-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/spice-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://lists.freedesktop.org/archives/spice-devel/attachments/20190117/a0fa62e8/attachment.sig>


More information about the Spice-devel mailing list