blob: bdb6a2f0275d460e3e9e787b830e45f3094dcc46 [file] [log] [blame]
<html devsite><head>
<title>接口要求</title>
<meta name="project_path" value="/_project.yaml"/>
<meta name="book_path" value="/_book.yaml"/>
</head>
<body>
<!--
Copyright 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<p>本页介绍了 Android 正常运行所需的一系列 Linux 内核接口。<a href="/devices/tech/vts/index.html">供应商测试套件 (VTS)</a> 会测试这些接口是否存在以及是否正确无误。这些接口的数量将随时间的推移不断增加,包含越来越多的 Android 内核接口。</p>
<h2 id="system-calls">系统调用</h2>
<p>系统调用提供的签名和语义应与上游 Linux 内核中的签名和语义相同。</p>
<p>根据 <code>bionic/libc/SYSCALLS.txt</code>,Bionic 所需的 ARM64 系统调用如下:</p>
<table>
<tbody><tr>
<td class="devsite-click-to-copy">accept4、acct、adjtimex、bind、brk、capget、capset、chdir、chroot、clock_adjtime、clock_getres、clock_gettime、clock_nanosleep、clock_settime、close、connect、delete_module、dup3、dup、epoll_create1、epoll_ctl、epoll_pwait、eventfd2、execve、exit、exit_group、faccessat、fadvise64、fallocate、fchdir、fchmodat、fchmod、fchownat、fchown、fcntl、fdatasync、fgetxattr、flistxattr、flock、fremovexattr、fsetxattr、fstat、newfstatat、fstatfs、fsync、ftruncate、getcpu、getcwd、getdents64、getegid、geteuid、getgid、getgroups、getitimer、getpeername、getpgid、getpid、getppid、getpriority、getresgid、getresuid、getrlimit、getrusage、getsid、getsockname、getsockopt、gettimeofday、getuid、getxattr、init_module、inotify_add_watch、inotify_init1、inotify_rm_watch、ioctl、kill、syslog、lgetxattr、linkat、listen、listxattr、llistxattr、lremovexattr、lseek、lsetxattr、madvise、mincore、mkdirat、mknodat、mlockall、mlock、mmap、mount、mprotect、mremap、msync、munlockall、munlock、munmap、nanosleep、openat、personality、pipe2、ppoll、prctl、pread64、preadv、prlimit64、process_vm_readv、process_vm_writev、pselect6、ptrace、pwrite64、pwritev、quotactl、readahead、readlinkat、read、readv、reboot、recvfrom、recvmmsg、recvmsg、removexattr、renameat、rt_sigaction、rt_sigpending、rt_sigprocmask、rt_sigqueueinfo、rt_sigsuspend、rt_sigtimedwait、sched_getaffinity、sched_getparam、sched_get_priority_max、sched_get_priority_min、sched_getscheduler、sched_rr_get_interval、sched_setaffinity、sched_setparam、sched_setscheduler、sched_yield、sendfile、sendmmsg、sendmsg、sendto、setdomainname、setfsgid、setfsuid、setgid、setgroups、sethostname、setitimer、setns、setpgid、setpriority、setregid、setresgid、setresuid、setreuid、setrlimit、setsid、setsockopt、set_tid_address、settimeofday、setuid、setxattr、shutdown、sigaltstack、signalfd4、socketpair、socket、splice、statfs、swapoff、swapon、symlinkat、sync_file_range、sync、sysinfo、tee、tgkill、timer_create、timer_delete、timerfd_create、timerfd_gettime、timerfd_settime、timer_getoverrun、timer_gettime、timer_settime、times、truncate、umask、umount2、uname、unlinkat、unshare、utimensat、vmsplice、wait4、waitid、write、writev</td>
</tr></tbody></table>
<p>根据 <code>bionic/libc/SYSCALLS.txt</code>,Bionic 所需的 ARM32 系统调用如下:</p>
<table>
<tbody><tr>
<td class="devsite-click-to-copy">accept4、acct、adjtimex、arm_fadvise64_64、bind、brk、cacheflush、capget、capset、chdir、chroot、clock_adjtime、clock_getres、clock_gettime、clock_nanosleep、clock_settime、close、connect、delete_module、dup3、dup、epoll_create1、epoll_ctl、epoll_pwait、eventfd2、execve、exit、exit_group、faccessat、fallocate、fchdir、fchmodat、fchmod、fchownat、fchown32、fcntl64、fdatasync、fgetxattr、flistxattr、flock、fremovexattr、fsetxattr、fstat64、fstatat64、fstatfs64、fsync、ftruncate64、getcpu、getcwd、getdents64、getegid32、geteuid32、getgid32、getgroups32、getitimer、getpeername、getpgid、getpid、getppid、getpriority、getresgid32、getresuid32、ugetrlimit、getrusage、getsid、getsockname、getsockopt、gettimeofday、getuid32、getxattr、init_module、inotify_add_watch、inotify_init1、inotify_rm_watch、ioctl、kill、syslog、lgetxattr、linkat、listen、listxattr、llistxattr、_llseek、lremovexattr、lseek、lsetxattr、madvise、mincore、mkdirat、mknodat、mlockall、mlock、mmap2、mount、mprotect、mremap、msync、munlockall、munlock、munmap、nanosleep、openat、personality、pipe2、ppoll、prctl、pread64、preadv、prlimit64、process_vm_readv、process_vm_writev、pselect6、ptrace、pwrite64、pwritev、quotactl、readahead、readlinkat、read、readv、reboot、recvfrom、recvmmsg、recvmsg、removexattr、renameat、rt_sigaction、rt_sigpending、rt_sigprocmask、rt_sigqueueinfo、rt_sigsuspend、rt_sigtimedwait、sched_getaffinity、sched_getparam、sched_get_priority_max、sched_get_priority_min、sched_getscheduler、sched_rr_get_interval、sched_setaffinity、sched_setparam、sched_setscheduler、sched_yield、sendfile64、sendfile、sendmmsg、sendmsg、sendto、setdomainname、setfsgid、setfsuid、setgid32、setgroups32、sethostname、setitimer、setns、setpgid、setpriority、setregid32、setresgid32、setresuid32、setreuid32、setrlimit、setsid、setsockopt、set_tid_address、settimeofday、set_tls、setuid32、setxattr、shutdown、sigaction、sigaltstack、signalfd4、socketpair、socket、splice、statfs64、swapoff、swapon、symlinkat、sync_file_range2、sync、sysinfo、tee、tgkill、timer_create、timer_delete、timerfd_create、timerfd_gettime、timerfd_settime、timer_getoverrun、timer_gettime、timer_settime、times、truncate64、truncate、umask、umount2、uname、unlinkat、unshare、utimensat、vmsplice、wait4、waitid、write、writev</td>
</tr></tbody></table>
<p>通过绕过 Bionic,可进行下列系统调用:</p>
<table>
<tbody><tr>
<th style="width:20%">所有架构</th>
<td>gettid、futex、clone、rt_sigreturn、rt_tgsigqueueinfo、restart_syscall、getrandom、perf_event_open、syncfs、tkill、seccomp</td>
</tr>
<tr>
<th>arm</th>
<td>vfork、sigreturn、pipe、access、stat64、lstat64、open、getdents、eventfd、epoll_wait、readlink、epoll_create、creat、unlink</td>
</tr>
<tr>
<th>arm64</th>
<td>pivot_root、ioprio_get、ioprio_set</td>
</tr>
</tbody></table>
<aside class="note"><strong>注意</strong>:未来的版本中将添加 x86 和 x86_64 系统调用。</aside>
<h3 id="prctl">prctl</h3>
<p>除了用于受支持的内核版本的上游 <code>prctl</code> 指令外,Android 还依赖于其他 <code>prctl</code> 指令;这些指令的实现可以在 android-common 内核中找到。</p>
<pre class="prettyprint">
PR_SET_TIMERSLACK_PID
PR_SET_VMA
</pre>
<h2 id="filesystems">文件系统</h2>
<p>Linux 内核可通过多个文件系统导出接口。Android 要求这些接口以相同的格式传递相同的信息,并且提供的语义与上游 Linux 内核中的语义相同。对于上游中不存在的接口,相应的行为将由对应的 Android 通用内核分支决定。</p>
<h3 id="procfs">procfs</h3>
<table>
<tbody><tr>
<th>路径</th>
<th>说明</th>
</tr>
<tr>
<td><code>/proc/cmdline</code></td>
<td>包含传递到内核的命令行参数的只读文件。
</td>
</tr>
<tr>
<td><code>/proc/config.gz</code></td>
<td>包含内核编译配置的只读文件。</td>
</tr>
<tr>
<td><code>/proc/cpuinfo</code></td>
<td>包含架构对应的 CPU 详细信息的只读文件。</td>
</tr>
<tr>
<td><code>/proc/kmsg</code></td>
<td>实时显示内核信息的只读文件。</td>
</tr>
<tr>
<td><code>/proc/meminfo</code></td>
<td>显示内存子系统详细信息的只读文件。</td>
</tr>
<tr>
<td><code>/proc/modules</code></td>
<td>包含已加载内核模块的相关信息的只读文件。</td>
</tr>
<tr>
<td><code>/proc/mounts</code></td>
<td>指向 <code>/proc/self/mounts</code>(一个只读文件,列出了已装载的文件系统的相关信息)的符号链接。</td>
</tr>
<tr>
<td><code>/proc/net/xt_qtaguid/ctrl</code></td>
<td>提供已标记的套接字相关信息的读写文件。</td>
</tr>
<tr>
<td><code>/proc/self/maps</code></td>
<td>包含当前映射的内存区域和权限的只读文件。</td>
</tr>
<tr>
<td><code>/proc/stat</code></td>
<td>包含各种内核和系统统计信息的只读文件。</td>
</tr>
<tr>
<td><code>/proc/sys/kernel/kptr_restrict</code></td>
<td>决定内核指针是否印在 <code>proc</code> 文件和其他接口中的读写文件。</td>
</tr>
<tr>
<td><code>/proc/sys/kernel/randomize_va_space</code></td>
<td>决定系统的地址布局随机化政策的读写文件。</td>
</tr>
<tr>
<td><code>/proc/sys/vm/mmap_min_addr</code></td>
<td>读写文件,用于确定可进行 <code>mmap</code> 调用的最小地址。</td>
</tr>
<tr>
<td><code>/proc/sys/vm/mmap_rnd_bits</code></td>
<td>读写文件,会指定 <code>mmap</code> 调用的地址中的随机性程度。</td>
</tr>
<tr>
<td><code>/proc/sys/vm/mmap_rnd_compat_bits</code></td>
<td>读写文件,会指定 <code>mmap</code> 调用的地址中的随机性程度。</td>
</tr>
<tr>
<td><code>/proc/sys/vm/overcommit_memory</code></td>
<td>确定内核虚拟内存记录模式的读写文件。</td>
</tr>
<tr>
<td><code>/proc/uid_cputime/remove_uid_range</code></td>
<td>只写文件,向其中写入数据时,会移除 <code>/proc/uid_cputime/show_uid_stat</code> 中显示的 UID。</td>
</tr>
<tr>
<td><code>/proc/uid_cputime/show_uid_stat</code></td>
<td>只读文件,包含 UID 进程在用户空间和内核空间中花费的时间。</td>
</tr>
<tr>
<td><code>/proc/version</code></td>
<td>只读文件,包含描述内核版本的字符串。</td>
</tr>
<tr>
<td><code>/proc/vmallocinfo</code></td>
<td>只读文件,包含 <code>vmalloc</code> 进行分配的范围。</td>
</tr>
<tr>
<td><code>/proc/zoneinfo</code></td>
<td>包含内存区域相关信息的只读文件。</td>
</tr>
</tbody></table>
<h3 id="dev">dev</h3>
<table>
<tbody><tr>
<th>路径</th>
<th>说明</th>
</tr>
<tr>
<td><code>/dev/ashmem</code></td>
<td>匿名的共享内存设备文件。</td>
</tr>
<tr>
<td><code>/dev/binder</code></td>
<td>Binder 设备文件。</td>
</tr>
<tr>
<td><code>/dev/hwbinder</code></td>
<td>硬件 binder 设备文件。</td>
</tr>
<tr>
<td><code>/dev/tun</code></td>
<td>通用 TUN/TAP 设备文件。</td>
</tr>
<tr>
<td><code>/dev/xt_qtaguid</code></td>
<td>QTAGUID netfilter 设备文件。</td>
</tr>
</tbody></table>
<h3 id="sysfs">sysfs</h3>
<table>
<tbody><tr>
<th>路径</th>
<th>说明</th>
</tr>
<tr>
<td><code>/sys/devices/system/cpu/online</code></td>
<td>显示当前在线的 CPU 范围的只读文件。</td>
</tr>
<tr>
<td><code>/sys/kernel/wakeup_reasons/last_resume_reason</code></td>
<td>只读文件,会显示系统为什么退出最后一个挂起实例的文字说明。</td>
</tr>
<tr>
<td><code>/sys/devices/system/cpu/kernel_max</code></td>
<td>只读文件,会显示内核支持的最大 CPU 指标。
</td>
</tr>
</tbody></table>
<h3 id="selinuxfs">selinuxfs</h3>
<p>该框架会将 <code>selinuxfs</code> 装载到 <code>/sys/fs/selinux</code> 中。
</p>
<table>
<tbody><tr>
<th>路径</th>
<th>说明</th>
</tr>
<tr>
<td><code>/sys/fs/selinux/checkreqprot</code></td>
<td>读/写文件,包含可用于确定如何在 <code>mmap</code><code>mprotect</code> 调用中检查 SElinux 保护的二进制标记。
</td>
</tr>
<tr>
<td><code>/sys/fs/selinux/null</code></td>
<td>供 SElinux 使用的读/写空设备。</td>
</tr>
<tr>
<td><code>/sys/fs/selinux/policy</code></td>
<td>只读文件,包含了二进制文件形式的 SElinux 政策。</td>
</tr>
</tbody></table>
<aside class="note"><strong>注意</strong>:要详细了解 Android 8.0 中的 SELinux,请参阅 <a href="/security/selinux/images/SELinux_Treble.pdf">SELinux for Android 8.0</a></aside>
</body></html>