1*cfd280c9SCarlos O'Donell /* 2*cfd280c9SCarlos O'Donell * Compatibility interface for userspace libc header coordination: 3*cfd280c9SCarlos O'Donell * 4*cfd280c9SCarlos O'Donell * Define compatibility macros that are used to control the inclusion or 5*cfd280c9SCarlos O'Donell * exclusion of UAPI structures and definitions in coordination with another 6*cfd280c9SCarlos O'Donell * userspace C library. 7*cfd280c9SCarlos O'Donell * 8*cfd280c9SCarlos O'Donell * This header is intended to solve the problem of UAPI definitions that 9*cfd280c9SCarlos O'Donell * conflict with userspace definitions. If a UAPI header has such conflicting 10*cfd280c9SCarlos O'Donell * definitions then the solution is as follows: 11*cfd280c9SCarlos O'Donell * 12*cfd280c9SCarlos O'Donell * * Synchronize the UAPI header and the libc headers so either one can be 13*cfd280c9SCarlos O'Donell * used and such that the ABI is preserved. If this is not possible then 14*cfd280c9SCarlos O'Donell * no simple compatibility interface exists (you need to write translating 15*cfd280c9SCarlos O'Donell * wrappers and rename things) and you can't use this interface. 16*cfd280c9SCarlos O'Donell * 17*cfd280c9SCarlos O'Donell * Then follow this process: 18*cfd280c9SCarlos O'Donell * 19*cfd280c9SCarlos O'Donell * (a) Include libc-compat.h in the UAPI header. 20*cfd280c9SCarlos O'Donell * e.g. #include <linux/libc-compat.h> 21*cfd280c9SCarlos O'Donell * This include must be as early as possible. 22*cfd280c9SCarlos O'Donell * 23*cfd280c9SCarlos O'Donell * (b) In libc-compat.h add enough code to detect that the comflicting 24*cfd280c9SCarlos O'Donell * userspace libc header has been included first. 25*cfd280c9SCarlos O'Donell * 26*cfd280c9SCarlos O'Donell * (c) If the userspace libc header has been included first define a set of 27*cfd280c9SCarlos O'Donell * guard macros of the form __UAPI_DEF_FOO and set their values to 1, else 28*cfd280c9SCarlos O'Donell * set their values to 0. 29*cfd280c9SCarlos O'Donell * 30*cfd280c9SCarlos O'Donell * (d) Back in the UAPI header with the conflicting definitions, guard the 31*cfd280c9SCarlos O'Donell * definitions with: 32*cfd280c9SCarlos O'Donell * #if __UAPI_DEF_FOO 33*cfd280c9SCarlos O'Donell * ... 34*cfd280c9SCarlos O'Donell * #endif 35*cfd280c9SCarlos O'Donell * 36*cfd280c9SCarlos O'Donell * This fixes the situation where the linux headers are included *after* the 37*cfd280c9SCarlos O'Donell * libc headers. To fix the problem with the inclusion in the other order the 38*cfd280c9SCarlos O'Donell * userspace libc headers must be fixed like this: 39*cfd280c9SCarlos O'Donell * 40*cfd280c9SCarlos O'Donell * * For all definitions that conflict with kernel definitions wrap those 41*cfd280c9SCarlos O'Donell * defines in the following: 42*cfd280c9SCarlos O'Donell * #if !__UAPI_DEF_FOO 43*cfd280c9SCarlos O'Donell * ... 44*cfd280c9SCarlos O'Donell * #endif 45*cfd280c9SCarlos O'Donell * 46*cfd280c9SCarlos O'Donell * This prevents the redefinition of a construct already defined by the kernel. 47*cfd280c9SCarlos O'Donell */ 48*cfd280c9SCarlos O'Donell #ifndef _UAPI_LIBC_COMPAT_H 49*cfd280c9SCarlos O'Donell #define _UAPI_LIBC_COMPAT_H 50*cfd280c9SCarlos O'Donell 51*cfd280c9SCarlos O'Donell /* We have included glibc headers... */ 52*cfd280c9SCarlos O'Donell #if defined(__GLIBC__) 53*cfd280c9SCarlos O'Donell 54*cfd280c9SCarlos O'Donell /* Coordinate with glibc netinet/in.h header. */ 55*cfd280c9SCarlos O'Donell #if defined(_NETINET_IN_H) 56*cfd280c9SCarlos O'Donell 57*cfd280c9SCarlos O'Donell /* GLIBC headers included first so don't define anything 58*cfd280c9SCarlos O'Donell * that would already be defined. */ 59*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR 0 60*cfd280c9SCarlos O'Donell /* The exception is the in6_addr macros which must be defined 61*cfd280c9SCarlos O'Donell * if the glibc code didn't define them. This guard matches 62*cfd280c9SCarlos O'Donell * the guard in glibc/inet/netinet/in.h which defines the 63*cfd280c9SCarlos O'Donell * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */ 64*cfd280c9SCarlos O'Donell #if defined(__USE_MISC) || defined (__USE_GNU) 65*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT 0 66*cfd280c9SCarlos O'Donell #else 67*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT 1 68*cfd280c9SCarlos O'Donell #endif 69*cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6 0 70*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ 0 71*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6 0 72*cfd280c9SCarlos O'Donell 73*cfd280c9SCarlos O'Donell #else 74*cfd280c9SCarlos O'Donell 75*cfd280c9SCarlos O'Donell /* Linux headers included first, and we must define everything 76*cfd280c9SCarlos O'Donell * we need. The expectation is that glibc will check the 77*cfd280c9SCarlos O'Donell * __UAPI_DEF_* defines and adjust appropriately. */ 78*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR 1 79*cfd280c9SCarlos O'Donell /* We unconditionally define the in6_addr macros and glibc must 80*cfd280c9SCarlos O'Donell * coordinate. */ 81*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT 1 82*cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6 1 83*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ 1 84*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6 1 85*cfd280c9SCarlos O'Donell 86*cfd280c9SCarlos O'Donell #endif /* _NETINET_IN_H */ 87*cfd280c9SCarlos O'Donell 88*cfd280c9SCarlos O'Donell 89*cfd280c9SCarlos O'Donell /* If we did not see any headers from any supported C libraries, 90*cfd280c9SCarlos O'Donell * or we are being included in the kernel, then define everything 91*cfd280c9SCarlos O'Donell * that we need. */ 92*cfd280c9SCarlos O'Donell #else /* !defined(__GLIBC__) */ 93*cfd280c9SCarlos O'Donell 94*cfd280c9SCarlos O'Donell /* Definitions for in6.h */ 95*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR 1 96*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT 1 97*cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6 1 98*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ 1 99*cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6 1 100*cfd280c9SCarlos O'Donell 101*cfd280c9SCarlos O'Donell #endif /* __GLIBC__ */ 102*cfd280c9SCarlos O'Donell 103*cfd280c9SCarlos O'Donell #endif /* _UAPI_LIBC_COMPAT_H */ 104