什么是 Windows 内核驱动程序?

发布于 2024-11-07 07:31:12 字数 60 浏览 2 评论 0原文

什么是用 WDK 编写的 Windows 内核驱动程序?

与普通应用程序或服务有什么不同?

What is Windows Kernel Driver written with the WDK?

What is different from normal app or service?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

滥情稳全场 2024-11-14 07:31:12

内核驱动程序是针对 Windows NT 的本机 API(而不是 Win32 子系统的 API)编写的程序,并且在底层硬件上以内核模式执行。这意味着驱动程序需要能够处理进程之间虚拟内存上下文的切换,并且需要编写得非常稳定——因为内核驱动程序在内核模式下运行,如果一个崩溃,就会导致整个系统崩溃。内核驱动程序不适合除硬件设备之外的任何设备,因为它们需要管理访问权限才能安装或启动,并且因为它们消除了内核通常为崩溃程序提供的安全性,即它们本身崩溃,而不是整个系统崩溃。

长话短说:

  • 驱动程序使用本机 API 而不是 Win32 API
    • 这意味着驱动程序通常无法显示任何 UI。
  • 驱动程序需要管理内存以及如何显式地对内存进行分页——使用分页池和非分页池之类的东西。
  • 驱动程序需要处理进程上下文切换,而不是依赖于哪个进程在运行时恰好拥有页表。
  • 受限用户无法将驱动程序安装到内核中。
  • 驱动程序在处理器级别以特权运行。
  • 用户级程序中的错误会导致该程序进程的终止。驱动程序的故障会导致系统崩溃并出现蓝屏死机。
  • 驱动程序需要处理低级硬件位,例如中断和中断请求级别 (IRQL)。

Kernel drivers are programs written against Windows NT's native API (rather than the Win32 Subsystem's API) and which execute in kernel mode on the underlying hardware. This means that a driver needs to be able to deal with switching virtual memory contexts between processes, and needs to be written to be incredibly stable -- because kernel drivers run in kernel mode, if one crashes, it brings down the entire system. Kernel drivers are unsuitable for anything but hardware devices because they require administrative access to install or start, and because they remove the security the kernel normally provides to programs that crash -- namely, that they crash themselves and not the entire system.

Long story short:

  • Drivers use the native API rather than the Win32 API
    • This means that drivers generally cannot display any UI.
  • Drivers need to manage memory and how memory is paged explicitly -- using things like paged pool and nonpaged pool.
  • Drivers need to deal with process context switching and not depend on which process happens to have the page table while they're running.
  • Drivers cannot be installed into the kernel by limited users.
  • Drivers run with privileged rights at the processor level.
  • A fault in a user-level program results in termination of that program's process. A fault in a driver brings down the system with a Blue Screen of Death.
  • Drivers need to deal with low level hardware bits like Interrupts and Interrupt Request Levels (IRQLs).
一曲爱恨情仇 2024-11-14 07:31:12

它是在内核模式而不是用户模式下运行的代码。内核模式代码可以直接访问操作系统、硬件等的内部结构。

您总是编写内核模式模块来实现 设备驱动程序

It is code that runs in kernel mode rather than user mode. Kernel mode code has direct access to the internals of the OS, hardware etc.

Invariably you write kernel mode modules to implement device drivers.

无语# 2024-11-14 07:31:12

内核驱动程序是“应用程序”的低级实现。
因为它运行在内核上下文中,所以它有能力直接访问内核API和内存。

例如,内核驱动程序应用于:

  • 控制对文件的访问(密码保护、隐藏)
  • 允许访问非标准文件系统(如 ext、reiserfs、zfs 等)和设备
  • 真正的 API 挂钩
  • ...以及许多其他原因

如果您想了解更多信息,您可以使用您喜欢的搜索引擎搜索关键字“ring0”。

A kernel driver is a low-level implementation of an "application".
Because it runs in the kernel context, it has the ability to access the kernel API and memory directly.

For example, a kernel driver should be used to:

  • Control access to files (password protection,hiding)
  • Allow accessing non-standard filesystems (like ext, reiserfs, zfs and etc.) and devices
  • True API hooks
  • ...and for many other reasons

If you'd like to get know more, you can search for keyword "ring0" with your favorite search engine.

陪你搞怪i 2024-11-14 07:31:12

其他人从系统级别的角度解释了这种差异。
如果您使用 C++ 进行开发,则用户模式开发和内核模式开发存在以下差异。

  1. 未处理的异常会导致用户模式下的进程崩溃,但在内核模式下,它会导致整个系统崩溃(出现 BSOD)。
  2. 当用户模式进程在没有释放私有内存的情况下终止时,系统会隐式释放进程内存。但在内核模式下,系统启动后剩余内存空闲。
  3. 用户模式代码是在 PASSIVE_LEVEL 中编写和执行的。在内核模式下,有更多的IRQL级别。
  4. 使用单独的机器完成内核代码调试。但您可以在同一台机器上调试用户模式。
  5. 您不能在内核模式下使用所有 C++ 功能,例如异常处理和 STL。
  6. 入口点不同,在用户模式下,您使用main作为入口点。但在内核模式下,我们需要使用DriverEntry。
  7. 您不能在内核模式下使用 new 运算符,您需要显式重载它。

Others have explained the difference as the perspective of system level.
If you are doing development in C++, there are below differences in User mode development and kernel-mode development.

  1. Unhandled exceptions crash the process in User mode, but in kernel mode, it crashes the whole system(face BSOD).
  2. When the user-mode process terminates without free private memory, the system implicitly free process memory. But in kernel mode, remaining memory free after system boot.
  3. The user-mode code is written and execute in PASSIVE_LEVEL. In kernel mode, there are more IRQL level.
  4. Kernel code debugging done using separate machines. But you can debug user mode on same machine.
  5. you can't use all C++ functionality in kernel-mode such as Exception handling and STL.
  6. Entry points are different, in user mode, you use the main as the entry point. But in kernel mode, we need to use DriverEntry.
  7. You can't use new operator in kernel mode, you need to overload it explictly.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文