Skip to content

Commit

Permalink
docs!: enable rustdoc lints and resolve errors
Browse files Browse the repository at this point in the history
BREAKING CHANGE: renames DriverConfig::KMDFConfig and DriverConfig::UMDFConfig to DriverConfig::KMDF and DriverConfig::UMDF, respectively.
  • Loading branch information
wmmc88 committed Oct 20, 2023
1 parent 9c1998e commit 136014b
Show file tree
Hide file tree
Showing 23 changed files with 404 additions and 841 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

This repo is a collection of Rust crates that enable developers to develop Windows Drivers in Rust. It is the intention to support both WDM and WDF driver development models. This repo contains the following crates:

* [wdk-build](./crates/wdk-build): A library to configure a Cargo build script for binding generation and downstream linking of the WDK (Windows Developer Kit). While this crate is written to be flexible with different WDK releases and different WDF version, it is currently only tested for NI eWDK, KMDF 1.33, UMDF 2.33, and WDM Drivers. There may be missing linker options for older DDKs.
* [wdk-build](./crates/wdk-build): A library to configure a Cargo build script for binding generation and downstream linking of the WDK (Windows Driver Kit). While this crate is written to be flexible with different WDK releases and different WDF version, it is currently only tested for NI eWDK, KMDF 1.33, UMDF 2.33, and WDM Drivers. There may be missing linker options for older DDKs.
* [wdk-sys](./crates/wdk-sys): Direct FFI bindings to APIs available in the Windows Development Kit (WDK). This includes both autogenerated ffi bindings from `bindgen`, and also manual re-implementations of macros that bindgen fails to generate.
* [wdk](./crates/wdk): Safe idiomatic bindings to APIs available in the Windows Development Kit (WDK)
* [wdk-panic](./crates/wdk-panic/): Default panic handler implementations for programs built with WDK
Expand Down
1 change: 1 addition & 0 deletions crates/sample-kmdf-driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#![deny(clippy::pedantic)]
#![deny(clippy::nursery)]
#![deny(clippy::cargo)]
#![deny(clippy::unnecessary_safety_doc)]

extern crate alloc;

Expand Down
37 changes: 36 additions & 1 deletion crates/wdk-alloc/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,37 @@
// Copyright (c) Microsoft Corporation
// License: MIT OR Apache-2.0

//! Allocator implementation to use with `#[global_allocator]` to allow use of
//! [`core::alloc`].
//!
//! # Example
//! ```rust, no_run
//! #[cfg(not(test))]
//! use wdk_alloc::WDKAllocator;
//!
//! #[cfg(not(test))]
//! #[global_allocator]
//! static GLOBAL_ALLOCATOR: WDKAllocator = WDKAllocator;
//! ```
#![no_std]
#![deny(warnings)]
#![deny(missing_docs)]
#![deny(clippy::all)]
#![deny(clippy::pedantic)]
#![deny(clippy::nursery)]
#![deny(clippy::cargo)]
#![deny(clippy::undocumented_unsafe_blocks)]
#![deny(clippy::unnecessary_safety_doc)]
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(rustdoc::private_intra_doc_links)]
#![deny(rustdoc::missing_crate_level_docs)]
#![deny(rustdoc::invalid_codeblock_attributes)]
#![deny(rustdoc::invalid_html_tags)]
#![deny(rustdoc::invalid_rust_codeblocks)]
#![deny(rustdoc::bare_urls)]
#![deny(rustdoc::unescaped_backticks)]
#![deny(rustdoc::redundant_explicit_links)]

use core::alloc::{GlobalAlloc, Layout};

Expand All @@ -17,6 +42,9 @@ use wdk_sys::{
SIZE_T,
ULONG,
};

/// Allocator implementation to use with `#[global_allocator]` to allow use of
/// [`core::alloc`].
pub struct WDKAllocator;

// The value of memory tags are stored in little-endian order, so it is
Expand All @@ -32,10 +60,17 @@ lazy_static! {
);
}

// SAFETY: This is safe because the WDK allocator:
// 1. can never unwind since it can never panic
// 2. has implementations of alloc and dealloc that maintain layout
// constraints (FIXME: Alignment of the layout is currenty not
// supported)
unsafe impl GlobalAlloc for WDKAllocator {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
let ptr = ExAllocatePool2(POOL_FLAG_NON_PAGED, layout.size() as SIZE_T, *RUST_TAG);
assert!(!ptr.is_null(), "wdk-alloc failed to allocate memory.");
if ptr.is_null() {
return core::ptr::null_mut();
}
ptr.cast()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/wdk-build/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
edition.workspace = true
name = "wdk-build"
version = "0.1.0"
description = "A library to configure a Cargo build script for binding generation and downstream linking of the WDK (Windows Developer Kit)"
description = "A library to configure a Cargo build script for binding generation and downstream linking of the WDK (Windows Driver Kit)"
repository.workspace = true
readme.workspace = true
license.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions crates/wdk-build/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
use bindgen::Builder;

use crate::{CPUArchitecture, Config, ConfigError, DriverConfig};

/// An extension trait that provides a way to create a [`bindgen::Builder`]
/// configured for generating bindings to the wdk
pub trait BuilderExt {
/// Returns a `bindgen::Builder` with the default configuration for
/// generation of bindings to the WDK
Expand Down Expand Up @@ -59,13 +62,13 @@ impl BuilderExt for Builder {
DriverConfig::WDM() => {
vec![]
}
DriverConfig::KMDFConfig(kmdf_config) => {
DriverConfig::KMDF(kmdf_config) => {
vec![
format!("KMDF_VERSION_MAJOR={}", kmdf_config.kmdf_version_major),
format!("KMDF_VERSION_MINOR={}", kmdf_config.kmdf_version_minor),
]
}
DriverConfig::UMDFConfig(umdf_config) => {
DriverConfig::UMDF(umdf_config) => {
let mut umdf_definitions = vec![
format!("UMDF_VERSION_MAJOR={}", umdf_config.umdf_version_major),
format!("UMDF_VERSION_MINOR={}", umdf_config.umdf_version_minor),
Expand Down
Loading

0 comments on commit 136014b

Please sign in to comment.