This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH 2/3] network: recvmsg and sendmsg standard compliance (BZ#16919)
- From: Szabolcs Nagy <szabolcs dot nagy at arm dot com>
- To: Adhemerval Zanella <adhemerval dot zanella at linaro dot org>, <libc-alpha at sourceware dot org>
- Cc: <mtk dot manpages at gmail dot com>, nd <nd at arm dot com>, Rich Felker <dalias at libc dot org>
- Date: Thu, 21 Apr 2016 15:01:15 +0100
- Subject: Re: [PATCH 2/3] network: recvmsg and sendmsg standard compliance (BZ#16919)
- Authentication-results: sourceware.org; auth=none
- Nodisclaimer: True
- References: <1459175641-12520-1-git-send-email-adhemerval dot zanella at linaro dot org> <1459175641-12520-3-git-send-email-adhemerval dot zanella at linaro dot org>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:23
On 28/03/16 15:34, Adhemerval Zanella wrote:
> /* Structure used for storage of ancillary data object information. */
> struct cmsghdr
> {
> - size_t cmsg_len; /* Length of data in cmsg_data plus length
> - of cmsghdr structure.
> - !! The type should be socklen_t but the
> - definition of the kernel is incompatible
> - with this. */
> +#if __BYTE_ORDER == __BIG_ENDIAN
> + int __glibc_reserved1; /* Pad toadjust Linux size to POSIX defined
> + size for cmsg_len. */
> + socklen_t cmsg_len; /* Length of data in cmsg_data plus length
> + of cmsghdr structure. */
> +#else
> + socklen_t cmsg_len;
> + int __glibc_reserved1;
> +#endif
> int cmsg_level; /* Originating protocol. */
> int cmsg_type; /* Protocol specific type. */
i think #if __WORDSIZE == 64 is missing here.
but even in that case there is a subtle issue:
if the size_t member is removed all other
members have 4byte alignment, so the struct
alignment changes from 8byte to 4byte.
it is not clear from the standard how the
msg_control buffer may be allocated (since
only CMSG_* macros can access it), on linux
the kernel makes a copy so it does not care
about alignment in user-space, but the struct
alignment is still visible in the c and c++ abi.
msg_control usage should be probably documented
in the linux man-page: glibc sunrpc sometimes
uses plain char[], nscd uses a union with struct
cmsghdr, i think neither of them makes a
CMSG_FIRSTHDR (&msg)->cmsg_len
access strictly iso c confrom, but the later at
least uses correct alignment.
maybe a posix issue should be filed to the
austin group.