1a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# this module contains all the defaults used by the generation of cleaned-up headers
2a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# for the Bionic C library
3a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#
4a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
5a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectimport time, os, sys
6a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectfrom utils import *
7a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
8a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# the list of supported architectures
9d1973ca51325393f304e82a4d79874f33e54ac16Colin Crosskernel_archs = [ 'arm', 'arm64', 'mips', 'x86' ]
10a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
11a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# the list of include directories that belong to the kernel
12a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# tree. used when looking for sources...
13a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
14a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
15a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# a special value that is used to indicate that a given macro is known to be
16a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# undefined during optimization
17a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source ProjectkCppUndefinedMacro = "<<<undefined>>>"
18a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
19a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# this is the set of known macros we want to totally optimize out from the
20a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# final headers
21a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_known_macros = {
22a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    "__KERNEL__": kCppUndefinedMacro,
23a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    "__KERNEL_STRICT_NAMES":"1",
24a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    "__CHECKER__": kCppUndefinedMacro,
25a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    "__CHECK_ENDIAN__": kCppUndefinedMacro,
269195a258ee96d6cf31b2fc7db9da16f92f5e7f65Elliott Hughes    "CONFIG_64BIT": "__LP64__",
27d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes    "CONFIG_X86_32": "__i386__",
28460fa7033b17c49e3e6fdaee49eb6d7d666e16d9Ben Cheng    "__EXPORTED_HEADERS__": "1",
29ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris    "__HAVE_BUILTIN_BSWAP16__": "1",
30ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris    "__HAVE_BUILTIN_BSWAP32__": "1",
31ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris    "__HAVE_BUILTIN_BSWAP64__": "1",
32a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    }
33a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
34a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# define to true if you want to remove all defined(CONFIG_FOO) tests
35a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# from the clean headers. testing shows that this is not strictly necessary
36a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# but just generates cleaner results
37a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_remove_config_macros = True
38a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
394e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project# maps an architecture to a set of default macros that would be provided by
404e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project# toolchain preprocessor
414e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Projectkernel_default_arch_macros = {
428ed7a23309cd6f1a73c19a23ade2e11ab31fcb2fElliott Hughes    "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
43d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross    "arm64": {},
44a69eaec4d48e978751356b2e8fd989d5e23a34dbDuane Sand    "mips": {"__MIPSEB__": kCppUndefinedMacro,
45a69eaec4d48e978751356b2e8fd989d5e23a34dbDuane Sand             "__MIPSEL__": "1",
46a69eaec4d48e978751356b2e8fd989d5e23a34dbDuane Sand             "CONFIG_32BIT": "_ABIO32",
47a69eaec4d48e978751356b2e8fd989d5e23a34dbDuane Sand             "CONFIG_CPU_LITTLE_ENDIAN": "1",
48a69eaec4d48e978751356b2e8fd989d5e23a34dbDuane Sand             "__SANE_USERSPACE_TYPES__": "1",},
49d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes    "x86": {},
504e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project    }
514e468ed2eb86a2406e14f1eca82072ee501d05fdThe Android Open Source Project
52a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandhamkernel_arch_token_replacements = {
53a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham    "arm": {},
54d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross    "arm64": {},
55a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham    "mips": {"off_t":"__kernel_off_t"},
56d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes    "x86": {},
57a864c2c23486e4ab7235829d8c9574426794298aRaghu Gandham    }
58199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes
5938dba2e7e16028cdede8f48c58d18e79491f8ed9Elliott Hughes# Replace tokens in the output according to this mapping.
60c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjokernel_token_replacements = {
6138dba2e7e16028cdede8f48c58d18e79491f8ed9Elliott Hughes    # The kernel's ARG_MAX is actually the "minimum" maximum (see fs/exec.c).
6238dba2e7e16028cdede8f48c58d18e79491f8ed9Elliott Hughes    "ARG_MAX": "_KERNEL_ARG_MAX",
63199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes    # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
64199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes    "__unused": "__linux_unused",
65106b3a8a7dc03c19a45e322de425ac56aafac358Christopher Ferris    # The kernel usage of C++ keywords causes problems for C++ code so rename.
66106b3a8a7dc03c19a45e322de425ac56aafac358Christopher Ferris    "private": "__linux_private",
67106b3a8a7dc03c19a45e322de425ac56aafac358Christopher Ferris    "virtual": "__linux_virtual",
687c59f3f6f3b6dbfcfb261b07062590d2dad2da62Elliott Hughes    # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
697c59f3f6f3b6dbfcfb261b07062590d2dad2da62Elliott Hughes    "msqid_ds": "__kernel_legacy_msqid_ds",
707c59f3f6f3b6dbfcfb261b07062590d2dad2da62Elliott Hughes    "semid_ds": "__kernel_legacy_semid_ds",
717c59f3f6f3b6dbfcfb261b07062590d2dad2da62Elliott Hughes    "shmid_ds": "__kernel_legacy_shmid_ds",
727c59f3f6f3b6dbfcfb261b07062590d2dad2da62Elliott Hughes    "ipc_perm": "__kernel_legacy_ipc_perm",
73497ad30d7d76721adab8830a76e72bcc9a840ba5Elliott Hughes    # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
74497ad30d7d76721adab8830a76e72bcc9a840ba5Elliott Hughes    "semun": "__kernel_legacy_semun",
75199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes    # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
76199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes    "_NSIG": "_KERNEL__NSIG",
77199346a2abd8b6ba282e1fe291cc3766fa921f40Elliott Hughes    "NSIG": "_KERNEL_NSIG",
780990d4fda898ada86e557f872f5cb7d16b138e3cElliott Hughes    # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
790990d4fda898ada86e557f872f5cb7d16b138e3cElliott Hughes    "SIGRTMIN": "__SIGRTMIN",
800990d4fda898ada86e557f872f5cb7d16b138e3cElliott Hughes    "SIGRTMAX": "__SIGRTMAX",
81f8a2243ebeb3ce60e412cd7b71b31c7b31313d58Elliott Hughes    # We want to support both BSD and Linux member names in struct udphdr.
82f8a2243ebeb3ce60e412cd7b71b31c7b31313d58Elliott Hughes    "udphdr": "__kernel_udphdr",
83893fd97cdcfbb040c938acac42658c885da879eeElliott Hughes    # The kernel's struct epoll_event just has __u64 for the data.
84893fd97cdcfbb040c938acac42658c885da879eeElliott Hughes    "epoll_event": "__kernel_uapi_epoll_event",
85ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris    # This causes problems when trying to export the headers for the ndk.
86ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris    "__attribute_const__": "__attribute__((__const__))",
87c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjo    }
88c9205dba43c45dc5a185aa26e1160c3f62e9b471Martin Storsjo
89ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris# This is the set of known static inline functions that we want to keep
90ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris# in the final kernel headers.
91d1973ca51325393f304e82a4d79874f33e54ac16Colin Crosskernel_known_arm_statics = set(
92ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris        [
938bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng        ]
948bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng    )
958bea2b6faca554a145bdafc6f3afafec1f3120b6Ben Cheng
96d1973ca51325393f304e82a4d79874f33e54ac16Colin Crosskernel_known_arm64_statics = set(
97d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross        [
98a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project        ]
99a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    )
100a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
10182fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandhamkernel_known_mips_statics = set(
10282fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham        [
10382fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham        ]
10482fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham    )
10582fa43febc9d679ae6276f6bf992b9b345bb5815Raghu Gandham
106d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hugheskernel_known_x86_statics = set(
107ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris        [
108d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes        ]
109d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes    )
110d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes
111a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_known_generic_statics = set(
1129195a258ee96d6cf31b2fc7db9da16f92f5e7f65Elliott Hughes        [
1139195a258ee96d6cf31b2fc7db9da16f92f5e7f65Elliott Hughes          "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h
1149195a258ee96d6cf31b2fc7db9da16f92f5e7f65Elliott Hughes          "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
115ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          # Byte swapping inlines from uapi/linux/swab.h
116ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          # The below functions are the ones we are guaranting we export.
117ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab16",
118ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab32",
119ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab64",
120ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab16p",
121ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab32p",
122ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab64p",
123ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab16s",
124ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab32s",
125ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swab64s",
126ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahw32",
127ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahb32",
128ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahw32p",
129ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahb32p",
130ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahw32s",
131ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__swahb32s",
132ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          # These are required to support the above functions.
133ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__fswahw32",
134ee1e0a34ae01aa01a207f00f0fe6cfb09852e44eChristopher Ferris          "__fswahb32",
135a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project        ]
136a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    )
137a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
138a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# this maps an architecture to the set of static inline functions that
139a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# we want to keep in the final headers
140a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#
141a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_known_statics = {
142a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project        "arm" : kernel_known_arm_statics,
143d1973ca51325393f304e82a4d79874f33e54ac16Colin Cross        "arm64" : kernel_known_arm64_statics,
144d3e64a3f403918abf2cc3f9f0f9a2204a420ec96Elliott Hughes        "mips" : kernel_known_mips_statics,
14537429fff4101f8f75db795048226169ede9e7413Shin-ichiro KAWASAKI        "x86" : kernel_known_x86_statics,
146a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project    }
147a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project
1486d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project# this is a list of macros which we want to specifically exclude from
1496d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project# the generated files.
1506d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project#
1516d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Projectkernel_ignored_macros = set(
1522d8f9b5aea90b57cd01c0a07cfff032092b4672eYabin Cui        [
1532d8f9b5aea90b57cd01c0a07cfff032092b4672eYabin Cui
1546d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project        ]
1556d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project    )
1566d6c82c7a0a6b9a89f61b61c66f9b90d9c7177dcThe Android Open Source Project
157a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project# this is the standard disclaimer
158a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project#
159a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Projectkernel_disclaimer = """\
160a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project/****************************************************************************
161a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ****************************************************************************
162a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***
163a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***   This header was automatically generated from a Linux kernel header
164a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***   of the same name, to make information necessary for userspace to
165a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***   call into the kernel available to libc.  It contains only constants,
166a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***   structures, and macros generated from the original header, and thus,
167a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***   contains no copyrightable information.
168a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ***
169fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***   To edit the content of this header, modify the corresponding
170fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***   source file (e.g. under external/kernel-headers/original/) then
171fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***   run bionic/libc/kernel/tools/update_all.py
172fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***
173fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***   Any manual change here will be lost the next time this script will
174fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***   be run. You've been warned!
175fc2693110ee8a2ba22a445ad9855fbe9e118d439David 'Digit' Turner ***
176a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ****************************************************************************
177a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project ****************************************************************************/
178a27d2baa0c1a2ec70f47ea9199b1dd6762c8a34The Android Open Source Project"""
179