blob: b0fb95fb76f255270dbaf9f734f289bb627586a4 [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
8# the list of supported architectures
Colin Crossd1973ca2014-01-21 19:50:58 -08009kernel_archs = [ 'arm', 'arm64', 'mips', 'x86' ]
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070010
11# the list of include directories that belong to the kernel
12# tree. used when looking for sources...
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070013kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
14
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070015# a special value that is used to indicate that a given macro is known to be
16# undefined during optimization
17kCppUndefinedMacro = "<<<undefined>>>"
18
19# this is the set of known macros we want to totally optimize out from the
20# final headers
21kernel_known_macros = {
22 "__KERNEL__": kCppUndefinedMacro,
23 "__KERNEL_STRICT_NAMES":"1",
24 "__CHECKER__": kCppUndefinedMacro,
25 "__CHECK_ENDIAN__": kCppUndefinedMacro,
Elliott Hughes9195a252014-04-08 10:15:06 -070026 "CONFIG_64BIT": "__LP64__",
Elliott Hughesd3e64a32013-09-30 17:41:08 -070027 "CONFIG_X86_32": "__i386__",
Ben Cheng460fa702013-10-23 14:38:25 -070028 "__EXPORTED_HEADERS__": "1",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070029 "__HAVE_BUILTIN_BSWAP16__": "1",
30 "__HAVE_BUILTIN_BSWAP32__": "1",
31 "__HAVE_BUILTIN_BSWAP64__": "1",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070032 }
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
37kernel_remove_config_macros = True
38
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080039# maps an architecture to a set of default macros that would be provided by
40# toolchain preprocessor
41kernel_default_arch_macros = {
Elliott Hughes8ed7a232014-05-15 12:01:11 -070042 "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
Colin Crossd1973ca2014-01-21 19:50:58 -080043 "arm64": {},
Duane Sanda69eaec2014-06-19 14:38:07 -070044 "mips": {"__MIPSEB__": kCppUndefinedMacro,
45 "__MIPSEL__": "1",
46 "CONFIG_32BIT": "_ABIO32",
47 "CONFIG_CPU_LITTLE_ENDIAN": "1",
48 "__SANE_USERSPACE_TYPES__": "1",},
Elliott Hughesd3e64a32013-09-30 17:41:08 -070049 "x86": {},
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080050 }
51
Raghu Gandhama864c2c2013-01-16 16:42:47 -080052kernel_arch_token_replacements = {
53 "arm": {},
Colin Crossd1973ca2014-01-21 19:50:58 -080054 "arm64": {},
Raghu Gandhama864c2c2013-01-16 16:42:47 -080055 "mips": {"off_t":"__kernel_off_t"},
Elliott Hughesd3e64a32013-09-30 17:41:08 -070056 "x86": {},
Raghu Gandhama864c2c2013-01-16 16:42:47 -080057 }
Elliott Hughes199346a2014-02-11 20:01:11 -080058
Elliott Hughes38dba2e2016-08-10 15:51:06 -070059# Replace tokens in the output according to this mapping.
Martin Storsjoc9205db2010-12-08 11:39:05 +010060kernel_token_replacements = {
Elliott Hughes38dba2e2016-08-10 15:51:06 -070061 # The kernel's ARG_MAX is actually the "minimum" maximum (see fs/exec.c).
62 "ARG_MAX": "_KERNEL_ARG_MAX",
Elliott Hughes199346a2014-02-11 20:01:11 -080063 # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
64 "__unused": "__linux_unused",
Christopher Ferris106b3a82016-08-24 12:15:38 -070065 # The kernel usage of C++ keywords causes problems for C++ code so rename.
66 "private": "__linux_private",
67 "virtual": "__linux_virtual",
Elliott Hughes7c59f3f2016-08-16 18:14:26 -070068 # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
69 "msqid_ds": "__kernel_legacy_msqid_ds",
70 "semid_ds": "__kernel_legacy_semid_ds",
71 "shmid_ds": "__kernel_legacy_shmid_ds",
72 "ipc_perm": "__kernel_legacy_ipc_perm",
Elliott Hughes497ad302017-05-18 15:05:26 -070073 # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
74 "semun": "__kernel_legacy_semun",
Elliott Hughes199346a2014-02-11 20:01:11 -080075 # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
76 "_NSIG": "_KERNEL__NSIG",
77 "NSIG": "_KERNEL_NSIG",
Elliott Hughes0990d4f2014-04-30 09:45:40 -070078 # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
79 "SIGRTMIN": "__SIGRTMIN",
80 "SIGRTMAX": "__SIGRTMAX",
Elliott Hughesf8a22432015-09-22 12:34:13 -070081 # We want to support both BSD and Linux member names in struct udphdr.
82 "udphdr": "__kernel_udphdr",
Elliott Hughes893fd972017-02-22 23:22:51 -080083 # The kernel's struct epoll_event just has __u64 for the data.
84 "epoll_event": "__kernel_uapi_epoll_event",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070085 # This causes problems when trying to export the headers for the ndk.
86 "__attribute_const__": "__attribute__((__const__))",
Christopher Ferris525ce912017-07-26 13:12:53 -070087 # There is a mismatch between upstream and our kernels for this structure.
88 "binder_fd_array_object": "__kernel_binder_fd_array_object",
Martin Storsjoc9205db2010-12-08 11:39:05 +010089 }
90
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070091# This is the set of known static inline functions that we want to keep
92# in the final kernel headers.
Colin Crossd1973ca2014-01-21 19:50:58 -080093kernel_known_arm_statics = set(
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070094 [
Ben Cheng8bea2b62013-10-16 15:28:56 -070095 ]
96 )
97
Colin Crossd1973ca2014-01-21 19:50:58 -080098kernel_known_arm64_statics = set(
99 [
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700100 ]
101 )
102
Raghu Gandham82fa43f2012-03-27 11:37:17 -0700103kernel_known_mips_statics = set(
104 [
105 ]
106 )
107
Elliott Hughesd3e64a32013-09-30 17:41:08 -0700108kernel_known_x86_statics = set(
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700109 [
Elliott Hughesd3e64a32013-09-30 17:41:08 -0700110 ]
111 )
112
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700113kernel_known_generic_statics = set(
Elliott Hughes9195a252014-04-08 10:15:06 -0700114 [
115 "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h
116 "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700117 # Byte swapping inlines from uapi/linux/swab.h
118 # The below functions are the ones we are guaranting we export.
119 "__swab16",
120 "__swab32",
121 "__swab64",
122 "__swab16p",
123 "__swab32p",
124 "__swab64p",
125 "__swab16s",
126 "__swab32s",
127 "__swab64s",
128 "__swahw32",
129 "__swahb32",
130 "__swahw32p",
131 "__swahb32p",
132 "__swahw32s",
133 "__swahb32s",
134 # These are required to support the above functions.
135 "__fswahw32",
136 "__fswahb32",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700137 ]
138 )
139
140# this maps an architecture to the set of static inline functions that
141# we want to keep in the final headers
142#
143kernel_known_statics = {
144 "arm" : kernel_known_arm_statics,
Colin Crossd1973ca2014-01-21 19:50:58 -0800145 "arm64" : kernel_known_arm64_statics,
Elliott Hughesd3e64a32013-09-30 17:41:08 -0700146 "mips" : kernel_known_mips_statics,
Shin-ichiro KAWASAKI37429ff2009-07-01 15:41:52 +0900147 "x86" : kernel_known_x86_statics,
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700148 }
149
The Android Open Source Project6d6c82c2009-01-09 17:50:54 -0800150# this is a list of macros which we want to specifically exclude from
151# the generated files.
152#
153kernel_ignored_macros = set(
Yabin Cui2d8f9b52015-02-09 13:58:28 -0800154 [
155
The Android Open Source Project6d6c82c2009-01-09 17:50:54 -0800156 ]
157 )
158
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700159# this is the standard disclaimer
160#
161kernel_disclaimer = """\
162/****************************************************************************
163 ****************************************************************************
164 ***
165 *** This header was automatically generated from a Linux kernel header
166 *** of the same name, to make information necessary for userspace to
167 *** call into the kernel available to libc. It contains only constants,
168 *** structures, and macros generated from the original header, and thus,
169 *** contains no copyrightable information.
170 ***
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200171 *** To edit the content of this header, modify the corresponding
172 *** source file (e.g. under external/kernel-headers/original/) then
173 *** run bionic/libc/kernel/tools/update_all.py
174 ***
175 *** Any manual change here will be lost the next time this script will
176 *** be run. You've been warned!
177 ***
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700178 ****************************************************************************
179 ****************************************************************************/
180"""