| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # this module contains all the defaults used by the generation of cleaned-up headers | 
|  | 2 | # for the Bionic C library | 
|  | 3 | # | 
|  | 4 |  | 
|  | 5 | import time, os, sys | 
|  | 6 | from utils import * | 
|  | 7 |  | 
|  | 8 | # the list of supported architectures | 
| Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 9 | kernel_archs = [ 'arm', 'arm64', 'mips', 'x86' ] | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 10 |  | 
|  | 11 | # the list of include directories that belong to the kernel | 
|  | 12 | # tree. used when looking for sources... | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 13 | kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ] | 
|  | 14 |  | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 15 | # a special value that is used to indicate that a given macro is known to be | 
|  | 16 | # undefined during optimization | 
|  | 17 | kCppUndefinedMacro = "<<<undefined>>>" | 
|  | 18 |  | 
|  | 19 | # this is the set of known macros we want to totally optimize out from the | 
|  | 20 | # final headers | 
|  | 21 | kernel_known_macros = { | 
|  | 22 | "__KERNEL__": kCppUndefinedMacro, | 
|  | 23 | "__KERNEL_STRICT_NAMES":"1", | 
|  | 24 | "__CHECKER__": kCppUndefinedMacro, | 
|  | 25 | "__CHECK_ENDIAN__": kCppUndefinedMacro, | 
| Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 26 | "CONFIG_64BIT": "__LP64__", | 
| Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 27 | "CONFIG_X86_32": "__i386__", | 
| Ben Cheng | 460fa70 | 2013-10-23 14:38:25 -0700 | [diff] [blame] | 28 | "__EXPORTED_HEADERS__": "1", | 
| Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 29 | "__HAVE_BUILTIN_BSWAP16__": "1", | 
|  | 30 | "__HAVE_BUILTIN_BSWAP32__": "1", | 
|  | 31 | "__HAVE_BUILTIN_BSWAP64__": "1", | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 32 | } | 
|  | 33 |  | 
|  | 34 | # define to true if you want to remove all defined(CONFIG_FOO) tests | 
|  | 35 | # from the clean headers. testing shows that this is not strictly necessary | 
|  | 36 | # but just generates cleaner results | 
|  | 37 | kernel_remove_config_macros = True | 
|  | 38 |  | 
| The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 39 | # maps an architecture to a set of default macros that would be provided by | 
|  | 40 | # toolchain preprocessor | 
|  | 41 | kernel_default_arch_macros = { | 
| Elliott Hughes | 8ed7a23 | 2014-05-15 12:01:11 -0700 | [diff] [blame] | 42 | "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"}, | 
| Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 43 | "arm64": {}, | 
| Duane Sand | a69eaec | 2014-06-19 14:38:07 -0700 | [diff] [blame] | 44 | "mips": {"__MIPSEB__": kCppUndefinedMacro, | 
|  | 45 | "__MIPSEL__": "1", | 
|  | 46 | "CONFIG_32BIT": "_ABIO32", | 
|  | 47 | "CONFIG_CPU_LITTLE_ENDIAN": "1", | 
|  | 48 | "__SANE_USERSPACE_TYPES__": "1",}, | 
| Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 49 | "x86": {}, | 
| The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 50 | } | 
|  | 51 |  | 
| Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 52 | kernel_arch_token_replacements = { | 
|  | 53 | "arm": {}, | 
| Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 54 | "arm64": {}, | 
| Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 55 | "mips": {"off_t":"__kernel_off_t"}, | 
| Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 56 | "x86": {}, | 
| Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 57 | } | 
| Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 58 |  | 
| Elliott Hughes | 38dba2e | 2016-08-10 15:51:06 -0700 | [diff] [blame] | 59 | # Replace tokens in the output according to this mapping. | 
| Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 60 | kernel_token_replacements = { | 
| Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 61 | # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>. | 
|  | 62 | "__unused": "__linux_unused", | 
| Christopher Ferris | 106b3a8 | 2016-08-24 12:15:38 -0700 | [diff] [blame] | 63 | # The kernel usage of C++ keywords causes problems for C++ code so rename. | 
|  | 64 | "private": "__linux_private", | 
|  | 65 | "virtual": "__linux_virtual", | 
| Elliott Hughes | 7c59f3f | 2016-08-16 18:14:26 -0700 | [diff] [blame] | 66 | # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants. | 
|  | 67 | "msqid_ds": "__kernel_legacy_msqid_ds", | 
|  | 68 | "semid_ds": "__kernel_legacy_semid_ds", | 
|  | 69 | "shmid_ds": "__kernel_legacy_shmid_ds", | 
|  | 70 | "ipc_perm": "__kernel_legacy_ipc_perm", | 
| Elliott Hughes | 497ad30 | 2017-05-18 15:05:26 -0700 | [diff] [blame] | 71 | # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400). | 
|  | 72 | "semun": "__kernel_legacy_semun", | 
| Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 73 | # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside. | 
|  | 74 | "_NSIG": "_KERNEL__NSIG", | 
|  | 75 | "NSIG": "_KERNEL_NSIG", | 
| Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 76 | # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few. | 
|  | 77 | "SIGRTMIN": "__SIGRTMIN", | 
|  | 78 | "SIGRTMAX": "__SIGRTMAX", | 
| Elliott Hughes | f8a2243 | 2015-09-22 12:34:13 -0700 | [diff] [blame] | 79 | # We want to support both BSD and Linux member names in struct udphdr. | 
|  | 80 | "udphdr": "__kernel_udphdr", | 
| Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 81 | # This causes problems when trying to export the headers for the ndk. | 
|  | 82 | "__attribute_const__": "__attribute__((__const__))", | 
| Elliott Hughes | 64f355f | 2017-08-30 16:10:24 -0700 | [diff] [blame] | 83 | # In this case the kernel tries to keep out of our way, but we're happy to use its definition. | 
|  | 84 | "__kernel_sockaddr_storage": "sockaddr_storage", | 
| Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 85 | } | 
|  | 86 |  | 
| Elliott Hughes | 64f355f | 2017-08-30 16:10:24 -0700 | [diff] [blame] | 87 |  | 
|  | 88 | # This is the set of struct definitions that we want to replace with | 
|  | 89 | # a #include of <bits/struct.h> instead. | 
|  | 90 | kernel_struct_replacements = set( | 
|  | 91 | [ | 
|  | 92 | "epoll_event", | 
|  | 93 | "in_addr", | 
|  | 94 | "ip_mreq_source", | 
|  | 95 | "ip_msfilter", | 
|  | 96 | ] | 
|  | 97 | ) | 
|  | 98 |  | 
|  | 99 |  | 
| Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 100 | # This is the set of known static inline functions that we want to keep | 
|  | 101 | # in the final kernel headers. | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 102 | kernel_known_generic_statics = set( | 
| Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 103 | [ | 
|  | 104 | "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h | 
|  | 105 | "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h | 
| Christopher Ferris | ee1e0a3 | 2017-04-20 13:38:49 -0700 | [diff] [blame] | 106 | # Byte swapping inlines from uapi/linux/swab.h | 
|  | 107 | # The below functions are the ones we are guaranting we export. | 
|  | 108 | "__swab16", | 
|  | 109 | "__swab32", | 
|  | 110 | "__swab64", | 
|  | 111 | "__swab16p", | 
|  | 112 | "__swab32p", | 
|  | 113 | "__swab64p", | 
|  | 114 | "__swab16s", | 
|  | 115 | "__swab32s", | 
|  | 116 | "__swab64s", | 
|  | 117 | "__swahw32", | 
|  | 118 | "__swahb32", | 
|  | 119 | "__swahw32p", | 
|  | 120 | "__swahb32p", | 
|  | 121 | "__swahw32s", | 
|  | 122 | "__swahb32s", | 
|  | 123 | # These are required to support the above functions. | 
|  | 124 | "__fswahw32", | 
|  | 125 | "__fswahb32", | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 126 | ] | 
|  | 127 | ) | 
|  | 128 |  | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 129 | # this is the standard disclaimer | 
|  | 130 | # | 
|  | 131 | kernel_disclaimer = """\ | 
|  | 132 | /**************************************************************************** | 
|  | 133 | **************************************************************************** | 
|  | 134 | *** | 
|  | 135 | ***   This header was automatically generated from a Linux kernel header | 
|  | 136 | ***   of the same name, to make information necessary for userspace to | 
|  | 137 | ***   call into the kernel available to libc.  It contains only constants, | 
|  | 138 | ***   structures, and macros generated from the original header, and thus, | 
|  | 139 | ***   contains no copyrightable information. | 
|  | 140 | *** | 
| David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 141 | ***   To edit the content of this header, modify the corresponding | 
|  | 142 | ***   source file (e.g. under external/kernel-headers/original/) then | 
|  | 143 | ***   run bionic/libc/kernel/tools/update_all.py | 
|  | 144 | *** | 
|  | 145 | ***   Any manual change here will be lost the next time this script will | 
|  | 146 | ***   be run. You've been warned! | 
|  | 147 | *** | 
| The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 148 | **************************************************************************** | 
|  | 149 | ****************************************************************************/ | 
|  | 150 | """ |