现在的位置: 首页 > 综合 > 正文

系统调用

2018年05月04日 ⁄ 综合 ⁄ 共 1299字 ⁄ 字号 评论关闭

首先在unistd.h中有系统调用编号,然后再linux1.0版本中在kernel/sys_call.S中有如下代码:

_system_call:
 pushl %eax   # save orig_eax
 SAVE_ALL
 movl $-ENOSYS,EAX(%esp)
 cmpl _NR_syscalls,%eax
 jae ret_from_sys_call
 movl _current,%ebx
 andl $~CF_MASK,EFLAGS(%esp) # clear carry - assume no errors
 movl $0,errno(%ebx)
 movl %db6,%edx
 movl %edx,dbgreg6(%ebx)  # save current hardware debugging status
 testb $0x20,flags(%ebx)  # PF_TRACESYS
 jne 1f
 call _sys_call_table(,%eax,4)
 movl %eax,EAX(%esp)  # save the return value
 movl errno(%ebx),%edx
 negl %edx
 je ret_from_sys_call
 movl %edx,EAX(%esp)
 orl $(CF_MASK),EFLAGS(%esp) # set carry to indicate error
 jmp ret_from_sys_call

 

这段代码在linux2.6.12中是

 # system call handler stub
ENTRY(system_call)
 pushl %eax   # save orig_eax
 SAVE_ALL
 GET_THREAD_INFO(%ebp)
     # system call tracing in operation
 /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
 testw $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),TI_flags(%ebp)
 jnz syscall_trace_entry
 cmpl $(nr_syscalls), %eax
 jae syscall_badsys
syscall_call:
 call *sys_call_table(,%eax,4)
 movl %eax,EAX(%esp)  # store the return value
syscall_exit:
 cli    # make sure we don't miss an interrupt
     # setting need_resched or sigpending
     # between sampling and the iret
 movl TI_flags(%ebp), %ecx
 testw $_TIF_ALLWORK_MASK, %cx # current->work
 jne syscall_exit_work
这个是系统调用的入口点,其中sys_call_table在linux1.0中的kernel/sched.c中定义了一个函数表。

 

抱歉!评论已关闭.