271-uapi-libc-compat.h-do-not-rely-on-__GLIBC__.patch 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. From: David Heidelberger <[email protected]>
  2. Subject: uapi/libc-compat.h: do not rely on __GLIBC__
  3. Musl provides the same structs as glibc, but does not provide a define to
  4. allow its detection. Since the absence of __GLIBC__ also can mean that it
  5. is included from the kernel, change the __GLIBC__ detection to
  6. !__KERNEL__, which should always be true when included from userspace.
  7. Signed-off-by: John Spencer <[email protected]>
  8. Tested-by: David Heidelberger <[email protected]>
  9. Signed-off-by: Jonas Gorski <[email protected]>
  10. ---
  11. include/uapi/linux/libc-compat.h | 18 +++++++++---------
  12. 1 file changed, 9 insertions(+), 9 deletions(-)
  13. --- a/include/uapi/linux/libc-compat.h
  14. +++ b/include/uapi/linux/libc-compat.h
  15. @@ -48,13 +48,13 @@
  16. #ifndef _UAPI_LIBC_COMPAT_H
  17. #define _UAPI_LIBC_COMPAT_H
  18. -/* We have included glibc headers... */
  19. -#if defined(__GLIBC__)
  20. +/* We have included libc headers... */
  21. +#if !defined(__KERNEL__)
  22. -/* Coordinate with glibc net/if.h header. */
  23. -#if defined(_NET_IF_H) && defined(__USE_MISC)
  24. +/* Coordinate with libc net/if.h header. */
  25. +#if defined(_NET_IF_H) && (!defined(__GLIBC__) || defined(__USE_MISC))
  26. -/* GLIBC headers included first so don't define anything
  27. +/* LIBC headers included first so don't define anything
  28. * that would already be defined. */
  29. #define __UAPI_DEF_IF_IFCONF 0
  30. @@ -65,7 +65,11 @@
  31. #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
  32. /* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
  33. #ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
  34. +#ifdef __GLIBC__
  35. #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
  36. +#else
  37. +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0
  38. +#endif
  39. #endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
  40. #else /* _NET_IF_H */
  41. @@ -85,10 +89,10 @@
  42. #endif /* _NET_IF_H */
  43. -/* Coordinate with glibc netinet/in.h header. */
  44. +/* Coordinate with libc netinet/in.h header. */
  45. #if defined(_NETINET_IN_H)
  46. -/* GLIBC headers included first so don't define anything
  47. +/* LIBC headers included first so don't define anything
  48. * that would already be defined. */
  49. #define __UAPI_DEF_IN_ADDR 0
  50. #define __UAPI_DEF_IN_IPPROTO 0
  51. @@ -102,7 +106,7 @@
  52. * if the glibc code didn't define them. This guard matches
  53. * the guard in glibc/inet/netinet/in.h which defines the
  54. * additional in6_addr macros e.g. s6_addr16, and s6_addr32. */
  55. -#if defined(__USE_MISC) || defined (__USE_GNU)
  56. +#if !defined(__GLIBC__) || defined(__USE_MISC) || defined (__USE_GNU)
  57. #define __UAPI_DEF_IN6_ADDR_ALT 0
  58. #else
  59. #define __UAPI_DEF_IN6_ADDR_ALT 1
  60. @@ -117,7 +121,7 @@
  61. #else
  62. /* Linux headers included first, and we must define everything
  63. - * we need. The expectation is that glibc will check the
  64. + * we need. The expectation is that the libc will check the
  65. * __UAPI_DEF_* defines and adjust appropriately. */
  66. #define __UAPI_DEF_IN_ADDR 1
  67. #define __UAPI_DEF_IN_IPPROTO 1
  68. @@ -127,7 +131,7 @@
  69. #define __UAPI_DEF_IN_CLASS 1
  70. #define __UAPI_DEF_IN6_ADDR 1
  71. -/* We unconditionally define the in6_addr macros and glibc must
  72. +/* We unconditionally define the in6_addr macros and the libc must
  73. * coordinate. */
  74. #define __UAPI_DEF_IN6_ADDR_ALT 1
  75. #define __UAPI_DEF_SOCKADDR_IN6 1
  76. @@ -168,7 +172,7 @@
  77. /* If we did not see any headers from any supported C libraries,
  78. * or we are being included in the kernel, then define everything
  79. * that we need. */
  80. -#else /* !defined(__GLIBC__) */
  81. +#else /* defined(__KERNEL__) */
  82. /* Definitions for if.h */
  83. #define __UAPI_DEF_IF_IFCONF 1
  84. @@ -208,6 +212,6 @@
  85. /* Definitions for xattr.h */
  86. #define __UAPI_DEF_XATTR 1
  87. -#endif /* __GLIBC__ */
  88. +#endif /* __KERNEL__ */
  89. #endif /* _UAPI_LIBC_COMPAT_H */