WSL/doc/docs/technical-documentation/wslservice.exe.md
WSL Team 697572d664 Initial open source commit for WSL.
Many Microsoft employees have contributed to the Windows Subsystem for Linux, this commit is the result of their work since 2016.

The entire history of the Windows Subsystem for Linux can't be shared here, but here's an overview of WSL's history after it moved to it own repository in 2021:

Number of commits on the main branch: 2930
Number of contributors: 31

Head over https://github.com/microsoft/WSL/releases for a more detailed history of the features added to WSL since 2021.
2025-05-15 12:09:45 -07:00

2.1 KiB

wslservice.exe

WslService is a session 0 service, running as SYSTEM. Its job is to manage WSL sessions, communicate with the WSL2 virtual machine and configure WSL distributions.

COM Interface

Clients can connect to WslService via its COM interface, ILxssUserSession. Its definition can be found in src/windows/service/incwslservice.idl.

When a COM client calls CoCreateInstance() on this interface, the service receives the requests via LxssUserSessionFactory (see src/windows/service/LxssUserSessionFactory.cpp) and returns an instance of LxssUserSession (see src/windows/service/LxssUserSession.cpp) per Windows user (calling CoCreateInstance() multiple times from the same Windows user accounts returns the same instance).

The client can then use its ILxssUserSession instance to call methods into the service, such as:

  • CreateInstance(): Launch a WSL distribution
  • CreateLxProcess(): Launch a process inside a distribution
  • RegisterDistribution(): Register a new WSL distribution
  • Shutdown(): Terminate all WSL distributions

WSL2 Virtual machine

WslService manages the WSL2 Virtual Machine. The virtual machine management logic can be found in src/windows/service/WslCoreVm.cpp.

Once booted, WslService maintains an hvsocket with the Virtual Machine which it uses to send various commands to Linux processes (see mini_init for more details.

WSL2 Distributions

Once the virtual machine is running, WSL distributions can be started by calling WslCoreVm::CreateInstance. Each running distribution is represented by a WslCoreInstance (see src/windows/service/WslCoreInstance.cpp).

Each WslCoreInstance maintains an hvsocket connection to init which allows WslService to perform various tasks such as:

  • Launching processes inside the distribution
  • Be notified when the distribution exits
  • Mount drvfs shares (/mnt/*)
  • Stop the distribution