- 论坛徽章:
- 0
|
linux内核分析之系统调用
在内核入口函数start_kernel中调用trap_init实现系统调用的初始化工作
view plaincopy to clipboard- 01.void __init trap_init(void)
- 02.{
- 03. ...
- 04. set_system_trap_gate(SYSCALL_VECTOR, &system_call);
- 05. ....
- 06.}
复制代码 也就是IDT中0x80用来实现系统调用,实现系统调用的函数为system_call,为汇编实现
view plaincopy to clipboard- 01.<pre name="code" class="html">ENTRY(system_call)
- 02. RING0_INT_FRAME # can't unwind into user space anyway
- 03. pushl %eax # save orig_eax
- 04. CFI_ADJUST_CFA_OFFSET 4
- 05. SAVE_ALL
- 06. GET_THREAD_INFO(%ebp)
- 07. # system call tracing in operation / emulation
- 08. testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
- 09. 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寄存器中。 |
|