Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 /*
0003  * Compatibility interface for userspace libc header coordination:
0004  *
0005  * Define compatibility macros that are used to control the inclusion or
0006  * exclusion of UAPI structures and definitions in coordination with another
0007  * userspace C library.
0008  *
0009  * This header is intended to solve the problem of UAPI definitions that
0010  * conflict with userspace definitions. If a UAPI header has such conflicting
0011  * definitions then the solution is as follows:
0012  *
0013  * * Synchronize the UAPI header and the libc headers so either one can be
0014  *   used and such that the ABI is preserved. If this is not possible then
0015  *   no simple compatibility interface exists (you need to write translating
0016  *   wrappers and rename things) and you can't use this interface.
0017  *
0018  * Then follow this process:
0019  *
0020  * (a) Include libc-compat.h in the UAPI header.
0021  *      e.g. #include <linux/libc-compat.h>
0022  *     This include must be as early as possible.
0023  *
0024  * (b) In libc-compat.h add enough code to detect that the comflicting
0025  *     userspace libc header has been included first.
0026  *
0027  * (c) If the userspace libc header has been included first define a set of
0028  *     guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
0029  *     set their values to 0.
0030  *
0031  * (d) Back in the UAPI header with the conflicting definitions, guard the
0032  *     definitions with:
0033  *     #if __UAPI_DEF_FOO
0034  *       ...
0035  *     #endif
0036  *
0037  * This fixes the situation where the linux headers are included *after* the
0038  * libc headers. To fix the problem with the inclusion in the other order the
0039  * userspace libc headers must be fixed like this:
0040  *
0041  * * For all definitions that conflict with kernel definitions wrap those
0042  *   defines in the following:
0043  *   #if !__UAPI_DEF_FOO
0044  *     ...
0045  *   #endif
0046  *
0047  * This prevents the redefinition of a construct already defined by the kernel.
0048  */
0049 #ifndef _UAPI_LIBC_COMPAT_H
0050 #define _UAPI_LIBC_COMPAT_H
0051 
0052 /* We have included glibc headers... */
0053 #if defined(__GLIBC__)
0054 
0055 /* Coordinate with glibc net/if.h header. */
0056 #if defined(_NET_IF_H) && defined(__USE_MISC)
0057 
0058 /* GLIBC headers included first so don't define anything
0059  * that would already be defined. */
0060 
0061 #define __UAPI_DEF_IF_IFCONF 0
0062 #define __UAPI_DEF_IF_IFMAP 0
0063 #define __UAPI_DEF_IF_IFNAMSIZ 0
0064 #define __UAPI_DEF_IF_IFREQ 0
0065 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
0066 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
0067 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
0068 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
0069 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
0070 #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
0071 
0072 #else /* _NET_IF_H */
0073 
0074 /* Linux headers included first, and we must define everything
0075  * we need. The expectation is that glibc will check the
0076  * __UAPI_DEF_* defines and adjust appropriately. */
0077 
0078 #define __UAPI_DEF_IF_IFCONF 1
0079 #define __UAPI_DEF_IF_IFMAP 1
0080 #define __UAPI_DEF_IF_IFNAMSIZ 1
0081 #define __UAPI_DEF_IF_IFREQ 1
0082 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
0083 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
0084 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
0085 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
0086 
0087 #endif /* _NET_IF_H */
0088 
0089 /* Coordinate with glibc netinet/in.h header. */
0090 #if defined(_NETINET_IN_H)
0091 
0092 /* GLIBC headers included first so don't define anything
0093  * that would already be defined. */
0094 #define __UAPI_DEF_IN_ADDR      0
0095 #define __UAPI_DEF_IN_IPPROTO       0
0096 #define __UAPI_DEF_IN_PKTINFO       0
0097 #define __UAPI_DEF_IP_MREQ      0
0098 #define __UAPI_DEF_SOCKADDR_IN      0
0099 #define __UAPI_DEF_IN_CLASS     0
0100 
0101 #define __UAPI_DEF_IN6_ADDR     0
0102 /* The exception is the in6_addr macros which must be defined
0103  * if the glibc code didn't define them. This guard matches
0104  * the guard in glibc/inet/netinet/in.h which defines the
0105  * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
0106 #if defined(__USE_MISC) || defined (__USE_GNU)
0107 #define __UAPI_DEF_IN6_ADDR_ALT     0
0108 #else
0109 #define __UAPI_DEF_IN6_ADDR_ALT     1
0110 #endif
0111 #define __UAPI_DEF_SOCKADDR_IN6     0
0112 #define __UAPI_DEF_IPV6_MREQ        0
0113 #define __UAPI_DEF_IPPROTO_V6       0
0114 #define __UAPI_DEF_IPV6_OPTIONS     0
0115 #define __UAPI_DEF_IN6_PKTINFO      0
0116 #define __UAPI_DEF_IP6_MTUINFO      0
0117 
0118 #else
0119 
0120 /* Linux headers included first, and we must define everything
0121  * we need. The expectation is that glibc will check the
0122  * __UAPI_DEF_* defines and adjust appropriately. */
0123 #define __UAPI_DEF_IN_ADDR      1
0124 #define __UAPI_DEF_IN_IPPROTO       1
0125 #define __UAPI_DEF_IN_PKTINFO       1
0126 #define __UAPI_DEF_IP_MREQ      1
0127 #define __UAPI_DEF_SOCKADDR_IN      1
0128 #define __UAPI_DEF_IN_CLASS     1
0129 
0130 #define __UAPI_DEF_IN6_ADDR     1
0131 /* We unconditionally define the in6_addr macros and glibc must
0132  * coordinate. */
0133 #define __UAPI_DEF_IN6_ADDR_ALT     1
0134 #define __UAPI_DEF_SOCKADDR_IN6     1
0135 #define __UAPI_DEF_IPV6_MREQ        1
0136 #define __UAPI_DEF_IPPROTO_V6       1
0137 #define __UAPI_DEF_IPV6_OPTIONS     1
0138 #define __UAPI_DEF_IN6_PKTINFO      1
0139 #define __UAPI_DEF_IP6_MTUINFO      1
0140 
0141 #endif /* _NETINET_IN_H */
0142 
0143 /* Coordinate with glibc netipx/ipx.h header. */
0144 #if defined(__NETIPX_IPX_H)
0145 
0146 #define __UAPI_DEF_SOCKADDR_IPX         0
0147 #define __UAPI_DEF_IPX_ROUTE_DEFINITION     0
0148 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 0
0149 #define __UAPI_DEF_IPX_CONFIG_DATA      0
0150 #define __UAPI_DEF_IPX_ROUTE_DEF        0
0151 
0152 #else /* defined(__NETIPX_IPX_H) */
0153 
0154 #define __UAPI_DEF_SOCKADDR_IPX         1
0155 #define __UAPI_DEF_IPX_ROUTE_DEFINITION     1
0156 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 1
0157 #define __UAPI_DEF_IPX_CONFIG_DATA      1
0158 #define __UAPI_DEF_IPX_ROUTE_DEF        1
0159 
0160 #endif /* defined(__NETIPX_IPX_H) */
0161 
0162 /* Definitions for xattr.h */
0163 #if defined(_SYS_XATTR_H)
0164 #define __UAPI_DEF_XATTR        0
0165 #else
0166 #define __UAPI_DEF_XATTR        1
0167 #endif
0168 
0169 /* If we did not see any headers from any supported C libraries,
0170  * or we are being included in the kernel, then define everything
0171  * that we need. Check for previous __UAPI_* definitions to give
0172  * unsupported C libraries a way to opt out of any kernel definition. */
0173 #else /* !defined(__GLIBC__) */
0174 
0175 /* Definitions for if.h */
0176 #ifndef __UAPI_DEF_IF_IFCONF
0177 #define __UAPI_DEF_IF_IFCONF 1
0178 #endif
0179 #ifndef __UAPI_DEF_IF_IFMAP
0180 #define __UAPI_DEF_IF_IFMAP 1
0181 #endif
0182 #ifndef __UAPI_DEF_IF_IFNAMSIZ
0183 #define __UAPI_DEF_IF_IFNAMSIZ 1
0184 #endif
0185 #ifndef __UAPI_DEF_IF_IFREQ
0186 #define __UAPI_DEF_IF_IFREQ 1
0187 #endif
0188 /* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
0189 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS
0190 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
0191 #endif
0192 /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
0193 #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
0194 #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
0195 #endif
0196 
0197 /* Definitions for in.h */
0198 #ifndef __UAPI_DEF_IN_ADDR
0199 #define __UAPI_DEF_IN_ADDR      1
0200 #endif
0201 #ifndef __UAPI_DEF_IN_IPPROTO
0202 #define __UAPI_DEF_IN_IPPROTO       1
0203 #endif
0204 #ifndef __UAPI_DEF_IN_PKTINFO
0205 #define __UAPI_DEF_IN_PKTINFO       1
0206 #endif
0207 #ifndef __UAPI_DEF_IP_MREQ
0208 #define __UAPI_DEF_IP_MREQ      1
0209 #endif
0210 #ifndef __UAPI_DEF_SOCKADDR_IN
0211 #define __UAPI_DEF_SOCKADDR_IN      1
0212 #endif
0213 #ifndef __UAPI_DEF_IN_CLASS
0214 #define __UAPI_DEF_IN_CLASS     1
0215 #endif
0216 
0217 /* Definitions for in6.h */
0218 #ifndef __UAPI_DEF_IN6_ADDR
0219 #define __UAPI_DEF_IN6_ADDR     1
0220 #endif
0221 #ifndef __UAPI_DEF_IN6_ADDR_ALT
0222 #define __UAPI_DEF_IN6_ADDR_ALT     1
0223 #endif
0224 #ifndef __UAPI_DEF_SOCKADDR_IN6
0225 #define __UAPI_DEF_SOCKADDR_IN6     1
0226 #endif
0227 #ifndef __UAPI_DEF_IPV6_MREQ
0228 #define __UAPI_DEF_IPV6_MREQ        1
0229 #endif
0230 #ifndef __UAPI_DEF_IPPROTO_V6
0231 #define __UAPI_DEF_IPPROTO_V6       1
0232 #endif
0233 #ifndef __UAPI_DEF_IPV6_OPTIONS
0234 #define __UAPI_DEF_IPV6_OPTIONS     1
0235 #endif
0236 #ifndef __UAPI_DEF_IN6_PKTINFO
0237 #define __UAPI_DEF_IN6_PKTINFO      1
0238 #endif
0239 #ifndef __UAPI_DEF_IP6_MTUINFO
0240 #define __UAPI_DEF_IP6_MTUINFO      1
0241 #endif
0242 
0243 /* Definitions for ipx.h */
0244 #ifndef __UAPI_DEF_SOCKADDR_IPX
0245 #define __UAPI_DEF_SOCKADDR_IPX         1
0246 #endif
0247 #ifndef __UAPI_DEF_IPX_ROUTE_DEFINITION
0248 #define __UAPI_DEF_IPX_ROUTE_DEFINITION     1
0249 #endif
0250 #ifndef __UAPI_DEF_IPX_INTERFACE_DEFINITION
0251 #define __UAPI_DEF_IPX_INTERFACE_DEFINITION 1
0252 #endif
0253 #ifndef __UAPI_DEF_IPX_CONFIG_DATA
0254 #define __UAPI_DEF_IPX_CONFIG_DATA      1
0255 #endif
0256 #ifndef __UAPI_DEF_IPX_ROUTE_DEF
0257 #define __UAPI_DEF_IPX_ROUTE_DEF        1
0258 #endif
0259 
0260 /* Definitions for xattr.h */
0261 #ifndef __UAPI_DEF_XATTR
0262 #define __UAPI_DEF_XATTR        1
0263 #endif
0264 
0265 #endif /* __GLIBC__ */
0266 
0267 #endif /* _UAPI_LIBC_COMPAT_H */