Make DrvFs initialization callback lifetime-safe - #41218
Draft
benhillis wants to merge 1 commit into
Draft
Conversation
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
Contributor
There was a problem hiding this comment.
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
InitializeDrvFsCallbackintoWslCoreVmcreation and stores it for instance creation. - Introduces a session-owned, generation-checked DrvFs init trampoline (
LxssUserSessionImpl::s_InitializeDrvFs) usingweak_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 |
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.
Summary