Using sys/types.h types in sys/socket.h

Bruce Evans brde at optusnet.com.au
Tue Dec 17 10:08:36 UTC 2013


On Tue, 17 Dec 2013, Adrian Chadd wrote:

> I have a patch to implement some new sendfile functionality, but this
> involves adding stuff to sys/socket.h:

This would undo FreeBSD's de-pollution of sys/socket.h.

> Index: sys/sys/socket.h
> ===================================================================
> --- sys/sys/socket.h (revision 258883)
> +++ sys/sys/socket.h (working copy)
> @@ -577,11 +577,27 @@
> };
>
> /*
> + * sendfile(2) kqueue information
> + */
> +struct sf_hdtr_kq {
> + int kq_fd; /* kq fd to post completion events on */
> + uint32_t kq_flags; /* extra flags to pass in */
> + void *kq_udata; /* user data pointer */
> + uintptr_t kq_ident; /* ident (from userland?) */
> +};

POSIX is bad enough to allow all the symbols in sys/type.h to be
declared here, but it doesn't allow sf_* or kq_*.  So this would
have to be under __BSD_VISIBLE, and POSIX is irrelevant for the
uintptr_t and uint32_t pollution.  In fact, this section is already
under __BSD_VISIBLE.  It doesn't have so many style bugs as this.
All tabs seem to have been corrupted by mail programs, except in
struct sf_hdtr where they are missing in the committed version.

> ... now, uintptr_t upsets things, because we don't include sys/types.h
> before sys/socket.h.
>
> The POSIX spec for sys/socket.h doesn't mention a dependency on
> sys/types.h and in fact says it should define a couple of types
> itself.
>
> http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/sys_socket.h.html
>
> .. so, what suggestions do people have? I'd like to do this right and
> not cause header pollution.

Either use __uintptr_t, or declare only uintptr_t as is done for 7 other
types near the beginning of the file, depending on whether the uintptr_t
field needs to be accessed from userland.

Bruce


More information about the freebsd-arch mailing list