Skip to content

Avoid duplicate process attach for retained PAL modules - #6059

Merged
hoyosjs merged 1 commit into
dotnet:mainfrom
matouskozak:fix-dbgshim-repeat-module-attach
Sep 25, 2026
Merged

hoyosjs merged 1 commit into
dotnet:mainfrom
matouskozak:fix-dbgshim-repeat-module-attach

Conversation

@matouskozak

@matouskozak matouskozak commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Do not send DLL_PROCESS_ATTACH again when the PAL reuses an existing module registration. A second attach can initialize the debugger transport lock twice and trigger its assertion.

LOADAddModule now reports whether it found an existing module. LOADRegisterLibraryDirect returns that module before calling DllMain again.

Return the existing module registration without sending DLL_PROCESS_ATTACH again. Preserve reference counting and first-load initialization.

Co-authored-by: Copilot App <[email protected]>
Copilot-Session: ac7ee271-d7df-4244-91de-e4758a4fe909
Copilot-Session: 76e25dcf-2f3d-4a88-929c-0e62afa57c6a
Copilot AI lite review requested due to automatic review settings September 23, 2026 08:34
@matouskozak
matouskozak requested a review from a team as a code owner September 23, 2026 08:34

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

No unresolved review comments were identified.

Review effort: Lite
Findings: None

What changed in this PR

Prevents duplicate DLL_PROCESS_ATTACH calls when the PAL reuses an existing module registration.

Changes:

  • Tracks duplicate module registrations.
  • Skips repeated DllMain initialization while preserving module reuse.
File Summary
src/​shared/​pal/​src/​loader/​module.cpp Updates module registration and duplicate-load handling.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

@hoyosjs

hoyosjs commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

This change should be done in the runtime, here it has no bearing on the attach I see that the problem is not the debugger but the DCB that gets initialized in loading the DBI through DllMain. This mostly ports dotnet/runtime#112285

@hoyosjs
hoyosjs merged commit 9fe82e7 into dotnet:main Sep 25, 2026
23 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 25, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants