Linux 系统调用编号

系统 32bit 与 64bit 调用编号不一样。以 Intel 平台 Linux 系统为例。

/usr/include/x86_64-linux-gnu/asm/unistd_32.h
#define __NR_restart_syscall 0
#define __NR_exit 1
#define __NR_fork 2
#define __NR_read 3
#define __NR_write 4
#define __NR_open 5
#define __NR_close 6
#define __NR_waitpid 7
#define __NR_creat 8
#define __NR_link 9
#define __NR_unlink 10
#define __NR_execve 11
#define __NR_chdir 12
...

系统调用通过int 0x80指令触发,eax寄存器包含了系统调用的编号。

; write(1, "ac", 2)
movl edx, len  # 参数三:字符串长度
movl ecx, msg  # 参数二:要显示的字符串
movl ebx, 1    # 参数一:文件描述符(stdout)
movl eax, 4    # 系统调用号(write)
int 0x80       # 调用内核功能


/usr/include/x86_64-linux-gnu/asm/unistd_64.h
#define __NR_read 0
#define __NR_write 1
#define __NR_open 2
#define __NR_close 3
#define __NR_stat 4
#define __NR_fstat 5
#define __NR_lstat 6
#define __NR_poll 7
#define __NR_lseek 8
#define __NR_mmap 9
#define __NR_mprotect 10
#define __NR_munmap 11
#define __NR_brk 12
...

系统调用通过syscall指令触发,rax寄存器包含了系统调用的编号。

; bytes_read = read(fd, buf, 100);
mov rdi, rax
mov rsi, rsp
mov rdx, 100
mov rax, 0
syscall

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值