microsoft / microsoft/Windows-driver-samples

ThrottleLimit calculation is incorrect on systems with more than one physical processor, breaking the build. (Added bonus: inf2cat travels through time to break the build)

Open
#1,313 1 comment 0 reactions 1 assignee View on GitHub

@v-junyli is already working on this.

Since Sep 8, 2025.

bug
Dominant language
C
Stars
7.8k
Forks
5k
Avg merge
3d 17h
Merged PRs (30d)
7

Description

The `ThrottleLimit` argument is currently implemented as follows:

https://github.com/microsoft/Windows-driver-samples/blob/7bc5255321145137d51beff5cc450932cb8db8b7/Build-SampleSet.ps1#L20-L25

However, this CIM query actually returns an array of values representing the logical processor cound per physical socket, rather than just a single integer:

```
PS C:\Users\Graham> $procs = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
PS C:\Users\Graham> $procs.GetType()

IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Object[] System.Array

PS C:\Users\Graham> $procs
56
56
```

As such, attempting to run the build without specifying the `-ThrottleLimit` argument results in an error when the script attempts to multiply the array by 5:

```
InvalidOperation: C:\Users\Graham\source\repos\Windows-driver-samples\Build-SampleSet.ps1:24
Line |
24 | $ThrottleLimit = $ThrottleFactor * $LogicalProcessors
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| Method invocation failed because [System.Object[]] does not contain a method named 'op_Multiply'.
```

The code should probably be something like this instead:

```ps
$LogicalProcessorsList = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$LogicalProcessors = ($LogicalProcessorsList | Measure-Object -Sum).Sum
```

Except... this doesn't really work. For some inexplicable reason, making this change causes the powershell script itself to work just fine without needing to specify `-ThrottleLimit`, but suddenly every single target fails to build due to `inf2cat.exe` exiting with a bad return code. Example error message:

```
Windows-driver-samples\packages\Microsoft.Windows.WDK.x64.10.0.26100.4204\c\build\10.0.26100.0\WindowsDriver.common.targets(1432,5): error MSB6006: "inf2cat.exe" exited with code -2. [C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\defect_toastmon.vcxproj]
```

Initially I thought that it was something downstream not liking that I got rid of it being an array, so I swapped the code to this:

```ps
$LogicalProcessorsList = (Get-CIMInstance -Class 'CIM_Processor' -Verbose:$false).NumberOfLogicalProcessors
$LogicalProcessors = @(($LogicalProcessorsList | Measure-Object -Sum).Sum)
```

This did not fix it, but instead I noticed that a completely random subset of projects would fail to build each time, seemingly nondeterministically.

I looked into the log files and found the following:

```
Building 'defect_toastmon' with toolset 'WindowsKernelModeDriver10.0' and the 'Universal' target platform.
Stamping x64\Debug\defect_toastmon.inf
Stamping [Version] section with DriverVer=07/24/2025,0.32.47.39
defect_toastmon.c
wmi.c
Generating Code...
defect_toastmon.vcxproj -> C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\x64\Debug\defect_toastmon.sys
Done Adding Additional Store
Successfully signed: C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\x64\Debug\defect_toastmon.sys

Driver is 'Universal'.
........................
Signability test failed.

Errors:
22.9.7: DriverVer set to a date in the future (postdated DriverVer not allowed) in defect_toastmon\defect_toastmon.inf.

Warnings:
None
C:\Users\Graham\source\repos\Windows-driver-samples\packages\Microsoft.Windows.WDK.x64.10.0.26100.4204\c\build\10.0.26100.0\WindowsDriver.common.targets(1432,5): error MSB6006: "inf2cat.exe" exited with code -2. [C:\Users\Graham\source\repos\Windows-driver-samples\tools\dv\samples\DV-FailDriver-WDM\driver\defect_toastmon.vcxproj]
```

Somehow these fixes are making inf2cat think the DriverVer is... in the future? What? I'm now deeply confused. I feel like maybe parallelism is somehow breaking the order of operations here and resulting in a weird race condition with inf2cat, but I'm very much questioning my sanity here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.