Christopher Ferris | 2974eec | 2016-07-08 15:25:21 -0700 | [diff] [blame] | 1 | Bionic Kernel Header Files |
| 2 | ========================== |
| 3 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 4 | Bionic comes with a processed set of all of the uapi Linux kernel headers that |
| 5 | can safely be included by userland applications and libraries. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 6 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 7 | These clean headers are automatically generated by several scripts located |
| 8 | in the 'bionic/kernel/tools' directory. The tools process the original |
| 9 | unmodified kernel headers in order to get rid of many annoying |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 10 | declarations and constructs that usually result in compilation failure. |
| 11 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 12 | The 'clean headers' only contain type and macro definitions, with the |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 13 | exception of a couple static inline functions used for performance |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 14 | reason (e.g. optimized CPU-specific byte-swapping routines). |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 15 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 16 | They can be included from C++, or when compiling code in strict ANSI mode. |
| 17 | They can be also included before or after any Bionic C library header. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 18 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 19 | Description of the directories involved in generating the parsed kernel headers: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 20 | |
Andrew Hsieh | 126601d | 2012-03-23 23:07:36 +0800 | [diff] [blame] | 21 | * 'external/kernel-headers/original/' |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 22 | Contains the uapi kernel headers found in the android kernel. Note this |
| 23 | also includes the header files that are generated by building the kernel |
| 24 | sources. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 25 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 26 | * 'bionic/libc/kernel/uapi' |
| 27 | Contains the cleaned kernel headers and mirrors the directory structure |
| 28 | in 'external/kernel-headers/original/uapi/'. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 30 | * 'bionic/libc/kernel/tools' |
| 31 | Contains various Python and shell scripts used to get and re-generate |
| 32 | the headers. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 33 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 34 | The tools to get/parse the headers: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 35 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 36 | * tools/generate_uapi_headers.sh |
| 37 | Checks out the android kernel and generates all uapi header files. |
| 38 | copies all the changed files into external/kernel-headers. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 39 | |
| 40 | * tools/clean_header.py |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 41 | Prints the clean version of a given kernel header. With the -u option, |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 42 | this will also update the corresponding clean header file if its |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 43 | content has changed. You can also process more than one file with -u. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 44 | |
| 45 | * tools/update_all.py |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 46 | Automatically update all clean headers from the content of |
| 47 | 'external/kernel-headers/original'. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 48 | |
Christopher Ferris | 2974eec | 2016-07-08 15:25:21 -0700 | [diff] [blame] | 49 | How To Update The Headers |
| 50 | ========================= |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 51 | |
| 52 | IMPORTANT IMPORTANT: |
| 53 | |
Christopher Ferris | 2974eec | 2016-07-08 15:25:21 -0700 | [diff] [blame] | 54 | WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO |
| 55 | NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE |
| 56 | OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT. |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 57 | |
Christopher Ferris | 2974eec | 2016-07-08 15:25:21 -0700 | [diff] [blame] | 58 | Download the Linux kernel source code: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 59 | |
Christopher Ferris | 2974eec | 2016-07-08 15:25:21 -0700 | [diff] [blame] | 60 | > mkdir kernel_src |
| 61 | > cd kernel_src |
| 62 | kernel_src> git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git |
| 63 | |
| 64 | Then checkout the stable tag for the new kernel headers to import: |
| 65 | |
| 66 | kernel_src> cd linux-stable |
| 67 | kernel_src/linux-stable> git checkout tags/vXXX |
| 68 | |
| 69 | Before running the command to import the headers, make sure that you have |
| 70 | done a lunch TARGET. The script uses a variable set by the lunch command |
| 71 | to determine which directory to use as the destination directory. |
| 72 | |
| 73 | After running lunch, run this command to import the headers into the android |
| 74 | source tree: |
| 75 | |
| 76 | bionic/libc/kernel/tools/generate_uapi_headers.sh --use-kernel-dir kernel_src |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 77 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 78 | Next, run this command to copy the parsed files to bionic/libc/kernel/uapi: |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 79 | |
Christopher Ferris | ea271fd | 2014-07-15 19:02:33 -0700 | [diff] [blame] | 80 | bionic/libc/kernel/tools/update_all.py |
| 81 | |
| 82 | Finally, run this command to regenerate the syscalls list: |
| 83 | |
| 84 | bionic/libc/tools/gensyscalls.py |
The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 85 | |
Christopher Ferris | 08b6074 | 2014-06-05 11:17:06 -0700 | [diff] [blame] | 86 | After this, you will need to build/test the tree to make sure that these |
| 87 | changes do not introduce any errors. |