Linux 2.6系统调用注册及调用流程:
init/main.c --->start_kernel()--->arch/x86/kernel/traps.c.trap_init()
在此文件中,执行如下函数进行system_call与int 0x80绑定:
# define SYSCALL_VECTOR 0x80
set_system_trap_gate(SYSCALL_VECTOR, &system_call);
arch/x86/kernel/entry_64.S.system_call():
cmpq $__NR_syscall_max,%rax #比较传入的系统调用号是否异常
call *sys_call_table(,%rax,8) #根据系统调用号,执行相应的系统调用函数
arch/x86/kernel/syscall_64.c.sys_call_table数组初始化如下:
const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
/*
*Smells like a like a compiler bug -- it doesn't work
*when the & below is removed.
*/
[0 ... __NR_syscall_max] = &sys_ni_syscall, //将所有下标设置成sys_ni_syscall函数
#include
//定义下标和函数对应关系
};
#### sys_ni_syscall,中ni 表示 “not implemented”没有实现的意思
arch/x86/include/asm/unistd_64.h
#define __SYSCALL(nr, call) [nr] = (call),
#define __NR_read 0
__SYSCALL(__NR_read, sys_read)
#define __NR_write 1
__SYSCALL(__NR_write, sys_write)
......
推演如下:
const sys_call_ptr_t sys_call_table[__NR_syscall_max+1] = {
[__NR_read] = sys_read,
[__NR_write]=sys_write,
......
}
阅读(1207) | 评论(0) | 转发(0) |