Awesome
windows-kernel-rs
Note: this is still work in progress!
This is a Windows kernel framework in Rust that consists of windows-kernel-sys, a crate that provides low-level unsafe bindings generated using bindgen, and windows-kernel-rs, a crate that provides safe abstractions in Rust on top.
Features
To give you an idea of whether these crates are useful to you, here is a non-exhaustive overview of the features that are currently supported and that are more or less planned:
-
KernelModule
to provide safe entry and exit points to your driver. - Batteries included: panic handler, global allocator, etc.
- Rust error handling using
Result
. - Device API to quickly set up with devices with a trait to provide the various callbacks.
- Support for reading from and writing to devices.
- Support for handling device I/O controls.
- Basic safe abstraction on top of I/O Request Packets (IRPs) using Rust ownership to model their lifetimes.
- Basic support for Memory Descriptor Lists (MDLs).
- Version API to query the current version of Microsoft Windows.
- Affinity API to run closures on a specific CPU or all CPUs in the system.
- Device API
-
FastMutex
(similar toMutex
) based on theFAST_MUTEX
API. -
PushLock
(similar toRwLock
) based on theEX_PUSH_LOCK
API. - Abstraction for processes and process attachments to execute code in the context of a process.
- Abstraction for sections.
- Basic x86-64 intrinsics.
- More complete model of IRP handling.
- Support for x86 and AArch64.
Articles
Note: this framework may progress faster than I can keep my articles up-to-date. They may currently be due for a bit of a rewrite to reflect some of the changes that made it into this repository since I have written the articles.
In addition, there are articles that cover implementing Windows kernel drivers in Rust from the ground up, including corresponding examples provided as part of this repository:
- Prerequisites
- Hello World - 02-hello-world
- Generating Bindings - 03-generating-bindings
- Safe Framework - 04-safe-framework
- Creating Devices - 05-creating-devices - user/05-creating-devices
- Reading and Writing - 06-reading-and-writing - user/06-reading-and-writing
- I/O Controls - 07-io-controls - user/07-io-controls