Linux内核分析之系统调用


在内核入口函数start_kernel中调用trap_init实现系统调用的初始化工作

  1. void __init trap_init(void)  
  2. {  
  3.     ...  
  4.     set_system_trap_gate(SYSCALL_VECTOR, &system_call);  
  5.     ....  
  6. }  
也就是IDT中0x80用来实现系统调用,实现系统调用的函数为system_call,为汇编实现
  1. ENTRY(system_call)  
  2.     RING0_INT_FRAME         # can't unwind into user space anyway  
  3.     pushl %eax          # save orig_eax  
  4.     CFI_ADJUST_CFA_OFFSET 4  
  5.     SAVE_ALL  
  6.     GET_THREAD_INFO(%ebp)  
  7.                     # system call tracing in operation / emulation   
  8.     testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)  
  9.     jnz syscall_trace_entry  
  10.     cmpl $(nr_syscalls), %eax  
  11.     jae syscall_badsys  
  12. syscall_call:  
  13.     call *sys_call_table(,%eax,4)/*跳转到具体的系统调用函数*/  
  14.     movl %eax,PT_EAX(%esp)      # store the return value  
  15. syscall_exit:  
  16.     LOCKDEP_SYS_EXIT  
  17.     DISABLE_INTERRUPTS(CLBR_ANY)    # make sure we don't miss an interrupt  
  18.                     # setting need_resched or sigpending   
  19.                     # between sampling and the iret   
  20.     TRACE_IRQS_OFF  
  21.     movl TI_flags(%ebp), %ecx  
  22.     testl $_TIF_ALLWORK_MASK, %ecx  # current->work  
  23.     jne syscall_exit_work  
........

具体的系统调用函数存放在sys_call_table表中,在调用system_call具体的系统调用号存放在eax寄存器中 

相关内容