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