Skip to content

Make DrvFs initialization callback lifetime-safe - #41218

Merged
Ben Hillis (benhillis) merged 2 commits into
microsoft:masterfrom
benhillis:user/benhill/lifetime-safe-drvfs-callback
Aug 20, 2026
Merged

Make DrvFs initialization callback lifetime-safe#41218
Ben Hillis (benhillis) merged 2 commits into
microsoft:masterfrom
benhillis:user/benhill/lifetime-safe-drvfs-callback

Conversation

@benhillis

@benhillis Ben Hillis (benhillis) commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

DrvFs initialization callbacks could outlive the utility VM instance they were created for when VM shutdown or replacement occurred concurrently.

This change:

  • routes DrvFs initialization through the owning user session
  • serializes callback execution with utility VM shutdown and replacement
  • avoids retaining a raw WslCoreVm pointer in instance callbacks

Validation

  • Existing WSL1, WSL2, and WSLC test suites pass

Route DrvFs initialization through the owning user session so VM shutdown and replacement are synchronized with callback execution.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7169104c-ee30-445e-b133-49bfa478ef12
Copilot AI lite review requested due to automatic review settings July 31, 2026 15:06

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.

Pull request overview

This PR makes DrvFs initialization callbacks lifetime-safe by routing them through the owning LxssUserSessionImpl, synchronizing callback execution with VM teardown/replacement, and ignoring callbacks that target an older VM generation (via runtime ID checks).

Changes:

  • Plumbs an InitializeDrvFsCallback into WslCoreVm creation and stores it for instance creation.
  • Introduces a session-owned, generation-checked DrvFs init trampoline (LxssUserSessionImpl::s_InitializeDrvFs) using weak_from_this().
  • Removes the VM-owned static DrvFs callback wrapper and uses the injected callback instead.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/windows/service/exe/WslCoreVm.h Adds InitializeDrvFsCallback type/member and extends Create/ctor signatures to accept the callback.
src/windows/service/exe/WslCoreVm.cpp Stores the callback and forwards it to instance creation; removes the old static wrapper.
src/windows/service/exe/LxssUserSession.h Makes LxssUserSessionImpl enable_shared_from_this and declares the new static callback trampoline.
src/windows/service/exe/LxssUserSession.cpp Creates a VM-generation-bound callback via weak_from_this() and implements the generation-checked trampoline.

Comment thread src/windows/service/exe/WslCoreVm.cpp
@benhillis
Ben Hillis (benhillis) marked this pull request as ready for review August 13, 2026 19:45
@benhillis
Ben Hillis (benhillis) requested a review from a team as a code owner August 13, 2026 19:45
Reject an empty callback at VM creation so a missing callback fails deterministically instead of throwing std::bad_function_call from a later process creation path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7cf83647-6fbe-47bb-a4df-888a6abed9de
Copilot AI review requested due to automatic review settings August 19, 2026 21: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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@benhillis
Ben Hillis (benhillis) merged commit a454dbd into microsoft:master Aug 20, 2026
9 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.

3 participants