Skip to content

Support thread-safe local statics#44

Merged
ntoskrnl7 merged 1 commit into
mainfrom
codex/thread-safe-local-statics
Jun 21, 2026
Merged

Support thread-safe local statics#44
ntoskrnl7 merged 1 commit into
mainfrom
codex/thread-safe-local-statics

Conversation

@ntoskrnl7

@ntoskrnl7 ntoskrnl7 commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add compiler TLS compatibility initialization for MSVC thread-safe function-local statics in kernel-mode drivers.
  • Remove the /Zc:threadSafeInit- opt-out from CMake, installed CMake package settings, and NuGet MSBuild targets.
  • Add a driver test that exercises function-local static initialization.
  • Update feature coverage docs to distinguish supported function-local statics from unsupported true per-thread thread_local storage.
  • Harden NuGet packaging and consumer-test scripts so local and CI packaging use nuget.exe, allow an explicit Visual Studio major version override, and avoid copying stale test build directories.

Why

MSVC's thread-safe local static initialization emits compiler TLS accesses such as _Init_thread_epoch lookups through the TLS vector. Kernel drivers do not have a normal user-mode TEB TLS vector, so the previous /Zc:threadSafeInit- workaround disabled the compiler feature. This change initializes a driver-wide compiler TLS image from the PE TLS template and installs that TLS slot vector on each processor so the compiler-managed static-local initialization path works.

This is intentionally not claiming full C++ thread_local support. The docs still call out true per-thread TLS as unsupported.

Validation

  • Rebuilt test/cmake/driver/build_2022_x64 Debug and confirmed the generated test driver contains a TLS directory and _Init_thread_* local-static codegen.
  • Loaded/unloaded the test driver in the Windows 10 x64 VM; the runtime output included function-local static initialized successfully and all 8 GoogleTest tests passed.
  • Built NuGet prebuilt libraries for x64/ARM64 Debug/Release with Windows SDK/WDK 10.0.22000.0.
  • Packed crtsys.0.1.17.nupkg with nuget.exe pack.
  • Ran NuGet driver consumer tests for x64/ARM64 Debug/Release locally; after the CI fix, reran x64 Release locally with -VisualStudioMajorVersion 16.
  • Packed GitHub release assets and ran prebuilt zip CMake consumer tests for x64/ARM64 Debug/Release.

Notes

The packaging step still emits the existing non-fatal NU5128 warning for the native package, and driver links still show the existing libcntpr duplicate-symbol /FORCE warnings.

@ntoskrnl7 ntoskrnl7 force-pushed the codex/thread-safe-local-statics branch from 1ba034b to 3e6844e Compare June 21, 2026 14:29
@ntoskrnl7 ntoskrnl7 marked this pull request as ready for review June 21, 2026 15:10
@ntoskrnl7 ntoskrnl7 changed the title [codex] Support thread-safe local statics Support thread-safe local statics Jun 21, 2026
@ntoskrnl7 ntoskrnl7 merged commit 92bf29b into main Jun 21, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant