中断向量中是否有一个系统调用服务例程?

时间:2021-03-20 02:59:16

I'm confused with system calls.

我对系统调用感到困惑。

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. ?

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

Are system calls also stored in a vector of function pointers ? Like shown on this picture ?

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

中断向量中是否有一个系统调用服务例程?

If 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 ?

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

Quote from Silberschatz Operating Systems Concepts:

引用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.

系统调用通常以一个陷阱的形式出现在中断向量的特定位置。这个陷阱可以通过通用的陷阱指令执行,尽管有些系统(比如MIPS)有一个特定的syscall指令来调用系统调用。

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.

当执行系统调用时,硬件通常将其视为软件中断。控件通过中断向量传递到操作系统中的服务例程,模式位被设置为内核模式。系统调用服务例程是操作系统的一部分。内核检查中断指令,以确定发生了什么系统调用;参数指示用户程序请求的服务类型。请求所需的其他信息可以在寄存器、堆栈或内存中传递(指针指向寄存器中传递的内存位置)。内核验证参数是否正确和合法,执行请求,并在系统调用之后将控制权返回给指令。

1 个解决方案

#1


3  

(Generalizing in a hardware independent manner)

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

The way a system call works is you execute an instruction something like

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

INT #100

(My INT instruction here is the trap described in your quote).

(我这里的INT指令是您引用的陷阱)。

That explicitly triggers exception/interrupt #100. The CPU then looks for entry #100 in the interrupt vector, then calls that routine in kernel mode.

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

As on many systems, I assume that the interrupt vector and the system call vector are the same. In such systems, there is a fixed number of interrupts and exceptions defined by the system. The Operating system can add additional vectors above the system defined ones.

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

That is the triggering mechanism. Prior to getting to the state, the system service will expect the registers and stack to be a in defined state (e.g., to pass a buffer and buffer size). All of that requires assembly language.

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

Therefore, most systems have wrapper functions that you call like a function that take the parameters, put them in the registers, set up the stack (possibly), trigger the interrupt, read the return values from the registers, update the parameters and return to the caller. Even assembly language programmers tend to use these wrappers.

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

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. ?

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

As described above, NO. You don't have to call a system service routine in order to trigger a kernel mode system services. However, most of the time you do so out of convenience.

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

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

那么,为什么有可能添加您自己的系统调用,并且不可能添加自己的中断处理程序?

Hardware exceptions and interrupts are predefined by the . . . . hardware. They are fixed.

硬件异常和中断是由…预定义的。硬件。他们是固定的。

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

为什么中断向量是固定大小的而系统调用向量不是?

It seems you are referring to a system the has separate interrupt vectors and system service vectors. Most, but not all, systems have them combined. The number of interrupts and exceptions recognized by the CPU is fixed and defined in hardware. An operating system can define any number of system services.

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

If the system has separate vectors for each class, the hardware vectors are fixed, and the system call vectors can be any size to account for the myriad of sets of system services different operating systems can provide.

如果系统为每个类都有单独的向量,那么硬件向量是固定的,系统调用向量可以是任意大小,以表示不同操作系统可以提供的大量系统服务。

If the system has one vector, the hardware handlers come first and any number of software system services usually follow. There will be a register that defines the length of the vector.

如果系统有一个向量,那么首先是硬件处理程序,然后是任意数量的软件系统服务。会有一个寄存器来定义向量的长度。

#1


3  

(Generalizing in a hardware independent manner)

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

The way a system call works is you execute an instruction something like

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

INT #100

(My INT instruction here is the trap described in your quote).

(我这里的INT指令是您引用的陷阱)。

That explicitly triggers exception/interrupt #100. The CPU then looks for entry #100 in the interrupt vector, then calls that routine in kernel mode.

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

As on many systems, I assume that the interrupt vector and the system call vector are the same. In such systems, there is a fixed number of interrupts and exceptions defined by the system. The Operating system can add additional vectors above the system defined ones.

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

That is the triggering mechanism. Prior to getting to the state, the system service will expect the registers and stack to be a in defined state (e.g., to pass a buffer and buffer size). All of that requires assembly language.

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

Therefore, most systems have wrapper functions that you call like a function that take the parameters, put them in the registers, set up the stack (possibly), trigger the interrupt, read the return values from the registers, update the parameters and return to the caller. Even assembly language programmers tend to use these wrappers.

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

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. ?

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

As described above, NO. You don't have to call a system service routine in order to trigger a kernel mode system services. However, most of the time you do so out of convenience.

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

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

那么,为什么有可能添加您自己的系统调用,并且不可能添加自己的中断处理程序?

Hardware exceptions and interrupts are predefined by the . . . . hardware. They are fixed.

硬件异常和中断是由…预定义的。硬件。他们是固定的。

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

为什么中断向量是固定大小的而系统调用向量不是?

It seems you are referring to a system the has separate interrupt vectors and system service vectors. Most, but not all, systems have them combined. The number of interrupts and exceptions recognized by the CPU is fixed and defined in hardware. An operating system can define any number of system services.

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

If the system has separate vectors for each class, the hardware vectors are fixed, and the system call vectors can be any size to account for the myriad of sets of system services different operating systems can provide.

如果系统为每个类都有单独的向量,那么硬件向量是固定的,系统调用向量可以是任意大小,以表示不同操作系统可以提供的大量系统服务。

If the system has one vector, the hardware handlers come first and any number of software system services usually follow. There will be a register that defines the length of the vector.

如果系统有一个向量,那么首先是硬件处理程序,然后是任意数量的软件系统服务。会有一个寄存器来定义向量的长度。