blob: e74b3460928b68248d047bc99d127f4a10714b99 [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
Elliott Hughesc2faf232020-02-03 17:56:06 -08009kernel_archs = [ 'arm', 'arm64', '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": {},
Elliott Hughesd3e64a32013-09-30 17:41:08 -070044 "x86": {},
The Android Open Source Project4e468ed2008-12-17 18:03:48 -080045 }
46
Raghu Gandhama864c2c2013-01-16 16:42:47 -080047kernel_arch_token_replacements = {
48 "arm": {},
Colin Crossd1973ca2014-01-21 19:50:58 -080049 "arm64": {},
Elliott Hughesd3e64a32013-09-30 17:41:08 -070050 "x86": {},
Raghu Gandhama864c2c2013-01-16 16:42:47 -080051 }
Elliott Hughes199346a2014-02-11 20:01:11 -080052
Elliott Hughes38dba2e2016-08-10 15:51:06 -070053# Replace tokens in the output according to this mapping.
Martin Storsjoc9205db2010-12-08 11:39:05 +010054kernel_token_replacements = {
Elliott Hughes199346a2014-02-11 20:01:11 -080055 # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
56 "__unused": "__linux_unused",
Christopher Ferris106b3a82016-08-24 12:15:38 -070057 # The kernel usage of C++ keywords causes problems for C++ code so rename.
58 "private": "__linux_private",
59 "virtual": "__linux_virtual",
Elliott Hughes7c59f3f2016-08-16 18:14:26 -070060 # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
61 "msqid_ds": "__kernel_legacy_msqid_ds",
62 "semid_ds": "__kernel_legacy_semid_ds",
63 "shmid_ds": "__kernel_legacy_shmid_ds",
64 "ipc_perm": "__kernel_legacy_ipc_perm",
Elliott Hughes497ad302017-05-18 15:05:26 -070065 # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
66 "semun": "__kernel_legacy_semun",
Elliott Hughes199346a2014-02-11 20:01:11 -080067 # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
68 "_NSIG": "_KERNEL__NSIG",
69 "NSIG": "_KERNEL_NSIG",
Elliott Hughes0990d4f2014-04-30 09:45:40 -070070 # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
71 "SIGRTMIN": "__SIGRTMIN",
72 "SIGRTMAX": "__SIGRTMAX",
Elliott Hughesf8a22432015-09-22 12:34:13 -070073 # We want to support both BSD and Linux member names in struct udphdr.
74 "udphdr": "__kernel_udphdr",
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070075 # This causes problems when trying to export the headers for the ndk.
76 "__attribute_const__": "__attribute__((__const__))",
Elliott Hughes64f355f2017-08-30 16:10:24 -070077 # In this case the kernel tries to keep out of our way, but we're happy to use its definition.
78 "__kernel_sockaddr_storage": "sockaddr_storage",
Martin Storsjoc9205db2010-12-08 11:39:05 +010079 }
80
Elliott Hughes64f355f2017-08-30 16:10:24 -070081
82# This is the set of struct definitions that we want to replace with
83# a #include of <bits/struct.h> instead.
84kernel_struct_replacements = set(
85 [
86 "epoll_event",
Elliott Hughes09e77f32020-01-29 19:20:45 -080087 "flock",
88 "flock64",
Elliott Hughes64f355f2017-08-30 16:10:24 -070089 "in_addr",
90 "ip_mreq_source",
91 "ip_msfilter",
92 ]
93 )
94
95
Christopher Ferrisee1e0a32017-04-20 13:38:49 -070096# This is the set of known static inline functions that we want to keep
97# in the final kernel headers.
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -070098kernel_known_generic_statics = set(
Elliott Hughes9195a252014-04-08 10:15:06 -070099 [
100 "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h
101 "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
Christopher Ferrisee1e0a32017-04-20 13:38:49 -0700102 # Byte swapping inlines from uapi/linux/swab.h
103 # The below functions are the ones we are guaranting we export.
104 "__swab16",
105 "__swab32",
106 "__swab64",
107 "__swab16p",
108 "__swab32p",
109 "__swab64p",
110 "__swab16s",
111 "__swab32s",
112 "__swab64s",
113 "__swahw32",
114 "__swahb32",
115 "__swahw32p",
116 "__swahb32p",
117 "__swahw32s",
118 "__swahb32s",
119 # These are required to support the above functions.
120 "__fswahw32",
121 "__fswahb32",
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700122 ]
123 )
124
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700125# this is the standard disclaimer
126#
127kernel_disclaimer = """\
128/****************************************************************************
129 ****************************************************************************
130 ***
131 *** This header was automatically generated from a Linux kernel header
132 *** of the same name, to make information necessary for userspace to
133 *** call into the kernel available to libc. It contains only constants,
134 *** structures, and macros generated from the original header, and thus,
135 *** contains no copyrightable information.
136 ***
David 'Digit' Turnerfc269312010-10-11 22:11:06 +0200137 *** To edit the content of this header, modify the corresponding
138 *** source file (e.g. under external/kernel-headers/original/) then
139 *** run bionic/libc/kernel/tools/update_all.py
140 ***
141 *** Any manual change here will be lost the next time this script will
142 *** be run. You've been warned!
143 ***
The Android Open Source Projecta27d2ba2008-10-21 07:00:00 -0700144 ****************************************************************************
145 ****************************************************************************/
146"""