Elliott Hughes | 0f0c18f | 2023-03-29 15:53:31 -0700 | [diff] [blame] | 1 | # All the defaults used to generate the cleaned-up uapi headers for bionic. |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 2 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 3 | # the list of include directories that belong to the kernel |
| 4 | # tree. used when looking for sources... |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 5 | kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ] |
| 6 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 7 | # a special value that is used to indicate that a given macro is known to be |
| 8 | # undefined during optimization |
| 9 | kCppUndefinedMacro = "<<<undefined>>>" |
| 10 | |
| 11 | # this is the set of known macros we want to totally optimize out from the |
| 12 | # final headers |
| 13 | kernel_known_macros = { |
| 14 | "__KERNEL__": kCppUndefinedMacro, |
| 15 | "__KERNEL_STRICT_NAMES":"1", |
| 16 | "__CHECKER__": kCppUndefinedMacro, |
| 17 | "__CHECK_ENDIAN__": kCppUndefinedMacro, |
Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 18 | "CONFIG_64BIT": "__LP64__", |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 19 | "CONFIG_X86_32": "__i386__", |
Ben Cheng | 460fa70 | 2013-10-23 14:38:25 -0700 | [diff] [blame] | 20 | "__EXPORTED_HEADERS__": "1", |
Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 21 | "__HAVE_BUILTIN_BSWAP16__": "1", |
| 22 | "__HAVE_BUILTIN_BSWAP32__": "1", |
| 23 | "__HAVE_BUILTIN_BSWAP64__": "1", |
Christopher Ferris | d32ca14 | 2020-02-04 16:16:51 -0800 | [diff] [blame] | 24 | # 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", |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Christopher Ferris | 3fc4e11 | 2022-08-05 13:38:09 -0700 | [diff] [blame] | 30 | # This is the set of known kernel data structures we want to remove from |
Elliott Hughes | 5850f6f | 2023-11-29 11:18:49 -0800 | [diff] [blame^] | 31 | # the final headers. If the map value is non-empty, that means that in |
| 32 | # addition to removing the structure, add a #include to the file. |
Christopher Ferris | 3fc4e11 | 2022-08-05 13:38:09 -0700 | [diff] [blame] | 33 | kernel_structs_to_remove = { |
Elliott Hughes | 5850f6f | 2023-11-29 11:18:49 -0800 | [diff] [blame^] | 34 | # Remove these structures since they are still the same as |
Christopher Ferris | 3fc4e11 | 2022-08-05 13:38:09 -0700 | [diff] [blame] | 35 | # timeval, itimerval. |
Elliott Hughes | 5850f6f | 2023-11-29 11:18:49 -0800 | [diff] [blame^] | 36 | "__kernel_old_timeval": None, |
| 37 | "__kernel_old_itimerval": None, |
Christopher Ferris | 3fc4e11 | 2022-08-05 13:38:09 -0700 | [diff] [blame] | 38 | # Replace all of the below structures with #include <bits/STRUCT.h> |
Elliott Hughes | 5850f6f | 2023-11-29 11:18:49 -0800 | [diff] [blame^] | 39 | "__kernel_sockaddr_storage": "bits/sockaddr_storage.h", |
| 40 | "epoll_event": "bits/epoll_event.h", |
| 41 | "flock": "bits/flock.h", |
| 42 | "flock64": "bits/flock64.h", |
| 43 | "in_addr": "bits/in_addr.h", |
| 44 | "ip_mreq_source": "bits/ip_mreq_source.h", |
| 45 | "ip_msfilter": "bits/ip_msfilter.h", |
| 46 | "tcphdr": "bits/tcphdr.h", |
| 47 | "timespec": "bits/timespec.h", |
Christopher Ferris | 3fc4e11 | 2022-08-05 13:38:09 -0700 | [diff] [blame] | 48 | } |
Christopher Ferris | bb9fcb4 | 2020-04-06 11:38:04 -0700 | [diff] [blame] | 49 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 50 | # define to true if you want to remove all defined(CONFIG_FOO) tests |
| 51 | # from the clean headers. testing shows that this is not strictly necessary |
| 52 | # but just generates cleaner results |
| 53 | kernel_remove_config_macros = True |
| 54 | |
Elliott Hughes | bba6ddf | 2022-10-06 20:40:44 +0000 | [diff] [blame] | 55 | # Maps an architecture to a set of default macros that would be provided by |
| 56 | # the toolchain's preprocessor. Currently only used to remove confusing |
| 57 | # big-endian junk from the 32-bit arm headers. |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 58 | kernel_default_arch_macros = { |
Elliott Hughes | 8ed7a23 | 2014-05-15 12:01:11 -0700 | [diff] [blame] | 59 | "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"}, |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Elliott Hughes | 38dba2e | 2016-08-10 15:51:06 -0700 | [diff] [blame] | 62 | # Replace tokens in the output according to this mapping. |
Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 63 | kernel_token_replacements = { |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 64 | # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>. |
| 65 | "__unused": "__linux_unused", |
Christopher Ferris | 106b3a8 | 2016-08-24 12:15:38 -0700 | [diff] [blame] | 66 | # The kernel usage of C++ keywords causes problems for C++ code so rename. |
Elliott Hughes | b10c99d | 2023-10-12 23:57:49 +0000 | [diff] [blame] | 67 | "class": "__linux_class", |
Christopher Ferris | 106b3a8 | 2016-08-24 12:15:38 -0700 | [diff] [blame] | 68 | "private": "__linux_private", |
| 69 | "virtual": "__linux_virtual", |
Elliott Hughes | 7c59f3f | 2016-08-16 18:14:26 -0700 | [diff] [blame] | 70 | # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants. |
| 71 | "msqid_ds": "__kernel_legacy_msqid_ds", |
| 72 | "semid_ds": "__kernel_legacy_semid_ds", |
| 73 | "shmid_ds": "__kernel_legacy_shmid_ds", |
| 74 | "ipc_perm": "__kernel_legacy_ipc_perm", |
Elliott Hughes | 497ad30 | 2017-05-18 15:05:26 -0700 | [diff] [blame] | 75 | # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400). |
| 76 | "semun": "__kernel_legacy_semun", |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 77 | # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside. |
| 78 | "_NSIG": "_KERNEL__NSIG", |
| 79 | "NSIG": "_KERNEL_NSIG", |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 80 | # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few. |
| 81 | "SIGRTMIN": "__SIGRTMIN", |
| 82 | "SIGRTMAX": "__SIGRTMAX", |
Elliott Hughes | f8a2243 | 2015-09-22 12:34:13 -0700 | [diff] [blame] | 83 | # We want to support both BSD and Linux member names in struct udphdr. |
| 84 | "udphdr": "__kernel_udphdr", |
Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 85 | # This causes problems when trying to export the headers for the ndk. |
| 86 | "__attribute_const__": "__attribute__((__const__))", |
Christopher Ferris | d32ca14 | 2020-02-04 16:16:51 -0800 | [diff] [blame] | 87 | # The kernel started using struct __kernel_old_timeval in some places, |
| 88 | # which is the exact same as struct timeval. Replace that name with |
| 89 | # timeval so that kernel structures all use the same named structure. |
| 90 | # If struct __kernel_old_timeval and struct timeval become different, |
| 91 | # then a different solution needs to be implemented. |
| 92 | "__kernel_old_timeval": "timeval", |
Christopher Ferris | bb9fcb4 | 2020-04-06 11:38:04 -0700 | [diff] [blame] | 93 | # Do the same for __kernel_old_itimerval as for timeval. |
| 94 | "__kernel_old_itimerval": "itimerval", |
Elliott Hughes | 5850f6f | 2023-11-29 11:18:49 -0800 | [diff] [blame^] | 95 | # Do the same for __kernel_sockaddr_storage. |
| 96 | "__kernel_sockaddr_storage": "sockaddr_storage", |
Colin Cross | 4ac3322 | 2022-12-15 15:45:35 -0800 | [diff] [blame] | 97 | # Replace __packed with __attribute__((__packed__)) to avoid depending |
| 98 | # on sys/cdefs.h |
| 99 | "__packed": "__attribute__((__packed__))", |
Elliott Hughes | 0f0c18f | 2023-03-29 15:53:31 -0700 | [diff] [blame] | 100 | # Remove unused macros (http://b/262917450). |
| 101 | "__force": "", |
| 102 | "__user": "", |
Elliott Hughes | df53b16 | 2023-11-28 14:20:43 -0800 | [diff] [blame] | 103 | # Rename the kernel's sigaction so we can expose our POSIX one publicly, |
| 104 | # but translate to the kernel's one internally. |
| 105 | "sigaction": "__kernel_sigaction", |
Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 106 | } |
| 107 | |
Elliott Hughes | 64f355f | 2017-08-30 16:10:24 -0700 | [diff] [blame] | 108 | |
Elliott Hughes | 180edef | 2023-11-02 00:08:05 +0000 | [diff] [blame] | 109 | # Static inline functions that we want to keep. |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 110 | kernel_known_generic_statics = set( |
Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 111 | [ |
| 112 | "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h |
| 113 | "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h |
Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 114 | # Byte swapping inlines from uapi/linux/swab.h |
| 115 | # The below functions are the ones we are guaranting we export. |
| 116 | "__swab16", |
| 117 | "__swab32", |
| 118 | "__swab64", |
| 119 | "__swab16p", |
| 120 | "__swab32p", |
| 121 | "__swab64p", |
| 122 | "__swab16s", |
| 123 | "__swab32s", |
| 124 | "__swab64s", |
| 125 | "__swahw32", |
| 126 | "__swahb32", |
| 127 | "__swahw32p", |
| 128 | "__swahb32p", |
| 129 | "__swahw32s", |
| 130 | "__swahb32s", |
| 131 | # These are required to support the above functions. |
| 132 | "__fswahw32", |
| 133 | "__fswahb32", |
Elliott Hughes | b10c99d | 2023-10-12 23:57:49 +0000 | [diff] [blame] | 134 | # This is used by various macros in <linux/ioprio.h>. |
| 135 | "ioprio_value", |
Elliott Hughes | 180edef | 2023-11-02 00:08:05 +0000 | [diff] [blame] | 136 | |
| 137 | # Contact opensource-licensing@ before adding to this set. |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 138 | ] |
| 139 | ) |