Linux中的系统调用是如何实现的? [英] How is the system call in Linux implemented?

查看:9
本文介绍了Linux中的系统调用是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在用户模式下调用系统调用时,调用在 OS 中是如何处理的?

它是调用一些可执行的二进制文件还是一些标准库?

如果是,完成通话需要什么样的东西?

解决方案

看看这个.

<块引用>

从 2.5 版开始,linux内核引入了一个新的系统调用Pentium II+ 上的进入机制处理器.由于性能问题奔腾 IV 处理器与现有的软件中断方法,一个替代系统调用条目机制是使用实现的SYSENTER/SYSEXIT 指令Pentium II+ 处理器上可用.本文探讨了这一新机制.讨论仅限于x86 架构和所有源代码清单基于 linux 内核2.6.15.6.

  1. 什么是系统调用?<块引用>

    系统调用提供用户空间处理请求服务的方式从内核.什么样的服务?管理的服务通过操作系统(如存储),内存、网络、进程管理等等例如,如果一个用户进程想要读取一个文件,它必须进行打开"和读取"系统调用.一般不调用系统调用直接通过进程.C 库为所有系统提供接口来电.

  2. 系统调用会发生什么?<块引用>

    内核代码片段在用户进程的请求.这段代码在环 0 中运行(具有当前权限级别-CPL- 0),这是最高的x86 中的特权级别建筑学.所有用户进程运行在环 3 (CPL 3) 中.

    所以,要实现系统调用机制,我们需要的是

    1) 一种从环 3 调用环 0 代码的方法.

    2) 一些内核代码来服务请求.

  3. 很好的老方法<块引用>

    直到前段时间,linux 曾经在所有 x86 上实现系统调用使用软件中断的平台.要执行系统调用,用户进程将复制所需的系统调用号到 %eax 并将执行 'int 0x80'.这将产生中断 0x80 和中断服务程序将是叫.对于中断 0x80,这例程是一个所有系统调用处理例程.这个例程将在环 0 中执行.这个例程,如在文件中定义/usr/src/linux/arch/i386/kernel/entry.S,将保存当前状态并调用基于适当的系统调用处理程序关于 %eax 中的值.

  4. 新的闪亮方式<块引用>

    发现这个软件中断方法要慢得多奔腾 IV 处理器.为了解决这个问题,Linus 实现了一个替代系统调用机制利用 SYSENTER/SYSEXIT所有奔腾提供的说明II+ 处理器.在更进一步之前用这种新的方式,让我们让自己更熟悉这些说明.

When I invoke a system call in user mode,how did the call get processed in OS?

Does it invoke some some executable binary or some standard library?

If yes,what kind of thing it needs to complete the call?

解决方案

Have a look at this.

Starting with version 2.5, linux kernel introduced a new system call entry mechanism on Pentium II+ processors. Due to performance issues on Pentium IV processors with existing software interrupt method, an alternative system call entry mechanism was implemented using SYSENTER/SYSEXIT instructions available on Pentium II+ processors. This article explores this new mechanism. Discussion is limited to x86 architecture and all source code listings are based on linux kernel 2.6.15.6.

  1. What are system calls?

    System calls provide userland processes a way to request services from the kernel. What kind of services? Services which are managed by operating system like storage, memory, network, process management etc. For example if a user process wants to read a file, it will have to make 'open' and 'read' system calls. Generally system calls are not called by processes directly. C library provides an interface to all system calls.

  2. What happens in a system call?

    A kernel code snippet is run on request of a user process. This code runs in ring 0 (with current privilege level -CPL- 0), which is the highest level of privilege in x86 architecture. All user processes run in ring 3 (CPL 3).

    So, to implement system call mechanism, what we need is

    1) a way to call ring 0 code from ring 3.

    2) some kernel code to service the request.

  3. Good old way of doing it

    Until some time back, linux used to implement system calls on all x86 platforms using software interrupts. To execute a system call, user process will copy desired system call number to %eax and will execute 'int 0x80'. This will generate interrupt 0x80 and an interrupt service routine will be called. For interrupt 0x80, this routine is an "all system calls handling" routine. This routine will execute in ring 0. This routine, as defined in the file /usr/src/linux/arch/i386/kernel/entry.S, will save the current state and call appropriate system call handler based on the value in %eax.

  4. New shiny way of doing it

    It was found out that this software interrupt method was much slower on Pentium IV processors. To solve this issue, Linus implemented an alternative system call mechanism to take advantage of SYSENTER/SYSEXIT instructions provided by all Pentium II+ processors. Before going further with this new way of doing it, let's make ourselves more familiar with these instructions.

这篇关于Linux中的系统调用是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆