qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 1/2] slirp: Avoid marking naturally packed struc


From: Eric Blake
Subject: Re: [Qemu-devel] [PATCH 1/2] slirp: Avoid marking naturally packed structs as QEMU_PACKED
Date: Tue, 22 Jan 2019 13:25:41 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 1/22/19 12:18 PM, Peter Maydell wrote:
> Various ipv6 structs in the slirp headers are marked QEMU_PACKED,
> but they are actually naturally aligned and will have no padding
> in them. Instead of marking them with the 'packed' attribute,
> assert at compile time that they are the size we expect. This
> allows us to take the address of fields within the structs
> without risking undefined behaviour, and suppresses clang
> -Waddress-of-packed-member warnings.
> 
> Signed-off-by: Peter Maydell <address@hidden>
> ---
>  slirp/ip6.h      | 12 ++++++++++--
>  slirp/ip6_icmp.h | 20 +++++++++++++++-----
>  2 files changed, 25 insertions(+), 7 deletions(-)
> 

> +/*
> + * We don't want to mark these ip6 structs as packed as they are naturally
> + * correctly aligned; instead assert that there is no stray padding.
> + * If we marked the struct as packed then we would be unable to take
> + * the address of any of the fields in it.
> + */
> +QEMU_BUILD_BUG_ON(sizeof(struct ip6) != 40);
> +QEMU_BUILD_BUG_ON(sizeof(struct ip6_pseudohdr) != 40);

Nice.  (And IIRC, the IPv6 designers tried to pick natural alignments on
purpose)

Reviewed-by: Eric Blake <address@hidden>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]