Blame include/uapi/linux/libc-compat.h

Packit Service 3880ab
/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
Packit Service 3880ab
/*
Packit Service 3880ab
 * Compatibility interface for userspace libc header coordination:
Packit Service 3880ab
 *
Packit Service 3880ab
 * Define compatibility macros that are used to control the inclusion or
Packit Service 3880ab
 * exclusion of UAPI structures and definitions in coordination with another
Packit Service 3880ab
 * userspace C library.
Packit Service 3880ab
 *
Packit Service 3880ab
 * This header is intended to solve the problem of UAPI definitions that
Packit Service 3880ab
 * conflict with userspace definitions. If a UAPI header has such conflicting
Packit Service 3880ab
 * definitions then the solution is as follows:
Packit Service 3880ab
 *
Packit Service 3880ab
 * * Synchronize the UAPI header and the libc headers so either one can be
Packit Service 3880ab
 *   used and such that the ABI is preserved. If this is not possible then
Packit Service 3880ab
 *   no simple compatibility interface exists (you need to write translating
Packit Service 3880ab
 *   wrappers and rename things) and you can't use this interface.
Packit Service 3880ab
 *
Packit Service 3880ab
 * Then follow this process:
Packit Service 3880ab
 *
Packit Service 3880ab
 * (a) Include libc-compat.h in the UAPI header.
Packit Service 3880ab
 *      e.g. #include <linux/libc-compat.h>
Packit Service 3880ab
 *     This include must be as early as possible.
Packit Service 3880ab
 *
Packit Service 3880ab
 * (b) In libc-compat.h add enough code to detect that the comflicting
Packit Service 3880ab
 *     userspace libc header has been included first.
Packit Service 3880ab
 *
Packit Service 3880ab
 * (c) If the userspace libc header has been included first define a set of
Packit Service 3880ab
 *     guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
Packit Service 3880ab
 *     set their values to 0.
Packit Service 3880ab
 *
Packit Service 3880ab
 * (d) Back in the UAPI header with the conflicting definitions, guard the
Packit Service 3880ab
 *     definitions with:
Packit Service 3880ab
 *     #if __UAPI_DEF_FOO
Packit Service 3880ab
 *       ...
Packit Service 3880ab
 *     #endif
Packit Service 3880ab
 *
Packit Service 3880ab
 * This fixes the situation where the linux headers are included *after* the
Packit Service 3880ab
 * libc headers. To fix the problem with the inclusion in the other order the
Packit Service 3880ab
 * userspace libc headers must be fixed like this:
Packit Service 3880ab
 *
Packit Service 3880ab
 * * For all definitions that conflict with kernel definitions wrap those
Packit Service 3880ab
 *   defines in the following:
Packit Service 3880ab
 *   #if !__UAPI_DEF_FOO
Packit Service 3880ab
 *     ...
Packit Service 3880ab
 *   #endif
Packit Service 3880ab
 *
Packit Service 3880ab
 * This prevents the redefinition of a construct already defined by the kernel.
Packit Service 3880ab
 */
Packit Service 3880ab
#ifndef _LIBC_COMPAT_H
Packit Service 3880ab
#define _LIBC_COMPAT_H
Packit Service 3880ab
Packit Service 3880ab
/* We have included glibc headers... */
Packit Service 3880ab
#if defined(__GLIBC__)
Packit Service 3880ab
Packit Service 3880ab
/* Coordinate with glibc net/if.h header. */
Packit Service 3880ab
#if defined(_NET_IF_H) && defined(__USE_MISC)
Packit Service 3880ab
Packit Service 3880ab
/* GLIBC headers included first so don't define anything
Packit Service 3880ab
 * that would already be defined. */
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_IF_IFCONF 0
Packit Service 3880ab
#define __UAPI_DEF_IF_IFMAP 0
Packit Service 3880ab
#define __UAPI_DEF_IF_IFNAMSIZ 0
Packit Service 3880ab
#define __UAPI_DEF_IF_IFREQ 0
Packit Service 3880ab
/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
Packit Service 3880ab
/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
Packit Service 3880ab
#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
Packit Service 3880ab
Packit Service 3880ab
#else /* _NET_IF_H */
Packit Service 3880ab
Packit Service 3880ab
/* Linux headers included first, and we must define everything
Packit Service 3880ab
 * we need. The expectation is that glibc will check the
Packit Service 3880ab
 * __UAPI_DEF_* defines and adjust appropriately. */
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_IF_IFCONF 1
Packit Service 3880ab
#define __UAPI_DEF_IF_IFMAP 1
Packit Service 3880ab
#define __UAPI_DEF_IF_IFNAMSIZ 1
Packit Service 3880ab
#define __UAPI_DEF_IF_IFREQ 1
Packit Service 3880ab
/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
Packit Service 3880ab
/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
Packit Service 3880ab
Packit Service 3880ab
#endif /* _NET_IF_H */
Packit Service 3880ab
Packit Service 3880ab
/* Coordinate with glibc netinet/in.h header. */
Packit Service 3880ab
#if defined(_NETINET_IN_H)
Packit Service 3880ab
Packit Service 3880ab
/* GLIBC headers included first so don't define anything
Packit Service 3880ab
 * that would already be defined. */
Packit Service 3880ab
#define __UAPI_DEF_IN_ADDR		0
Packit Service 3880ab
#define __UAPI_DEF_IN_IPPROTO		0
Packit Service 3880ab
#define __UAPI_DEF_IN_PKTINFO		0
Packit Service 3880ab
#define __UAPI_DEF_IP_MREQ		0
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN		0
Packit Service 3880ab
#define __UAPI_DEF_IN_CLASS		0
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR		0
Packit Service 3880ab
/* The exception is the in6_addr macros which must be defined
Packit Service 3880ab
 * if the glibc code didn't define them. This guard matches
Packit Service 3880ab
 * the guard in glibc/inet/netinet/in.h which defines the
Packit Service 3880ab
 * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
Packit Service 3880ab
#if defined(__USE_MISC) || defined (__USE_GNU)
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR_ALT		0
Packit Service 3880ab
#else
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR_ALT		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN6		0
Packit Service 3880ab
#define __UAPI_DEF_IPV6_MREQ		0
Packit Service 3880ab
#define __UAPI_DEF_IPPROTO_V6		0
Packit Service 3880ab
#define __UAPI_DEF_IPV6_OPTIONS		0
Packit Service 3880ab
#define __UAPI_DEF_IN6_PKTINFO		0
Packit Service 3880ab
#define __UAPI_DEF_IP6_MTUINFO		0
Packit Service 3880ab
Packit Service 3880ab
#else
Packit Service 3880ab
Packit Service 3880ab
/* Linux headers included first, and we must define everything
Packit Service 3880ab
 * we need. The expectation is that glibc will check the
Packit Service 3880ab
 * __UAPI_DEF_* defines and adjust appropriately. */
Packit Service 3880ab
#define __UAPI_DEF_IN_ADDR		1
Packit Service 3880ab
#define __UAPI_DEF_IN_IPPROTO		1
Packit Service 3880ab
#define __UAPI_DEF_IN_PKTINFO		1
Packit Service 3880ab
#define __UAPI_DEF_IP_MREQ		1
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN		1
Packit Service 3880ab
#define __UAPI_DEF_IN_CLASS		1
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR		1
Packit Service 3880ab
/* We unconditionally define the in6_addr macros and glibc must
Packit Service 3880ab
 * coordinate. */
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR_ALT		1
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN6		1
Packit Service 3880ab
#define __UAPI_DEF_IPV6_MREQ		1
Packit Service 3880ab
#define __UAPI_DEF_IPPROTO_V6		1
Packit Service 3880ab
#define __UAPI_DEF_IPV6_OPTIONS		1
Packit Service 3880ab
#define __UAPI_DEF_IN6_PKTINFO		1
Packit Service 3880ab
#define __UAPI_DEF_IP6_MTUINFO		1
Packit Service 3880ab
Packit Service 3880ab
#endif /* _NETINET_IN_H */
Packit Service 3880ab
Packit Service 3880ab
/* Coordinate with glibc netipx/ipx.h header. */
Packit Service 3880ab
#if defined(__NETIPX_IPX_H)
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IPX			0
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEFINITION		0
Packit Service 3880ab
#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	0
Packit Service 3880ab
#define __UAPI_DEF_IPX_CONFIG_DATA		0
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEF		0
Packit Service 3880ab
Packit Service 3880ab
#else /* defined(__NETIPX_IPX_H) */
Packit Service 3880ab
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IPX			1
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEFINITION		1
Packit Service 3880ab
#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	1
Packit Service 3880ab
#define __UAPI_DEF_IPX_CONFIG_DATA		1
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEF		1
Packit Service 3880ab
Packit Service 3880ab
#endif /* defined(__NETIPX_IPX_H) */
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for xattr.h */
Packit Service 3880ab
#if defined(_SYS_XATTR_H)
Packit Service 3880ab
#define __UAPI_DEF_XATTR		0
Packit Service 3880ab
#else
Packit Service 3880ab
#define __UAPI_DEF_XATTR		1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
/* If we did not see any headers from any supported C libraries,
Packit Service 3880ab
 * or we are being included in the kernel, then define everything
Packit Service 3880ab
 * that we need. Check for previous __UAPI_* definitions to give
Packit Service 3880ab
 * unsupported C libraries a way to opt out of any kernel definition. */
Packit Service 3880ab
#else /* !defined(__GLIBC__) */
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for if.h */
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_IFCONF
Packit Service 3880ab
#define __UAPI_DEF_IF_IFCONF 1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_IFMAP
Packit Service 3880ab
#define __UAPI_DEF_IF_IFMAP 1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_IFNAMSIZ
Packit Service 3880ab
#define __UAPI_DEF_IF_IFNAMSIZ 1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_IFREQ
Packit Service 3880ab
#define __UAPI_DEF_IF_IFREQ 1
Packit Service 3880ab
#endif
Packit Service 3880ab
/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
Packit Service 3880ab
#endif
Packit Service 3880ab
/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
Packit Service 3880ab
#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
Packit Service 3880ab
#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for in.h */
Packit Service 3880ab
#ifndef __UAPI_DEF_IN_ADDR
Packit Service 3880ab
#define __UAPI_DEF_IN_ADDR		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IN_IPPROTO
Packit Service 3880ab
#define __UAPI_DEF_IN_IPPROTO		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IN_PKTINFO
Packit Service 3880ab
#define __UAPI_DEF_IN_PKTINFO		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IP_MREQ
Packit Service 3880ab
#define __UAPI_DEF_IP_MREQ		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_SOCKADDR_IN
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IN_CLASS
Packit Service 3880ab
#define __UAPI_DEF_IN_CLASS		1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for in6.h */
Packit Service 3880ab
#ifndef __UAPI_DEF_IN6_ADDR
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IN6_ADDR_ALT
Packit Service 3880ab
#define __UAPI_DEF_IN6_ADDR_ALT		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_SOCKADDR_IN6
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IN6		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPV6_MREQ
Packit Service 3880ab
#define __UAPI_DEF_IPV6_MREQ		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPPROTO_V6
Packit Service 3880ab
#define __UAPI_DEF_IPPROTO_V6		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPV6_OPTIONS
Packit Service 3880ab
#define __UAPI_DEF_IPV6_OPTIONS		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IN6_PKTINFO
Packit Service 3880ab
#define __UAPI_DEF_IN6_PKTINFO		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IP6_MTUINFO
Packit Service 3880ab
#define __UAPI_DEF_IP6_MTUINFO		1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for ipx.h */
Packit Service 3880ab
#ifndef __UAPI_DEF_SOCKADDR_IPX
Packit Service 3880ab
#define __UAPI_DEF_SOCKADDR_IPX			1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPX_ROUTE_DEFINITION
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEFINITION		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPX_INTERFACE_DEFINITION
Packit Service 3880ab
#define __UAPI_DEF_IPX_INTERFACE_DEFINITION	1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPX_CONFIG_DATA
Packit Service 3880ab
#define __UAPI_DEF_IPX_CONFIG_DATA		1
Packit Service 3880ab
#endif
Packit Service 3880ab
#ifndef __UAPI_DEF_IPX_ROUTE_DEF
Packit Service 3880ab
#define __UAPI_DEF_IPX_ROUTE_DEF		1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
/* Definitions for xattr.h */
Packit Service 3880ab
#ifndef __UAPI_DEF_XATTR
Packit Service 3880ab
#define __UAPI_DEF_XATTR		1
Packit Service 3880ab
#endif
Packit Service 3880ab
Packit Service 3880ab
#endif /* __GLIBC__ */
Packit Service 3880ab
Packit Service 3880ab
#endif /* _LIBC_COMPAT_H */