/introduction-to-linux-x86_64-syscall

Linux x86_64系统调用简介(长线更新中)

Primary LanguageCCreative Commons Attribution 4.0 InternationalCC-BY-4.0

Linux x86_64系统调用简介

如果要对Linux上的恶意软件进行细致地分析,或者想了解Linux内核,又或是想对Linux内核做进一步的定制,那么了解Linux的全部系统调用就是一个很好的帮助。在分析Linux上的恶意软件时,如果对Linux的系统调用不了解,那么往往会忽视某些重要的关键细节。因此,在充分了解Linux的系统调用之后,就能做到有的放矢,更好地达到我们的需求。

本仓库将详细记录每个Linux x86_64系统调用的功能、用法与实现细节。

环境

所有实现细节均基于v5.4版本的Linux内核,glibc-2.31版本的glibc。所记录的系统调用列表位于Linux内核源码的arch/x86/entry/syscalls/syscall_64.tbl。功能、用法基于其相应的manual page,可在man7.org中查看。涉及到验证代码的,则会在Ubuntu 20.04中进行验证。

如果仅想阅读本仓库的文章以及相应的测试代码,可以使用

git clone git@github.com:Evian-Zhang/introduction-to-linux-x86_64-syscall.git

如果想同时把相应版本的Linux内核源码与glibc源码一并下载,可以使用

git clone --recurse-submodules git@github.com:Evian-Zhang/introduction-to-linux-x86_64-syscall.git

对于在国内的网友,可以考虑使用清华大学开源软件镜像站:

git clone git@github.com:Evian-Zhang/introduction-to-linux-x86_64-syscall.git
cd introduction-to-linux-x86_64-syscall
git config submodule.linux.url https://mirrors.tuna.tsinghua.edu.cn/git/linux.git
git config submodule.glibc.url https://mirrors.tuna.tsinghua.edu.cn/git/glibc.git
git pull --recurse-submodules

构建

请安装mdBook后,在项目根目录下使用

mdbook build

请注意,如果您使用了--recurse-submodules命令克隆本仓库,从而在本地仓库中包含了全部的Linux和glibc源码,请不要使用上述命令构建。因为mdBook目前会将项目根目录中所有的文件都拷贝进输出的构建目录中。

系统调用对照表

每个系统调用名都超链接到了其在本仓库中对应的文章。

名称 系统调用号 头文件 内核实现
read 0 unistd.h fs/read_write.c
write 1 unistd.h fs/read_write.c
open 2 fcntl.h fs/open.c
close 3 unistd.h fs/open.c
stat 4 sys/stat.h fs/stat.c
fstat 5 sys/stat.h fs/stat.c
lstat 6 sys/stat.h fs/stat.c
poll 7 poll.h fs/select.c
lseek 8 unistd.h fs/read_write.c
mmap 9 sys/mman.h arch/x86/kernel/sys_x86_64.c
munmap 11 sys/mman.h mm/mmap.c
pread64 17 unistd.h fs/read_write.c
pwrite64 18 unistd.h fs/read_write.c
readv 19 sys/uio.h fs/read_write.c
writev 20 sys/uio.h fs/read_write.c
select 23 sys/select.h fs/select.c
mremap 25 sys/mman.h mm/mremap.c
msync 26 sys/mman.h mm/msync.c
epoll_create 213 sys/epoll.h fs/eventpoll.c
remap_file_pages 216 sys/mman.h mm/mmap.c
epoll_ctl 232 sys/epoll.h fs/eventpoll.c
epoll_wait 233 sys/epoll.h fs/eventpoll.c
openat 257 fcntl.h fs/open.c
newfstatat 262 sys/stat.h fs/stat.c
pselect6 270 sys/select.h fs/select.c
ppoll 271 poll.h fs/select.c
epoll_pwait 281 sys/epoll.h fs/eventpoll.c
eventfd 284 sys/eventfd.h fs/eventfd.c
eventfd2 290 sys/eventfd.h fs/eventfd.c
epoll_create1 291 sys/epoll.h fs/eventpoll.c
preadv 295 sys/uio.h fs/read_write.c
pwritev 296 sys/uio.h fs/read_write.c
name_to_handle_at 303 fcntl.h fs/fhandle.c
open_by_handle_at 304 fcntl.h fs/fhandle.c
preadv2 327 sys/uio.h fs/read_write.c
pwritev2 328 sys/uio.h fs/read_write.c
statx 332 linux/stat.h fs/stat.c
open_tree 428 fs/namespace.c

License

本仓库遵循CC-BY-4.0版权协议
作为copyleft的支持者之一,我由衷地欢迎大家积极热情地参与到开源社区中。Happy coding!