Bionic comes with a set of 'clean' Linux kernel headers that can safely be
included by userland applications and libraries without fear of hideous
conflicts. for more information why this is needed, see the "RATIONALE"
section at the end of this document.
these clean headers are automatically generated by several scripts located
in the 'bionic/kernel/tools' directory, which process a set of original
and unmodified kernel headers in order to get rid of many annoying
declarations and constructs that usually result in compilation failure.
the 'clean headers' only contain type and macro definitions, with the
exception of a couple static inline functions used for performance
reason (e.g. optimized CPU-specific byte-swapping routines)
they can be included from C++, or when compiling code in strict ANSI mode.
they can be also included before or after any Bionic C library header.
the generation process works as follows:
* 'external/kernel-headers/original/'
contains a set of kernel headers as normally found in the 'include'
directory of a normal Linux kernel source tree. note that this should
only contain the files that are really needed by Android (use
'find_headers.py' to find these automatically).
* 'bionic/libc/kernel/common'
contains the non-arch-specific clean headers and directories
(e.g. linux, asm-generic and mtd)
* 'bionic/libc/kernel/arch-arm/'
contains the ARM-specific directory tree of clean headers.
* 'bionic/libc/kernel/arch-arm/asm'
contains the real ARM-specific headers
* 'bionic/libc/kernel/arch-x86'
'bionic/libc/kernel/arch-x86/asm'
similarly contains all headers and symlinks to be used on x86
* 'bionic/libc/kernel/tools' contains various Python and shell scripts used
to manage and re-generate the headers
the tools you can use are:
* tools/find_users.py
scans a list of source files or directories and prints which ones do
include Linux headers.
* tools/find_headers.py
scans a list of source files or directories and recursively finds all
the original kernel headers they need.
* tools/clean_header.py
prints the clean version of a given kernel header. with the -u option,
this will also update the corresponding clean header file if its
content has changed. you can also process more than one file with -u
* tools/update_all.py
automatically update all clean headers from the content of
'external/kernel-headers/original'. this is the script you're likely going to
run whenever you update the original headers.
HOW TO BUILD BIONIC AND OTHER PROGRAMS WITH THE CLEAN HEADERS:
==============================================================
add bionic/kernel/common and bionic/kernel/arch-<yourarch> to your C
include path. that should be enough. Note that Bionic will not compile properly
if you don't.
HOW TO SUPPORT ANOTHER ARCHITECTURE:
====================================
see the content of tools/defaults.py, you will need to make a few updates
here:
- add a new item to the 'kernel_archs' list of supported architectures
- add a proper definition for 'kernel_known_<arch>_statics' with
relevant definitions.
- update 'kernel_known_statics' to map "<arch>" to
'kernel_known_<arch>_statics'
then, add the new architecture-specific headers to original/asm-<arch>.
(please ensure that these are really needed, e.g. with tools/find_headers.py)
finally, run tools/update_all.py
HOW TO UPDATE THE HEADERS WHEN NEEDED:
======================================
IMPORTANT IMPORTANT:
WHEN UPDATING THE HEADERS, ALWAYS CHECK THAT THE NEW CLEAN HEADERS DO
NOT BREAK THE KERNEL <-> USER ABI, FOR EXAMPLE BY CHANGING THE SIZE
OF A GIVEN TYPE. THIS TASK CANNOT BE EASILY AUTOMATED AT THE MOMENT
copy any updated kernel header into the corresponding location under
'bionic/kernel/original'.
for any new kernel header you want to add, first run tools/find_headers.py to be
sure that it is really needed by the Android sources. then add it to
'bionic/kernel/original'
then, run tools/update_all.py to re-run the auto-cleaning
HOW THE CLEANUP PROCESS WORKS:
==============================
this section describes the action performed by the cleanup program(s) when they
process the original kernel headers into clean ones:
1. Optimize well-known macros (e.g. __KERNEL__, __KERNEL_STRICT_NAMES)
this pass gets rid of everything that is guarded by a well-known macro
definition. this means that a block like
#ifdef __KERNEL__
....
#endif
will be totally omitted from the output. the optimizer is smart enough to
handle all complex C-preprocessor conditional expression appropriately.
this means that, for example:
#if defined(__KERNEL__) || defined(FOO)
...
#endif
will be transformed into:
#ifdef FOO
...
#endif
see tools/defaults.py for the list of well-known macros used in this pass,
in case you need to update it in the future.
note that this also remove any reference to a kernel-specific configuration
macro like CONFIG_FOO from the clean headers.
2. remove variable and function declarations:
this pass scans non-directive text and only keeps things that look like a
typedef/struct/union/enum declaration. this allows to get rid of any variable
or function declaration that should only be used within the kernel anyway
(and which normally *should* be guarded in a #ifdef __KERNEL__ ... #endif
block, if the kernel writers were not so messy)
there are however a few exceptions: it is seldom useful to keep the definition
of some static inline functions performing very simple operations. a good
example is the optimized 32-bit byte-swap function found in
arch-arm/asm/byteorder.h
the list of exceptions is in tools/defaults.py in case you need to update it
in the future.
note that we do *not* remove macro definitions, including these macro that
perform a call to one of these kernel-header functions, or even define other
functions. we consider it safe since userland applications have no business
using them anyway.
3. whitespace cleanup:
the final pass remove any comments and empty lines from the final headers.
4. add a standard disclaimer:
prepended to each generated header, contains a message like
"do not edit directly - file was auto-generated by ...."
RATIONALE:
==========
OVERVIEW OF THE CURRENT KERNEL HEADER MESS:
-------------------------------------------
The original kernel headers are not easily usable from userland applications.
they contain many declarations and construct that will result in a compilation
failure or even worse, incorrect behaviour. for example:
- some headers try to define Posix types (e.g. size_t, ssize_t) that can
conflict with the corresponding definitions provided by your C library.
- some headers use constructs that cannot be compiled in ANSI C mode.
- some headers use constructs do not compile with C++ at all.
- some headers contain invalid "legacy" definitions for the benefit of old
C libraries (e.g. glibc5) but result in incorrect behaviour if used
directly.
e.g. gid_t being defined in <linux/types.h> as a 16-bit type while the
kernel uses 32-bit ids. this results in problems when getgroups() or
setgroups() are called, since they operate on gid_t arrays.
unfortunately, these headers are also the only source of some really extensive
constant and type definitions that are required by userland applications.
think any library/program that need to access ALSA, or Video4Linux, or
anything related to a specific device or Linux-specific system interface
(e.g. IOCTLS, etc...)
As a consequence, every Linux distribution provides a set of patched kernel
headers to be used by userland applications (which installs in
/usr/include/linux/, /usr/include/asm/, etc...). these are manually maintained
by distribution packagers, and generated either manually or with vario
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
bionic -- libc from google android (2000个子文件)
malloc.c 217KB
res_cache.c 75KB
localtime.c 68KB
getaddrinfo.c 59KB
strtod.c 53KB
regcomp.c 44KB
pthread.c 41KB
res_send.c 35KB
gethnamaddr.c 32KB
vfprintf.c 31KB
res_debug.c 30KB
engine.c 30KB
fts.c 27KB
strftime.c 26KB
res_init.c 23KB
ns_print.c 22KB
time64.c 21KB
ns_name.c 21KB
pthread-timers.c 19KB
vfscanf.c 19KB
system_properties.c 18KB
fnmatch.c 18KB
getopt_long.c 16KB
k_rem_pio2.c 16KB
e_j0.c 14KB
e_sqrt.c 14KB
s_exp2.c 14KB
e_j1.c 14KB
b_log.c 14KB
strptime.c 13KB
res_query.c 13KB
getnameinfo.c 12KB
s_erf.c 11KB
e_lgamma_r.c 11KB
base64.c 11KB
ev_timers.c 11KB
e_j0f.c 10KB
semaphore.c 10KB
e_j1f.c 10KB
e_pow.c 10KB
sha1.c 9KB
pthread-rwlocks.c 9KB
syslog.c 9KB
fenv.c 9KB
b_tgamma.c 9KB
res_comp.c 8KB
regexec.c 8KB
res_mkquery.c 8KB
res_data.c 8KB
s_fma.c 8KB
ev_streams.c 8KB
arc4random.c 8KB
regerror.c 7KB
s_fmal.c 7KB
e_powf.c 7KB
res_random.c 7KB
inet_pton.c 7KB
s_expm1.c 7KB
e_lgammaf_r.c 7KB
md5.c 7KB
e_jn.c 7KB
inet_addr.c 7KB
libgcc_compat.c 7KB
fseek.c 7KB
s_erff.c 7KB
res_state.c 6KB
realpath.c 6KB
pathconf.c 6KB
libthread_db.c 6KB
inet_ntop.c 6KB
fvwrite.c 6KB
findfp.c 6KB
popen.c 6KB
s_log1p.c 6KB
mips_strlen.c 6KB
fread.c 6KB
nsdispatch.c 5KB
exec.c 5KB
strlen.c 5KB
ns_parse.c 5KB
qsort.c 5KB
b_exp.c 5KB
atexit.c 5KB
freopen.c 5KB
e_exp.c 5KB
ctype_.c 5KB
ns_samedomain.c 5KB
strtoimax.c 5KB
e_rem_pio2.c 5KB
s_csinh.c 5KB
s_ccosh.c 5KB
regfree.c 5KB
mktemp.c 5KB
e_jnf.c 5KB
setvbuf.c 5KB
fgetln.c 5KB
strcasecmp.c 5KB
herror.c 5KB
e_log.c 4KB
s_remquol.c 4KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
- wenbin200420092018-02-20挺好的。。。
- w19806800652017-10-20应该不错,先mark
- dynast_zfz2015-07-28很不错,刚好在找这个材料
fleshboy
- 粉丝: 13
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功