blob: 6ad0a32b6d85e5d8789e5de8a5f109f218e9bd4f [file] [log] [blame]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07001# this module contains all the defaults used by the generation of cleaned-up headers
2# for the Bionic C library
3#
4
5import time, os, sys
6from utils import *
7
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -07008# the list of include directories that belong to the kernel
9# tree. used when looking for sources...
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070010kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
11
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070012# a special value that is used to indicate that a given macro is known to be
13# undefined during optimization
14kCppUndefinedMacro = "<<<undefined>>>"
15
16# this is the set of known macros we want to totally optimize out from the
17# final headers
18kernel_known_macros = {
19 "__KERNEL__": kCppUndefinedMacro,
20 "__KERNEL_STRICT_NAMES":"1",
21 "__CHECKER__": kCppUndefinedMacro,
22 "__CHECK_ENDIAN__": kCppUndefinedMacro,
Elliott Hughes9195a252014-04-08 10:15:06 -070023 "CONFIG_64BIT": "__LP64__",
Elliott Hughesd3e64a32013-09-30 17:41:08 -070024 "CONFIG_X86_32": "__i386__",
Ben Cheng460fa702013-10-23 14:38:25 -070025 "__EXPORTED_HEADERS__": "1",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070026 "__HAVE_BUILTIN_BSWAP16__": "1",
27 "__HAVE_BUILTIN_BSWAP32__": "1",
28 "__HAVE_BUILTIN_BSWAP64__": "1",
Christopher Ferrisd32ca142020-02-04 16:16:51 -080029 # Use this to remove the struct __kernel_old_timeval definition.
30 # Otherwise, there will be two struct timeval definitions when
31 # __kernel_old_timeval is renamed to timeval.
32 "__kernel_old_timeval": "1",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070033 }
34
Christopher Ferris3fc4e112022-08-05 13:38:09 -070035# This is the set of known kernel data structures we want to remove from
36# the final headers. If the map value is False, that means that in
37# addition to removing the structure, add an #include <bits/STRUCT.h>
38# to the file.
39kernel_structs_to_remove = {
40 # Remove the structures since they are still the same as
41 # timeval, itimerval.
42 "__kernel_old_timeval": True,
43 "__kernel_old_itimerval": True,
44 # Replace all of the below structures with #include <bits/STRUCT.h>
45 "epoll_event": False,
46 "flock": False,
47 "flock64": False,
48 "in_addr": False,
49 "ip_mreq_source": False,
50 "ip_msfilter": False,
51 }
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -070052
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070053# define to true if you want to remove all defined(CONFIG_FOO) tests
54# from the clean headers. testing shows that this is not strictly necessary
55# but just generates cleaner results
56kernel_remove_config_macros = True
57
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080058# maps an architecture to a set of default macros that would be provided by
59# toolchain preprocessor
60kernel_default_arch_macros = {
Elliott Hughes8ed7a232014-05-15 12:01:11 -070061 "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
Colin Crossd1973ca2014-01-21 19:50:58 -080062 "arm64": {},
Elliott Hughesd3e64a32013-09-30 17:41:08 -070063 "x86": {},
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080064 }
65
Elliott Hughes38dba2e2016-08-10 15:51:06 -070066# Replace tokens in the output according to this mapping.
Martin Storsjoc9205db2010-12-08 11:39:05 +010067kernel_token_replacements = {
Elliott Hughes199346a2014-02-11 20:01:11 -080068 # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
69 "__unused": "__linux_unused",
Christopher Ferris106b3a82016-08-24 12:15:38 -070070 # The kernel usage of C++ keywords causes problems for C++ code so rename.
71 "private": "__linux_private",
72 "virtual": "__linux_virtual",
Elliott Hughes7c59f3f2016-08-16 18:14:26 -070073 # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
74 "msqid_ds": "__kernel_legacy_msqid_ds",
75 "semid_ds": "__kernel_legacy_semid_ds",
76 "shmid_ds": "__kernel_legacy_shmid_ds",
77 "ipc_perm": "__kernel_legacy_ipc_perm",
Elliott Hughes497ad302017-05-18 15:05:26 -070078 # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
79 "semun": "__kernel_legacy_semun",
Elliott Hughes199346a2014-02-11 20:01:11 -080080 # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
81 "_NSIG": "_KERNEL__NSIG",
82 "NSIG": "_KERNEL_NSIG",
Elliott Hughes0990d4f2014-04-30 09:45:40 -070083 # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
84 "SIGRTMIN": "__SIGRTMIN",
85 "SIGRTMAX": "__SIGRTMAX",
Elliott Hughesf8a22432015-09-22 12:34:13 -070086 # We want to support both BSD and Linux member names in struct udphdr.
87 "udphdr": "__kernel_udphdr",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070088 # This causes problems when trying to export the headers for the ndk.
89 "__attribute_const__": "__attribute__((__const__))",
Christopher Ferrisd32ca142020-02-04 16:16:51 -080090 # The kernel started using struct __kernel_old_timeval in some places,
91 # which is the exact same as struct timeval. Replace that name with
92 # timeval so that kernel structures all use the same named structure.
93 # If struct __kernel_old_timeval and struct timeval become different,
94 # then a different solution needs to be implemented.
95 "__kernel_old_timeval": "timeval",
Christopher Ferrisbb9fcb42020-04-06 11:38:04 -070096 # Do the same for __kernel_old_itimerval as for timeval.
97 "__kernel_old_itimerval": "itimerval",
Martin Storsjoc9205db2010-12-08 11:39:05 +010098 }
99
Elliott Hughes64f355f2017-08-30 16:10:24 -0700100
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700101# This is the set of known static inline functions that we want to keep
102# in the final kernel headers.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700103kernel_known_generic_statics = set(
Elliott Hughes9195a252014-04-08 10:15:06 -0700104 [
105 "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h
106 "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700107 # Byte swapping inlines from uapi/linux/swab.h
108 # The below functions are the ones we are guaranting we export.
109 "__swab16",
110 "__swab32",
111 "__swab64",
112 "__swab16p",
113 "__swab32p",
114 "__swab64p",
115 "__swab16s",
116 "__swab32s",
117 "__swab64s",
118 "__swahw32",
119 "__swahb32",
120 "__swahw32p",
121 "__swahb32p",
122 "__swahw32s",
123 "__swahb32s",
124 # These are required to support the above functions.
125 "__fswahw32",
126 "__fswahb32",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700127 ]
128 )
129
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700130# this is the standard disclaimer
131#
132kernel_disclaimer = """\
133/****************************************************************************
134 ****************************************************************************
135 ***
136 *** This header was automatically generated from a Linux kernel header
137 *** of the same name, to make information necessary for userspace to
138 *** call into the kernel available to libc. It contains only constants,
139 *** structures, and macros generated from the original header, and thus,
140 *** contains no copyrightable information.
141 ***
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200142 *** To edit the content of this header, modify the corresponding
143 *** source file (e.g. under external/kernel-headers/original/) then
144 *** run bionic/libc/kernel/tools/update_all.py
145 ***
146 *** Any manual change here will be lost the next time this script will
147 *** be run. You've been warned!
148 ***
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700149 ****************************************************************************
150 ****************************************************************************/
151"""