kcet-bench measures the cost of Windows kernel-mode hardware-enforced stack protection, the Windows 11 feature that turns on CET shadow stacks in the kernel. With it on, every kernel call also pushes the return address to a shadow stack, and every ret checks it. kcet-bench times kernel paths with few and many call/ret pairs, with the feature off and then on, and reports the difference for each path.
Each test sizes a batch to take 20-50 ms, runs 5 warm-up batches, then times 50 batches with QueryPerformanceCounter. It reports nanoseconds per unit: the median, p5, p95, and minimum over the 50 batches.
| Test | Operation | Unit |
|---|---|---|
syscall_shallow |
SetEvent on a manual-reset event that is already signaled |
call |
syscall_deep |
GetFileAttributesW on a 64-byte file in %TEMP%, through the I/O manager, the filesystem, and its filter drivers |
call |
ctx_switch |
Two threads on the same CPU pass control back and forth through two auto-reset events with SignalObjectAndWait. One round trip is two switches. |
switch |
thread_create |
CreateThread with a start routine that returns 0, then WaitForSingleObject and CloseHandle |
thread |
kernel_seh_baseline |
NtQueryInformationProcess(ProcessBasicInformation) into a valid buffer |
call |
kernel_seh |
The same call into a committed PAGE_NOACCESS page. The kernel faults when it copies the result out, and its own exception handler returns STATUS_ACCESS_VIOLATION. |
call |
The tool checks the result of every call. If a test gets an unexpected result, it stops, and the run file records the reason instead of numbers.
All measuring threads run at HIGH_PRIORITY_CLASS, pinned to one logical CPU, with power throttling turned off for the process. The executable is not marked /CETCOMPAT, so user-mode shadow stacks stay off and only the kernel's cost changes. run confirms that before it measures.
- Windows 11 on a CPU with shadow stacks: Intel 11th generation Core or later, or AMD Zen 3 or later.
- Memory integrity turned on for both settings. Kernel stack protection requires it, and keeping it on means only one thing changes between runs.
Download the latest release from the releases page. Unpack kcet-bench-<version>-windows-x86_64.zip and run kcet-bench.exe from the folder inside it. SHA256SUMS beside the archive holds its checksum. To build it yourself, see Development.
The setting changes only at boot, and the first minutes after a boot are noisy. For each boot:
-
Open Windows Security > Device security > Core isolation details. Turn Kernel-mode Hardware-enforced Stack Protection on or off, and leave Memory integrity on.
-
Restart Windows.
-
Run
wsl --shutdown, so the WSL virtual machine stops using CPU time. -
Close every other app.
-
Open PowerShell in the folder that holds
kcet-bench.exe, and run:.\kcet-bench.exe run
run reads the setting from Windows, so there is no label to type. If Windows booted less than 3 minutes ago, it waits until 3 minutes have passed. It then measures every test 3 times and writes each run to its own file in the results folder, such as results\off-boot2-run1.json. The boot and run numbers continue from the files already there. At the end it prints the comparison so far and the next step: which way to turn the setting before the next restart.
Repeat with the setting alternating from boot to boot: off, on, off, on. Stop when each setting has at least 3 boots. run warns when two boots in a row have the same setting, and when WSL or another virtual machine is running.
Keep everything else the same for every boot: the power plan, Microsoft Defender real-time protection, and any other antivirus or filter driver. Filter drivers take most of the time in syscall_deep, so a change there hides the kernel stack protection cost.
run refuses to start when memory integrity is not running, or when kernel stack protection runs in audit mode. It never overwrites a file. Its options:
--runs <n>: runs in this boot, 3 by default.--dir <folder>: the results folder,resultsby default.--cpu <n>: the logical CPU to pin to, 2 by default. Use the same CPU for every run. CPU 0 is not allowed, because it handles most interrupts. On a CPU with performance and efficiency cores, pick a performance core.--label <on|off>: refuse to run unless the system has this setting.
If the Device Guard query fails, run PowerShell as administrator.
.\kcet-bench.exe comparecompare reads every run file in results. To read other files or folders, name them: compare D:\old-results on-boot1-run1.json.
For each test, compare prints the median of the run medians for each label, the change from off to on in percent, and the spread of each label: the lowest and highest run median. A change is "within noise" when the difference between the two medians is smaller than the larger of the two spreads. The verdict needs at least 2 runs per label. The notes under the table name aborted runs, labels with fewer than 3 boots, and runs that mix Windows builds, CPUs, power plans, or pinned CPUs.
compare also runs on Linux, so you can read the files from WSL with cargo run --release -- compare /mnt/c/Users/<you>/kcet-bench/results.
Each run file holds the label, the time, the Windows build, the CPU, the power plan, the Win32_DeviceGuard state, every batch's time per unit, and the summary for each test.
Everything except run builds and tests on any OS, including Linux. run measures the Windows kernel, so it only works on Windows.
cargo fmt --all -- --check
cargo test --workspace
cargo clippy --workspace --all-targets -- -D warningsCI runs those three commands on Ubuntu and the last two on Windows, where the tests also call each measured kernel path. It also runs cargo audit and cargo machete. Linux Clippy skips the Windows-only code, so before you push a change to src/win/, also lint for the Windows target:
cargo clippy --workspace --all-targets --target x86_64-pc-windows-msvc -- -D warningsTo cross-build the Windows x86-64 executable from Linux or WSL2, use cargo-xwin:
cargo xwin build --release --target x86_64-pc-windows-msvcThe executable is target/x86_64-pc-windows-msvc/release/kcet-bench.exe. From WSL2, copy it to a Windows folder, such as /mnt/c/Users/<you>/kcet-bench/, and run it from there.
To pack the same archive and SHA256SUMS a release publishes, under dist/:
bash scripts/package-windows.shThe packaging script needs cargo-xwin 0.23.1, jq, zip, unzip, and GNU sha256sum. It checks the archive contents and the checksums before it reports success.
Licensed under the MIT License.