linux - 中断向量中是否有系统调用服务程序?

标签 linux operating-system interrupt system-calls

我对系统调用感到困惑。

问题是:是否有一个系统调用服务例程,它总是被调用,以找到特定的系统调用,如写、读等?

系统调用是否也存储在函数指针向量中?就像这张照片上显示的那样?

syscall table

如果是这样,为什么有可能添加您自己的系统调用而没有可能添加您自己的中断处理程序?为什么中断向量是固定大小的而系统调用向量不是?

引自 Silberschatz 操作系统概念:

A system call usually takes the form of a trap to a specific location in the interrupt vector. This trap can be executed by a generic trap instruction, although some systems (such as MIPS) have a specific syscall instruction to invoke a system call.

When a system call is executed, it is typically treated by the hardware as a software interrupt. Control passes through the interrupt vector to a service routine in the operating system, and the mode bit is set to kernel mode. The system-call service routine is a part of the operating system. The kernel examines the interrupting instruction to determine what system call has occurred; a parameter indicates what type of service the user program is requesting. Additional information needed for the request may be passed in registers, on the stack, or in memory (with pointers to the memory locations passed in registers). The kernel verifies that the parameters are correct and legal, executes the request, and returns control to the instruction following the system call.

最佳答案

(以独立于硬件的方式进行概括)

系统调用的工作方式是执行类似这样的指令

INT #100

(我这里的 INT 指令是你引用中描述的陷阱)。

这会显式触发异常/中断 #100。然后 CPU 在中断向量中查找条目 #100,然后在内核模式下调用该例程。

与许多系统一样,我假设中断向量和系统调用向量是相同的。在这样的系统中,系统定义了固定数量的中断和异常。操作系统可以在系统定义的向量之上添加额外的向量。

这就是触发机制。在进入该状态之前,系统服务将期望寄存器和堆栈处于定义状态(例如,传递缓冲区和缓冲区大小)。所有这些都需要汇编语言。

因此,大多数系统都有包装函数,您可以像调用函数一样调用这些函数,这些函数接受参数、将它们放入寄存器、设置堆栈(可能)、触发中断、从寄存器读取返回值、更新参数并返回给调用者。甚至汇编语言程序员也倾向于使用这些包装器。

The question is: Is there a system call service routine, which is always called, in order to find a specific system call, like write, read, etc. ?

如上所述,不。您不必调用系统服务例程来触发内核模式系统服务。但是,大多数时候您这样做是出于方便。

Of so why there is a possibility to add your own system call and there is no possibility to add your own interrupt handler ?

硬件异常和中断由 . . . .硬件。它们是固定的。

Why interrupt-vector is fixed-size and system call vector not ?

您似乎指的是一个具有独立中断向量和系统服务向量的系统。大多数(但不是全部)系统将它们结合在一起。 CPU 识别的中断和异常的数量是固定的,并在硬件中定义。操作系统可以定义任意数量的系统服务。

如果系统对每个类都有单独的向量,则硬件向量是固定的,系统调用向量可以是任意大小,以说明不同操作系统可以提供的无数系统服务集。

如果系统只有一个向量,则硬件处理程序排在第一位,随后通常是任意数量的软件系统服务。将有一个寄存器定义向量的长度。

关于linux - 中断向量中是否有系统调用服务程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29656136/

相关文章:

c - 在 Minix 中添加新的系统调用

assembly - 如果处理器不产生中断,系统软件必须做什么?

c - 定时器中断期间重新配置定时器 中断 8051

io - 什么时候轮询比中断好?

linux - 使用linux命令连接两个文件

linux - 内核模块和 SSL

linux - 使用 bash 在 Linux 中获取子网掩码

c - 进出子进程的管道不起作用

operating-system - 为什么要在代码中尽量减少对系统调用的使用?

python - struct.unpack 和 win/lin 中 python 2.4 和 2.4.4 的问题