xref: /linux/include/uapi/linux/libc-compat.h (revision 279c6c7fa64f5763e6b9f05e7ab3840092e702e7)
1cfd280c9SCarlos O'Donell /*
2cfd280c9SCarlos O'Donell  * Compatibility interface for userspace libc header coordination:
3cfd280c9SCarlos O'Donell  *
4cfd280c9SCarlos O'Donell  * Define compatibility macros that are used to control the inclusion or
5cfd280c9SCarlos O'Donell  * exclusion of UAPI structures and definitions in coordination with another
6cfd280c9SCarlos O'Donell  * userspace C library.
7cfd280c9SCarlos O'Donell  *
8cfd280c9SCarlos O'Donell  * This header is intended to solve the problem of UAPI definitions that
9cfd280c9SCarlos O'Donell  * conflict with userspace definitions. If a UAPI header has such conflicting
10cfd280c9SCarlos O'Donell  * definitions then the solution is as follows:
11cfd280c9SCarlos O'Donell  *
12cfd280c9SCarlos O'Donell  * * Synchronize the UAPI header and the libc headers so either one can be
13cfd280c9SCarlos O'Donell  *   used and such that the ABI is preserved. If this is not possible then
14cfd280c9SCarlos O'Donell  *   no simple compatibility interface exists (you need to write translating
15cfd280c9SCarlos O'Donell  *   wrappers and rename things) and you can't use this interface.
16cfd280c9SCarlos O'Donell  *
17cfd280c9SCarlos O'Donell  * Then follow this process:
18cfd280c9SCarlos O'Donell  *
19cfd280c9SCarlos O'Donell  * (a) Include libc-compat.h in the UAPI header.
20cfd280c9SCarlos O'Donell  *      e.g. #include <linux/libc-compat.h>
21cfd280c9SCarlos O'Donell  *     This include must be as early as possible.
22cfd280c9SCarlos O'Donell  *
23cfd280c9SCarlos O'Donell  * (b) In libc-compat.h add enough code to detect that the comflicting
24cfd280c9SCarlos O'Donell  *     userspace libc header has been included first.
25cfd280c9SCarlos O'Donell  *
26cfd280c9SCarlos O'Donell  * (c) If the userspace libc header has been included first define a set of
27cfd280c9SCarlos O'Donell  *     guard macros of the form __UAPI_DEF_FOO and set their values to 1, else
28cfd280c9SCarlos O'Donell  *     set their values to 0.
29cfd280c9SCarlos O'Donell  *
30cfd280c9SCarlos O'Donell  * (d) Back in the UAPI header with the conflicting definitions, guard the
31cfd280c9SCarlos O'Donell  *     definitions with:
32cfd280c9SCarlos O'Donell  *     #if __UAPI_DEF_FOO
33cfd280c9SCarlos O'Donell  *       ...
34cfd280c9SCarlos O'Donell  *     #endif
35cfd280c9SCarlos O'Donell  *
36cfd280c9SCarlos O'Donell  * This fixes the situation where the linux headers are included *after* the
37cfd280c9SCarlos O'Donell  * libc headers. To fix the problem with the inclusion in the other order the
38cfd280c9SCarlos O'Donell  * userspace libc headers must be fixed like this:
39cfd280c9SCarlos O'Donell  *
40cfd280c9SCarlos O'Donell  * * For all definitions that conflict with kernel definitions wrap those
41cfd280c9SCarlos O'Donell  *   defines in the following:
42cfd280c9SCarlos O'Donell  *   #if !__UAPI_DEF_FOO
43cfd280c9SCarlos O'Donell  *     ...
44cfd280c9SCarlos O'Donell  *   #endif
45cfd280c9SCarlos O'Donell  *
46cfd280c9SCarlos O'Donell  * This prevents the redefinition of a construct already defined by the kernel.
47cfd280c9SCarlos O'Donell  */
48cfd280c9SCarlos O'Donell #ifndef _UAPI_LIBC_COMPAT_H
49cfd280c9SCarlos O'Donell #define _UAPI_LIBC_COMPAT_H
50cfd280c9SCarlos O'Donell 
51cfd280c9SCarlos O'Donell /* We have included glibc headers... */
52cfd280c9SCarlos O'Donell #if defined(__GLIBC__)
53cfd280c9SCarlos O'Donell 
54cfd280c9SCarlos O'Donell /* Coordinate with glibc netinet/in.h header. */
55cfd280c9SCarlos O'Donell #if defined(_NETINET_IN_H)
56cfd280c9SCarlos O'Donell 
57cfd280c9SCarlos O'Donell /* GLIBC headers included first so don't define anything
58cfd280c9SCarlos O'Donell  * that would already be defined. */
59*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_ADDR		0
60*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_IPPROTO		0
61*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_PKTINFO		0
62*279c6c7fSStephen Hemminger #define __UAPI_DEF_IP_MREQ		0
63*279c6c7fSStephen Hemminger #define __UAPI_DEF_SOCKADDR_IN		0
64*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_CLASS		0
65*279c6c7fSStephen Hemminger 
66cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR		0
67cfd280c9SCarlos O'Donell /* The exception is the in6_addr macros which must be defined
68cfd280c9SCarlos O'Donell  * if the glibc code didn't define them. This guard matches
69cfd280c9SCarlos O'Donell  * the guard in glibc/inet/netinet/in.h which defines the
70cfd280c9SCarlos O'Donell  * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
71cfd280c9SCarlos O'Donell #if defined(__USE_MISC) || defined (__USE_GNU)
72cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT		0
73cfd280c9SCarlos O'Donell #else
74cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT		1
75cfd280c9SCarlos O'Donell #endif
76cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6		0
77cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ		0
78cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6		0
796d08acd2Sstephen hemminger #define __UAPI_DEF_IPV6_OPTIONS		0
803b50d902SWANG Cong #define __UAPI_DEF_IN6_PKTINFO		0
813b50d902SWANG Cong #define __UAPI_DEF_IP6_MTUINFO		0
82cfd280c9SCarlos O'Donell 
83cfd280c9SCarlos O'Donell #else
84cfd280c9SCarlos O'Donell 
85cfd280c9SCarlos O'Donell /* Linux headers included first, and we must define everything
86cfd280c9SCarlos O'Donell  * we need. The expectation is that glibc will check the
87cfd280c9SCarlos O'Donell  * __UAPI_DEF_* defines and adjust appropriately. */
88*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_ADDR		1
89*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_IPPROTO		1
90*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_PKTINFO		1
91*279c6c7fSStephen Hemminger #define __UAPI_DEF_IP_MREQ		1
92*279c6c7fSStephen Hemminger #define __UAPI_DEF_SOCKADDR_IN		1
93*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_CLASS		1
94*279c6c7fSStephen Hemminger 
95cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR		1
96cfd280c9SCarlos O'Donell /* We unconditionally define the in6_addr macros and glibc must
97cfd280c9SCarlos O'Donell  * coordinate. */
98cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT		1
99cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6		1
100cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ		1
101cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6		1
1026d08acd2Sstephen hemminger #define __UAPI_DEF_IPV6_OPTIONS		1
1033b50d902SWANG Cong #define __UAPI_DEF_IN6_PKTINFO		1
1043b50d902SWANG Cong #define __UAPI_DEF_IP6_MTUINFO		1
105cfd280c9SCarlos O'Donell 
106cfd280c9SCarlos O'Donell #endif /* _NETINET_IN_H */
107cfd280c9SCarlos O'Donell 
108ea1a8217SSerge Hallyn /* Definitions for xattr.h */
109ea1a8217SSerge Hallyn #if defined(_SYS_XATTR_H)
110ea1a8217SSerge Hallyn #define __UAPI_DEF_XATTR		0
111ea1a8217SSerge Hallyn #else
112ea1a8217SSerge Hallyn #define __UAPI_DEF_XATTR		1
113ea1a8217SSerge Hallyn #endif
114cfd280c9SCarlos O'Donell 
115cfd280c9SCarlos O'Donell /* If we did not see any headers from any supported C libraries,
116cfd280c9SCarlos O'Donell  * or we are being included in the kernel, then define everything
117cfd280c9SCarlos O'Donell  * that we need. */
118cfd280c9SCarlos O'Donell #else /* !defined(__GLIBC__) */
119cfd280c9SCarlos O'Donell 
120*279c6c7fSStephen Hemminger /* Definitions for in.h */
121*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_ADDR		1
122*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_IPPROTO		1
123*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_PKTINFO		1
124*279c6c7fSStephen Hemminger #define __UAPI_DEF_IP_MREQ		1
125*279c6c7fSStephen Hemminger #define __UAPI_DEF_SOCKADDR_IN		1
126*279c6c7fSStephen Hemminger #define __UAPI_DEF_IN_CLASS		1
127*279c6c7fSStephen Hemminger 
128cfd280c9SCarlos O'Donell /* Definitions for in6.h */
129cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR		1
130cfd280c9SCarlos O'Donell #define __UAPI_DEF_IN6_ADDR_ALT		1
131cfd280c9SCarlos O'Donell #define __UAPI_DEF_SOCKADDR_IN6		1
132cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPV6_MREQ		1
133cfd280c9SCarlos O'Donell #define __UAPI_DEF_IPPROTO_V6		1
1346d08acd2Sstephen hemminger #define __UAPI_DEF_IPV6_OPTIONS		1
1353b50d902SWANG Cong #define __UAPI_DEF_IN6_PKTINFO		1
1363b50d902SWANG Cong #define __UAPI_DEF_IP6_MTUINFO		1
137cfd280c9SCarlos O'Donell 
138ea1a8217SSerge Hallyn /* Definitions for xattr.h */
139ea1a8217SSerge Hallyn #define __UAPI_DEF_XATTR		1
140ea1a8217SSerge Hallyn 
141cfd280c9SCarlos O'Donell #endif /* __GLIBC__ */
142cfd280c9SCarlos O'Donell 
143cfd280c9SCarlos O'Donell #endif /* _UAPI_LIBC_COMPAT_H */
144