Repository navigation
Use NativeMemory instead of AllocHGlobal in WindowsIdentity and EventProvider - #136706
Merged
Merged
Conversation
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @bartonjs, @vcsjones, @dotnet/area-system-security |
Contributor
|
Tagging subscribers to this area: @dotnet/interop-contrib |
jkotas
reviewed
Oct 30, 2026
jkotas
reviewed
Oct 30, 2026
This was referenced Oct 30, 2026
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are recorded for the Windows identity and ETW native-memory allocation changes.
No open issues 🎉
What changed in this PR
This PR advances the allocation audit in #54297 by replacing local-heap allocations in Windows identity and ETW tracing code with NativeMemory. Together with #126544, it aims to remove the LocalAlloc import from a NativeAOT Web API executable.
Changes:
- Adds a
SafeNativeMemoryHandleand updates token-information interop and project references. - Migrates Windows identity buffers to native memory and pins the source-name buffer instead of allocating a copy.
- Replaces ETW session-buffer allocation and cleanup with
NativeMemory.AllocandFree.
| File | Description |
|---|---|
src/libraries/System.Security.Principal.Windows/src/System/Security/Principal/WindowsIdentity.cs |
Migrates authentication and token buffers; pins source-name bytes. |
src/libraries/System.Security.Principal.Windows/src/System.Security.Principal.Windows.csproj |
Includes the new handle and updated interop file. |
src/libraries/System.Private.CoreLib/src/System/Diagnostics/Tracing/EventProvider.cs |
Uses native memory for ETW session buffers. |
src/libraries/Common/src/Microsoft/Win32/SafeHandles/SafeNativeMemoryHandle.cs |
Adds a safe buffer backed by NativeMemory. |
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.GetTokenInformation_SafeNativeMemoryHandle.cs |
Updates token-information overloads to accept the new handle. |
Review effort: Balanced
jkotas
reviewed
Oct 31, 2026
… cast can overflow
jkotas
enabled auto-merge (squash)
October 31, 2026 06:14
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
contributes to #54297
WindowsIdentity and EtwEventProvider.GetSessionInfo allocate with AllocHGlobal, so a
dotnet new webapiaotexe imports LocalAlloc. this moves them to NativeMemory. with #126544 too, the exe no longer imports LocalAlloc.tested: Principal.Windows 120 and Tracing 55 tests pass (Tracing run as admin so the ETW tests run),
dumpbin /importsbefore and after.