io - 驱动程序和用户应用程序之间的主要区别是什么?

标签 io operating-system kernel driver usermode

我知道用户应用程序只能在用户模式下运行,这是为了系统安全。相反,大多数驱动程序在内核模式下运行,以访问 I/O 设备。尽管如此,一些驱动程序在用户模式下运行,但被允许访问 I/O 设备。所以我有以下问题。驱动程序和用户应用程序之间的主要区别是什么?不能像某些驱动程序那样允许用户应用程序访问 I/O 设备吗?

谢谢。

最佳答案

首先,some preview from this link :-

Applications run in user mode, and core operating system components run in kernel mode. Many drivers run in kernel mode, but some drivers run in user mode.

When you start a user-mode application, Windows(/any OS) creates a process for the application. The process provides the application with a private virtual address space and a private handle table. Because an application's virtual address space is private, one application cannot alter data that belongs to another application.

In addition to being private, the virtual address space of a user-mode application is limited. A processor running in user mode cannot access virtual addresses that are reserved for the operating system. Limiting the virtual address space of a user-mode application prevents the application from altering, and possibly damaging, critical operating system data.

All code that runs in kernel mode shares a single virtual address space. This means that a kernel-mode driver is not isolated from other drivers and the operating system itself. If a kernel-mode driver accidentally writes to the wrong virtual address, data that belongs to the operating system or another driver could be compromised.


另外,from this link

Software drivers

Some drivers are not associated with any hardware device at all. For example, suppose you need to write a tool that has access to core operating system data structures, which can be accessed only by code running in kernel mode. You can do that by splitting the tool into two components. The first component runs in user mode and presents the user interface. The second component runs in kernel mode and has access to the core operating system data. The component that runs in user mode is called an application, and the component that runs in kernel mode is called a software driver. A software driver is not associated with a hardware device.

Also, software drivers() always run in kernel mode. The main reason for writing a software driver is to gain access to protected data that is available only in kernel mode. But device drivers do not always need access to kernel-mode data and resources. So some device drivers run in user mode.



What is the main difference between drivers and user applications?


区别与潜艇和船舶之间的区别相同。驱动程序依赖于硬件和操作系统。它们通常提供任何必要的异步时间相关硬件接口(interface)所需的中断处理。因此,几乎 它们都在内核模式下运行。然而,如第二段所述,为了防止应用程序损坏关键操作系统数据,用户应用程序必须在用户空间中运行。
此外,并非所有驱动程序都直接与设备通信。对于给定的 I/O 请求(例如从设备读取数据),通常有多个驱动程序,分层在堆栈中,参与请求。堆栈中与设备直接通信的驱动程序称为功能驱动程序;执行辅助处理的驱动程序称为过滤器驱动程序。

Can't user application be allowed to access I/O devices like some drivers do?


应用程序调用操作系统实现的函数,操作系统调用驱动程序实现的函数。驱动程序知道如何与设备硬件通信以获取数据。驱动程序从设备获取数据后,将数据返回给操作系统,操作系统将数据返回给应用程序。
应用程序通过设备驱动程序(而不是操作系统)提供的 API/接口(interface)连接到 IO 设备。操作系统处理大多数硬件/软件交互。硬件供应商编写允许操作系统控制其特定硬件的“插件/模块/驱动程序”。因此,使用操作系统提供的接口(interface),您可以编写应用程序来访问 IO 设备。
因此,如果没有驱动程序的帮助,您不能让用户应用程序直接访问硬件,因为访问设备的是层次结构下的所有驱动程序,因为设备驱动程序是用可以与硬件通信的低级语言编写的,而用户应用程序是用高级语言编写的。
另外,check this answer了解更多关于各种操作系统中的驱动程序地址空间的信息。

关于io - 驱动程序和用户应用程序之间的主要区别是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31370366/

相关文章:

c# - 在 Web 应用程序中使用相对路径读取文件内容

c - 将 Windows 套接字用于新进程 I/O

java - 为复制的文件生成文件名

linux - 我们可以写入物理地址linux吗

linux - 如果汇编程序中没有退出系统调用会怎样?

c - 无法从用户空间应用程序访问结构数组

linux - 为什么 sizeof(spinlock_t) 在单处理器上大于零?

java - java中反序列化对象

user-interface - GUI是如何真正制作的?

kernel - 如何在虚拟化环境中启用英特尔处理器跟踪 (IPT)?