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

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

问题描述

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

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?

推荐答案

看看.

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

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. 什么是系统调用?
  1. What are system calls?

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

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.

  • 系统调用中会发生什么?

  • What happens in a system call?

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

    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)一种从环3调用环0代码的方法.

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

    2)一些用于处理请求的内核代码.

    2) some kernel code to service the request.

  • 好的旧方法

  • Good old way of doing it

    直到很久以前,Linux习惯了 在所有x86上实施系统调用 平台使用软件中断. 要执行系统调用,用户进程 将复制所需的系统电话号码 到%eax并执行'int 0x80'. 这将产生中断0x80和 中断服务程序将是 叫.对于中断0x80,这 例行程序是所有系统调用 处理"例程.该例程将 在环0中执行.该例程为 在文件中定义 /usr/src/linux/arch/i386/kernel/entry.S, 将保存当前状态并调用 基于适当的系统调用处理程序 %eax中的值.

    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.

  • 新的闪亮方式

  • New shiny way of doing it

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

    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天全站免登陆