Skip to content

Make DrvFs initialization callback lifetime-safe - #41218

Draft
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:user/benhill/lifetime-safe-drvfs-callback
Draft

Make DrvFs initialization callback lifetime-safe#41218
benhillis wants to merge 1 commit into
microsoft:masterfrom
benhillis:user/benhill/lifetime-safe-drvfs-callback

Conversation

@benhillis

@benhillis benhillis commented Jul 31, 2026

Copy link
Copy Markdown
Member

Summary

  • route DrvFs initialization callbacks through the owning user session
  • synchronize callback execution with VM shutdown and replacement
  • ignore callbacks associated with an older VM generation

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 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 on lines +86 to 90
std::unique_ptr<WslCoreVm> WslCoreVm::Create(
_In_ const wil::shared_handle& UserToken, _In_ wsl::core::Config&& VmConfig, _In_ const GUID& VmId, _In_ InitializeDrvFsCallback InitializeDrvFs)
{
auto newInstance = std::unique_ptr<WslCoreVm>{new WslCoreVm{std::move(VmConfig)}};
auto newInstance = std::unique_ptr<WslCoreVm>{new WslCoreVm{std::move(VmConfig), std::move(InitializeDrvFs)}};
try
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.

2 participants