# 设备驱动程序

设备驱动程序是一种软件，负责管理硬件设备与操作系统之间的数据传输，通过标准接口将设备呈现给系统其余部分，使应用程序和内核无需了解硬件的具体命令序列。<sup>[1](https://docs.oracle.com/cd/E19963-01/pdf/819-3159.pdf)</sup> 在 Solaris 中，驱动程序以[可加载内核模块](https://www.edgepedia.org/zh/loadable-kernel-module)的形式存在；在 Windows 和 macOS 中，驱动程序可以在内核模式下运行，也可以越来越多地在用户模式下运行。<sup>[1](https://docs.oracle.com/cd/E19963-01/pdf/819-3159.pdf)</sup><sup> • </sup><sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 管理设备与操作系统之间数据传输的软件；在 Solaris 中为可加载内核模块<sup>[1](https://docs.oracle.com/cd/E19963-01/pdf/819-3159.pdf)</sup> |
| Windows 分类 | 两种基本类型：用户模式驱动程序（所有打印机驱动程序均为用户模式）和内核模式驱动程序，后者按最高级、中间级和最低级（总线）驱动程序分层<sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)</sup> |
| 中断处理 | 产生中断的设备的驱动程序必须提供中断服务例程（ISR），该例程在设备 IRQL（DIRQL）下运行，并将 DPC 排队以在较低优先级下完成 I/O<sup>[3](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/writing-an-isr)</sup> |
| 可靠性 | 设备驱动程序是 Linux 内核中最易出现回归的子系统，在 2021–2024 年的样本中约占回归缺陷的 55%<sup>[4](https://arxiv.org/abs/2411.02091)</sup> |
| 安全暴露面 | 内核模式驱动程序以内核权限执行并共享内核虚拟地址空间，而部分驱动程序在用户模式下执行，无法访问操作系统保留的虚拟地址；Coverity 对 Linux 内核的审计发现超过 50% 的缺陷位于设备驱动程序中<sup>[5](https://pages.cs.wisc.edu/~swift/papers/drivers-acsac09.pdf)</sup><sup> • </sup><sup>[20](https://learn.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)</sup> |
| 用户空间趋势 | Apple 的 DriverKit 在用户空间运行驱动程序，在 macOS 11 及更高版本中，当存在等效的 DriverKit 方案时，内核拒绝加载内核扩展（kext）<sup>[6](https://developer.apple.com/documentation/kernel/implementing_drivers_system_extensions_and_kexts?changes=l__3)</sup> |
| Windows 加固 | 2026 年 4 月 14 日及之后发布的 Windows 更新通过 Microsoft 易受攻击驱动程序阻止列表阻止所列内核驱动程序的易受攻击版本<sup>[7](https://support.microsoft.com/en-us/servicing/os/windows/docs/2026/04/april-2026-windows-security-updates-introduce-protections-to-known-vulnerable-kernel-drivers)</sup> |

## 目的与位置

驱动程序位于操作系统的 I/O 机制与特定硬件之间。它配置设备，实现与设备通信的接口，并将通用操作系统请求转换为设备特定操作。<sup>[6](https://developer.apple.com/documentation/kernel/implementing_drivers_system_extensions_and_kexts?changes=l__3)</sup> 这种抽象的价值在于共享：与其让每个程序员为每个输入或输出设备编写例程，不如为每种设备类型编写一次通用驱动程序并共享使用——这一方法可追溯至早期操作系统开发时期，当时此类库函数在研究人员之间自由分发。<sup>[8](https://osdata.com/kind/history.htm)</sup>

在 UNIX System V 中，内核分为文件与进程控制子系统及其下方的设备驱动程序，因此对大多数应用程序员而言，驱动程序不过是[设备文件](https://www.edgepedia.org/zh/device-file)背后的机制。<sup>[9](https://bitsavers.trailing-edge.com/pdf/att/unix/System_V_Release_4.2/0130426237_Device_Driver_Programming_1992.pdf)</sup>

## 驱动程序如何工作

**中断。** 设备通过引发中断来发出完成信号，此类设备的驱动程序必须包含至少一个中断服务例程。在 Windows 上，ISR 在设备 IRQL 下运行，该 IRQL 会屏蔽当前处理器上同等或更低优先级的中断，因此它必须快速返回控制权：它解除中断、保存设备上下文，并将延迟过程调用（DPC）排队，以在较低 IRQL 下完成 I/O 处理。<sup>[3](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/writing-an-isr)</sup> 保持 ISR 简短可提高机器中每个设备的 I/O 吞吐量。<sup>[3](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/writing-an-isr)</sup>

**直接内存访问。** 对于较大的传输，驱动程序使用 DMA，即由设备或 DMA 控制器在无需处理器干预的情况下将数据移入或移出系统内存。<sup>[10](https://cmp.felk.cvut.cz/~pisa/linux/tlk-0.8-3.pdf)</sup> Linux USB 驱动程序可以感知 DMA，分配 DMA 缓冲区并管理 DMA 映射，也可以忽略大多数 DMA 问题而让 usbcore 子系统为其映射地址；驱动程序绝不能在 USB 接口或设备上调用 `dma_set_mask()`，因为这样做可能破坏共享该总线的所有设备。<sup>[11](https://docs.kernel.org/driver-api/usb/dma.html)</sup> 在 Windows 上，内核模式驱动程序框架直到 [Windows 7](https://www.edgepedia.org/zh/windows-7)（含该版本）都仅支持总线主控 DMA 设备，并在运行 [Windows 8](https://www.edgepedia.org/zh/windows-8) 及更高版本的 SoC 平台上增加了系统模式 DMA，即多个设备共享一个多通道 DMA 控制器。<sup>[12](https://learn.microsoft.com/en-nz/windows-hardware/drivers/wdf/introduction-to-dma-in-windows-driver-framework)</sup>

**绑定。** 在 Linux 驱动程序模型中，当添加新设备时，总线遍历其驱动程序列表，并使用总线特定的匹配回调将设备 ID 与每个驱动程序支持的 ID 进行比较。匹配时，驱动程序的探测回调运行以验证其确实支持该硬件，设备注册到其类别，sysfs 中出现符号链接；当设备或驱动程序被移除时，移除回调针对每个受影响的配对运行。<sup>[13](https://docs.kernel.org/6.6/driver-api/driver-model/binding.html)</sup>

## 内核模式与用户模式

Windows 区分两种基本驱动程序类型。用户模式驱动程序在用户模式下执行，通常介于 Win32 应用程序与内核模式组件之间；所有打印机驱动程序均为用户模式。内核模式驱动程序作为执行体的一部分运行，通常分层：最高级文件系统驱动程序（如 NTFS、FAT 和 CDFS）依赖于中间功能驱动程序，后者又依赖于最低级总线驱动程序。部分内核模式驱动程序遵循 Windows 驱动程序模型（WDM），所有 WDM 驱动程序均支持即插即用和电源管理。<sup>[2](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)</sup> 内核模式驱动程序若误写错误的虚拟地址，可能危及操作系统或其他驱动程序的数据，这是内核模式执行的核心风险。<sup>[14](https://learn.microsoft.com/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)</sup>

用户模式驱动程序框架（UMDF）将供应商驱动程序托管在由 Windows 服务管理的驱动程序主机进程中，内核模式反射器调解应用程序与主机进程之间的所有通信。<sup>[15](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/overview-of-the-umdf)</sup> [文件系统](https://www.edgepedia.org/zh/file-system)驱动程序、完整显示驱动程序和打印驱动程序不能是 UMDF 驱动程序。<sup>[15](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/overview-of-the-umdf)</sup>

Apple 也朝着同一方向前进。DriverKit 为 IOKit 提供了现代化替代方案，其中 USB、串行、网卡和 HID 设备的驱动程序在用户空间运行，无法危及 macOS 的安全性或稳定性；自 macOS 11 起，若存在等效的 DriverKit 方案，内核不加载内核扩展（kext），且 Apple 芯片上的内核扩展必须支持 arm64e 架构。<sup>[6](https://developer.apple.com/documentation/kernel/implementing_drivers_system_extensions_and_kexts?changes=l__3)</sup><sup> • </sup><sup>[16](https://developer.apple.com/system-extensions/)</sup>

## 历史

在最早的开放式作业时代，每个用户随编译器和汇编器一起显式加载设备特定例程。<sup>[17](https://www2.cs.uregina.ca/~anima/330/Notes/history/history.html)</sup> 随着操作系统的发展，驱动程序移入常驻内核：IBM OS/360 等多道批处理系统将设备驱动程序与进程和中断管理一起保留在内核中。<sup>[17](https://www2.cs.uregina.ca/~anima/330/Notes/history/history.html)</sup>

在个人计算机上，MS-DOS 通过 [CONFIG.SYS](https://www.edgepedia.org/zh/config-sys) 文件为原配设备和附加卡加载实模式设备驱动程序。[Windows NT](https://www.edgepedia.org/zh/windows-nt) 驱动程序几乎完全用 C 语言编写，以便无需修改源代码即可为新 CPU 架构重新编译，Microsoft 在 [Windows 98](https://www.edgepedia.org/zh/windows-98) 和 Windows Me 中引入了 Windows 驱动程序模型（WDM）。<sup>[18](https://flylib.com/books/en/4.168.1.14/1/)</sup>

## 可靠性与安全性

由于内核模式驱动程序以内核权限执行并可不受限制地访问内核数据结构，此类驱动程序中的漏洞可能危及整个系统，尽管部分驱动程序在用户模式下运行，无法访问操作系统保留的虚拟地址。一项关于 [Linux 内核](https://www.edgepedia.org/zh/linux-kernel)中用户/内核缺陷的研究发现，11 个缺陷中有 9 个位于设备驱动程序中，Coverity 审计发现超过 50% 的内核缺陷位于驱动程序中；已公开的针对 [Windows XP](https://www.edgepedia.org/zh/windows-xp) 和 Mac OS X 无线驱动程序的漏洞利用展示了攻击面。<sup>[5](https://pages.cs.wisc.edu/~swift/papers/drivers-acsac09.pdf)</sup> 对 297 个 Linux 网络、声音和 SCSI 驱动程序的分析表明，多达 65% 的驱动程序代码可以在用户模式下执行，无需内核权限且不影响常见情况下的性能，这推动了混合架构的发展——将驱动程序拆分为小型可信内核组件和通过 RPC 通信的不可信用户模式组件。<sup>[5](https://pages.cs.wisc.edu/~swift/papers/drivers-acsac09.pdf)</sup>

回归数据证实了这一模式：设备驱动程序是 Linux 内核中最易出现回归的子系统，在 2021–2024 年的样本中约占回归缺陷的 55%，平均修复时间和中位修复时间分别为 25 天和 12 天。<sup>[4](https://arxiv.org/abs/2411.02091)</sup>

供应商现在将易受攻击的驱动程序本身视为供应链风险。2026 年 4 月 14 日及之后发布的 Windows 更新通过 Microsoft 易受攻击驱动程序阻止列表阻止第三方内核驱动程序 psmounterex.sys（CVE-2023-43896）的易受攻击版本，导致依赖它的备份应用程序在发布更新版本之前无法执行映像挂载操作；管理员可以通过代码完整性操作日志中的事件 ID 3077 确认阻止。<sup>[7](https://support.microsoft.com/en-us/servicing/os/windows/docs/2026/04/april-2026-windows-security-updates-introduce-protections-to-known-vulnerable-kernel-drivers)</sup> GPU 驱动程序按类似时间表修补：2026 年 5 月，Nvidia 发布安全公告，修复其 GeForce、RTX、Quadro、Tesla 和 NVS 产品线中的 15 个问题，其中 9 个被评为高危，修复程序在 Windows 驱动程序版本 569.49 和 Linux 驱动程序版本 590.48.01 中提供。<sup>[19](https://www.tomsguide.com/computing/gpus/update-your-nvidia-gpu-drivers-now-to-protect-your-pc-from-9-high-severity-vulnerabilities-heres-whats-at-risk)</sup>

## References

1. [Device Driver Tutorial, Oracle](https://docs.oracle.com/cd/E19963-01/pdf/819-3159.pdf)
2. [Types of Windows Drivers, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/types-of-windows-drivers)
3. [Writing an ISR, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/kernel/writing-an-isr)
4. [Fast Fixes and Faulty Drivers: An Empirical Analysis of Regression Bug Fixing Times in the Linux Kernel, arXiv](https://arxiv.org/abs/2411.02091)
5. [Protecting Commodity Operating System Kernels from Vulnerable Device Drivers, ACSAC 2009](https://pages.cs.wisc.edu/~swift/papers/drivers-acsac09.pdf)
6. [Implementing drivers, system extensions, and kexts, Apple Developer Documentation](https://developer.apple.com/documentation/kernel/implementing_drivers_system_extensions_and_kexts?changes=l__3)
7. [April 2026 Windows security updates introduce protections to known vulnerable kernel drivers, Microsoft Support](https://support.microsoft.com/en-us/servicing/os/windows/docs/2026/04/april-2026-windows-security-updates-introduce-protections-to-known-vulnerable-kernel-drivers)
8. [History of operating systems, osdata.com](https://osdata.com/kind/history.htm)
9. [UNIX System V Release 4.2 Device Driver Programming, bitsavers](https://bitsavers.trailing-edge.com/pdf/att/unix/System_V_Release_4.2/0130426237_Device_Driver_Programming_1992.pdf)
10. [The Linux Kernel Module Programming Guide, Chapter 8: Device Drivers](https://cmp.felk.cvut.cz/~pisa/linux/tlk-0.8-3.pdf)
11. [USB DMA, The Linux Kernel documentation](https://docs.kernel.org/driver-api/usb/dma.html)
12. [Introduction to DMA in Windows Driver Framework, Microsoft Learn](https://learn.microsoft.com/en-nz/windows-hardware/drivers/wdf/introduction-to-dma-in-windows-driver-framework)
13. [Driver Binding, The Linux Kernel documentation](https://docs.kernel.org/6.6/driver-api/driver-model/binding.html)
14. [User Mode and Kernel Mode, Microsoft Learn](https://learn.microsoft.com/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)
15. [Overview of UMDF, Microsoft Learn](https://learn.microsoft.com/en-us/windows-hardware/drivers/wdf/overview-of-the-umdf)
16. [System Extensions and DriverKit, Apple Developer](https://developer.apple.com/system-extensions/)
17. [History of Operating Systems, University of Regina CS 330 notes](https://www2.cs.uregina.ca/~anima/330/Notes/history/history.html)
18. [A Brief History of Device Drivers, Programming the Microsoft Windows Driver Model](https://flylib.com/books/en/4.168.1.14/1/)
19. [Update your Nvidia GPU drivers now to protect your PC from 9 high-severity vulnerabilities, Tom's Guide](https://www.tomsguide.com/computing/gpus/update-your-nvidia-gpu-drivers-now-to-protect-your-pc-from-9-high-severity-vulnerabilities-heres-whats-at-risk)
20. [User Mode and Kernel Mode - Windows drivers](https://learn.microsoft.com/en-us/windows-hardware/drivers/gettingstarted/user-mode-and-kernel-mode)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Sep 30, 2026; Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Operating systems › Operating system concepts

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/device-driver

English original: https://www.edgepedia.org/device-driver
