Skip to content

Implement the WSLC plugin API#40521

Merged
OneBlue merged 26 commits into
masterfrom
user/oneblue/plugin-api-wslc
May 16, 2026
Merged

Implement the WSLC plugin API#40521
OneBlue merged 26 commits into
masterfrom
user/oneblue/plugin-api-wslc

Conversation

@OneBlue
Copy link
Copy Markdown
Collaborator

@OneBlue OneBlue commented May 13, 2026

Summary of the Pull Request

This change implements the WSLC plugin API.

Notable design changes:

  • All plugins are only loaded once, by wslservice.exe
  • Plugins remain loaded regardless of the WSL policies registry keys
  • User errors originated from plugins clearly say which plugin the error comes from

PR Checklist

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

Copilot AI review requested due to automatic review settings May 13, 2026 06:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 implements the WSLC plugin API by extending the WSL plugin surface and wiring WSLC session/container/image notifications (plus a small WSLC control API) through wslservice.exe to loaded plugins, with corresponding end-to-end test coverage updates.

Changes:

  • Adds a WSLC-facing notifier COM interface and threads it through WSLC session creation and container/image lifecycle to notify plugins.
  • Extends WslPluginApi.h and PluginManager with WSLC plugin hooks and WSLC API calls (mount/unmount, create process, process IO helpers).
  • Refactors/extends Windows tests and the test plugin to validate WSLC callbacks and API calls.

Reviewed changes

Copilot reviewed 24 out of 25 changed files in this pull request and generated 15 comments.

Show a summary per file
File Description
test/windows/WSLCTests.cpp Switches to shared WSLC E2E helpers and updates session-list struct usage.
test/windows/wslc/e2e/WSLCE2EHelpers.cpp Updates local registry helper to ensure the registry image exists in the target session.
test/windows/testplugin/Plugin.cpp Adds WSLC hook implementations and exercises WSLC plugin API calls.
test/windows/PluginTests.h Extends test-mode enum with WSLC test scenarios.
test/windows/PluginTests.cpp Adds new WSLC plugin API tests (success, pull notification, rejection paths).
test/windows/Common.h / Common.cpp Centralizes LoadTestImage and COM error validation helpers for reuse.
src/windows/wslcsession/WSLCSessionFactory.h / .cpp Threads IWSLCPluginNotifier into session initialization.
src/windows/wslcsession/WSLCSession.h / .cpp Stores notifier and emits image-created/image-deleted notifications; passes notifier to containers.
src/windows/wslcsession/WSLCContainer.h / .cpp Emits container-start/container-stopping notifications via the notifier.
src/windows/wslc/services/SessionService.cpp Updates to renamed session-list struct.
src/windows/service/inc/wslc.idl Introduces IWSLCPluginNotifier, changes WSLC session factory/init signatures, renames session list entry struct.
src/windows/service/exe/WSLCSessionManager.h / .cpp Creates and owns plugin notifier per session; triggers plugin session create/stop notifications; adds session lookup for plugin API calls.
src/windows/service/exe/ServiceMain.cpp Loads plugins once at service startup (policy-independent); leaves an unload placeholder comment.
src/windows/service/exe/PluginManager.h / .cpp Extends plugin API vtable with WSLC calls and adds WSLC hook dispatch.
src/windows/service/exe/LxssUserSessionFactory.cpp Switches to global g_pluginManager loaded by service rather than per-policy instantiation.
src/windows/service/exe/CMakeLists.txt Adds WSLC plugin notifier implementation sources/headers to the service build.
src/windows/inc/WslPluginApi.h Defines WSLC plugin hooks + WSLC API call function pointers and related types.
msipackage/package.wix.in Registers the IWSLCPluginNotifier interface for COM proxy/stub.

Comment thread src/windows/service/inc/wslc.idl
Comment on lines 824 to 830
// Creates a new session and returns both the session interface and a service reference.
HRESULT CreateSession(
[in] const WSLCSessionInitSettings* Settings,
[in] IWSLCVirtualMachine* Vm,
[in, unique] IWSLCPluginNotifier* PluginNotifier,
[out] IWSLCSession** Session,
[out] IWSLCSessionReference** ServiceRef);
Comment thread src/windows/service/inc/wslc.idl Outdated
Comment on lines +744 to +764
const auto pluginResult = m_pluginNotifier->OnContainerStarted(inspectJson.c_str());
if (FAILED(pluginResult))
{
// Forward the COM error message, if available.
auto comError = wsl::windows::common::wslutil::GetCOMErrorInfo();

LOG_HR_MSG(pluginResult, "Plugin rejected start of container '%hs' (0x%x)", m_id.c_str(), pluginResult);
try
{
m_dockerClient.StopContainer(m_id.c_str(), {}, {});
}
CATCH_LOG();

if (comError.has_value() && comError->Message)
{
THROW_HR_WITH_USER_ERROR(pluginResult, comError->Message.get());
}
else
{
THROW_HR(pluginResult);
}
Comment thread src/windows/wslcsession/WSLCContainer.cpp
Comment thread src/windows/service/exe/PluginManager.h Outdated
Comment thread src/windows/service/exe/ServiceMain.cpp Outdated
Comment thread src/windows/service/exe/PluginManager.cpp
Comment thread src/windows/wslcsession/WSLCSessionFactory.h
Comment thread src/windows/service/inc/wslc.idl
Comment thread src/windows/service/inc/wslc.idl Outdated
Copy link
Copy Markdown
Member

@benhillis benhillis left a comment

Choose a reason for hiding this comment

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

🤖 AI-generated review (GitHub Copilot CLI, Claude Opus 4.7, run by @benhillis).

This is automated feedback — please use your judgment on every item. I focused on correctness / lifetime / API contract issues and skipped style. Three items from a prior pass were already addressed in 581b849e / af4affd8 (dead UnloadPlugins, nullable notifier contract, path-traversal in WSLCMountFolder) — thanks for those. Remaining items are inline.

Separately: I noted in another context that this design is compatible with #40120 (out-of-process plugin host); the lock-held-across-callbacks point below is the one place where the two PRs would interact and would benefit from a fix in-tree regardless of #40120.

Comment thread src/windows/wslcsession/WSLCContainer.h
Comment thread src/windows/service/exe/PluginManager.cpp
Comment thread src/windows/service/exe/PluginManager.cpp Outdated
Comment thread src/windows/service/exe/WSLCSessionManager.cpp Outdated
Comment thread src/windows/service/exe/WSLCSessionManager.cpp
Comment thread src/windows/service/exe/PluginManager.cpp Outdated
@OneBlue OneBlue marked this pull request as ready for review May 14, 2026 22:27
@OneBlue OneBlue requested a review from a team as a code owner May 14, 2026 22:27
@benhillis benhillis requested a review from Copilot May 15, 2026 19:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 26 out of 27 changed files in this pull request and generated 3 comments.

Comment thread test/windows/testplugin/Plugin.cpp Outdated
Comment thread test/windows/wslc/e2e/WSLCE2EHelpers.cpp Outdated
Comment thread src/windows/inc/WslPluginApi.h Outdated
benhillis
benhillis previously approved these changes May 15, 2026
Copilot AI review requested due to automatic review settings May 15, 2026 21:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 26 out of 27 changed files in this pull request and generated 5 comments.

Comment thread src/windows/service/exe/PluginManager.cpp
Comment thread src/windows/inc/WslPluginApi.h
Comment thread test/windows/testplugin/Plugin.cpp
Comment thread src/windows/service/exe/PluginManager.cpp Outdated
Comment thread src/windows/service/inc/wslc.idl Outdated
Copilot AI review requested due to automatic review settings May 15, 2026 22:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 26 out of 27 changed files in this pull request and generated 1 comment.

Comment thread src/windows/service/exe/PluginManager.cpp
@OneBlue OneBlue enabled auto-merge (squash) May 15, 2026 22:57
@OneBlue OneBlue merged commit c9e4671 into master May 16, 2026
15 checks passed
@OneBlue OneBlue deleted the user/oneblue/plugin-api-wslc branch May 16, 2026 00:08
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