Skip to content

Commit

Permalink
fix!: explicitly mark _KGDTENTRY64 and _KIDTENTRY64as opaque type…
Browse files Browse the repository at this point in the history
…s in bindgen

BREAKING CHANGE: defintions for `_KGDTENTRY64` and `_KIDTENTRY64` have been removed
  • Loading branch information
wmmc88 committed Jan 24, 2025
1 parent eb47e2f commit 85dc60f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 80 deletions.
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
86 changes: 6 additions & 80 deletions crates/wdk-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,96 +690,22 @@ 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
/// headers to be processed sucessfully
/// headers to be processed successfully
pub fn bindgen_header_contents(
&self,
api_subsets: impl IntoIterator<Item = ApiSubset>,
) -> 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!(r#"#include "{header}"\n"#))
})
.collect::<String>()
}

/// Configure a Cargo build of a library that depends on the WDK. This
Expand Down

0 comments on commit 85dc60f

Please sign in to comment.