blob: 2994e5e29fb1cfc7aecbcd831f0c189f6712240e [file] [log] [blame]
Elliott Hughes0f0c18f2023-03-29 15:53:31 -07001# All the defaults used to generate the cleaned-up uapi headers for bionic.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07002
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07003# the list of include directories that belong to the kernel
4# tree. used when looking for sources...
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07005kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
6
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07007# a special value that is used to indicate that a given macro is known to be
8# undefined during optimization
9kCppUndefinedMacro = "<<<undefined>>>"
10
11# this is the set of known macros we want to totally optimize out from the
12# final headers
13kernel_known_macros = {
14 "__KERNEL__": kCppUndefinedMacro,
15 "__KERNEL_STRICT_NAMES":"1",
16 "__CHECKER__": kCppUndefinedMacro,
17 "__CHECK_ENDIAN__": kCppUndefinedMacro,
Elliott Hughes9195a252014-04-08 10:15:06 -070018 "CONFIG_64BIT": "__LP64__",
Elliott Hughesd3e64a32013-09-30 17:41:08 -070019 "CONFIG_X86_32": "__i386__",
Ben Cheng460fa702013-10-23 14:38:25 -070020 "__EXPORTED_HEADERS__": "1",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070021 "__HAVE_BUILTIN_BSWAP16__": "1",
22 "__HAVE_BUILTIN_BSWAP32__": "1",
23 "__HAVE_BUILTIN_BSWAP64__": "1",
Christopher Ferrisd32ca142020-02-04 16:16:51 -080024 # Use this to remove the struct __kernel_old_timeval definition.
25 # Otherwise, there will be two struct timeval definitions when
26 # __kernel_old_timeval is renamed to timeval.
27 "__kernel_old_timeval": "1",
Elliott Hughes0c603c32024-12-01 22:03:29 -050028 # Drop the custom byte swap functions and just use the clang builtins.
29 # https://github.com/android/ndk/issues/2107
30 "__arch_swab16": kCppUndefinedMacro,
31 "__arch_swab16p": kCppUndefinedMacro,
32 "__arch_swab16s": kCppUndefinedMacro,
33 "__arch_swab32": kCppUndefinedMacro,
34 "__arch_swab32p": kCppUndefinedMacro,
35 "__arch_swab32s": kCppUndefinedMacro,
36 "__arch_swab64": kCppUndefinedMacro,
37 "__arch_swab64p": kCppUndefinedMacro,
38 "__arch_swab64s": kCppUndefinedMacro,
39 "__arch_swahb32": kCppUndefinedMacro,
40 "__arch_swahb32p": kCppUndefinedMacro,
41 "__arch_swahb32s": kCppUndefinedMacro,
42 "__arch_swahw32": kCppUndefinedMacro,
43 "__arch_swahw32p": kCppUndefinedMacro,
44 "__arch_swahw32s": kCppUndefinedMacro,
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070045 }
46
Christopher Ferris3fc4e112022-08-05 13:38:09 -070047# This is the set of known kernel data structures we want to remove from
Elliott Hughes5850f6f2023-11-29 11:18:49 -080048# the final headers. If the map value is non-empty, that means that in
49# addition to removing the structure, add a #include to the file.
Christopher Ferris3fc4e112022-08-05 13:38:09 -070050kernel_structs_to_remove = {
Elliott Hughes5850f6f2023-11-29 11:18:49 -080051 # Remove these structures since they are still the same as
Christopher Ferrisb830ddf2024-03-28 11:48:08 -070052 # timeval, itimerval. Also, add an include of linux/time.h
53 # since __kernel_old_timeval is being changed to timeval, and
54 # is only present in linux/time.h.
55 "__kernel_old_timeval": "linux/time.h",
Elliott Hughes5850f6f2023-11-29 11:18:49 -080056 "__kernel_old_itimerval": None,
Christopher Ferris3fc4e112022-08-05 13:38:09 -070057 # Replace all of the below structures with #include <bits/STRUCT.h>
Elliott Hughes5850f6f2023-11-29 11:18:49 -080058 "__kernel_sockaddr_storage": "bits/sockaddr_storage.h",
59 "epoll_event": "bits/epoll_event.h",
60 "flock": "bits/flock.h",
61 "flock64": "bits/flock64.h",
62 "in_addr": "bits/in_addr.h",
63 "ip_mreq_source": "bits/ip_mreq_source.h",
64 "ip_msfilter": "bits/ip_msfilter.h",
65 "tcphdr": "bits/tcphdr.h",
66 "timespec": "bits/timespec.h",
Christopher Ferris3fc4e112022-08-05 13:38:09 -070067 }
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -070068
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070069# define to true if you want to remove all defined(CONFIG_FOO) tests
70# from the clean headers. testing shows that this is not strictly necessary
71# but just generates cleaner results
72kernel_remove_config_macros = True
73
Elliott Hughesbba6ddf2022-10-06 20:40:44 +000074# Maps an architecture to a set of default macros that would be provided by
75# the toolchain's preprocessor. Currently only used to remove confusing
76# big-endian junk from the 32-bit arm headers.
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080077kernel_default_arch_macros = {
Elliott Hughes8ed7a232014-05-15 12:01:11 -070078 "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080079 }
80
Elliott Hughes38dba2e2016-08-10 15:51:06 -070081# Replace tokens in the output according to this mapping.
Martin Storsjoc9205db2010-12-08 11:39:05 +010082kernel_token_replacements = {
Elliott Hughes199346a2014-02-11 20:01:11 -080083 # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
84 "__unused": "__linux_unused",
Christopher Ferris106b3a82016-08-24 12:15:38 -070085 # The kernel usage of C++ keywords causes problems for C++ code so rename.
Elliott Hughesb10c99d2023-10-12 23:57:49 +000086 "class": "__linux_class",
Christopher Ferris106b3a82016-08-24 12:15:38 -070087 "private": "__linux_private",
88 "virtual": "__linux_virtual",
Elliott Hughes7c59f3f2016-08-16 18:14:26 -070089 # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
90 "msqid_ds": "__kernel_legacy_msqid_ds",
91 "semid_ds": "__kernel_legacy_semid_ds",
92 "shmid_ds": "__kernel_legacy_shmid_ds",
93 "ipc_perm": "__kernel_legacy_ipc_perm",
Elliott Hughes497ad302017-05-18 15:05:26 -070094 # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
95 "semun": "__kernel_legacy_semun",
Elliott Hughes199346a2014-02-11 20:01:11 -080096 # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
97 "_NSIG": "_KERNEL__NSIG",
98 "NSIG": "_KERNEL_NSIG",
Elliott Hughes0990d4f2014-04-30 09:45:40 -070099 # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
100 "SIGRTMIN": "__SIGRTMIN",
101 "SIGRTMAX": "__SIGRTMAX",
Elliott Hughesf8a22432015-09-22 12:34:13 -0700102 # We want to support both BSD and Linux member names in struct udphdr.
103 "udphdr": "__kernel_udphdr",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700104 # This causes problems when trying to export the headers for the ndk.
105 "__attribute_const__": "__attribute__((__const__))",
Christopher Ferrisd32ca142020-02-04 16:16:51 -0800106 # The kernel started using struct __kernel_old_timeval in some places,
107 # which is the exact same as struct timeval. Replace that name with
108 # timeval so that kernel structures all use the same named structure.
109 # If struct __kernel_old_timeval and struct timeval become different,
110 # then a different solution needs to be implemented.
111 "__kernel_old_timeval": "timeval",
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -0700112 # Do the same for __kernel_old_itimerval as for timeval.
113 "__kernel_old_itimerval": "itimerval",
Elliott Hughes5850f6f2023-11-29 11:18:49 -0800114 # Do the same for __kernel_sockaddr_storage.
115 "__kernel_sockaddr_storage": "sockaddr_storage",
Colin Cross4ac33222022-12-15 15:45:35 -0800116 # Replace __packed with __attribute__((__packed__)) to avoid depending
117 # on sys/cdefs.h
118 "__packed": "__attribute__((__packed__))",
Elliott Hughes0f0c18f2023-03-29 15:53:31 -0700119 # Remove unused macros (http://b/262917450).
120 "__force": "",
121 "__user": "",
Elliott Hughesdf53b162023-11-28 14:20:43 -0800122 # Rename the kernel's sigaction so we can expose our POSIX one publicly,
123 # but translate to the kernel's one internally.
124 "sigaction": "__kernel_sigaction",
Martin Storsjoc9205db2010-12-08 11:39:05 +0100125 }
126
Elliott Hughes64f355f2017-08-30 16:10:24 -0700127
Elliott Hughes180edef2023-11-02 00:08:05 +0000128# Static inline functions that we want to keep.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700129kernel_known_generic_statics = set(
Elliott Hughes9195a252014-04-08 10:15:06 -0700130 [
131 "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h
132 "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700133 # Byte swapping inlines from uapi/linux/swab.h
134 # The below functions are the ones we are guaranting we export.
135 "__swab16",
136 "__swab32",
137 "__swab64",
138 "__swab16p",
139 "__swab32p",
140 "__swab64p",
141 "__swab16s",
142 "__swab32s",
143 "__swab64s",
144 "__swahw32",
145 "__swahb32",
146 "__swahw32p",
147 "__swahb32p",
148 "__swahw32s",
149 "__swahb32s",
150 # These are required to support the above functions.
151 "__fswahw32",
152 "__fswahb32",
Elliott Hughesb10c99d2023-10-12 23:57:49 +0000153 # This is used by various macros in <linux/ioprio.h>.
154 "ioprio_value",
Elliott Hughes180edef2023-11-02 00:08:05 +0000155
156 # Contact opensource-licensing@ before adding to this set.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700157 ]
158 )