MCPcopy Index your code
hub / github.com/StephanvanSchaik/windows-kernel-rs

github.com/StephanvanSchaik/windows-kernel-rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
241 symbols 381 edges 50 files 26 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

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:

  • [x] KernelModule to provide safe entry and exit points to your driver.
  • [x] Batteries included: panic handler, global allocator, etc.
  • [x] Rust error handling using Result.
  • [x] Device API to quickly set up with devices with a trait to provide the various callbacks.
  • [x] Support for reading from and writing to devices.
  • [x] Support for handling device I/O controls.
  • [x] Basic safe abstraction on top of I/O Request Packets (IRPs) using Rust ownership to model their lifetimes.
  • [x] Basic support for Memory Descriptor Lists (MDLs).
  • [x] Version API to query the current version of Microsoft Windows.
  • [x] Affinity API to run closures on a specific CPU or all CPUs in the system.
  • [x] Device API
  • [x] FastMutex (similar to Mutex) based on the FAST_MUTEX API.
  • [x] PushLock (similar to RwLock) based on the EX_PUSH_LOCK API.
  • [x] Abstraction for processes and process attachments to execute code in the context of a process.
  • [x] Abstraction for sections.
  • [x] 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:

  1. Prerequisites
  2. Hello World - 02-hello-world
  3. Generating Bindings - 03-generating-bindings
  4. Safe Framework - 04-safe-framework
  5. Creating Devices - 05-creating-devices - user/05-creating-devices
  6. Reading and Writing - 06-reading-and-writing - user/06-reading-and-writing
  7. I/O Controls - 07-io-controls - user/07-io-controls

Extension points exported contracts — how you extend this code

KernelModule (Interface)
(no doc) [4 implementers]
windows-kernel-rs/src/lib.rs
DeviceOperations (Interface)
(no doc) [3 implementers]
windows-kernel-rs/src/device.rs
IntoResult (Interface)
(no doc) [1 implementers]
windows-kernel-rs/src/error.rs

Core symbols most depended-on inside this repo

into_result
called by 12
windows-kernel-rs/src/error.rs
as_ptr
called by 8
windows-kernel-rs/src/process.rs
into
called by 7
winioctl/src/ioctl.rs
stack_location
called by 7
windows-kernel-rs/src/request.rs
build
called by 6
windows-kernel-build/src/lib.rs
irp
called by 6
windows-kernel-rs/src/request.rs
as_slice
called by 6
windows-kernel-rs/src/user_ptr.rs
get_km_dir
called by 5
windows-kernel-build/src/lib.rs

Shape

Method 122
Function 63
Class 38
Enum 15
Interface 3

Languages

Rust91%
C9%

Modules by API surface

windows-kernel-rs/src/device.rs32 symbols
windows-kernel-rs/src/request.rs17 symbols
windows-kernel-sys/src/wrapper.c14 symbols
windows-kernel-rs/src/memory.rs13 symbols
windows-kernel-rs/src/sync/fast_mutex.rs11 symbols
windows-kernel-rs/src/user_ptr.rs10 symbols
windows-kernel-rs/src/sync/push_lock.rs10 symbols
windows-kernel-rs/src/process.rs10 symbols
windows-kernel-rs/src/mdl.rs9 symbols
windows-kernel-rs/src/section.rs8 symbols
windows-kernel-rs/src/ioctl.rs8 symbols
07-io-controls/src/lib.rs8 symbols

For agents

$ claude mcp add windows-kernel-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact