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
4 changes: 2 additions & 2 deletions crates/wdk-build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

//! Build script for the `wdk-build` crate
//!
//! This provides a `nightly_feature` to the `wdk-build` crate, so that it can
//! conditionally enable nightly features.
//! This provides a `nightly_toolchain` feature to the `wdk-build` crate, so
//! that it can conditionally enable unstable features.

fn main() {
println!("cargo::rustc-check-cfg=cfg(nightly_toolchain)");
Expand Down
2 changes: 2 additions & 0 deletions crates/wdk-build/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ impl BuilderExt for Builder {
.blocklist_item("ExAllocatePoolWithQuotaTag") // Deprecated
.blocklist_item("ExAllocatePoolWithTagPriority") // Deprecated
.blocklist_item("ExAllocatePool") // Deprecated
.opaque_type("_KGDTENTRY64") // No definition in WDK
.opaque_type("_KIDTENTRY64") // No definition in WDK
// FIXME: bitfield generated with non-1byte alignment in _MCG_CAP
.blocklist_item(".*MCG_CAP(?:__bindgen.*)?")
.blocklist_item(".*WHEA_XPF_MCA_SECTION")
Expand Down
142 changes: 63 additions & 79 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ impl Config {
}

/// Returns a [`String`] containing the contents of a header file designed
/// for [`bindgen`](https://docs.rs/bindgen) to processs
/// for [`bindgen`](https://docs.rs/bindgen) to process
///
/// The contents contain `#include`'ed headers based off the [`ApiSubset`]
/// and [`Config`], as well as any additional definitions required for the
Expand All @@ -686,85 +686,11 @@ impl Config {
) -> String {
api_subsets
.into_iter()
.fold(String::new(), |mut acc, api_subset| {
acc.push_str(
self.headers(api_subset)
.fold(String::new(), |mut acc, header| {
acc.push_str(r#"#include ""#);
acc.push_str(&header);
acc.push_str("\"\n");
acc
})
.as_str(),
);

if api_subset == ApiSubset::Base
&& matches!(
self.driver_config,
DriverConfig::Wdm | DriverConfig::Kmdf(_)
)
{
// TODO: Why is there no definition for this struct? Maybe blocklist this struct
// in bindgen.
acc.push_str(
r"
typedef union _KGDTENTRY64
{
struct
{
unsigned short LimitLow;
unsigned short BaseLow;
union
{
struct
{
unsigned char BaseMiddle;
unsigned char Flags1;
unsigned char Flags2;
unsigned char BaseHigh;
} Bytes;
struct
{
unsigned long BaseMiddle : 8;
unsigned long Type : 5;
unsigned long Dpl : 2;
unsigned long Present : 1;
unsigned long LimitHigh : 4;
unsigned long System : 1;
unsigned long LongMode : 1;
unsigned long DefaultBig : 1;
unsigned long Granularity : 1;
unsigned long BaseHigh : 8;
} Bits;
};
unsigned long BaseUpper;
unsigned long MustBeZero;
};
unsigned __int64 Alignment;
} KGDTENTRY64, *PKGDTENTRY64;

typedef union _KIDTENTRY64
{
struct
{
unsigned short OffsetLow;
unsigned short Selector;
unsigned short IstIndex : 3;
unsigned short Reserved0 : 5;
unsigned short Type : 5;
unsigned short Dpl : 2;
unsigned short Present : 1;
unsigned short OffsetMiddle;
unsigned long OffsetHigh;
unsigned long Reserved1;
};
unsigned __int64 Alignment;
} KIDTENTRY64, *PKIDTENTRY64;
",
);
}
acc
.flat_map(|api_subset| {
self.headers(api_subset)
.map(|header| format!("#include \"{header}\"\n"))
})
.collect::<String>()
}

/// Configure a Cargo build of a library that depends on the WDK. This
Expand Down Expand Up @@ -1332,6 +1258,64 @@ mod tests {
assert_eq!(CpuArchitecture::try_from_cargo_str("arm"), None);
}

mod bindgen_header_contents {
use super::*;
use crate::{KmdfConfig, UmdfConfig};

#[test]
fn wdm() {
let config = with_env(&[("CARGO_CFG_TARGET_ARCH", "x86_64")], || Config {
driver_config: DriverConfig::Wdm,
..Default::default()
});

assert_eq!(
config.bindgen_header_contents([ApiSubset::Base]),
r#"#include "ntifs.h"
#include "ntddk.h"
"#,
);
}

#[test]
fn kmdf() {
let config = with_env(&[("CARGO_CFG_TARGET_ARCH", "x86_64")], || Config {
driver_config: DriverConfig::Kmdf(KmdfConfig {
kmdf_version_major: 1,
target_kmdf_version_minor: 33,
minimum_kmdf_version_minor: None,
}),
..Default::default()
});

assert_eq!(
config.bindgen_header_contents([ApiSubset::Base, ApiSubset::Wdf]),
r#"#include "ntifs.h"
#include "ntddk.h"
#include "wdf.h"
"#,
);
}

#[test]
fn umdf() {
let config = with_env(&[("CARGO_CFG_TARGET_ARCH", "aarch64")], || Config {
driver_config: DriverConfig::Umdf(UmdfConfig {
umdf_version_major: 2,
target_umdf_version_minor: 15,
minimum_umdf_version_minor: None,
}),
..Default::default()
});

assert_eq!(
config.bindgen_header_contents([ApiSubset::Base, ApiSubset::Wdf]),
r#"#include "windows.h"
#include "wdf.h"
"#,
);
}
}
mod compute_wdffunctions_symbol_name {
use super::*;
use crate::{KmdfConfig, UmdfConfig};
Expand Down