系统调用

来源:互联网 发布:淘宝家质量好的内衣店 编辑:程序博客网 时间:2024/06/06 17:10
系统调用:1.在Linux下,程序的功能是使用系统调用来实现的!2.一般情况下,为了更好的保护内核,用户空间的进程是不能访问内核空间的,也就是说进程是不能够存取系统内核的,它不能存取系统内核使用的内存段,也不能调用内核函数!CPU的硬件结构也保证了这一点3.在系统中,真正被进程所使用的是内核通信方式叫做系统调用,也就是说,在进程里调用内核中用于实现各种功能的内核函数的通信方式就是系统调用。系统调用我们可以理解为一个程序,而这个程序就是linux内核中设置的一组用于实现各种系统功能的子程序。4.系统调用的实现的简单原理:        利用中断 0x80中断是指当主机接到外界硬件发来的信号时,马上停止原来的工作,转去处理这一中断事件。在处理完这个事件后,再回到原来的工作继续工作。进程可以跳转到内核中的位置叫做system_call,在此位置的过程检查系统调用号,它将告诉内核进程请求的服务是什么。然后在查找系统调用表sys_call_table,找到需要调用的内核函数的地址,并调用此函数,最后返回。linux里面的每个系统调用是靠一些宏,一张系统调用表,一个系统调用入口来完成的。5.宏见system_call.s || entry.s/* *  system_call.s  contains the system-call low-level handling routines. * This also contains the timer-interrupt handler, as some of the code is * the same. The hd-interrupt is also here. * * NOTE: This code handles signal-recognition, which happens every time * after a timer-interrupt and after each system call. Ordinary interrupts * don't handle signal-recognition, as that would clutter them up totally * unnecessarily. * * Stack layout in 'ret_from_system_call': * * 0(%esp) - %eax * 4(%esp) - %ebx * 8(%esp) - %ecx * C(%esp) - %edx *10(%esp) - %fs *14(%esp) - %es *18(%esp) - %ds *1C(%esp) - %eip *20(%esp) - %cs *24(%esp) - %eflags *28(%esp) - %oldesp *2C(%esp) - %oldss */

原创粉丝点击