The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # this module contains all the defaults used by the generation of cleaned-up headers |
| 2 | # for the Bionic C library |
| 3 | # |
| 4 | |
| 5 | import time, os, sys |
| 6 | from utils import * |
| 7 | |
| 8 | # the list of supported architectures |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 9 | kernel_archs = [ 'arm', 'arm64', 'mips', 'x86' ] |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 10 | |
| 11 | # the list of include directories that belong to the kernel |
| 12 | # tree. used when looking for sources... |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 13 | kernel_dirs = [ "linux", "asm", "asm-generic", "mtd" ] |
| 14 | |
| 15 | # path to the directory containing the original kernel headers |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 16 | kernel_original_path = os.path.normpath( find_program_dir() + '/../../../../external/kernel-headers/original' ) |
| 17 | |
| 18 | # path to the default location of the cleaned-up headers |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 19 | kernel_cleaned_path = os.path.normpath( find_program_dir() + '/..' ) |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 20 | |
| 21 | # a special value that is used to indicate that a given macro is known to be |
| 22 | # undefined during optimization |
| 23 | kCppUndefinedMacro = "<<<undefined>>>" |
| 24 | |
| 25 | # this is the set of known macros we want to totally optimize out from the |
| 26 | # final headers |
| 27 | kernel_known_macros = { |
| 28 | "__KERNEL__": kCppUndefinedMacro, |
| 29 | "__KERNEL_STRICT_NAMES":"1", |
| 30 | "__CHECKER__": kCppUndefinedMacro, |
| 31 | "__CHECK_ENDIAN__": kCppUndefinedMacro, |
Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 32 | "CONFIG_64BIT": "__LP64__", |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 33 | "CONFIG_X86_32": "__i386__", |
Ben Cheng | 460fa70 | 2013-10-23 14:38:25 -0700 | [diff] [blame] | 34 | "__EXPORTED_HEADERS__": "1", |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | # define to true if you want to remove all defined(CONFIG_FOO) tests |
| 38 | # from the clean headers. testing shows that this is not strictly necessary |
| 39 | # but just generates cleaner results |
| 40 | kernel_remove_config_macros = True |
| 41 | |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 42 | # maps an architecture to a set of default macros that would be provided by |
| 43 | # toolchain preprocessor |
| 44 | kernel_default_arch_macros = { |
Elliott Hughes | 8ed7a23 | 2014-05-15 12:01:11 -0700 | [diff] [blame] | 45 | "arm": {"__ARMEB__": kCppUndefinedMacro, "__ARM_EABI__": "1"}, |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 46 | "arm64": {}, |
Elliott Hughes | 8ed7a23 | 2014-05-15 12:01:11 -0700 | [diff] [blame] | 47 | "mips": {"CONFIG_32BIT":"1", "__MIPSEB__": kCppUndefinedMacro, "__MIPSEL__": "1"}, |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 48 | "x86": {}, |
The Android Open Source Project | 4e468ed | 2008-12-17 18:03:48 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 51 | kernel_arch_token_replacements = { |
| 52 | "arm": {}, |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 53 | "arm64": {}, |
Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 54 | "mips": {"off_t":"__kernel_off_t"}, |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 55 | "x86": {}, |
Raghu Gandham | a864c2c | 2013-01-16 16:42:47 -0800 | [diff] [blame] | 56 | } |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 57 | |
Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 58 | # Replace tokens in the output according to this mapping |
| 59 | kernel_token_replacements = { |
David 'Digit' Turner | b969b5a | 2011-01-11 17:23:10 +0100 | [diff] [blame] | 60 | "asm": "__asm__", |
Elliott Hughes | 199346a | 2014-02-11 20:01:11 -0800 | [diff] [blame] | 61 | # The kernel usage of __unused for unused struct fields conflicts with the macro defined in <sys/cdefs.h>. |
| 62 | "__unused": "__linux_unused", |
| 63 | # The kernel's _NSIG/NSIG are one less than the userspace value, so we need to move them aside. |
| 64 | "_NSIG": "_KERNEL__NSIG", |
| 65 | "NSIG": "_KERNEL_NSIG", |
Elliott Hughes | 0990d4f | 2014-04-30 09:45:40 -0700 | [diff] [blame] | 66 | # The kernel's SIGRTMIN/SIGRTMAX are absolute limits; userspace steals a few. |
| 67 | "SIGRTMIN": "__SIGRTMIN", |
| 68 | "SIGRTMAX": "__SIGRTMAX", |
Martin Storsjo | c9205db | 2010-12-08 11:39:05 +0100 | [diff] [blame] | 69 | } |
| 70 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 71 | # this is the set of known static inline functions that we want to keep |
| 72 | # in the final ARM headers. this is only used to keep optimized byteswapping |
| 73 | # static functions and stuff like that. |
Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 74 | # TODO: this isn't working! |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 75 | kernel_known_arm_statics = set( |
| 76 | [ "___arch__swab32", # asm-arm/byteorder.h |
Ben Cheng | 8bea2b6 | 2013-10-16 15:28:56 -0700 | [diff] [blame] | 77 | ] |
| 78 | ) |
| 79 | |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 80 | kernel_known_arm64_statics = set( |
| 81 | [ |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 82 | ] |
| 83 | ) |
| 84 | |
Raghu Gandham | 82fa43f | 2012-03-27 11:37:17 -0700 | [diff] [blame] | 85 | kernel_known_mips_statics = set( |
| 86 | [ |
| 87 | ] |
| 88 | ) |
| 89 | |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 90 | kernel_known_x86_statics = set( |
| 91 | [ "___arch__swab32", # asm-x86/byteorder.h |
| 92 | "___arch__swab64", # asm-x86/byteorder.h |
| 93 | ] |
| 94 | ) |
| 95 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 96 | kernel_known_generic_statics = set( |
Elliott Hughes | 9195a25 | 2014-04-08 10:15:06 -0700 | [diff] [blame] | 97 | [ |
| 98 | "ipt_get_target", # uapi/linux/netfilter_ipv4/ip_tables.h |
| 99 | "ip6t_get_target", # uapi/linux/netfilter_ipv6/ip6_tables.h |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 100 | ] |
| 101 | ) |
| 102 | |
| 103 | # this maps an architecture to the set of static inline functions that |
| 104 | # we want to keep in the final headers |
| 105 | # |
| 106 | kernel_known_statics = { |
| 107 | "arm" : kernel_known_arm_statics, |
Colin Cross | d1973ca | 2014-01-21 19:50:58 -0800 | [diff] [blame] | 108 | "arm64" : kernel_known_arm64_statics, |
Elliott Hughes | d3e64a3 | 2013-09-30 17:41:08 -0700 | [diff] [blame] | 109 | "mips" : kernel_known_mips_statics, |
Shin-ichiro KAWASAKI | 37429ff | 2009-07-01 15:41:52 +0900 | [diff] [blame] | 110 | "x86" : kernel_known_x86_statics, |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 111 | } |
| 112 | |
The Android Open Source Project | 6d6c82c | 2009-01-09 17:50:54 -0800 | [diff] [blame] | 113 | # this is a list of macros which we want to specifically exclude from |
| 114 | # the generated files. |
| 115 | # |
| 116 | kernel_ignored_macros = set( |
| 117 | [ "MAXHOSTNAMELEN", # for some reason, Linux defines it to 64 |
| 118 | # while most of the BSD code expects this to be 256 |
| 119 | # so ignore the kernel-provided definition and |
| 120 | # define it in the Bionic headers instead |
| 121 | ] |
| 122 | ) |
| 123 | |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 124 | # this is the standard disclaimer |
| 125 | # |
| 126 | kernel_disclaimer = """\ |
| 127 | /**************************************************************************** |
| 128 | **************************************************************************** |
| 129 | *** |
| 130 | *** This header was automatically generated from a Linux kernel header |
| 131 | *** of the same name, to make information necessary for userspace to |
| 132 | *** call into the kernel available to libc. It contains only constants, |
| 133 | *** structures, and macros generated from the original header, and thus, |
| 134 | *** contains no copyrightable information. |
| 135 | *** |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 136 | *** To edit the content of this header, modify the corresponding |
| 137 | *** source file (e.g. under external/kernel-headers/original/) then |
| 138 | *** run bionic/libc/kernel/tools/update_all.py |
| 139 | *** |
| 140 | *** Any manual change here will be lost the next time this script will |
| 141 | *** be run. You've been warned! |
| 142 | *** |
The Android Open Source Project | a27d2ba | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 143 | **************************************************************************** |
| 144 | ****************************************************************************/ |
| 145 | """ |
David 'Digit' Turner | fc26931 | 2010-10-11 22:11:06 +0200 | [diff] [blame] | 146 | |
| 147 | # This is the warning line that will be inserted every N-th line in the output |
| 148 | kernel_warning = """\ |
| 149 | /* WARNING: DO NOT EDIT, AUTO-GENERATED CODE - SEE TOP FOR INSTRUCTIONS */ |
| 150 | """ |