• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 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
9kernel_archs = [ 'arm', 'arm64', 'x86' ]
10
11# the list of include directories that belong to the kernel
12# tree. used when looking for sources...
13kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ]
14
15# 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,
26    "CONFIG_64BIT": "__LP64__",
27    "CONFIG_X86_32": "__i386__",
28    "__EXPORTED_HEADERS__": "1",
29    "__HAVE_BUILTIN_BSWAP16__": "1",
30    "__HAVE_BUILTIN_BSWAP32__": "1",
31    "__HAVE_BUILTIN_BSWAP64__": "1",
32    # Use this to remove the struct __kernel_old_timeval definition.
33    # Otherwise, there will be two struct timeval definitions when
34    # __kernel_old_timeval is renamed to timeval.
35    "__kernel_old_timeval": "1",
36    }
37
38# define to true if you want to remove all defined(CONFIG_FOO) tests
39# from the clean headers. testing shows that this is not strictly necessary
40# but just generates cleaner results
41kernel_remove_config_macros = True
42
43# maps an architecture to a set of default macros that would be provided by
44# toolchain preprocessor
45kernel_default_arch_macros = {
46    "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"},
47    "arm64": {},
48    "x86": {},
49    }
50
51kernel_arch_token_replacements = {
52    "arm": {},
53    "arm64": {},
54    "x86": {},
55    }
56
57# Replace tokens in the output according to this mapping.
58kernel_token_replacements = {
59    # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>.
60    "__unused": "__linux_unused",
61    # The kernel usage of C++ keywords causes problems for C++ code so rename.
62    "private": "__linux_private",
63    "virtual": "__linux_virtual",
64    # The non-64 stuff is legacy; msqid64_ds/ipc64_perm is what userspace wants.
65    "msqid_ds": "__kernel_legacy_msqid_ds",
66    "semid_ds": "__kernel_legacy_semid_ds",
67    "shmid_ds": "__kernel_legacy_shmid_ds",
68    "ipc_perm": "__kernel_legacy_ipc_perm",
69    # The kernel semun isn't usable (https://github.com/android-ndk/ndk/issues/400).
70    "semun": "__kernel_legacy_semun",
71    # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside.
72    "_NSIG": "_KERNEL__NSIG",
73    "NSIG": "_KERNEL_NSIG",
74    # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few.
75    "SIGRTMIN": "__SIGRTMIN",
76    "SIGRTMAX": "__SIGRTMAX",
77    # We want to support both BSD and Linux member names in struct udphdr.
78    "udphdr": "__kernel_udphdr",
79    # This causes problems when trying to export the headers for the ndk.
80    "__attribute_const__": "__attribute__((__const__))",
81    # In this case the kernel tries to keep out of our way, but we're happy to use its definition.
82    "__kernel_sockaddr_storage": "sockaddr_storage",
83    # The kernel started using struct __kernel_old_timeval in some places,
84    # which is the exact same as struct timeval. Replace that name with
85    # timeval so that kernel structures all use the same named structure.
86    # If struct __kernel_old_timeval and struct timeval become different,
87    # then a different solution needs to be implemented.
88    "__kernel_old_timeval": "timeval",
89    }
90
91
92# This is the set of struct definitions that we want to replace with
93# a #include of <bits/struct.h> instead.
94kernel_struct_replacements = set(
95        [
96          "epoll_event",
97          "flock",
98          "flock64",
99          "in_addr",
100          "ip_mreq_source",
101          "ip_msfilter",
102        ]
103    )
104
105
106# This is the set of known static inline functions that we want to keep
107# in the final kernel headers.
108kernel_known_generic_statics = set(
109        [
110          "ipt_get_target",  # uapi/linux/netfilter_ipv4/ip_tables.h
111          "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h
112          # Byte swapping inlines from uapi/linux/swab.h
113          # The below functions are the ones we are guaranting we export.
114          "__swab16",
115          "__swab32",
116          "__swab64",
117          "__swab16p",
118          "__swab32p",
119          "__swab64p",
120          "__swab16s",
121          "__swab32s",
122          "__swab64s",
123          "__swahw32",
124          "__swahb32",
125          "__swahw32p",
126          "__swahb32p",
127          "__swahw32s",
128          "__swahb32s",
129          # These are required to support the above functions.
130          "__fswahw32",
131          "__fswahb32",
132        ]
133    )
134
135# this is the standard disclaimer
136#
137kernel_disclaimer = """\
138/****************************************************************************
139 ****************************************************************************
140 ***
141 ***   This header was automatically generated from a Linux kernel header
142 ***   of the same name, to make information necessary for userspace to
143 ***   call into the kernel available to libc.  It contains only constants,
144 ***   structures, and macros generated from the original header, and thus,
145 ***   contains no copyrightable information.
146 ***
147 ***   To edit the content of this header, modify the corresponding
148 ***   source file (e.g. under external/kernel-headers/original/) then
149 ***   run bionic/libc/kernel/tools/update_all.py
150 ***
151 ***   Any manual change here will be lost the next time this script will
152 ***   be run. You've been warned!
153 ***
154 ****************************************************************************
155 ****************************************************************************/
156"""
157