Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: ci

on:
push:
branches: [main]
pull_request:

jobs:
logic:
name: Build, test, pack (ubuntu)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Restore
run: dotnet restore

- name: Build
run: dotnet build --no-restore -c Release

- name: Test
run: dotnet test --no-build -c Release

- name: Pack
run: dotnet pack --no-build -c Release -o artifacts/

- name: InfGen smoke test
run: |
dotnet tool install --prerelease --tool-path ./tools-out --add-source ./artifacts WindowsDriver.InfGen
./tools-out/infgen generate --manifest samples/VirtualAudio/manifest.json --out /tmp/virtualaudio.inf
./tools-out/infgen validate --inf /tmp/virtualaudio.inf

- name: Template smoke test
run: |
dotnet new install ./artifacts/WindowsDriver.Templates.*.nupkg
mkdir -p /tmp/tpl && pushd /tmp/tpl
dotnet new driver-solution -n SmokeDriver
cd SmokeDriver && dotnet new sln -n SmokeDriver
dotnet sln add SmokeDriver/SmokeDriver.csproj SmokeDriver.Tests/SmokeDriver.Tests.csproj
dotnet restore --source "${{ github.workspace }}/artifacts" --source https://api.nuget.org/v3/index.json
dotnet test
popd

- name: Upload packages
uses: actions/upload-artifact@v4
with:
name: nuget-packages
path: artifacts/*.nupkg

windows:
name: Build samples (windows)
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x

- name: Build + test
run: |
dotnet build -c Release
dotnet test --no-build -c Release

# NOTE: GitHub-hosted Windows runners do not ship the WDK, so the native
# KMDF shim and real INF signing cannot run here. Compile shim/WdsKmdfShim
# and run InfVerif/SignTool on a machine (or private runner) with the WDK.
# See docs/inf-and-signing.md for the full pipeline.
30 changes: 30 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Build artifacts
bin/
obj/
artifacts/
out/
publish/
*.user
*.suo
.vs/

# NuGet
*.nupkg
*.snupkg
packages/
nuget/

# Test results
TestResults/
*.trx
*.coverage
test-results/

# Generated INF output
*.inf.bak

# IDE
.idea/
*.swp
.DS_Store
Thumbs.db
59 changes: 59 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Changelog

All notable changes to the Windows Driver SDK are documented in this file.
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [0.1.0-preview.1] - 2026-11-18

First public preview of the SDK. Everything below ships in this bundle.

### Added

- `WindowsDriver.Sdk` core runtime:
- Driver lifecycle model (`IDriver`: `OnDriverEntryAsync` / `OnDeviceAddAsync` / `OnDriverUnloadAsync`)
and device lifecycle model (`DeviceBase`: prepare/release hardware, D0 entry/exit,
query-remove, surprise-removal) mirroring the WDF callback order.
- IO model: `IoQueue` with Sequential / Parallel / Manual dispatch modes (the WDF
`WdfIoQueueDispatch*` equivalents), `IoRequest` with buffered completion,
`IoResult` for request outcomes.
- `NtStatus` enum with the common NTSTATUS values plus severity helpers.
- `WinIoctl.CtlCode` implementing the exact `CTL_CODE` C macro bit layout, and the
common `FILE_DEVICE_*` / method / access constants.
- `DriverContext`, `DeviceContext`, `PropertyStore`, `IDriverRegistry` (+ in-memory
implementation), `IDriverLog` (+ console / file / composite loggers).
- `ByteRingBuffer`: thread-safe byte ring buffer used by audio and serial.
- Device-class modules:
- **Audio**: `PcmFormat` + `AudioFormatNegotiator`, `AudioDeviceStateMachine`,
`VolumeState` (dB/mute/ramp), `AudioIoctlCodes` contract, `VirtualAudioDevice`,
`SineSource` generator and `PcmWavWriter` capture.
- **HID**: `HidReportDescriptorBuilder` emitting real USB HID report descriptors
(main/global/local items, report IDs, automatic bit padding), a descriptor parser
for validation, the 9-byte HID class descriptor builder, `GamepadInputReport`
pack/unpack, and a `HidDevice` wired for descriptor + input-report IOCTLs.
- **Sensor**: `AccelerometerSimulator` (gravity + deterministic noise + impulses),
`AmbientLightSimulator` (day-cycle lux curve), `SensorDevice` publishing readings
over IOCTL and an event queue.
- **Serial**: `SerialLineConfig` (baud/data bits/parity/stop bits/flow control),
`VirtualSerialPort` loopback pair, `SerialDevice` with line-control IOCTLs and
TX/RX statistics.
- `WindowsDriver.Interop`:
- UMDF layer: C# contract mirrors of the key `IWDF*` interfaces (documented, without
invented COM IIDs), the C-shim export contract, and `ManagedDriverBootstrap` —
the entry point a native UMDF shim calls after hosting the .NET runtime via
`hostfxr`.
- KMDF layer: control-plane IOCTL contract (`KmdfIoctlCodes`), `KmdfControlPlane`
(real `CreateFileW` / `DeviceIoControl` P/Invoke client for talking to a KMDF
shim driver), and the request/event wire structs shared with the C shim.
- `Win32Native` P/Invoke declarations (CreateFile, DeviceIoControl, CloseHandle).
- `WindowsDriver.Testing`: `TestDriverHost` / `TestDevice` (in-memory device bus that
runs driver logic without Windows), `FakeTimeProvider` (advanceable .NET 8
`TimeProvider`), `CapturedLog`, `FakeRegistry`, and check helpers.
- `WindowsDriver.InfGen`: `dotnet` tool that generates a spec-compliant driver INF
from a JSON manifest (`infgen generate`) and lints an existing INF
(`infgen validate`).
- Four sample drivers with unit tests and INF manifests: **VirtualAudio**,
**HidGamepad**, **VirtualSensor**, **VirtualSerial**.
- `dotnet new` templates (`driver-umdf`, `driver-tests`, `driver-solution`).
- Install/uninstall/test-signing PowerShell scripts (`tools/`), a ready-to-build
KMDF shim driver skeleton in C (`shim/WdsKmdfShim/`), a GitHub Actions CI workflow,
and the full documentation set under `docs/`.
20 changes: 20 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project>

<!-- Shared build settings for every project in the Windows Driver SDK. -->
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>12.0</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<Version>0.1.0-preview.1</Version>
<Authors>Windows Driver SDK contributors</Authors>
<Company>Windows Driver SDK contributors</Company>
<NeutralLanguage>en-US</NeutralLanguage>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- CS1591: XML docs are encouraged but not enforced for public members. -->
<NoWarn>$(NoWarn);CS1591</NoWarn>
<Deterministic>true</Deterministic>
<InvariantGlobalization>false</InvariantGlobalization>
</PropertyGroup>

</Project>
14 changes: 14 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project>

<!-- Central package versions for the whole repository. -->
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>

<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.11.1" />
<PackageVersion Include="xunit" Version="2.9.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2026 Full Dive Research Society
Copyright (c) 2026 Windows Driver SDK contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
130 changes: 130 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
# Windows Driver SDK for .NET

Write Windows device drivers in C#. The SDK gives you a managed driver runtime
with the WDF programming model — driver/device lifecycle, IO queues, IOCTL
dispatch, NTSTATUS semantics — plus ready-made device-class modules for
**audio**, **HID**, **sensor** and **serial** devices, an INF generator, a
test host that runs your driver without Windows, and the native shim contracts
that take the same code to production.

```
┌────────────────────────────────────────────────────────────┐
│ Your driver: IDriver + DeviceBase subclass in pure C# │
├────────────────────────────────────────────────────────────┤
│ WindowsDriver.Sdk │
│ • runtime: lifecycle, IoQueue, IOCTL, NTSTATUS, logging │
│ • modules: Audio · HID · Sensor · Serial │
├────────────────────────────────────────────────────────────┤
│ Hosting (choose one) │
│ • WindowsDriver.Testing.TestDriverHost (unit tests) │
│ • UMDF shim (user-mode, WUDFHost) │
│ • KMDF control plane over the C shim (kernel reach) │
└────────────────────────────────────────────────────────────┘
```

## Why

Microsoft's Windows Driver Kit supports C/C++ for driver code (UMDF drivers are
C++/COM; kernel drivers are C). Managed code has never been officially
supported in kernel mode, and UMDF is C++-only in the box. This SDK fills the
gap the practical way:

- **Driver logic in C#** — the parts that iterate quickly (device logic, state
machines, protocol handling, policy) run in .NET 8.
- **Native where required** — the parts that must be native (COM activation in
WUDFHost, kernel-mode DDIs) are thin, frozen-ABI shims documented and
scaffolded in this repository (`shim/`).
- **Testable without Windows** — `TestDriverHost` runs your driver with a fake
clock and in-memory bus on any OS. The full sample suite (62 tests) runs on
Linux CI in under a second.

This is the same architecture commercial products (e.g. Jungo WinDriver's
user-mode .NET offering) and many in-house drivers use — but open, and with the
WDF-shaped API surface you already know.

## Packages

| Package | What it gives you |
| --- | --- |
| `WindowsDriver.Sdk` | Core runtime + Audio/HID/Sensor/Serial modules |
| `WindowsDriver.Interop` | UMDF shim contracts, KMDF control plane, Win32 P/Invoke |
| `WindowsDriver.Testing` | `TestDriverHost`, `FakeTimeProvider`, captured logging |
| `WindowsDriver.InfGen` | `infgen` dotnet tool: manifest → INF, INF lint |
| `WindowsDriver.Templates` | `dotnet new driver-umdf` / `driver-tests` / `driver-solution` |

## Quickstart

Prerequisites: [.NET 8 SDK](https://dotnet.microsoft.com/download/dotnet/8.0).
Building/deploying a real driver additionally needs the
[WDK](https://learn.microsoft.com/windows-hardware/drivers/download-the-wdk)
on a Windows machine.

```bash
# 1. Create a driver project from the template
dotnet new install WindowsDriver.Templates --prerelease
dotnet new driver-solution -n ContosoButton
cd ContosoButton && dotnet new sln -n ContosoButton
dotnet sln add ContosoButton/ContosoButton.csproj ContosoButton.Tests/ContosoButton.Tests.csproj

# 2. Test it — no Windows, no device, no VM
dotnet test

# 3. Generate the INF for deployment
dotnet tool install --prerelease --tool-path ./.tools WindowsDriver.InfGen
./.tools/infgen generate --manifest ContosoButton/ContosoButton.manifest.json
```

That is a complete driver: a `DeviceBase` subclass with IOCTL handlers, a
passing test, and an INF you can sign and deploy.

## Sample drivers (all with tests + INF manifests)

| Sample | Class | Highlights |
| --- | --- | --- |
| [VirtualAudio](samples/VirtualAudio/) | Media | PCM ring buffer, 44.1/48/96 kHz format negotiation, volume ramps, tone generator |
| [HidGamepad](samples/HidGamepad/) | HIDClass | Real USB HID report descriptor builder (6-axis + 12 buttons), report pack/unpack |
| [VirtualSensor](samples/VirtualSensor/) | Sensor | Accelerometer + ambient light simulators, IOCTL + event-queue publishing |
| [VirtualSerial](samples/VirtualSerial/) | Ports | Line config validation, loopback, null-modem pairs, break/framing faults |

## Documentation

| Doc | Content |
| --- | --- |
| [Getting started](docs/getting-started.md) | Install, first driver end-to-end, deploy |
| [Architecture](docs/architecture.md) | The managed-host model, layering, hosting paths |
| [UMDF guide](docs/umdf-guide.md) | Hosting C# drivers in WUDFHost, shim ABI, lifecycle mapping |
| [KMDF interop guide](docs/kmdf-interop-guide.md) | Kernel constraints, control plane, the C shim protocol |
| [Audio guide](docs/audio-guide.md) | Ring buffer, negotiation, the audio IOCTL contract |
| [HID guide](docs/hid-guide.md) | HID item encoding, descriptor building, report layout |
| [Sensor guide](docs/sensor-guide.md) | Simulators, sampling loop, SensorCx mapping |
| [Serial guide](docs/serial-guide.md) | Line config, loopback pairs, Windows serial stack |
| [INF and signing](docs/inf-and-signing.md) | Manifest schema, INF anatomy, test-signing, attestation |
| [Testing guide](docs/testing-guide.md) | TestDriverHost, fake clock, patterns |
| [CI/CD](docs/ci-cd.md) | GitHub Actions setup, WDK limitations on runners |
| [API reference](docs/api-reference.md) | Type-by-type summary of the SDK surface |

## Repository layout

```
src/WindowsDriver.Sdk core runtime + device-class modules
src/WindowsDriver.Interop UMDF/KMDF interop, Win32 P/Invoke
src/WindowsDriver.Testing test host helpers
src/WindowsDriver.InfGen infgen tool
src/WindowsDriver.Templates dotnet new templates
samples/ VirtualAudio, HidGamepad, VirtualSensor, VirtualSerial
tests/ SDK unit tests
shim/WdsKmdfShim KMDF shim driver skeleton (C, build with the WDK)
shim/UmdfShim UMDF COM shim design notes + ABI
tools/ Install-Driver.ps1, Uninstall-Driver.ps1, Enable-TestSigning.ps1
docs/ the documentation set
.github/workflows/ci.yml build + test + pack + smoke tests
```

## Status and support

Version 0.1.0-preview.1. The managed SDK surface is complete and tested (62
tests, all green). The KMDF C shim compiles as a WDK skeleton and implements
the full IOCTL contract; the UMDF C++/COM shim is specified and ABIs frozen,
with implementation notes in `shim/UmdfShim/README.md`.

License: MIT (see [LICENSE](LICENSE)).
Loading
Loading