├── .clang-format ├── .gdnsuppress ├── .github ├── CODEOWNERS ├── ISSUE_TEMPLATE │ ├── Bug_Report.yaml │ └── feature_request.md ├── actions │ └── triage │ │ └── action.yml ├── policies │ └── resourceManagement.yml ├── pull_request_template.md └── workflows │ ├── distributions.yml │ ├── documentation.yml │ ├── issue_edited.yml │ ├── modern-distributions.yml │ ├── new_issue.yml │ ├── new_issue_comment.yml │ └── winget.yml ├── .gitignore ├── .pipelines ├── build-stage.yml ├── flight-stage.yml ├── nuget-stage.yml ├── test-job.yml ├── test-stage.yml ├── wsl-build-nightly-localization.yml ├── wsl-build-nightly-onebranch.yml ├── wsl-build-notice.yml ├── wsl-build-pr-onebranch.yml ├── wsl-build-pr.yml └── wsl-build-release-onebranch.yml ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── DATA_AND_PRIVACY.md ├── Directory.Build.Props ├── Images ├── LargeTile.scale-100.png ├── SettingsOOBECrossOSFileAccess.gif ├── SettingsOOBEDistroManagement.png ├── SettingsOOBEDockerDesktopIntegration.png ├── SettingsOOBEDockerIcon.png ├── SettingsOOBEFileExplorerIcon.png ├── SettingsOOBEGPUAcceleration.gif ├── SettingsOOBEGUIApps.png ├── SettingsOOBEGeneral.png ├── SettingsOOBENetworkingIntegration.png ├── SettingsOOBEVSCodeIcon.png ├── SettingsOOBEVSCodeIntegration.png ├── SmallTile.scale-100.png ├── SplashScreen.scale-100.png ├── Square150x150Logo.scale-100.png ├── Square44x44Logo.altform-lightunplated_targetsize-16.png ├── Square44x44Logo.altform-lightunplated_targetsize-24.png ├── Square44x44Logo.altform-lightunplated_targetsize-256.png ├── Square44x44Logo.altform-lightunplated_targetsize-32.png ├── Square44x44Logo.altform-lightunplated_targetsize-48.png ├── Square44x44Logo.altform-unplated_targetsize-16.png ├── Square44x44Logo.altform-unplated_targetsize-256.png ├── Square44x44Logo.altform-unplated_targetsize-32.png ├── Square44x44Logo.altform-unplated_targetsize-48.png ├── Square44x44Logo.scale-100.png ├── Square44x44Logo.targetsize-16.png ├── Square44x44Logo.targetsize-24.png ├── Square44x44Logo.targetsize-24_altform-unplated.png ├── Square44x44Logo.targetsize-256.png ├── Square44x44Logo.targetsize-32.png ├── Square44x44Logo.targetsize-48.png ├── StoreLogo.backup.png ├── StoreLogo.scale-100.png ├── Wide310x150Logo.scale-100.png ├── wsl.ico └── wslbw.ico ├── LICENSE ├── NOTICE.txt ├── README.md ├── SECURITY.md ├── SUPPORT.md ├── UserConfig.cmake.sample ├── cgmanifest.json ├── cloudtest ├── CMakeLists.txt ├── TestGroup.xml.in └── TestMap.xml.in ├── cmake ├── FindIDL.cmake ├── FindLINUXBUILD.cmake ├── FindMC.cmake ├── findAppx.cmake ├── findNuget.cmake └── findVersion.cmake ├── diagnostics ├── collect-networking-logs.ps1 ├── collect-wsl-logs.ps1 ├── dump-init-stacks.sh ├── dump-init.sh ├── networking.sh ├── wsl.wprp ├── wsl_networking.wprp └── wsl_storage.wprp ├── distributions ├── DistributionInfo.json ├── requirements.txt ├── validate-modern.py └── validate.py ├── doc ├── README.md ├── docs │ ├── debugging.md │ ├── dev-loop.md │ ├── index.md │ └── technical-documentation │ │ ├── boot-process.md │ │ ├── drvfs.md │ │ ├── gns.md │ │ ├── index.md │ │ ├── init.md │ │ ├── interop.md │ │ ├── localhost.md │ │ ├── mini_init.md │ │ ├── plan9.md │ │ ├── relay.md │ │ ├── session-leader.md │ │ ├── systemd.md │ │ ├── wsl.exe.md │ │ ├── wslconfig.exe.md │ │ ├── wslg.exe.md │ │ ├── wslhost.exe.md │ │ ├── wslrelay.exe.md │ │ └── wslservice.exe.md └── mkdocs.yml ├── img ├── networkinglog1.gif ├── networkinglog2.gif ├── networkinglog3.gif └── networkinglog4.gif ├── intune ├── WSL.admx └── en-US │ └── WSL.adml ├── localization ├── CMakeLists.txt └── strings │ ├── cs-CZ │ └── Resources.resw │ ├── da-DK │ └── Resources.resw │ ├── de-DE │ └── Resources.resw │ ├── en-GB │ └── Resources.resw │ ├── en-US │ └── Resources.resw │ ├── es-ES │ └── Resources.resw │ ├── fi-FI │ └── Resources.resw │ ├── fr-FR │ └── Resources.resw │ ├── hu-HU │ └── Resources.resw │ ├── it-IT │ └── Resources.resw │ ├── ja-JP │ └── Resources.resw │ ├── ko-KR │ └── Resources.resw │ ├── nb-NO │ └── Resources.resw │ ├── nl-NL │ └── Resources.resw │ ├── pl-PL │ └── Resources.resw │ ├── pt-BR │ └── Resources.resw │ ├── pt-PT │ └── Resources.resw │ ├── ru-RU │ └── Resources.resw │ ├── sv-SE │ └── Resources.resw │ ├── tr-TR │ └── Resources.resw │ ├── zh-CN │ └── Resources.resw │ └── zh-TW │ └── Resources.resw ├── msipackage ├── CMakeLists.txt └── package.wix.in ├── msixgluepackage ├── AppxManifest.in └── CMakeLists.txt ├── msixinstaller ├── AppxManifest.in └── CMakeLists.txt ├── nuget.config ├── nuget ├── CMakeLists.txt ├── Microsoft.WSL.PluginApi.nuspec.in └── README.WslPluginApi.MD ├── packages.config ├── src ├── linux │ ├── inc │ │ ├── lxdef.h │ │ ├── lxwil.h │ │ └── seccomp_defs.h │ ├── init │ │ ├── CMakeLists.txt │ │ ├── DnsServer.cpp │ │ ├── DnsServer.h │ │ ├── DnsTunnelingChannel.cpp │ │ ├── DnsTunnelingChannel.h │ │ ├── DnsTunnelingManager.cpp │ │ ├── DnsTunnelingManager.h │ │ ├── GnsEngine.cpp │ │ ├── GnsEngine.h │ │ ├── GnsPortTracker.cpp │ │ ├── GnsPortTracker.h │ │ ├── Localization.cpp │ │ ├── NetworkManager.cpp │ │ ├── NetworkManager.h │ │ ├── SecCompDispatcher.cpp │ │ ├── SecCompDispatcher.h │ │ ├── WslDistributionConfig.cpp │ │ ├── WslDistributionConfig.h │ │ ├── binfmt.cpp │ │ ├── binfmt.h │ │ ├── common.h │ │ ├── config.cpp │ │ ├── config.h │ │ ├── drvfs.cpp │ │ ├── drvfs.h │ │ ├── escape.cpp │ │ ├── escape.h │ │ ├── init.cpp │ │ ├── localhost.cpp │ │ ├── localhost.h │ │ ├── main.cpp │ │ ├── plan9.cpp │ │ ├── plan9.h │ │ ├── telemetry.cpp │ │ ├── telemetry.h │ │ ├── timezone.cpp │ │ ├── timezone.h │ │ ├── util.cpp │ │ ├── util.h │ │ ├── waitablevalue.h │ │ ├── wslinfo.cpp │ │ ├── wslinfo.h │ │ ├── wslpath.cpp │ │ └── wslpath.h │ ├── mountutil │ │ ├── CMakeLists.txt │ │ ├── mountflags.cpp │ │ ├── mountutil.c │ │ ├── mountutil.h │ │ └── mountutilcpp.h │ ├── netlinkutil │ │ ├── Address.cpp │ │ ├── CMakeLists.txt │ │ ├── Forwarder.h │ │ ├── Forwarder.hxx │ │ ├── Fwd.h │ │ ├── Interface.cpp │ │ ├── Interface.h │ │ ├── InterfaceConfiguration.h │ │ ├── IpNeighborManager.cpp │ │ ├── IpNeighborManager.h │ │ ├── IpRuleManager.cpp │ │ ├── IpRuleManager.h │ │ ├── Makefile.linux │ │ ├── Neighbor.cpp │ │ ├── Neighbor.h │ │ ├── NetLinkStrings.h │ │ ├── NetlinkChannel.h │ │ ├── NetlinkChannel.hxx │ │ ├── NetlinkError.cpp │ │ ├── NetlinkError.h │ │ ├── NetlinkMessage.h │ │ ├── NetlinkMessage.hxx │ │ ├── NetlinkParseException.cpp │ │ ├── NetlinkParseException.h │ │ ├── NetlinkResponse.cpp │ │ ├── NetlinkResponse.h │ │ ├── NetlinkResponse.hxx │ │ ├── NetlinkTransaction.cpp │ │ ├── NetlinkTransaction.h │ │ ├── NetlinkTransactionError.cpp │ │ ├── NetlinkTransactionError.h │ │ ├── Operation.h │ │ ├── Packet.h │ │ ├── Protocol.h │ │ ├── Route.cpp │ │ ├── Route.h │ │ ├── RoutingTable.cpp │ │ ├── RoutingTable.h │ │ ├── Rule.cpp │ │ ├── Rule.h │ │ ├── RuntimeErrorWithSourceLocation.cpp │ │ ├── RuntimeErrorWithSourceLocation.h │ │ ├── Syscall.h │ │ ├── Syscall.hxx │ │ ├── SyscallError.cpp │ │ ├── SyscallError.h │ │ ├── Utils.cpp │ │ ├── Utils.h │ │ ├── Utils.hxx │ │ └── address.h │ └── plan9 │ │ ├── CMakeLists.txt │ │ ├── expected.h │ │ ├── p9await.h │ │ ├── p9commonutil.h │ │ ├── p9data.h │ │ ├── p9defs.h │ │ ├── p9errors.h │ │ ├── p9fid.cpp │ │ ├── p9fid.h │ │ ├── p9file.cpp │ │ ├── p9file.h │ │ ├── p9fs.cpp │ │ ├── p9fs.h │ │ ├── p9handler.cpp │ │ ├── p9handler.h │ │ ├── p9ihandler.h │ │ ├── p9io.cpp │ │ ├── p9io.h │ │ ├── p9log.h │ │ ├── p9lx.cpp │ │ ├── p9lx.h │ │ ├── p9platform.h │ │ ├── p9protohelpers.h │ │ ├── p9readdir.cpp │ │ ├── p9readdir.h │ │ ├── p9scheduler.cpp │ │ ├── p9scheduler.h │ │ ├── p9tracelogging.cpp │ │ ├── p9tracelogging.h │ │ ├── p9tracelogginghelper.h │ │ ├── p9util.cpp │ │ ├── p9util.h │ │ ├── p9xattr.cpp │ │ ├── p9xattr.h │ │ ├── precomp.h │ │ └── result_macros.h ├── shared │ ├── configfile │ │ ├── CMakeLists.txt │ │ ├── configfile.cpp │ │ ├── configfile.h │ │ ├── linux │ │ │ └── CMakeLists.txt │ │ └── windows │ │ │ └── CMakeLists.txt │ └── inc │ │ ├── CommandLine.h │ │ ├── JsonUtils.h │ │ ├── SocketChannel.h │ │ ├── conncheckshared.h │ │ ├── defs.h │ │ ├── gslhelpers.h │ │ ├── hns_schema.h │ │ ├── lxfsshares.h │ │ ├── lxinitshared.h │ │ ├── message.h │ │ ├── prettyprintshared.h │ │ ├── retryshared.h │ │ ├── socketshared.h │ │ └── stringshared.h └── windows │ ├── common │ ├── CMakeLists.txt │ ├── ConsoleProgressBar.cpp │ ├── ConsoleProgressBar.h │ ├── ConsoleProgressIndicator.cpp │ ├── ConsoleProgressIndicator.h │ ├── Distribution.cpp │ ├── Distribution.h │ ├── ExecutionContext.cpp │ ├── ExecutionContext.h │ ├── HandleConsoleProgressBar.cpp │ ├── HandleConsoleProgressBar.h │ ├── Localization.cpp │ ├── LxssMessagePort.cpp │ ├── LxssMessagePort.h │ ├── LxssPort.h │ ├── LxssServerPort.cpp │ ├── LxssServerPort.h │ ├── Redirector.cpp │ ├── Redirector.h │ ├── Stringify.h │ ├── SubProcess.cpp │ ├── SubProcess.h │ ├── WslClient.cpp │ ├── WslClient.h │ ├── WslCoreConfig.cpp │ ├── WslCoreConfig.h │ ├── WslCoreFirewallSupport.cpp │ ├── WslCoreFirewallSupport.h │ ├── WslCoreNetworkingSupport.cpp │ ├── WslCoreNetworkingSupport.h │ ├── WslInstall.cpp │ ├── WslInstall.h │ ├── WslSecurity.cpp │ ├── WslSecurity.h │ ├── WslTelemetry.cpp │ ├── WslTelemetry.h │ ├── disk.cpp │ ├── disk.hpp │ ├── filesystem.cpp │ ├── filesystem.hpp │ ├── hcs.cpp │ ├── hcs.hpp │ ├── hcs_schema.h │ ├── helpers.cpp │ ├── helpers.hpp │ ├── hvsocket.cpp │ ├── hvsocket.hpp │ ├── interop.cpp │ ├── interop.hpp │ ├── lxssbusclient.cpp │ ├── lxssclient.cpp │ ├── notifications.cpp │ ├── notifications.h │ ├── precomp.h │ ├── registry.cpp │ ├── registry.hpp │ ├── relay.cpp │ ├── relay.hpp │ ├── socket.cpp │ ├── socket.hpp │ ├── string.cpp │ ├── string.hpp │ ├── svccomm.cpp │ ├── svccomm.hpp │ ├── svccommio.cpp │ ├── svccommio.hpp │ ├── wslutil.cpp │ └── wslutil.h │ ├── inc │ ├── LxssDynamicFunction.h │ ├── RegistryWatcher.h │ ├── WmiService.h │ ├── WmiVariant.h │ ├── WslCoreConfigInterface.h │ ├── WslPluginApi.h │ ├── comservicehelper.h │ ├── lxssbusclient.h │ ├── lxssclient.h │ ├── traceloggingconfig.h │ ├── wdk.h │ ├── wsl.h │ ├── wslconfig.h │ ├── wslhost.h │ ├── wslpolicies.h │ ├── wslrelay.h │ └── wslversioninfo.h │ ├── libwsl │ ├── CMakeLists.txt │ ├── DllMain.cpp │ ├── WslCoreConfigInterface.cpp │ └── libwsl.def │ ├── service │ ├── CMakeLists.txt │ ├── exe │ │ ├── BridgedNetworking.cpp │ │ ├── BridgedNetworking.h │ │ ├── CMakeLists.txt │ │ ├── DeviceHostProxy.cpp │ │ ├── DeviceHostProxy.h │ │ ├── DistributionRegistration.cpp │ │ ├── DistributionRegistration.h │ │ ├── Dmesg.cpp │ │ ├── Dmesg.h │ │ ├── DnsResolver.cpp │ │ ├── DnsResolver.h │ │ ├── DnsTunnelingChannel.cpp │ │ ├── DnsTunnelingChannel.h │ │ ├── GnsChannel.cpp │ │ ├── GnsChannel.h │ │ ├── GnsPortTrackerChannel.cpp │ │ ├── GnsPortTrackerChannel.h │ │ ├── GnsRpcServer.cpp │ │ ├── GnsRpcServer.h │ │ ├── GuestTelemetryLogger.cpp │ │ ├── GuestTelemetryLogger.h │ │ ├── IMirroredNetworkManager.h │ │ ├── INetworkingEngine.h │ │ ├── Lifetime.cpp │ │ ├── Lifetime.h │ │ ├── LxssConsoleManager.cpp │ │ ├── LxssConsoleManager.h │ │ ├── LxssCreateProcess.cpp │ │ ├── LxssCreateProcess.h │ │ ├── LxssHttpProxy.cpp │ │ ├── LxssHttpProxy.h │ │ ├── LxssInstance.cpp │ │ ├── LxssInstance.h │ │ ├── LxssIpTables.cpp │ │ ├── LxssIpTables.h │ │ ├── LxssSecurity.cpp │ │ ├── LxssSecurity.h │ │ ├── LxssUserCallback.cpp │ │ ├── LxssUserCallback.h │ │ ├── LxssUserSession.cpp │ │ ├── LxssUserSession.h │ │ ├── LxssUserSessionFactory.cpp │ │ ├── LxssUserSessionFactory.h │ │ ├── MirroredNetworking.cpp │ │ ├── MirroredNetworking.h │ │ ├── NatNetworking.cpp │ │ ├── NatNetworking.h │ │ ├── PluginManager.cpp │ │ ├── PluginManager.h │ │ ├── RingBuffer.cpp │ │ ├── RingBuffer.h │ │ ├── ServiceMain.cpp │ │ ├── VirtioNetworking.cpp │ │ ├── VirtioNetworking.h │ │ ├── WslCoreAdviseHandler.h │ │ ├── WslCoreFilesystem.cpp │ │ ├── WslCoreFilesystem.h │ │ ├── WslCoreGuestNetworkService.cpp │ │ ├── WslCoreGuestNetworkService.h │ │ ├── WslCoreHostDnsInfo.cpp │ │ ├── WslCoreHostDnsInfo.h │ │ ├── WslCoreInstance.cpp │ │ ├── WslCoreInstance.h │ │ ├── WslCoreMessageQueue.h │ │ ├── WslCoreNetworkEndpoint.h │ │ ├── WslCoreNetworkEndpointSettings.cpp │ │ ├── WslCoreNetworkEndpointSettings.h │ │ ├── WslCoreTcpIpStateTracking.cpp │ │ ├── WslCoreTcpIpStateTracking.h │ │ ├── WslCoreVm.cpp │ │ ├── WslCoreVm.h │ │ ├── WslMirroredNetworking.cpp │ │ ├── WslMirroredNetworking.h │ │ ├── application.manifest │ │ ├── main.rc │ │ └── resource.h │ ├── inc │ │ ├── CMakeLists.txt │ │ ├── windowsdefs.idl │ │ └── wslservice.idl │ ├── mc │ │ ├── CMakeLists.txt │ │ └── wsleventschema.mc │ └── stub │ │ ├── CMakeLists.txt │ │ ├── WslServiceProxyStub.def │ │ └── WslServiceProxyStub.rc │ ├── wsl │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main.rc │ └── resource.h │ ├── wslg │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main.rc │ └── resource.h │ ├── wslhost │ ├── CMakeLists.txt │ ├── main.cpp │ ├── main.rc │ └── resource.h │ ├── wslinstall │ ├── CMakeLists.txt │ ├── DllMain.cpp │ ├── version.rc │ └── wslinstall.def │ ├── wslinstaller │ ├── exe │ │ ├── CMakeLists.txt │ │ ├── ServiceMain.cpp │ │ ├── WslInstaller.cpp │ │ ├── WslInstaller.h │ │ ├── WslInstallerFactory.cpp │ │ ├── WslInstallerFactory.h │ │ └── main.rc │ ├── inc │ │ ├── CMakeLists.txt │ │ └── wslinstallerservice.idl │ ├── stub │ │ ├── CMakeLists.txt │ │ ├── WslInstallerProxyStub.def │ │ └── WslInstallerProxyStub.rc │ └── wslinstaller.idl │ ├── wslrelay │ ├── CMakeLists.txt │ ├── localhost.cpp │ ├── localhost.h │ ├── main.cpp │ ├── main.rc │ └── resource.h │ └── wslsettings │ ├── Activation │ ├── ActivationHandler.cs │ ├── DefaultActivationHandler.cs │ ├── IActivationHandler.cs │ └── ProtocolActivationHandler.cs │ ├── App.xaml │ ├── App.xaml.cs │ ├── Behaviors │ ├── NavigationViewHeaderBehavior.cs │ └── NavigationViewHeaderMode.cs │ ├── CMakeLists.txt │ ├── Constants.cs │ ├── Contracts │ ├── Services │ │ ├── IActivationService.cs │ │ ├── INavigationService.cs │ │ ├── INavigationViewService.cs │ │ ├── IPageService.cs │ │ ├── IWindowService.cs │ │ └── IWslConfigService.cs │ └── ViewModels │ │ └── INavigationAware.cs │ ├── Controls │ ├── HyperlinkTextBlock.xaml │ ├── HyperlinkTextBlock.xaml.cs │ ├── OOBEContent.xaml │ └── OOBEContent.xaml.cs │ ├── Converters │ ├── BooleanToVisibilityConverter.cs │ ├── MegabyteNumberConverter.cs │ ├── MegabyteStringConverter.cs │ └── MillisecondsStringConverter.cs │ ├── Helpers │ ├── FrameExtensions.cs │ ├── NavigationHelper.cs │ ├── ResourceExtensions.cs │ ├── RuntimeHelper.cs │ └── TitleBarHelper.cs │ ├── LibWsl.cs │ ├── Services │ ├── ActivationService.cs │ ├── NavigationService.cs │ ├── NavigationViewService.cs │ ├── PageService.cs │ ├── WindowService.cs │ └── WslConfigService.cs │ ├── Styles │ ├── Button.xaml │ ├── CommonStyles.xaml │ ├── FontSizes.xaml │ └── Thickness.xaml │ ├── Usings.cs │ ├── ViewModels │ ├── OOBE │ │ ├── DistroManagementViewModel.cs │ │ ├── DockerDesktopIntegrationViewModel.cs │ │ ├── GPUAccelerationViewModel.cs │ │ ├── GUIAppsViewModel.cs │ │ ├── GeneralViewModel.cs │ │ ├── NetworkingIntegrationViewModel.cs │ │ ├── VSCodeIntegrationViewModel.cs │ │ ├── WelcomeToUbuntuViewModel.cs │ │ └── WorkingAcrossFileSystemsViewModel.cs │ ├── Settings │ │ ├── AboutViewModel.cs │ │ ├── DeveloperViewModel.cs │ │ ├── FileSystemViewModel.cs │ │ ├── MemAndProcViewModel.cs │ │ ├── NetworkingViewModel.cs │ │ ├── OptionalFeaturesViewModel.cs │ │ └── WslConfigSettingViewModel.cs │ └── ShellViewModel.cs │ ├── Views │ ├── OOBE │ │ ├── DistroManagementPage.xaml │ │ ├── DistroManagementPage.xaml.cs │ │ ├── DockerDesktopIntegrationPage.xaml │ │ ├── DockerDesktopIntegrationPage.xaml.cs │ │ ├── GPUAccelerationPage.xaml │ │ ├── GPUAccelerationPage.xaml.cs │ │ ├── GUIAppsPage.xaml │ │ ├── GUIAppsPage.xaml.cs │ │ ├── GeneralPage.xaml │ │ ├── GeneralPage.xaml.cs │ │ ├── NetworkingIntegrationPage.xaml │ │ ├── NetworkingIntegrationPage.xaml.cs │ │ ├── ShellPage.xaml │ │ ├── ShellPage.xaml.cs │ │ ├── VSCodeIntegrationPage.xaml │ │ ├── VSCodeIntegrationPage.xaml.cs │ │ ├── WorkingAcrossFileSystemsPage.xaml │ │ └── WorkingAcrossFileSystemsPage.xaml.cs │ └── Settings │ │ ├── AboutPage.xaml │ │ ├── AboutPage.xaml.cs │ │ ├── DeveloperPage.xaml │ │ ├── DeveloperPage.xaml.cs │ │ ├── FileSystemPage.xaml │ │ ├── FileSystemPage.xaml.cs │ │ ├── MemAndProcPage.xaml │ │ ├── MemAndProcPage.xaml.cs │ │ ├── NetworkingPage.xaml │ │ ├── NetworkingPage.xaml.cs │ │ ├── OptionalFeaturesPage.xaml │ │ ├── OptionalFeaturesPage.xaml.cs │ │ ├── ShellPage.xaml │ │ └── ShellPage.xaml.cs │ ├── Windows │ ├── MainWindow.xaml │ ├── MainWindow.xaml.cs │ ├── OOBEWindow.xaml │ └── OOBEWindow.xaml.cs │ ├── app.manifest │ ├── directory.build.targets.in │ └── properties │ └── AssemblyInfo.cs.in ├── storebroker ├── Media │ └── en-us │ │ ├── WSLAppList 1.png │ │ ├── WSLTerminalAssetSettingsColour-Export.png │ │ ├── WSLTerminalPanes-Export.png │ │ └── WSLTerminalWSLgAsset-Export.png ├── PDPs │ ├── cs-CZ │ │ └── PDP.xml │ ├── da-DK │ │ └── PDP.xml │ ├── de-DE │ │ └── PDP.xml │ ├── en-GB │ │ └── PDP.xml │ ├── en-us │ │ └── PDP.xml │ ├── es-ES │ │ └── PDP.xml │ ├── fi-FI │ │ └── PDP.xml │ ├── fr-FR │ │ └── PDP.xml │ ├── hu-HU │ │ └── PDP.xml │ ├── it-IT │ │ └── PDP.xml │ ├── ja-JP │ │ └── PDP.xml │ ├── ko-KR │ │ └── PDP.xml │ ├── nb-NO │ │ └── PDP.xml │ ├── nl-NL │ │ └── PDP.xml │ ├── pl-PL │ │ └── PDP.xml │ ├── pt-BR │ │ └── PDP.xml │ ├── pt-PT │ │ └── PDP.xml │ ├── qps-ploc │ │ └── PDP.xml │ ├── qps-ploca │ │ └── PDP.xml │ ├── qps-plocm │ │ └── PDP.xml │ ├── ru-RU │ │ └── PDP.xml │ ├── sv-SE │ │ └── PDP.xml │ ├── tr-TR │ │ └── PDP.xml │ ├── zh-CN │ │ └── PDP.xml │ └── zh-TW │ │ └── PDP.xml └── sbconfig.json ├── test ├── README.md ├── linux │ └── unit_tests │ │ ├── Makefile │ │ ├── auxv.c │ │ ├── binfmt.c │ │ ├── brk.c │ │ ├── build_tests.sh │ │ ├── cgroup.c │ │ ├── common.c │ │ ├── common.h │ │ ├── dev_pt.c │ │ ├── dev_pt_2.c │ │ ├── dev_pt_common.c │ │ ├── dev_pt_common.h │ │ ├── drvfs.c │ │ ├── dup.c │ │ ├── epoll.c │ │ ├── eventfd.c │ │ ├── execve.c │ │ ├── flock.c │ │ ├── fork.c │ │ ├── fscommon.c │ │ ├── fstab.c │ │ ├── get_set_id.c │ │ ├── getaddrinfo.c │ │ ├── gettime.c │ │ ├── inotify.c │ │ ├── interop.c │ │ ├── ioprio.c │ │ ├── keymgmt.c │ │ ├── lxtcommon.h │ │ ├── lxtevent.c │ │ ├── lxtevent.h │ │ ├── lxtfs.c │ │ ├── lxtfs.h │ │ ├── lxtlog.c │ │ ├── lxtlog.h │ │ ├── lxtmount.c │ │ ├── lxtmount.h │ │ ├── lxtutil.c │ │ ├── lxtutil.h │ │ ├── madvise.c │ │ ├── mprotect.c │ │ ├── mremap.c │ │ ├── namespace.c │ │ ├── netlink.c │ │ ├── overlayfs.c │ │ ├── pipe.c │ │ ├── poll.c │ │ ├── random.c │ │ ├── resourcelimits.c │ │ ├── sched.c │ │ ├── select.c │ │ ├── sem.c │ │ ├── shm.c │ │ ├── socket.c │ │ ├── socket_nonblock.c │ │ ├── splice.c │ │ ├── sysfs.c │ │ ├── sysinfo.c │ │ ├── timer.c │ │ ├── timerfd.c │ │ ├── tty.c │ │ ├── ttys.c │ │ ├── unittests.c │ │ ├── unittests.h │ │ ├── user.c │ │ ├── utimensat.c │ │ ├── vfsaccess.c │ │ ├── vnet.c │ │ ├── waitpid.c │ │ ├── wslpath.c │ │ └── xattr.c └── windows │ ├── CMakeLists.txt │ ├── Common.cpp │ ├── Common.h │ ├── DrvFsTests.cpp │ ├── InstallerTests.cpp │ ├── MountTests.cpp │ ├── NetworkTests.cpp │ ├── Plan9Tests.cpp │ ├── PluginTests.cpp │ ├── PluginTests.h │ ├── PolicyTests.cpp │ ├── SimpleTests.cpp │ ├── UnitTests.cpp │ ├── lxsstest.h │ └── testplugin │ ├── CMakeLists.txt │ └── Plugin.cpp ├── tools ├── FormatSource.ps1.in ├── SetupClangFormat.bat ├── bin2cpio │ ├── CPIOImage.pm │ └── bin2cpio.pl ├── build-bundle.bat ├── create-dev-cert.ps1 ├── deploy │ ├── deploy-to-host.ps1 │ └── deploy-to-vm.ps1 ├── devops │ ├── create-change.py │ ├── create-release.py │ ├── find-release.py │ ├── requirements.txt │ ├── validate-copyright-headers.py │ ├── validate-localization.py │ └── version_functions.ps1 ├── generateLocalizationHeader.ps1 ├── hooks │ └── pre-commit ├── test │ ├── CloudTest-Setup.bat │ ├── Microsoft.WSL.TestDistro.nuspec │ ├── build-test-distro.ps1 │ ├── copy_and_build_tests.ps1 │ ├── copy_tests.ps1 │ ├── gh-release-server.py │ ├── run-tests.ps1 │ ├── setup-vm-for-tests.ps1 │ ├── test-setup.ps1 │ └── test.bat.in └── wsl.wprp └── triage ├── config.yml ├── install-latest-wsl.ps1 └── no-filter.wpaProfile /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # File containing policy for file ownership 2 | 3 | # Reviewers for all files in the repository 4 | * @microsoft/wsl-maintainers -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request / Contribution idea 3 | about: Suggest a feature or improvement for the Windows Subsystem for Linux 4 | title: '' 5 | labels: 'feature' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | ## Summary of the Pull Request 3 | 4 | 5 | ## PR Checklist 6 | 7 | - [ ] **Closes:** Link to issue #xxx 8 | - [ ] **Communication:** I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected 9 | - [ ] **Tests:** Added/updated if needed and all pass 10 | - [ ] **Localization:** All end user facing strings can be localized 11 | - [ ] **Dev docs:** Added/updated if needed 12 | - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/wsl/) and link it here: #xxx 13 | 14 | 15 | ## Detailed Description of the Pull Request / Additional comments 16 | 17 | 18 | ## Validation Steps Performed 19 | -------------------------------------------------------------------------------- /.github/workflows/distributions.yml: -------------------------------------------------------------------------------- 1 | name: Validate distributions 2 | 3 | on: 4 | pull_request: 5 | paths: ['distributions/**'] 6 | 7 | jobs: 8 | check: 9 | name: Validate distributions 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repo 13 | uses: actions/checkout@v4 14 | 15 | - name: Run validation 16 | run: python distributions/validate.py distributions/DistributionInfo.json 17 | shell: bash 18 | -------------------------------------------------------------------------------- /.github/workflows/documentation.yml: -------------------------------------------------------------------------------- 1 | name: Build documentation 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: [main, master] 6 | 7 | jobs: 8 | DeployDocs: 9 | environment: 10 | name: github-pages 11 | url: ${{ steps.deployment.outputs.page_url }} 12 | runs-on: ubuntu-latest 13 | permissions: 14 | contents: read 15 | pages: write 16 | id-token: write 17 | steps: 18 | - name: Checkout actions 19 | uses: actions/checkout@v4 20 | 21 | - name: Install packages 22 | run: pip install mkdocs-mermaid2-plugin mkdocs --break-system-packages 23 | shell: bash 24 | 25 | - name: Build documentation 26 | run: mkdocs build -f doc/mkdocs.yml 27 | shell: bash 28 | 29 | - uses: actions/upload-pages-artifact@v3 30 | with: 31 | path: doc/site 32 | 33 | - name: Deploy to GitHub Pages 34 | id: deployment 35 | uses: actions/deploy-pages@v4 -------------------------------------------------------------------------------- /.github/workflows/issue_edited.yml: -------------------------------------------------------------------------------- 1 | name: Process edited issue 2 | 3 | on: 4 | workflow_dispatch: 5 | issues: 6 | types: [edited] 7 | 8 | jobs: 9 | wti: 10 | name: Run wti 11 | runs-on: windows-2022 12 | permissions: 13 | issues: write 14 | steps: 15 | - name: Checkout repo 16 | uses: actions/checkout@v4 17 | 18 | - uses: ./.github/actions/triage 19 | with: 20 | issue: "${{ github.event.issue.number }}" 21 | previous_body: "${{ github.event.changes.body.from }}" 22 | token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/modern-distributions.yml: -------------------------------------------------------------------------------- 1 | name: Validate tar based distributions 2 | 3 | on: 4 | pull_request: 5 | paths: ['distributions/**'] 6 | 7 | jobs: 8 | check: 9 | name: Validate tar based distributions changes 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout repo 13 | uses: actions/checkout@v4 14 | with: 15 | fetch-depth: 0 16 | 17 | - name: Install pip packages 18 | run: pip install -r distributions/requirements.txt 19 | shell: bash 20 | 21 | - name: Run validation 22 | run: | 23 | python distributions/validate-modern.py \ 24 | --repo-path . \ 25 | --compare-with-branch 'origin/${{ github.base_ref }}' \ 26 | --manifest distributions/DistributionInfo.json \ 27 | 28 | shell: bash 29 | -------------------------------------------------------------------------------- /.github/workflows/new_issue.yml: -------------------------------------------------------------------------------- 1 | name: Process new issue 2 | 3 | on: 4 | workflow_dispatch : 5 | issues: 6 | types: [opened] 7 | 8 | jobs: 9 | wti: 10 | name: Run wti 11 | runs-on: windows-2022 12 | permissions: 13 | issues: write 14 | steps: 15 | - name: Checkout repo 16 | uses: actions/checkout@v4 17 | 18 | - uses: ./.github/actions/triage 19 | with: 20 | issue: "${{ github.event.issue.number }}" 21 | token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/new_issue_comment.yml: -------------------------------------------------------------------------------- 1 | name: Process new comment on issue 2 | 3 | on: 4 | workflow_dispatch : 5 | issue_comment: 6 | types: [created] 7 | 8 | jobs: 9 | wti: 10 | name: Run wti 11 | runs-on: windows-2022 12 | permissions: 13 | issues: write 14 | if: ${{ !github.event.issue.pull_request && github.event.issue.user.id == github.event.comment.user.id }} 15 | steps: 16 | - name: Checkout repo 17 | uses: actions/checkout@v4 18 | 19 | - uses: ./.github/actions/triage 20 | with: 21 | issue: '${{ github.event.issue.number }}' 22 | comment: '${{ github.event.comment.id }}' 23 | token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.github/workflows/winget.yml: -------------------------------------------------------------------------------- 1 | name: Publish to Winget 2 | 3 | on: 4 | release: 5 | types: [released] 6 | 7 | jobs: 8 | publish: 9 | if: github.event.release.prerelease == false 10 | runs-on: windows-latest # Action can only run on Windows 11 | steps: 12 | - name: Publish WSL 13 | run: | 14 | 15 | Set-StrictMode -Version Latest 16 | $ErrorActionPreference = "Stop" 17 | 18 | $assets = '${{ toJSON(github.event.release.assets) }}' | ConvertFrom-Json 19 | $wingetRelevantAssetx64 = $assets | Where-Object { $_.name -like '*x64.msi' } | Select-Object -First 1 20 | $wingetRelevantAssetARM64 = $assets | Where-Object { $_.name -like '*arm64.msi' } | Select-Object -First 1 21 | 22 | $version = "${{ github.event.release.tag_name }}" 23 | 24 | $wingetx64URL = $wingetRelevantAssetx64.browser_download_url 25 | $wingetARM64URL = $wingetRelevantAssetARM64.browser_download_url 26 | 27 | $wingetPackageId = "Microsoft.WSL" 28 | 29 | & curl.exe -JLO https://aka.ms/wingetcreate/latest 30 | & .\wingetcreate.exe update $wingetPackageId -s -v $version -u "$wingetx64URL|x64" "$wingetARM64URL|arm64" -t "${{ secrets.WINGET_TOKEN }}" 31 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/* 2 | .vs/ 3 | !vendor/.preserve 4 | out 5 | tmp 6 | /.vs/ 7 | /.vscode/ 8 | *.sln 9 | *.user 10 | *.csproj 11 | *.vcxproj 12 | *.targets 13 | *.filters 14 | *.pdb 15 | *.lib 16 | *.dll 17 | obj/ 18 | Debug/ 19 | Release/ 20 | Properties/ 21 | /_deps/ 22 | /package/Strings/en-US/ 23 | /packages/ 24 | CMakeFiles/ 25 | CMakeCache.txt 26 | *.msix 27 | cmake_install.cmake 28 | build_tools/ 29 | *_i.c 30 | *_p.c 31 | *_p.c 32 | wslsupport/wslsupport.h 33 | dlldata.c 34 | .gdbinit 35 | llvm/ 36 | *.a 37 | *.so 38 | *.o 39 | linux/init/init 40 | linux/init 41 | initrd/init 42 | bin/ 43 | *.nupkg 44 | build/ 45 | generated/ 46 | Microsoft.WSL.PluginApi.nuspec 47 | test/linux/unit_tests/wsl_unit_tests 48 | *.dir/ 49 | UserConfig.cmake 50 | *.wix 51 | *.wixobj 52 | *.wixpdb 53 | test.bat 54 | AppxManifest.xml 55 | package_layout/ 56 | priconf.xml 57 | resources.map.txt 58 | resources.pri 59 | msi-install-*.txt 60 | kernellogs.txt 61 | FormatSource.ps1 62 | msixinstaller/x64 63 | package/x64 64 | /appx-logs.txt 65 | tools/clang-format.exe 66 | /linux-crashes 67 | doc/site/ -------------------------------------------------------------------------------- /.pipelines/test-stage.yml: -------------------------------------------------------------------------------- 1 | parameters: 2 | - name: rs_prerelease_only 3 | type: boolean 4 | default: false 5 | 6 | - name: pool 7 | type: string 8 | default: '' 9 | 10 | - name: versions 11 | type: object 12 | default: 13 | - wsl1 14 | - wsl2 15 | 16 | - name: test_images 17 | type: object 18 | default: 19 | - name: rs_prerelease 20 | image: rs_prerelease-2025-01-30 21 | - name: ni_release 22 | image: win11-23h2-ent-2024-11-18 23 | - name: fe_release 24 | image: 2022-datacenter-g2-2024-09-10 25 | - name: vb_release 26 | image: win10-22h2-ent-g2-2024-09-10 27 | 28 | # TODO: ge_release 29 | 30 | stages: 31 | - stage: test 32 | dependsOn: [build] 33 | jobs: 34 | - ${{ each version in parameters.versions }}: 35 | - ${{ each image in parameters.test_images }}: 36 | - template: test-job.yml@self 37 | parameters: 38 | branch: "${{ image.name }}" 39 | version: ${{ version }} 40 | image: "${{ image.image }}" 41 | run: ${{ or(not(parameters.rs_prerelease_only), eq(image.name, 'rs_prerelease')) }} 42 | pool: "${{ parameters.pool }}" -------------------------------------------------------------------------------- /.pipelines/wsl-build-nightly-onebranch.yml: -------------------------------------------------------------------------------- 1 | trigger: none 2 | 3 | schedules: 4 | # "0 8" = 8AM UTC = 12AM PST 5 | - cron: "0 8 * * *" 6 | displayName: Nightly build 7 | branches: 8 | include: [main] 9 | always: true 10 | 11 | variables: 12 | WindowsContainerImage: "onebranch.azurecr.io/windows/ltsc2022/vse2022:latest" 13 | WindowsHostVersion: '1ESWindows2022' 14 | 15 | resources: 16 | repositories: 17 | - repository: templates 18 | type: git 19 | name: OneBranch.Pipelines/GovernedTemplates 20 | ref: refs/heads/main 21 | 22 | extends: 23 | template: v2/Microsoft.NonOfficial.yml@templates 24 | parameters: 25 | platform: 26 | name: "windows_undocked" 27 | featureFlags: 28 | EnableCDPxPAT: false 29 | WindowsHostVersion: 1ESWindows2022 30 | globalSdl: 31 | credscan: 32 | enabled: true 33 | perStage: 34 | credscan: 35 | enabled: true 36 | tsa: 37 | enabled: false 38 | git: 39 | fetchDepth: -1 40 | fetchTags: true 41 | 42 | stages: 43 | - template: build-stage.yml@self 44 | parameters: 45 | isRelease: false 46 | isNightly: true 47 | vsoOrg: microsoft 48 | vsoProject: Microsoft.WSL 49 | 50 | - template: test-stage.yml@self 51 | parameters: 52 | rs_prerelease_only: false -------------------------------------------------------------------------------- /.pipelines/wsl-build-notice.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | include: 4 | - master 5 | 6 | pool: 7 | vmImage: 'windows-latest' 8 | 9 | steps: 10 | - checkout : self 11 | persistCredentials: true 12 | 13 | - task: ComponentGovernanceComponentDetection@0 14 | displayName: Component Detection 15 | 16 | - task: notice@0 17 | displayName: Generate NOTICE file 18 | inputs: 19 | outputfile: $(System.DefaultWorkingDirectory)/NOTICE.txt 20 | outputformat: text 21 | 22 | - task: PipAuthenticate@1 23 | inputs: 24 | artifactFeeds: 'wsl' 25 | 26 | - powershell: | 27 | pip install --user -r tools/devops/requirements.txt 28 | python tools/devops/create-change.py . "$env:token" "WSL notice" "Notice change from build: $env:buildId" "user/notice/$env:buildId" 29 | 30 | displayName: Create pull request 31 | env: 32 | token: $(GithubPRToken) 33 | buildId: $(Build.BuildId) -------------------------------------------------------------------------------- /.pipelines/wsl-build-pr-onebranch.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | include: 4 | - master 5 | - release/* 6 | 7 | variables: 8 | WindowsContainerImage: "onebranch.azurecr.io/windows/ltsc2022/vse2022:latest" 9 | WindowsHostVersion: '1ESWindows2022' 10 | 11 | resources: 12 | repositories: 13 | - repository: templates 14 | type: git 15 | name: OneBranch.Pipelines/GovernedTemplates 16 | ref: refs/heads/main 17 | 18 | extends: 19 | template: v2/Microsoft.NonOfficial.yml@templates 20 | parameters: 21 | platform: 22 | name: "windows_undocked" 23 | featureFlags: 24 | EnableCDPxPAT: false 25 | WindowsHostVersion: 1ESWindows2022 26 | globalSdl: 27 | suppression: 28 | suppressionFile: $(Build.SourcesDirectory)\.gdnsuppress 29 | suppressionSet: default 30 | apiscan: 31 | enabled: false 32 | credscan: 33 | enabled: true 34 | perStage: 35 | credscan: 36 | enabled: true 37 | policheck: 38 | enabled: true 39 | break: true 40 | severity: Note 41 | git: 42 | fetchDepth: -1 43 | fetchTags: true 44 | 45 | stages: 46 | - template: build-stage.yml@self 47 | parameters: 48 | isRelease: false 49 | 50 | - template: test-stage.yml@self 51 | parameters: 52 | rs_prerelease_only: true 53 | -------------------------------------------------------------------------------- /.pipelines/wsl-build-pr.yml: -------------------------------------------------------------------------------- 1 | trigger: 2 | branches: 3 | include: 4 | - master 5 | - release/* 6 | 7 | stages: 8 | - template: build-stage.yml@self 9 | parameters: 10 | isRelease: false 11 | pool: 'wsl-build' 12 | vsoOrg: shine-oss 13 | vsoProject: wsl 14 | 15 | - template: test-stage.yml@self 16 | parameters: 17 | rs_prerelease_only: true 18 | pool: server 19 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /DATA_AND_PRIVACY.md: -------------------------------------------------------------------------------- 1 | # WSL data & privacy 2 | 3 | ## Overview 4 | 5 | WSL collects diagnostic data using Windows telemetry, just like other Windows components. You can disable this by opening Windows Settings, navigating to Privacy and Security -> Diagnostics & Feedback and disabling 'Diagnostic data'. You can also view all diagnostic data that you are sending in that menu using the 'View diagnostic data' option. 6 | 7 | For more information please read the [Microsoft privacy statement](https://www.microsoft.com/privacy/privacystatement). 8 | 9 | ## What does WSL collect? 10 | 11 | 1. Usage 12 | - Understanding what features and settings are most often used in WSL helps us make decisions on where to focus our time and energy. 13 | 2. Stability 14 | - Monitoring bugs and system crashes assists us in prioritizing the most urgent issues. 15 | 3. Performance 16 | - Assessing the performance of WSL gives us an understanding of what runtimes / components could be causing slow downs. This supports our commitment in providing you a speedy and effective WSL. 17 | 18 | You can search for WSL telemetry events by looking for calls to `WSL_LOG_TELEMETRY` in the source code of this repository. -------------------------------------------------------------------------------- /Directory.Build.Props: -------------------------------------------------------------------------------- 1 | 2 | 3 | true 4 | true 5 | 6 | 7 | 8 | true 9 | 10 | 11 | -------------------------------------------------------------------------------- /Images/LargeTile.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/LargeTile.scale-100.png -------------------------------------------------------------------------------- /Images/SettingsOOBECrossOSFileAccess.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBECrossOSFileAccess.gif -------------------------------------------------------------------------------- /Images/SettingsOOBEDistroManagement.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEDistroManagement.png -------------------------------------------------------------------------------- /Images/SettingsOOBEDockerDesktopIntegration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEDockerDesktopIntegration.png -------------------------------------------------------------------------------- /Images/SettingsOOBEDockerIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEDockerIcon.png -------------------------------------------------------------------------------- /Images/SettingsOOBEFileExplorerIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEFileExplorerIcon.png -------------------------------------------------------------------------------- /Images/SettingsOOBEGPUAcceleration.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEGPUAcceleration.gif -------------------------------------------------------------------------------- /Images/SettingsOOBEGUIApps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEGUIApps.png -------------------------------------------------------------------------------- /Images/SettingsOOBEGeneral.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEGeneral.png -------------------------------------------------------------------------------- /Images/SettingsOOBENetworkingIntegration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBENetworkingIntegration.png -------------------------------------------------------------------------------- /Images/SettingsOOBEVSCodeIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEVSCodeIcon.png -------------------------------------------------------------------------------- /Images/SettingsOOBEVSCodeIntegration.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SettingsOOBEVSCodeIntegration.png -------------------------------------------------------------------------------- /Images/SmallTile.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SmallTile.scale-100.png -------------------------------------------------------------------------------- /Images/SplashScreen.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/SplashScreen.scale-100.png -------------------------------------------------------------------------------- /Images/Square150x150Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square150x150Logo.scale-100.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-lightunplated_targetsize-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-lightunplated_targetsize-16.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-lightunplated_targetsize-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-lightunplated_targetsize-24.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-lightunplated_targetsize-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-lightunplated_targetsize-256.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-lightunplated_targetsize-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-lightunplated_targetsize-32.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-lightunplated_targetsize-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-lightunplated_targetsize-48.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-unplated_targetsize-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-unplated_targetsize-16.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-unplated_targetsize-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-unplated_targetsize-256.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-unplated_targetsize-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-unplated_targetsize-32.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.altform-unplated_targetsize-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.altform-unplated_targetsize-48.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.scale-100.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-16.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-24.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-24_altform-unplated.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-24_altform-unplated.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-256.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-256.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-32.png -------------------------------------------------------------------------------- /Images/Square44x44Logo.targetsize-48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Square44x44Logo.targetsize-48.png -------------------------------------------------------------------------------- /Images/StoreLogo.backup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/StoreLogo.backup.png -------------------------------------------------------------------------------- /Images/StoreLogo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/StoreLogo.scale-100.png -------------------------------------------------------------------------------- /Images/Wide310x150Logo.scale-100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/Wide310x150Logo.scale-100.png -------------------------------------------------------------------------------- /Images/wsl.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/wsl.ico -------------------------------------------------------------------------------- /Images/wslbw.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/Images/wslbw.ico -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /SUPPORT.md: -------------------------------------------------------------------------------- 1 | # Support 2 | 3 | ## How to file issues and get help 4 | 5 | This project uses [GitHub Issues][gh-issue] to [track bugs][gh-bug] and [feature requests][gh-feature]. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or 6 | feature request as a new Issue. 7 | 8 | For general information on the Windows Subsystem for Linux, including help, tutorials, how-tos and reference guides, please view our [WSL documentation](https://docs.microsoft.com/windows/wsl/). 9 | 10 | ## Microsoft Support Policy 11 | 12 | Technical Support for the use of WSL may also be available from Microsoft’s Customer Support Services (CSS). If you are a Premier or Unified Support customer, you may reach out to your account manager for further assistance. Otherwise, you may visit Microsoft’s [Support For Business site](https://support.serviceshub.microsoft.com/supportforbusiness/create) to [open a new support case for WSL](https://support.serviceshub.microsoft.com/supportforbusiness/create?sapid=9d5af292-506b-63ca-cb2c-7f4eaa380c56). 13 | 14 | 15 | [gh-issue]: https://github.com/microsoft/WSL/issues/new/choose 16 | [gh-bug]: https://github.com/microsoft/WSL/issues/new?assignees=&labels=&template=bug_report.md&title= 17 | [gh-feature]: https://github.com/microsoft/WSL/issues/new?assignees=&labels=feature&template=feature_request.md&title= 18 | -------------------------------------------------------------------------------- /cgmanifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "$schema": "https://json.schemastore.org/component-detection-manifest.json", 4 | "registrations": [ 5 | { 6 | "component": { 7 | "type": "git", 8 | "git": { 9 | "repositoryUrl": "https://github.com/microsoft/GSL", 10 | "commitHash": "0f6dbc9e2915ef5c16830f3fa3565738de2a9230" 11 | } 12 | } 13 | }, 14 | { 15 | "component": { 16 | "type": "git", 17 | "git": { 18 | "repositoryUrl": "https://github.com/llvm/llvm-project", 19 | "commitHash": "d32170dbd5b0d54436537b6b75beaf44324e0c28" 20 | } 21 | } 22 | }, 23 | { 24 | "component": { 25 | "type": "other", 26 | "other": { 27 | "name": "libarchive", 28 | "version": "3.7.7", 29 | "downloadUrl": "https://github.com/libarchive/libarchive/releases/download/v3.7.7/libarchive-3.7.7.tar.gz", 30 | "hash": "sha1:918692098b11db61aff23684ab04f375e4a68f69" 31 | } 32 | } 33 | } 34 | ] 35 | } -------------------------------------------------------------------------------- /cloudtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(OUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/cloudtest) 2 | file(MAKE_DIRECTORY ${OUT}) 3 | 4 | if (${TARGET_PLATFORM} STREQUAL x64) 5 | set(CLOUDTEST_IMAGES 6 | "wsl-test-image-rs_prerelease-2025-01-30" 7 | "wsl-test-image-win11-23h2-ent-2024-11-18" 8 | "wsl-test-image-2022-datacenter-g2-2024-09-10" 9 | "wsl-test-image-win10-22h2-ent-g2-2024-09-10") 10 | 11 | 12 | set(CLOUDTEST_TEST_PACKAGES "Test_Packages_2024_02_27") 13 | set(DUMPTOOL_DROP "DumpTool_X64_2025-01-27") 14 | elseif (${TARGET_PLATFORM} STREQUAL arm64) 15 | set(CLOUDTEST_IMAGES) 16 | else() 17 | message(FATAL_ERROR "Unsupported target platform: ${TARGET_PLATFORM}") 18 | endif() 19 | 20 | # Passed down to test-setup.ps1 to determine if -AllowUnsigned should be passed to Add-AppxPackage 21 | if (OFFICIAL_BUILD) 22 | set(ALLOW_UNSIGNED_PACKAGE "0") 23 | else() 24 | set(ALLOW_UNSIGNED_PACKAGE "1") 25 | endif() 26 | 27 | function(add_test_group image version) 28 | set(DIR ${OUT}/${image}-wsl${version}) 29 | 30 | file(MAKE_DIRECTORY ${DIR}) 31 | 32 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TestMap.xml.in ${DIR}/TestMap.xml) 33 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/TestGroup.xml.in ${DIR}/TestGroup.xml) 34 | endfunction() 35 | 36 | foreach(image ${CLOUDTEST_IMAGES}) 37 | add_test_group("${image}" "1") 38 | add_test_group("${image}" "2") 39 | endforeach() 40 | -------------------------------------------------------------------------------- /cmake/FindMC.cmake: -------------------------------------------------------------------------------- 1 | function(add_mc target mc_file) 2 | 3 | cmake_path(GET mc_file STEM MC_NAME) 4 | 5 | set(OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR}\\${TARGET_PLATFORM}\\${CMAKE_BUILD_TYPE}) 6 | set(RC_FILE ${OUTPUT_DIR}/${MC_NAME}.rc) 7 | set(HEADER_FILE ${OUTPUT_DIR}/${MC_NAME}.h) 8 | 9 | add_custom_command( 10 | OUTPUT ${RC_FILE} ${HEADER_FILE} ${CMAKE_CURRENT_BINARY_DIR}/CmakeFiles/${target} 11 | COMMAND mc.exe -A -b -c -h ${OUTPUT_DIR} -r ${OUTPUT_DIR} ${mc_file} 12 | COMMAND rc.exe -nologo -fo${OUTPUT_DIR}\\${MC_NAME}.res ${RC_FILE} 13 | COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/CmakeFiles/${target}" 14 | WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} 15 | DEPENDS ${mc_file} 16 | MAIN_DEPENDENCY ${mc_file} 17 | VERBATIM 18 | ) 19 | 20 | add_custom_target(${target} DEPENDS ${RC_FILE} SOURCES ${mc_file}) 21 | 22 | set_source_files_properties(${RC_FILE} PROPERTIES GENERATED TRUE) 23 | endfunction() -------------------------------------------------------------------------------- /cmake/findVersion.cmake: -------------------------------------------------------------------------------- 1 | function(get_version_impl command var_name) 2 | execute_process( 3 | COMMAND powershell.exe 4 | -NoProfile 5 | -NonInteractive 6 | -ExecutionPolicy Bypass 7 | -Command "$env:Path += ';${GITVERSION_SOURCE_DIR}' ; . .\\tools\\devops\\version_functions.ps1 ; ${command}" 8 | OUTPUT_VARIABLE OUTPUT_VERSION 9 | WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} 10 | COMMAND_ERROR_IS_FATAL ANY) 11 | string(STRIP "${OUTPUT_VERSION}" OUTPUT_VERSION) 12 | SET(${var_name} ${OUTPUT_VERSION} PARENT_SCOPE) 13 | endfunction() 14 | 15 | function(find_commit_hash var_name) 16 | get_version_impl("Get-Current-Commit-Hash" "command_output") 17 | SET(${var_name} ${command_output} PARENT_SCOPE) 18 | endfunction() 19 | 20 | function(find_version msix_var_name nuget_var_name) 21 | get_version_impl("Get-VersionInfo -Nightly $false | ConvertTo-Json" "command_output") 22 | string(JSON "${msix_var_name}" GET "${command_output}" MsixVersion) 23 | string(JSON "${nuget_var_name}" GET "${command_output}" NugetVersion) 24 | 25 | return(PROPAGATE ${msix_var_name} ${nuget_var_name}) 26 | endfunction() -------------------------------------------------------------------------------- /diagnostics/dump-init-stacks.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | set -ue 4 | 5 | for proc in /proc/[0-9]*; do 6 | pid=$(basename "$proc") 7 | 8 | echo -e "\nProcess: $pid" 9 | echo -en "cmd: " 10 | cat "/proc/$pid/cmdline" || true 11 | echo -e "\nstat: " 12 | cat "/proc/$pid/stat" || true 13 | 14 | for tid in $(ls "/proc/$pid/task" || true); do 15 | echo -n "tid: $tid - " 16 | cat "/proc/$pid/task/$tid/comm" || true 17 | cat "/proc/$pid/task/$tid/stack" || true 18 | done 19 | 20 | echo "fds: " 21 | ls -la "/proc/$pid/fd" || true 22 | done 23 | 24 | echo "hvsockets: " 25 | ss -lap --vsock 26 | 27 | echo "meminfo: " 28 | cat /proc/meminfo -------------------------------------------------------------------------------- /diagnostics/dump-init.sh: -------------------------------------------------------------------------------- 1 | #! /bin/bash 2 | 3 | set -ue 4 | 5 | if [ $(whoami) != "root" ]; then 6 | echo "This script must be run as root in the system distro (via wsl.exe -u root --system)" 7 | exit 1 8 | fi 9 | 10 | ts=$(date +%F_%H-%M-%S) 11 | target="/mnt/c/wsl-init-dump-$ts" 12 | 13 | mkdir -p "$target" 14 | 15 | tdnf install -y gdb 16 | 17 | bash -c "cd $target && gcore -a \$(pgrep init)" 18 | 19 | stack_log="$target/stacks.txt" 20 | fd_log="$target/fd.txt" 21 | for pid in $(pgrep init); do 22 | echo -e "\nProcess: $pid" >> "$stack_log" 23 | echo -e "\nProcess: $pid" >> "$fd_log" 24 | for tid in $(ls "/proc/$pid/task" || true); do 25 | echo "tid: $tid" >> "$stack_log" 26 | cat "/proc/$pid/task/$tid/stack" >> "$stack_log" || true 27 | done 28 | 29 | ls -la "/proc/$pid/fd" >> "$fd_log" || true 30 | done 31 | 32 | 33 | ss -lap --vsock > "/$target/sockets.txt" 34 | dmesg > "/$target/dmesg.txt" 35 | cat /proc/meminfo > "/$target/meminfo.txt" 36 | 37 | echo "Logs and dumps written in $target" 38 | -------------------------------------------------------------------------------- /distributions/requirements.txt: -------------------------------------------------------------------------------- 1 | python-magic==0.4.27 2 | click==8.1.3 3 | GitPython==3.1.41 4 | PyGithub==2.5.0 5 | json-cfg==0.4.2 -------------------------------------------------------------------------------- /doc/README.md: -------------------------------------------------------------------------------- 1 | # WSL open source documentation 2 | 3 | Build instructions: 4 | 5 | ``` 6 | $ pip install mkdocs mkdocs-mermaid2-plugin 7 | $ mkdocs serve 8 | ``` 9 | 10 | You can then view the documentation at `http://127.0.0.1:8000/`. -------------------------------------------------------------------------------- /doc/docs/index.md: -------------------------------------------------------------------------------- 1 | # WSL open source documentation 2 | 3 | This site contains the developer documentation for the Windows Subsystem for Linux. 4 | 5 | For user documentation, including installation and configuration, see [https://learn.microsoft.com/windows/wsl/](https://learn.microsoft.com/windows/wsl/). 6 | 7 | 8 | To get started developing (building, testing and deploying), see [Getting started](dev-loop.md). 9 | 10 | To learn more about how WSL works, see [technical documentation](technical-documentation/index.md) 11 | -------------------------------------------------------------------------------- /doc/docs/technical-documentation/gns.md: -------------------------------------------------------------------------------- 1 | # GNS 2 | 3 | `gns` is a process created by `mini_init`. Its jobs is to configure networking within the WSL2 virtual machine. 4 | 5 | ## Networking configuration 6 | 7 | Networking settings are shared by all WSL2 distributions. While WSL2 is running, `gns` maintains an hvsocket channel to [wslservice.exe](wslservice.exe.md), which is used to send various networking related configurations such as: 8 | 9 | - Interface IP configuration 10 | - Routing table entries 11 | - DNS configuration 12 | - MTU size configuration 13 | 14 | When DNS tunneling is enabled, `gns` is also responsible for replying to DNS requests. 15 | 16 | See `src/linux/init/GnsEngine.cpp` and `src/windows/service/exe/GnsChannel.cpp` -------------------------------------------------------------------------------- /doc/docs/technical-documentation/localhost.md: -------------------------------------------------------------------------------- 1 | # Localhost 2 | 3 | `localhost` is a WSL2 linux process, created by [mini_init](mini_init.md). Its role is to forward network traffic between the WSL2 virtual machine, and Windows. 4 | 5 | 6 | ## NAT networking 7 | 8 | When `wsl2.networkingMode` is set to NAT, `localhost` will watch for bound TCP ports, and relay the network traffic to Windows via [wslrelay.exe](wslrelay.exe.md) 9 | 10 | ## Mirrored networking 11 | 12 | In mirrored mode, `localhost` register a BPF program to intercept calls to `bind()`, and forward the calls to Windows via [wslservice.exe](wslservice.exe.md) so Windows can route the network traffic directly to the WSL2 virtual machine. 13 | 14 | See `src/linux/localhost.cpp`. -------------------------------------------------------------------------------- /doc/docs/technical-documentation/plan9.md: -------------------------------------------------------------------------------- 1 | # Plan 9 2 | 3 | Plan9 is a linux process that hosts a plan9 filesystem server for WSL1 and WSL2 distributions. It's created by [init](init.md) in each distribution. 4 | 5 | ## WSL 1 6 | 7 | In WSL1 distributions, `plan9` serves its filesystem through a unix socket, which can then be connected to from Windows. 8 | 9 | ## WSL2 10 | 11 | In WSL2 distributions, `plan9` runs its filesystem through an `hvsocket` 12 | 13 | ## Accessing the distribution files from Windows 14 | 15 | From Windows, a special redirector driver (p9rdr.sys) registers both `\\wsl$` and `\\wsl.localhost`. When either of those paths are accessed, `p9rdr.sys` calls [wslservice.exe](wslservice.exe.md) to list the available distributions for a given Windows users. 16 | 17 | When a distribution path is accessed (like `\\wsl.localhost\debian`), `p9rdr.sys` calls into [wslservice.exe](wslservice.exe.md) via COM to start the distribution, and connect to its plan9 server, which allows the files to be accessed from Windows. 18 | 19 | See `src/linux/init/plan9.cpp` -------------------------------------------------------------------------------- /doc/docs/technical-documentation/relay.md: -------------------------------------------------------------------------------- 1 | # Relay 2 | 3 | Relay is a WSL2 linux process creating by a [session leader](session-leader.md). Its job is to create a linux process on behalf of the user, and relay its output back to Windows. 4 | 5 | ## Creating a user process 6 | 7 | A relay is created when a `LxInitMessageCreateProcessUtilityVm` message is sent to a [session leader](session-leader.md). Once created, the `relay` creates multiple `hvsocket` channels with [wslservice.exe](wslservice.exe.md). 8 | 9 | These channels are used to: 10 | 11 | - Relay standard file descriptors (stdin, stdout, stderr) 12 | - Relay information about the terminal (for instance when the terminal window is resized from Windows) 13 | - Notify Windows when the linux process exits 14 | 15 | Once those channels are configured, the `relay` forks() into two processes: 16 | 17 | - The parent, which will read & write to the child's standard file descriptors and relay it to Windows 18 | - The child, which calls `exec()` and starts the user process -------------------------------------------------------------------------------- /doc/docs/technical-documentation/session-leader.md: -------------------------------------------------------------------------------- 1 | # Session leader 2 | 3 | A session leader is a linux process, which is forked from [init](init.md) after receiving a `LxInitMessageCreateSession` message (see `src/linux/init.cpp`) 4 | 5 | ## Creating linux processes 6 | 7 | Session leaders are used to create linux processes on behalf of the user. Each linux session leader is associated to a Windows console. 8 | 9 | To create a user process, [wslservice.exe](wslservice.exe.md) sends a `LxInitMessageCreateProcess` message (WSL1) or a `LxInitMessageCreateProcessUtilityVm` message (WSL2), which contains details about the process to create such as: 10 | 11 | - Command line 12 | - Current directory 13 | - Environment variables 14 | - User name 15 | 16 | ### Creating a WSL1 process 17 | 18 | When running in a WSL1 distribution, the session leader forks(), and uses the child process to `exec()` into the user linux process. Before calling `exec()`, child configures various settings such as: 19 | 20 | - The user and group id 21 | - The current directory 22 | - The standard file descriptors (stdin, stdout, stderr) 23 | 24 | ## Creating a WSL2 process 25 | 26 | When running in a WSL2 distribution, the session leaders forks() to create a [relay](relay.md) process, which is responsible for creating the user process and relaying its output back to [wsl.exe](wsl.exe.md) -------------------------------------------------------------------------------- /doc/docs/technical-documentation/systemd.md: -------------------------------------------------------------------------------- 1 | # Systemd 2 | 3 | Systemd support for a WSL distribution can be enabled by setting the following in `/etc/wsl.conf`: 4 | 5 | ``` 6 | [boot] 7 | systemd=true 8 | ``` 9 | 10 | When enabled, [init](init.md) will take launch `/sbin/init` (which points to systemd's init) when the distribution starts. One key difference when this setting is enabled is that [init](init.md) won't be pid 1 in the given distribution, since systemd's init requires running as pid 1, so [init](init.md) will fork(), and launch systemd in the parent while continuing WSL configuration in the child process. 11 | 12 | After launching `/sbin/init`, [init](init.md) waits for systemd to be ready by waiting for `systemctl is-system-running` to return either `running`, or `degraded`. After a given amount of time, WSL will time out and allow the distribution to continue starting, even if systemd isn't ready. 13 | 14 | ## User sessions 15 | 16 | When systemd is enabled, WSL tries synchronizes launching processes with systemd user sessions. This is currently done by launching `login -f ` to start the associated systemd user session. 17 | 18 | ## Additional systemd configuration 19 | 20 | To improve compatibility with systemd, WSL creates various systemd configuration files during boot (under `/run`). These configurations files are used to: 21 | 22 | - Protect the WSL [binfmt interpret](interop.md) from being deleted by `systemd-binfmt.service` 23 | - Protect the X11 socket from being deleted by `systemd-tmpfiles.serviceè -------------------------------------------------------------------------------- /doc/docs/technical-documentation/wsl.exe.md: -------------------------------------------------------------------------------- 1 | # wsl.exe 2 | 3 | wsl.exe is main command line entrypoint from WSL. Its job is to: 4 | 5 | - Parse the command line arguments (See `src/windows/common/wslclient.cpp`) 6 | - Call [wslservice.exe](wslservice.exe.md) via COM to launch WSL (see `src/windows/common/svccomm.cpp`) 7 | - Relay stdin / stdout / stderr from and to the linux process 8 | 9 | -------------------------------------------------------------------------------- /doc/docs/technical-documentation/wslconfig.exe.md: -------------------------------------------------------------------------------- 1 | # Wslconfig.exe 2 | 3 | `wslconfig.exe` is a Windows executable that can be used to configure WSL distributions. -------------------------------------------------------------------------------- /doc/docs/technical-documentation/wslg.exe.md: -------------------------------------------------------------------------------- 1 | # Wslg.exe 2 | 3 | `wslg.exe` is a Windows executable that is used mostly to run graphical applications with WSL. 4 | 5 | Its behavior is exactly the same as [wsl.exe](wsl.exe.md) with the difference that it's a win32 application, and not a console application, which allows it to start without a creating a console. 6 | -------------------------------------------------------------------------------- /doc/docs/technical-documentation/wslhost.exe.md: -------------------------------------------------------------------------------- 1 | # Wslhost.exe 2 | 3 | `wslhost.exe` is a Windows executable that's used to display desktop notifications, and run Linux processes in the background. 4 | 5 | ## COM server 6 | 7 | When running as COM server, `wslhost.exe` registers a [NotificationActivatorFactory](https://learn.microsoft.com/dotnet/api/microsoft.toolkit.uwp.notifications.notificationactivator?view=win-comm-toolkit-dotnet-7.1), which is then used to display desktop notifications to the user. 8 | 9 | Notifications can be used to: 10 | 11 | - Notify the user about a WSL update 12 | - Warn the user about a configuration error 13 | - Notify the user about a proxy change 14 | 15 | See: `src/windows/common/notifications.cpp` 16 | 17 | ## Background processes 18 | 19 | When [wsl.exe](wsl.exe.md) terminates before the associated Linux processes terminates, `wslhost.exe` takes over the lifetime of the Linux process. 20 | 21 | This allows Linux processes to keep running Windows commands and access the terminal even after the associated `wsl.exe` terminates. 22 | 23 | See `src/windows/wslhost/main.cpp` and [interop](interop.md) -------------------------------------------------------------------------------- /doc/docs/technical-documentation/wslrelay.exe.md: -------------------------------------------------------------------------------- 1 | # Wslrelay.exe 2 | 3 | `wslrelay.exe` is a windows executable that is used to relay network and debug console traffic from Linux to Windows. 4 | 5 | It is responsible for: 6 | 7 | - Relaying localhost traffic between Linux and Windows in NAT mode (see [localhost](localhost.md)) 8 | - Displaying the debug console output when `wsl2.debugConsole` is set to `true` 9 | 10 | See `src/windows/wslrelay/main.cpp` -------------------------------------------------------------------------------- /img/networkinglog1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/img/networkinglog1.gif -------------------------------------------------------------------------------- /img/networkinglog2.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/img/networkinglog2.gif -------------------------------------------------------------------------------- /img/networkinglog3.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/img/networkinglog3.gif -------------------------------------------------------------------------------- /img/networkinglog4.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/img/networkinglog4.gif -------------------------------------------------------------------------------- /localization/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LOCALIZATION_PS1 ${PROJECT_SOURCE_DIR}/tools/generateLocalizationHeader.ps1) 2 | set (MESSAGESHEAD ${GENERATED_DIR}/Localization.h) 3 | add_custom_command( 4 | OUTPUT ${MESSAGESHEAD} ${CMAKE_CURRENT_BINARY_DIR}/CmakeFiles/localization 5 | COMMAND powershell.exe -ExecutionPolicy Bypass -NoProfile -NonInteractive ${LOCALIZATION_PS1} -OutFile ${MESSAGESHEAD} 6 | COMMAND ${CMAKE_COMMAND} -E touch "${CMAKE_CURRENT_BINARY_DIR}/CmakeFiles/localization" 7 | DEPENDS ${CMAKE_CURRENT_LIST_DIR}/strings/en-US/Resources.resw ${LOCALIZATION_PS1} # Make sure the head file is rebuilt if any of the resources change 8 | VERBATIM 9 | ) 10 | 11 | add_custom_target(localization DEPENDS ${MESSAGESHEAD} ${LOCALIZATION_PS1} SOURCES ${CMAKE_CURRENT_LIST_DIR}/strings/en-US/Resources.resw) -------------------------------------------------------------------------------- /msixgluepackage/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_appx_target(msixgluepackage 2 | "wsl.exe" 3 | "${CMAKE_CURRENT_LIST_DIR}/AppxManifest.in" 4 | "${BIN}/gluepackage.msix" 5 | "wsl") -------------------------------------------------------------------------------- /nuget.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /nuget/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(NUGET_PACKAGES Microsoft.WSL.PluginApi.nuspec) 2 | 3 | # generate vars with native paths since nuget won't accept unix path separators 4 | cmake_path(NATIVE_PATH CMAKE_SOURCE_DIR CMAKE_SOURCE_DIR_NATIVE) 5 | cmake_path(NATIVE_PATH CMAKE_BINARY_DIR CMAKE_BINARY_DIR_NATIVE) 6 | 7 | foreach(PACKAGE ${NUGET_PACKAGES}) 8 | configure_file("${CMAKE_CURRENT_LIST_DIR}/${PACKAGE}.in" "${CMAKE_BINARY_DIR}/${PACKAGE}") 9 | endforeach() -------------------------------------------------------------------------------- /nuget/Microsoft.WSL.PluginApi.nuspec.in: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Microsoft.WSL.PluginApi 5 | ${WSL_NUGET_PACKAGE_VERSION} 6 | Microsoft 7 | https://github.com/microsoft/WSL 8 | WSL Plugin Interface 9 | © Microsoft Corporation. All rights reserved. 10 | images\icon.png 11 | docs\README.MD 12 | WSL 13 | en-us 14 | MIT 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /nuget/README.WslPluginApi.MD: -------------------------------------------------------------------------------- 1 | # WSL plugin api 2 | 3 | This package contains the `WslPluginApi.h` header which defines the WSL plugin interface. 4 | 5 | For more details, see: https://learn.microsoft.com/windows/wsl/ . -------------------------------------------------------------------------------- /src/linux/inc/seccomp_defs.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | // This file defines all the seccomp structures and constants that aren't available in the sdk yet 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | // From include\asm\unist_32.h 10 | // Read socketcall.2, there is no socketcall systemcall on x86_64 systems. 11 | // You will not get this value with the standard defines. 12 | #define I386_NR_socketcall (102) 13 | #define ARMV7_NR_bind (282) 14 | -------------------------------------------------------------------------------- /src/linux/init/DnsTunnelingManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | 5 | #include "DnsTunnelingChannel.h" 6 | #include "DnsServer.h" 7 | 8 | class DnsTunnelingManager 9 | { 10 | public: 11 | DnsTunnelingManager(int hvsocketFd, const std::string& dnsTunnelingIpAddress); 12 | ~DnsTunnelingManager(); 13 | 14 | DnsTunnelingManager(const DnsTunnelingManager&) = delete; 15 | DnsTunnelingManager(DnsTunnelingManager&&) = delete; 16 | DnsTunnelingManager& operator=(const DnsTunnelingManager&) = delete; 17 | DnsTunnelingManager& operator=(DnsTunnelingManager&&) = delete; 18 | 19 | private: 20 | // Hvsocket channel used to communicate with the host. 21 | DnsTunnelingChannel m_dnsChannel; 22 | 23 | // DNS server used for tunneling, supporting both UDP and TCP. 24 | DnsServer m_dnsServer; 25 | 26 | std::atomic m_stopped = false; 27 | }; 28 | -------------------------------------------------------------------------------- /src/linux/init/SecCompDispatcher.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include "common.h" 12 | #include "util.h" 13 | #include 14 | 15 | class SecCompDispatcher 16 | { 17 | public: 18 | SecCompDispatcher(int SecCompFd); 19 | ~SecCompDispatcher(); 20 | 21 | SecCompDispatcher(const SecCompDispatcher&) = delete; 22 | SecCompDispatcher(SecCompDispatcher&&) = delete; 23 | SecCompDispatcher& operator=(const SecCompDispatcher&) = delete; 24 | SecCompDispatcher& operator=(SecCompDispatcher&&) = delete; 25 | 26 | void RegisterHandler(int SysCallNr, const std::function& Handler); 27 | void UnregisterHandler(int SysCallNr); 28 | 29 | bool ValidateCookie(uint64_t id) noexcept; 30 | 31 | std::optional> ReadProcessMemory(uint64_t cookie, pid_t pid, size_t address, size_t length) noexcept; 32 | 33 | private: 34 | void Run(); 35 | 36 | seccomp_notif_sizes m_notificationSizes; 37 | std::map> m_handlers; 38 | wil::unique_fd m_notifyFd; 39 | wil::unique_fd m_shutdown; 40 | std::thread m_worker; 41 | }; 42 | -------------------------------------------------------------------------------- /src/linux/init/binfmt.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | binfmt.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for the Windows interop binfmt interpreter. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | // 18 | // Name of the WSL binfmt_misc intrepreter. 19 | // 20 | 21 | #define LX_INIT_BINFMT_NAME "WSLInterop" 22 | 23 | // 24 | // Name of the WSL 'late' binfmt_misc intrepreter. 25 | // This name is used by the wsl-binfmt systemd unit which 26 | // registers the interpreter a second time after systemd-binfmt to make sure 27 | // that wsl's interpreter is always registered last. 28 | // 29 | 30 | #define LX_INIT_BINFMT_NAME_LATE "WSLInterop-late" 31 | #define BINFMT_MISC_MOUNT_TARGET "/proc/sys/fs/binfmt_misc" 32 | #define BINFMT_MISC_REGISTER_FILE BINFMT_MISC_MOUNT_TARGET "/register" 33 | #define BINFMT_INTEROP_REGISTRATION_STRING(Name) ":" Name ":M::MZ::" LX_INIT_PATH ":P" 34 | 35 | int CreateNtProcess(int Argc, char* Argv[]); 36 | -------------------------------------------------------------------------------- /src/linux/init/drvfs.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | drvfs.h 8 | 9 | Abstract: 10 | 11 | This file contains DrvFs function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | #include 17 | #include "WslDistributionConfig.h" 18 | 19 | #define DRVFS_FS_TYPE "drvfs" 20 | #define MOUNT_DRVFS_NAME "mount.drvfs" 21 | 22 | int MountDrvfs(const char* Source, const char* Target, const char* Options, std::optional Admin, const wsl::linux::WslDistributionConfig& Config, int* ExitCode = nullptr); 23 | 24 | int MountDrvfsEntry(int Argc, char* Argv[]); 25 | 26 | int MountPlan9Filesystem( 27 | const char* Source, const char* Target, const char* Options, bool Admin, const wsl::linux::WslDistributionConfig& Config, int* ExitCode = nullptr); 28 | 29 | int MountVirtioFs(const char* Source, const char* Target, const char* Options, std::optional Admin, const wsl::linux::WslDistributionConfig& Config, int* ExitCode = nullptr); 30 | 31 | int RemountVirtioFs(const char* Tag, const char* Target, const char* Options, bool Admin); 32 | -------------------------------------------------------------------------------- /src/linux/init/escape.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | escape.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for escaping Linux paths for us on NTFS using 12 | the DrvFs escape conventions. 13 | 14 | --*/ 15 | 16 | void EscapePathForNt(const char* Path, char* EscapedPath); 17 | 18 | size_t EscapePathForNtLength(const char* Path); 19 | 20 | void UnescapePathInplace(char* Path); 21 | -------------------------------------------------------------------------------- /src/linux/init/localhost.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | int RunPortTracker(int argc, char** argv); 5 | -------------------------------------------------------------------------------- /src/linux/init/plan9.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include "SocketChannel.h" 7 | #include "WslDistributionConfig.h" 8 | 9 | std::pair StartPlan9Server(const char* socketWindowsPath, const wsl::linux::WslDistributionConfig& Config); 10 | 11 | void RunPlan9Server(const char* socketPath, const char* logFile, int logLevel, bool truncateLog, int controlSocket, int serverFd, wil::unique_fd& pipeFd); 12 | 13 | bool StopPlan9Server(bool force, wsl::linux::WslDistributionConfig& Config); -------------------------------------------------------------------------------- /src/linux/init/telemetry.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | unsigned int StartTelemetryAgent(); 5 | -------------------------------------------------------------------------------- /src/linux/init/timezone.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | timezone.h 8 | 9 | Abstract: 10 | 11 | This file contains timezone function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include "WslDistributionConfig.h" 18 | 19 | void UpdateTimezone(std::string_view Timezone, const wsl::linux::WslDistributionConfig& Config); 20 | 21 | void UpdateTimezone(gsl::span Buffer, const wsl::linux::WslDistributionConfig& Config); 22 | -------------------------------------------------------------------------------- /src/linux/init/wslinfo.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslinfo.h 8 | 9 | Abstract: 10 | 11 | This file contains wslinfo function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #define WSLINFO_NAME "wslinfo" 18 | 19 | #define WSLINFO_MSAL_PROXY_PATH "--msal-proxy-path" 20 | #define WSLINFO_NETWORKING_MODE "--networking-mode" 21 | #define WSLINFO_WSL_VERSION "--version" 22 | #define WSLINFO_WSL_VERSION_LEGACY "--wsl-version" 23 | #define WSLINFO_WSL_HELP "--help" 24 | #define WSLINFO_NO_NEWLINE 'n' 25 | 26 | int WslInfoEntry(int Argc, char* Argv[]); 27 | -------------------------------------------------------------------------------- /src/linux/init/wslpath.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslpath.h 8 | 9 | Abstract: 10 | 11 | This file contains wslpath function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #define WSLPATH_NAME "wslpath" 18 | 19 | #define TRANSLATE_FLAG_ABSOLUTE (0x1) 20 | #define TRANSLATE_FLAG_RESOLVE_SYMLINKS (0x2) 21 | 22 | #define TRANSLATE_MODE_ABSOLUTE 'a' 23 | #define TRANSLATE_MODE_UNIX 'u' 24 | #define TRANSLATE_MODE_WINDOWS 'w' 25 | #define TRANSLATE_MODE_MIXED 'm' 26 | #define TRANSLATE_MODE_HELP 'h' 27 | 28 | int WslPathEntry(int Argc, char* Argv[]); 29 | 30 | std::string WslPathTranslate(char* Path, int Flags, char Mode); 31 | -------------------------------------------------------------------------------- /src/linux/mountutil/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | mountflags.cpp 3 | mountutil.c) 4 | 5 | set(HEADERS 6 | mountutil.h 7 | mountutilcpp.h) 8 | 9 | add_linux_library(libmountutil "${SOURCES}" "${HEADERS}") 10 | set_target_properties(libmountutil PROPERTIES FOLDER linux) -------------------------------------------------------------------------------- /src/linux/mountutil/mountutil.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #define MOUNT_INFO_FILE_NAME "/mountinfo" 5 | #define MOUNT_INFO_FILE "/proc/self" MOUNT_INFO_FILE_NAME 6 | 7 | // Represents the parsed data from a line in the /proc/self/mountinfo file. 8 | typedef struct _MOUNT_ENTRY 9 | { 10 | int Id; 11 | int ParentId; 12 | dev_t Device; 13 | char* Root; 14 | char* MountPoint; 15 | char* MountOptions; 16 | char* FileSystemType; 17 | char* Source; 18 | char* SuperOptions; 19 | } MOUNT_ENTRY, *PMOUNT_ENTRY; 20 | 21 | // Represents an enumeration of entries in the /proc/self/mountinfo file. 22 | typedef struct _MOUNT_ENUM 23 | { 24 | FILE* MountInfo; 25 | char* Line; 26 | size_t LineLength; 27 | MOUNT_ENTRY Current; 28 | } MOUNT_ENUM, *PMOUNT_ENUM; 29 | 30 | int MountEnumCreate(PMOUNT_ENUM mountEnum); 31 | 32 | int MountEnumCreateEx(PMOUNT_ENUM mountEnum, const char* mountInfoFile); 33 | 34 | void MountEnumFree(PMOUNT_ENUM mountEnum); 35 | 36 | int MountEnumNext(PMOUNT_ENUM mountEnum); 37 | 38 | int MountParseMountInfoLine(char* line, PMOUNT_ENTRY entry); 39 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | Address.cpp 3 | Interface.cpp 4 | IpNeighborManager.cpp 5 | IpRuleManager.cpp 6 | Neighbor.cpp 7 | NetlinkError.cpp 8 | NetlinkParseException.cpp 9 | NetlinkResponse.cpp 10 | NetlinkTransaction.cpp 11 | NetlinkTransactionError.cpp 12 | Route.cpp 13 | RoutingTable.cpp 14 | Rule.cpp 15 | RuntimeErrorWithSourceLocation.cpp 16 | SyscallError.cpp 17 | Utils.cpp) 18 | 19 | set(HEADERS 20 | address.h 21 | Forwarder.h 22 | Fwd.h 23 | Interface.h 24 | InterfaceConfiguration.h 25 | IpNeighborManager.h 26 | IpRuleManager.h 27 | Neighbor.h 28 | NetlinkError.h 29 | NetlinkChannel.h 30 | NetlinkMessage.h 31 | NetlinkParseException.h 32 | NetlinkResponse.h 33 | NetlinkTransaction.h 34 | NetlinkTransactionError.h 35 | Packet.h 36 | Protocol.h 37 | Operation.h 38 | Route.h 39 | RoutingTable.h 40 | Rule.h 41 | RuntimeErrorWithSourceLocation.h 42 | Syscall.h 43 | SyscallError.h 44 | Utils.h 45 | Forwarder.hxx 46 | NetlinkChannel.hxx 47 | NetlinkMessage.hxx 48 | NetlinkResponse.hxx 49 | NetLinkStrings.h 50 | Syscall.hxx 51 | Utils.hxx) 52 | 53 | set(LINUX_CXXFLAGS ${LINUX_CXXFLAGS} -I "${CMAKE_CURRENT_LIST_DIR}/../init") 54 | 55 | add_linux_library(libnetlinkutil "${SOURCES}" "${HEADERS}") 56 | set_target_properties(libnetlinkutil PROPERTIES FOLDER linux) 57 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Forwarder.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | // SPDX-License-Identifier: MIT 3 | 4 | #pragma once 5 | 6 | #include 7 | #include 8 | #include 9 | 10 | #include "Packet.h" 11 | 12 | class IForwarder 13 | { 14 | public: 15 | virtual ~IForwarder() {}; 16 | }; 17 | 18 | template 19 | class Forwarder : public IForwarder 20 | { 21 | public: 22 | Forwarder(int SourceFd, int DestinationFd, ProcessingFunction Handler, ExceptionHandler exceptionHandler); 23 | ~Forwarder() override; 24 | 25 | private: 26 | std::thread Worker; 27 | int SourceFd; 28 | int DestinationFd; 29 | int TerminateFd; 30 | }; 31 | 32 | #include "Forwarder.hxx" 33 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Fwd.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | class NetlinkResponse; 5 | class NetlinkChannel; 6 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/InterfaceConfiguration.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include "address.h" 8 | 9 | struct InterfaceConfiguration 10 | { 11 | std::vector
Addresses; 12 | std::vector
LocalAddresses; 13 | std::optional
BroadcastAddress; 14 | }; 15 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/IpNeighborManager.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include "NetlinkChannel.h" 6 | #include "Neighbor.h" 7 | #include "Operation.h" 8 | 9 | class IpNeighborManager 10 | { 11 | public: 12 | /* 13 | Implement netlink equivalent of "ip neigh lladdr dev nud permanent". 14 | */ 15 | void ModifyNeighborEntry(const Neighbor& Neighbor, Operation operation); 16 | 17 | static bool PerformNeighborDiscovery(Neighbor& Local, Neighbor& Neighbor); 18 | 19 | private: 20 | template 21 | void ModifyNeighborEntryImpl(const Neighbor& Neighbor, int operation, int flags); 22 | 23 | /* 24 | Creates the message using the routine, then sends the message via netlink. 25 | */ 26 | template 27 | void SendMessage(const Neighbor& Neighbor, int operation, int flags, const std::function& routine = [](auto&) {}); 28 | 29 | NetlinkChannel m_channel; 30 | }; 31 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Makefile.linux: -------------------------------------------------------------------------------- 1 | # This makefile is used to work from a linux environement and is not part of the OS build process. 2 | 3 | CXXFLAGS += -std=c++20 -Wall -Wextra -g3 -fPIC -I../inc 4 | LDFLAGS += 5 | 6 | SRC = SyscallError main Interface NetlinkResponse NetlinkParseException RuntimeErrorWithSourceLocation Utils Address NetlinkTransaction NetlinkTransactionError 7 | OBJ = $(addsuffix .o, $(SRC)) 8 | BIN = test 9 | CXX=clang++ 10 | 11 | $(BIN): $(OBJ) 12 | $(CXX) $(CXXFLAGS) $(OBJ) $(LDFLAGS) -o $(BIN) 13 | 14 | clean: 15 | $(RM) $(OBJ) $(LIB) $(BIN) 16 | 17 | check: test 18 | ./test 19 | 20 | all: check 21 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Neighbor.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include "Neighbor.h" 3 | 4 | Neighbor::Neighbor(const Address& ipAddress, const MacAddress& macAddress, int dev) : 5 | ipAddress(ipAddress), macAddress(macAddress), dev(dev) 6 | { 7 | } 8 | 9 | int Neighbor::getFamily() const 10 | { 11 | return ipAddress.Family(); 12 | } 13 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Neighbor.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "address.h" 5 | 6 | struct Neighbor 7 | { 8 | Address ipAddress; 9 | MacAddress macAddress; 10 | int dev = -1; 11 | 12 | Neighbor(const Address& ipAddress, const MacAddress& macAddress, int dev); 13 | 14 | int getFamily() const; 15 | }; 16 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetLinkStrings.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | 7 | inline std::string NetLinkFormatFlagsToString(int flags) 8 | { 9 | if (flags == 0) 10 | { 11 | return "[zero]"; 12 | } 13 | 14 | std::string returnString; 15 | if (flags & NLM_F_CREATE) 16 | { 17 | returnString.append("NLM_F_CREATE "); 18 | } 19 | if (flags & NLM_F_REPLACE) 20 | { 21 | returnString.append("NLM_F_REPLACE "); 22 | } 23 | if (flags & NLM_F_DUMP) 24 | { 25 | returnString.append("NLM_F_DUMP "); 26 | } 27 | if (flags & NLM_F_REQUEST) 28 | { 29 | returnString.append("NLM_F_REQUEST "); 30 | } 31 | if (flags & NLM_F_EXCL) 32 | { 33 | returnString.append("NLM_F_EXCL "); 34 | } 35 | return returnString; 36 | } 37 | 38 | inline auto* RouteOperationToString(int operation) 39 | { 40 | if (operation == RTM_DELROUTE) 41 | { 42 | return "RTM_DELROUTE "; 43 | } 44 | if (operation == RTM_NEWROUTE) 45 | { 46 | return "RTM_NEWROUTE "; 47 | } 48 | return "[unknown route operation]"; 49 | } 50 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkError.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include 4 | #include "NetlinkError.h" 5 | 6 | NetlinkError::NetlinkError(int error, const std::source_location& source) : 7 | RuntimeErrorWithSourceLocation(std::format("Netlink returned error: {}", error), source), m_error(error) 8 | { 9 | } 10 | 11 | int NetlinkError::Error() const 12 | { 13 | return m_error; 14 | } 15 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkError.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | 6 | class NetlinkError : public RuntimeErrorWithSourceLocation 7 | { 8 | public: 9 | NetlinkError(int error, const std::source_location& source = std::source_location::current()); 10 | 11 | int Error() const; 12 | 13 | private: 14 | int m_error = -1; 15 | }; 16 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkMessage.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "Fwd.h" 9 | 10 | template 11 | class NetlinkMessage 12 | { 13 | public: 14 | using Titerator = std::vector::const_iterator; 15 | 16 | NetlinkMessage(const NetlinkResponse& response, Titerator responseBegin, Titerator begin, Titerator end); 17 | 18 | const TMessage* Payload() const; 19 | 20 | const nlmsghdr* Header() const; 21 | 22 | template 23 | std::vector Attributes(int type) const; 24 | 25 | template 26 | std::optional UniqueAttribute(int type) const; 27 | 28 | private: 29 | const rtattr* FirstAttribute() const; 30 | 31 | const NetlinkResponse& m_response; 32 | Titerator m_responseBegin; 33 | Titerator m_begin; 34 | Titerator m_end; 35 | }; 36 | 37 | #include "NetlinkMessage.hxx" 38 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkParseException.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include "NetlinkParseException.h" 4 | #include "NetlinkResponse.h" 5 | #include "Utils.h" 6 | 7 | NetlinkParseException::NetlinkParseException(const NetlinkResponse& response, const std::string& reason, const std::source_location& source) : 8 | RuntimeErrorWithSourceLocation(BuildMessage(response, reason), source) 9 | { 10 | } 11 | 12 | std::string NetlinkParseException::BuildMessage(const NetlinkResponse& response, const std::string& reason) 13 | { 14 | std::stringstream str; 15 | str << reason << " Netlink response: "; 16 | utils::FormatBinary(str, &*response.Begin(), response.End() - response.Begin()); 17 | 18 | return str.str(); 19 | } 20 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkParseException.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | #include "Fwd.h" 6 | 7 | class NetlinkParseException : public RuntimeErrorWithSourceLocation 8 | { 9 | public: 10 | NetlinkParseException(const NetlinkResponse& response, const std::string& reason, const std::source_location& source = std::source_location::current()); 11 | 12 | private: 13 | static std::string BuildMessage(const NetlinkResponse& response, const std::string& reason); 14 | }; 15 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkResponse.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include "NetlinkMessage.h" 6 | 7 | class NetlinkResponse 8 | { 9 | public: 10 | using Titerator = std::vector::const_iterator; 11 | 12 | NetlinkResponse(std::vector&& content); 13 | 14 | void ThrowIfErrorFound() const; 15 | 16 | std::vector::const_iterator Begin() const; 17 | std::vector::const_iterator End() const; 18 | 19 | template 20 | std::vector> Messages(int type) const; 21 | 22 | __u32 Sequence() const; 23 | 24 | bool MultiMessage() const; 25 | 26 | bool Done() const; 27 | 28 | private: 29 | std::vector m_data; 30 | }; 31 | 32 | std::ostream& operator<<(std::ostream& out, const NetlinkResponse& response); 33 | 34 | #include "NetlinkResponse.hxx" 35 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkResponse.hxx: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "NetlinkResponse.h" 5 | #include "NetlinkParseException.h" 6 | 7 | template 8 | std::vector> NetlinkResponse::Messages(int type) const 9 | { 10 | std::vector> messages; 11 | 12 | size_t size = m_data.size(); 13 | for (const auto* header = reinterpret_cast(m_data.data()); NLMSG_OK(header, size); header = NLMSG_NEXT(header, size)) 14 | { 15 | if (header->nlmsg_type == type) 16 | { 17 | auto begin = m_data.begin() + (reinterpret_cast(header) - m_data.data()); 18 | auto end = begin + header->nlmsg_len; 19 | messages.emplace_back(*this, m_data.begin(), begin, end); 20 | } 21 | } 22 | 23 | if (size != 0) 24 | { 25 | throw NetlinkParseException(*this, std::format("Netlink message is truncated. Missing bytes: {}", size)); 26 | } 27 | 28 | return messages; 29 | } 30 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkTransaction.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include "Fwd.h" 7 | 8 | class NetlinkTransaction 9 | { 10 | public: 11 | NetlinkTransaction(NetlinkChannel& channel, std::vector&& request, __u32 seq); 12 | 13 | void Execute(const std::function& routine = [](const auto&) {}); 14 | 15 | // Useful for debugging how netlink requests are composed 16 | void PrintRequest() const; 17 | std::string GetRawRequestString() const; 18 | 19 | private: 20 | NetlinkChannel& m_channel; 21 | std::vector m_request; 22 | __u32 m_seq; 23 | }; 24 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkTransactionError.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include "NetlinkTransactionError.h" 4 | #include "NetlinkError.h" 5 | #include "NetlinkResponse.h" 6 | #include "Utils.h" 7 | 8 | NetlinkTransactionError::NetlinkTransactionError( 9 | const std::vector& request, const std::vector& responses, const std::exception& inner, const std::source_location& source) : 10 | RuntimeErrorWithSourceLocation(BuildMessage(request, responses, inner), source) 11 | { 12 | const auto* error = dynamic_cast(&inner); 13 | if (error != nullptr) 14 | { 15 | m_error = error->Error(); 16 | } 17 | } 18 | 19 | std::optional NetlinkTransactionError::Error() const 20 | { 21 | return m_error; 22 | } 23 | 24 | std::string NetlinkTransactionError::BuildMessage(const std::vector& request, const std::vector& responses, const std::exception& inner) 25 | { 26 | std::stringstream str; 27 | 28 | str << "Error in netlink transaction.\n"; 29 | str << "Innermost exception: " << inner.what(); 30 | str << "\nRequest: "; 31 | utils::FormatBinary(str, request.data(), request.size()); 32 | str << "\nResponses: (seen: " << std::to_string(responses.size()) << ") "; 33 | utils::FormatArray(str, responses); 34 | 35 | return str.str(); 36 | } 37 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/NetlinkTransactionError.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | #include "NetlinkMessage.h" 6 | 7 | class NetlinkTransactionError : public RuntimeErrorWithSourceLocation 8 | { 9 | public: 10 | NetlinkTransactionError( 11 | const std::vector& request, 12 | const std::vector& responses, 13 | const std::exception& inner, 14 | const std::source_location& source = std::source_location::current()); 15 | 16 | std::optional Error() const; 17 | 18 | private: 19 | static std::string BuildMessage(const std::vector& request, const std::vector& responses, const std::exception& inner); 20 | 21 | std::optional m_error; 22 | }; 23 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Operation.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | enum Operation 5 | { 6 | Create, 7 | Update, 8 | Remove 9 | }; 10 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Protocol.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | enum Protocol 5 | { 6 | Tcp, 7 | Udp 8 | }; 9 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Route.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include "address.h" 6 | 7 | struct Route 8 | { 9 | int family = -1; 10 | std::optional
via; 11 | int dev = -1; 12 | bool defaultRoute = false; 13 | std::optional
to; 14 | int metric = 0; 15 | bool isLoopbackRoute = false; 16 | 17 | Route(int family, const std::optional
& via, int dev, bool defaultRoute, const std::optional
& to, int metric); 18 | 19 | bool IsOnlink() const; 20 | bool IsMulticast() const; 21 | }; 22 | 23 | std::ostream& operator<<(std::ostream& out, const Route& route); 24 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Rule.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include "Rule.h" 4 | 5 | Rule::Rule(int family, int routingTable, int priority) : family(family), routingTable(routingTable), priority(priority) 6 | { 7 | } 8 | 9 | Rule::Rule(int family, int routingTable, int priority, const std::optional protocol) : 10 | family(family), routingTable(routingTable), priority(priority), protocol(protocol) 11 | { 12 | } 13 | 14 | Rule::Rule(int family, int routingTable, int priority, const std::string& oif, const std::optional protocol) : 15 | family(family), routingTable(routingTable), priority(priority), oif(oif), protocol(protocol) 16 | { 17 | } 18 | 19 | std::ostream& operator<<(std::ostream& out, const Rule& rule) 20 | { 21 | out << "priority " << rule.priority << " family " << (rule.family == AF_INET ? "ipv4" : "ipv6") << " "; 22 | 23 | if (rule.sourceAddress) 24 | { 25 | out << "from " << rule.sourceAddress.value() << " "; 26 | } 27 | 28 | if (rule.protocol) 29 | { 30 | out << "ipproto " << (rule.protocol.value() == Protocol::Tcp ? "tcp" : "udp") << " "; 31 | } 32 | 33 | if (!rule.oif.empty()) 34 | { 35 | out << "oif " << rule.oif << " "; 36 | } 37 | 38 | if (!rule.iif.empty()) 39 | { 40 | out << "iif " << rule.iif << " "; 41 | } 42 | 43 | return out << "lookup table " << rule.routingTable << " "; 44 | } 45 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Rule.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include "address.h" 6 | #include "Protocol.h" 7 | 8 | /* 9 | Currently Rule only supports family, table, priority, input or output interface, source IP and protocol (tcp/udp). 10 | It can be extended destination IP and source/destination port. 11 | */ 12 | struct Rule 13 | { 14 | int family = AF_INET; 15 | int routingTable = -1; 16 | int priority = -1; 17 | std::string iif; 18 | std::string oif; 19 | std::optional protocol; 20 | std::optional
sourceAddress; 21 | 22 | Rule(int family, int routingTable, int priority); 23 | 24 | Rule(int family, int routingTable, int priority, std::optional protocol); 25 | 26 | Rule(int family, int routingTable, int priority, const std::string& oif, std::optional protocol); 27 | }; 28 | 29 | std::ostream& operator<<(std::ostream& out, const Rule& rule); -------------------------------------------------------------------------------- /src/linux/netlinkutil/RuntimeErrorWithSourceLocation.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | 6 | RuntimeErrorWithSourceLocation::RuntimeErrorWithSourceLocation(const std::string& reason, const std::source_location& location) : 7 | std::runtime_error(BuildMessage(reason, {}, location)) 8 | { 9 | } 10 | 11 | RuntimeErrorWithSourceLocation::RuntimeErrorWithSourceLocation(const std::string& reason, const std::exception& inner, const std::source_location& location) : 12 | std::runtime_error(BuildMessage(reason, inner, location)) 13 | { 14 | } 15 | 16 | std::string RuntimeErrorWithSourceLocation::BuildMessage(const std::string& reason, const std::optional& inner, const std::source_location& source) 17 | { 18 | std::stringstream str; 19 | str << "Exception thrown by " << source.function_name() << " in " << source.file_name() << ":" << source.line() << ":" << reason; 20 | if (inner.has_value()) 21 | { 22 | str << "\nInner exception: " << inner.value().what(); 23 | } 24 | 25 | return str.str(); 26 | } 27 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/RuntimeErrorWithSourceLocation.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include 4 | #include 5 | 6 | #pragma once 7 | 8 | class RuntimeErrorWithSourceLocation : public std::runtime_error 9 | { 10 | public: 11 | RuntimeErrorWithSourceLocation(const std::string& reason, const std::source_location& location = std::source_location::current()); 12 | 13 | RuntimeErrorWithSourceLocation( 14 | const std::string& reason, const std::exception& inner, const std::source_location& location = std::source_location::current()); 15 | 16 | private: 17 | static std::string BuildMessage(const std::string& reason, const std::optional& inner, const std::source_location& location); 18 | }; 19 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Syscall.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | template 8 | typename std::invoke_result::type _Syscall(const std::source_location& source, Routine routine, Args... args); 9 | #define Syscall(...) _Syscall(std::source_location::current(), __VA_ARGS__) 10 | 11 | template 12 | typename std::invoke_result::type _SyscallInterruptable(const std::source_location& source, Routine routine, Args... args); 13 | #define SyscallInterruptable(...) _SyscallInterruptable(std::source_location::current(), __VA_ARGS__) 14 | 15 | #include "Syscall.hxx" 16 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/SyscallError.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #include 3 | #include 4 | #include "SyscallError.h" 5 | 6 | SyscallError::SyscallError(const std::string& method, const std::string& arguments, int err, const std::source_location& source) : 7 | RuntimeErrorWithSourceLocation(BuildMessage(method, arguments, err), source), savedErrno(err) 8 | { 9 | } 10 | 11 | std::string SyscallError::BuildMessage(const std::string& method, const std::string& arguments, int err) 12 | { 13 | std::stringstream str; 14 | 15 | str << method << "(" << arguments << ") failed with errno=" << err << " (" << strerror(err) << ")"; 16 | 17 | return str.str(); 18 | } 19 | 20 | int SyscallError::GetErrno() const 21 | { 22 | return savedErrno; 23 | } 24 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/SyscallError.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | 6 | class SyscallError : public RuntimeErrorWithSourceLocation 7 | { 8 | public: 9 | SyscallError(const std::string& method, const std::string& arguments, int err, const std::source_location& source); 10 | 11 | static std::string BuildMessage(const std::string& method, const std::string& arguments, int err); 12 | 13 | int GetErrno() const; 14 | 15 | private: 16 | int savedErrno; 17 | }; 18 | -------------------------------------------------------------------------------- /src/linux/netlinkutil/Utils.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #include "Utils.h" 4 | #include "RuntimeErrorWithSourceLocation.h" 5 | #include 6 | #include 7 | #include 8 | 9 | std::ostream& utils::FormatBinary(std::ostream& out, const void* ptr, size_t bytes) 10 | { 11 | out << "(" << bytes << " bytes) {"; 12 | out << BytesToHex(ptr, bytes, ","); 13 | 14 | return out << "}"; 15 | } 16 | 17 | std::string utils::BytesToHex(const void* ptr, size_t bytes, const std::string& separator) 18 | { 19 | std::stringstream out; 20 | for (size_t i = 0; i < bytes; i++) 21 | { 22 | if (i != 0) 23 | { 24 | out << separator; 25 | } 26 | 27 | out << std::hex << std::setw(2) << std::setfill('0') << static_cast(reinterpret_cast(ptr)[i]); 28 | } 29 | 30 | return out.str(); 31 | } 32 | 33 | Address utils::ComputeBroadcastAddress(const Address& address) 34 | { 35 | if (address.Family() != AF_INET) 36 | { 37 | throw RuntimeErrorWithSourceLocation(std::format("Can't compute broadcast address for address family: {}", address.Family())); 38 | } 39 | 40 | auto bytes = address.AsBytes(); 41 | 42 | // Set all the bits between the prefixLength and 32 to 1 43 | std::uint32_t suffix = (1 << (32 - address.PrefixLength())) - 1; 44 | bytes.s_addr |= htonl(suffix); 45 | 46 | return Address::FromBytes(AF_INET, address.PrefixLength(), bytes); 47 | } 48 | -------------------------------------------------------------------------------- /src/linux/plan9/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | p9fid.cpp 3 | p9file.cpp 4 | p9fs.cpp 5 | p9handler.cpp 6 | p9io.cpp 7 | p9lx.cpp 8 | p9readdir.cpp 9 | p9scheduler.cpp 10 | p9tracelogging.cpp 11 | p9util.cpp 12 | p9xattr.cpp) 13 | 14 | set(HEADERS 15 | p9fid.h 16 | p9file.h 17 | p9fs.h 18 | p9handler.h 19 | p9io.h 20 | p9lx.h 21 | p9readdir.h 22 | p9scheduler.h 23 | p9tracelogging.h 24 | p9tracelogginghelper.h 25 | p9util.h 26 | p9xattr.h 27 | p9defs.h 28 | p9protohelpers.h 29 | p9await.h 30 | p9errors.h 31 | result_macros.h 32 | expected.h 33 | p9platform.h 34 | p9ihandler.h 35 | p9log.h 36 | p9data.h 37 | p9commonutil.h 38 | precomp.h) 39 | 40 | add_linux_library(libplan9 "${SOURCES}" "${HEADERS}") 41 | set_target_properties(libplan9 PROPERTIES FOLDER linux) -------------------------------------------------------------------------------- /src/linux/plan9/p9errors.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "p9defs.h" 5 | #include "expected.h" 6 | #include "result_macros.h" 7 | 8 | namespace p9fs { 9 | 10 | using util::BasicExpected; 11 | using util::Unexpected; 12 | 13 | using LxError = Unexpected; 14 | 15 | template 16 | using Expected = BasicExpected; 17 | 18 | namespace util { 19 | 20 | LX_INT LinuxErrorFromCaughtException(); 21 | 22 | } // namespace util 23 | 24 | } // namespace p9fs 25 | -------------------------------------------------------------------------------- /src/linux/plan9/p9fs.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | namespace p9fs { 5 | 6 | // Interface for running the Plan 9 server. 7 | // N.B. The main reason this is an interface, despite not needing COM like the Windows equivalent, 8 | // is so consumers can just include this header rather than needing most of the library's 9 | // headers and needing to compile with coroutine support, which would be required to directly 10 | // use the implementation of this interface. 11 | class IPlan9FileSystem 12 | { 13 | public: 14 | virtual ~IPlan9FileSystem() noexcept = default; 15 | 16 | virtual void AddShare(const std::string& name, int rootFd) = 0; 17 | virtual void Pause() = 0; 18 | virtual void Resume() = 0; 19 | virtual void Teardown() = 0; 20 | virtual bool HasConnections() const noexcept = 0; 21 | }; 22 | 23 | std::unique_ptr CreateFileSystem(int socket); 24 | 25 | } // namespace p9fs 26 | -------------------------------------------------------------------------------- /src/linux/plan9/p9ihandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | namespace p9fs { 5 | 6 | // This class serves as a base for the platform-specific Root class. It has 7 | // no functionality. 8 | class IRoot 9 | { 10 | public: 11 | virtual ~IRoot() = default; 12 | 13 | protected: 14 | IRoot() = default; 15 | }; 16 | 17 | class IShareList 18 | { 19 | public: 20 | virtual ~IShareList() = default; 21 | 22 | virtual Expected> MakeRoot(std::string_view aname, LX_UID_T uid) = 0; 23 | virtual size_t MaximumConnectionCount() = 0; 24 | }; 25 | 26 | // Interface through which virtio can process messages on a handler. 27 | // N.B. This definition is not in p9handler so it can be used without needing to include all the 28 | // coroutine related headers as well. 29 | class IHandler 30 | { 31 | public: 32 | using HandlerCallback = std::function& response)>; 33 | virtual void ProcessMessageAsync(std::vector&& message, size_t responseSize, HandlerCallback&& callback) = 0; 34 | }; 35 | 36 | class HandlerFactory 37 | { 38 | public: 39 | HandlerFactory(IShareList& shareList) : m_shareList{shareList} 40 | { 41 | } 42 | 43 | std::unique_ptr CreateHandler() const; 44 | 45 | private: 46 | IShareList& m_shareList; 47 | }; 48 | 49 | } // namespace p9fs 50 | -------------------------------------------------------------------------------- /src/linux/plan9/p9lx.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "p9platform.h" 5 | #include "p9io.h" 6 | 7 | namespace p9fs { 8 | 9 | class Socket final : public ISocket 10 | { 11 | public: 12 | Socket(int socket = -1); 13 | 14 | Task> AcceptAsync(CancelToken& token) override; 15 | Task RecvAsync(gsl::span buffer, CancelToken& token) override; 16 | Task SendAsync(gsl::span buffer, CancelToken& token) override; 17 | void Reset(int socket = -1); 18 | 19 | private: 20 | wil::unique_fd m_Socket; 21 | CoroutineEpollIssuer m_Io; 22 | }; 23 | 24 | class WorkItem final : public IWorkItem 25 | { 26 | public: 27 | WorkItem(std::function callback); 28 | 29 | void Submit() override; 30 | 31 | private: 32 | std::function m_Callback; 33 | }; 34 | 35 | class ThreadPool final 36 | { 37 | public: 38 | ThreadPool(); 39 | 40 | void SubmitWork(std::function callback); 41 | 42 | private: 43 | void WorkerCallback(); 44 | 45 | std::queue> m_WorkQueue; 46 | std::mutex m_Lock; 47 | std::condition_variable m_Condition; 48 | unsigned int m_MaxThreads{}; 49 | unsigned int m_AvailableThreads{}; 50 | unsigned int m_RunningThreads{}; 51 | }; 52 | 53 | } // namespace p9fs 54 | -------------------------------------------------------------------------------- /src/linux/plan9/p9platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "p9await.h" 5 | 6 | namespace p9fs { 7 | 8 | // Platform-independent wrapper around socket operations. 9 | class ISocket 10 | { 11 | public: 12 | virtual ~ISocket() = default; 13 | 14 | virtual Task> AcceptAsync(CancelToken& token) = 0; 15 | virtual Task RecvAsync(gsl::span buffer, CancelToken& token) = 0; 16 | virtual Task SendAsync(gsl::span buffer, CancelToken& token) = 0; 17 | }; 18 | 19 | // Platform-independent wrapper around threadpool work 20 | class IWorkItem 21 | { 22 | public: 23 | virtual ~IWorkItem() = default; 24 | 25 | virtual void Submit() = 0; 26 | }; 27 | 28 | std::unique_ptr CreateWorkItem(std::function callback); 29 | 30 | } // namespace p9fs 31 | -------------------------------------------------------------------------------- /src/linux/plan9/p9readdir.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | namespace p9fs { 5 | 6 | class DirectoryEnumerator final 7 | { 8 | public: 9 | DirectoryEnumerator(int fd); 10 | ~DirectoryEnumerator(); 11 | 12 | struct dirent* Next(); 13 | void Seek(long offset); 14 | int Fd(); 15 | 16 | private: 17 | DIR* m_Dir{}; 18 | long m_LastOffset{}; 19 | }; 20 | 21 | } // namespace p9fs 22 | -------------------------------------------------------------------------------- /src/linux/plan9/p9scheduler.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | namespace p9fs { 5 | 6 | class IWorkItem; 7 | 8 | class Scheduler 9 | { 10 | public: 11 | using Coroutine = std::coroutine_handle<>; 12 | 13 | struct Unblocker 14 | { 15 | Scheduler& m_Scheduler; 16 | bool m_Run{}; 17 | 18 | bool await_ready() const 19 | { 20 | return m_Run; 21 | } 22 | 23 | void await_suspend(Coroutine handle) 24 | { 25 | m_Scheduler.Schedule(handle); 26 | } 27 | 28 | static void await_resume() 29 | { 30 | } 31 | }; 32 | 33 | Scheduler(); 34 | void Schedule(Coroutine coroutine) noexcept; 35 | void DonateThreadAndResume(Coroutine coroutine) noexcept; 36 | bool Block() noexcept; 37 | struct Unblocker Unblock() noexcept; 38 | 39 | private: 40 | void RunAndRelease() noexcept; 41 | bool Claim(bool owner) noexcept; 42 | void WorkerCallback() noexcept; 43 | 44 | std::shared_mutex m_Lock; 45 | std::queue m_Queue; 46 | std::unique_ptr m_Work; 47 | bool m_Running; 48 | bool m_ThreadEnqueued; 49 | static thread_local bool tls_Blocked; 50 | static thread_local bool tls_SchedulerThread; 51 | }; 52 | 53 | extern Scheduler g_Scheduler; 54 | 55 | } // namespace p9fs 56 | -------------------------------------------------------------------------------- /src/linux/plan9/p9tracelogginghelper.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | namespace p9fs { 5 | 6 | // Class to help construct tracelogging messages for verbose logging of server traffic. 7 | // N.B. To avoid needlessly increasing the size of the statically linked WSL init binary, this 8 | // helper allows for constructing log messages without the use of printf or iostream. 9 | class LogMessageBuilder 10 | { 11 | public: 12 | void AddName(std::string_view name); 13 | void AddField(std::string_view name, std::string_view value); 14 | void AddField(std::string_view name, UINT64 value, int base = 10); 15 | void AddField(std::string_view name, const Qid& value); 16 | void AddValue(std::string_view value); 17 | void AddValue(const Qid& qid); 18 | 19 | const char* String() const; 20 | 21 | private: 22 | void AddFieldName(std::string_view name); 23 | void AddRawValue(UINT64 value, int base = 10); 24 | void AddRawValue(const Qid& value); 25 | void AddRawValue(std::string_view value); 26 | 27 | std::string m_message; 28 | }; 29 | 30 | } // namespace p9fs 31 | -------------------------------------------------------------------------------- /src/linux/plan9/p9util.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "p9errors.h" 5 | 6 | namespace p9fs::util { 7 | 8 | constexpr uid_t c_InvalidUid = std::numeric_limits::max(); 9 | constexpr gid_t c_InvalidGid = std::numeric_limits::max(); 10 | 11 | Expected Reopen(int fd, int openFlags); 12 | 13 | Expected OpenAt(int dirfd, const std::string& name, int openFlags, mode_t mode = 0600); 14 | 15 | std::string GetFdPath(int fd); 16 | 17 | LX_INT AccessHelper(int fd, const std::string& path, int mode); 18 | 19 | LX_INT CheckFOwnerCapability(); 20 | 21 | gid_t GetUserGroupId(uid_t uid); 22 | 23 | gid_t GetGroupIdByName(const char* name); 24 | 25 | // Changes the effective uid and gid of the current thread for the lifetime of this object. 26 | class FsUserContext final 27 | { 28 | public: 29 | FsUserContext(uid_t uid, gid_t gid, const std::vector& groups); 30 | ~FsUserContext(); 31 | 32 | private: 33 | bool m_Restore{}; 34 | bool m_restoreGroups{}; 35 | }; 36 | 37 | } // namespace p9fs::util 38 | -------------------------------------------------------------------------------- /src/linux/plan9/p9xattr.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include "p9fid.h" 5 | 6 | namespace p9fs { 7 | 8 | class XAttr final : public XAttrBase 9 | { 10 | public: 11 | enum class Access 12 | { 13 | Read, 14 | Write 15 | }; 16 | 17 | XAttr(const std::shared_ptr& root, const std::string& fileName, const std::string& name, Access access, UINT64 size = 0, UINT32 flags = 0); 18 | 19 | Task> Read(UINT64 Offset, gsl::span Buffer) override; 20 | Task> Write(UINT64 Offset, gsl::span Buffer) override; 21 | LX_INT Clunk() override; 22 | 23 | Expected GetSize() override; 24 | 25 | private: 26 | Expected GetValue(gsl::span Buffer); 27 | 28 | std::shared_mutex m_Lock; 29 | const std::shared_ptr m_Root; 30 | const std::string m_FileName; 31 | const std::string m_Name; 32 | std::vector m_Value; 33 | const Access m_Access; 34 | const UINT32 m_Flags; 35 | }; 36 | 37 | } // namespace p9fs 38 | -------------------------------------------------------------------------------- /src/linux/plan9/precomp.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | #pragma once 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | // C standard library 22 | #include 23 | #include 24 | #include 25 | 26 | // C++ standard library 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | 43 | // Guideline Support Library 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include "lxdef.h" 51 | #include "lxwil.h" 52 | -------------------------------------------------------------------------------- /src/shared/configfile/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES ${CMAKE_CURRENT_LIST_DIR}/configfile.cpp) 2 | set(HEADERS ${CMAKE_CURRENT_LIST_DIR}/configfile.h) 3 | 4 | add_subdirectory(linux) 5 | add_subdirectory(windows) -------------------------------------------------------------------------------- /src/shared/configfile/linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_linux_library_no_sources(libconfigfile "${SOURCES}" "${HEADERS}") 2 | set_target_properties(libconfigfile PROPERTIES FOLDER common) 3 | add_dependencies(libconfigfile localization) -------------------------------------------------------------------------------- /src/shared/configfile/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(configfile STATIC ${SOURCES} ${HEADERS}) 2 | add_dependencies(configfile wslserviceidl localization common) 3 | set_target_properties(configfile PROPERTIES FOLDER common) -------------------------------------------------------------------------------- /src/shared/inc/defs.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | defs.h 8 | 9 | Abstract: 10 | 11 | This file contains shared platform definitions. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #if defined(_MSC_VER) 18 | #define THROW_INVALID_ARG_IF(condition) THROW_HR_IF(E_INVALIDARG, condition) 19 | #elif defined(__GNUC__) 20 | #define THROW_INVALID_ARG_IF(condition) THROW_ERRNO_IF(EINVAL, condition) 21 | #define _stricmp strcasecmp 22 | #define _wcsicmp wcscasecmp 23 | #endif 24 | 25 | namespace wsl::shared { 26 | 27 | inline constexpr std::uint32_t VersionMajor = WSL_PACKAGE_VERSION_MAJOR; 28 | inline constexpr std::uint32_t VersionMinor = WSL_PACKAGE_VERSION_MINOR; 29 | inline constexpr std::uint32_t VersionRevision = WSL_PACKAGE_VERSION_REVISION; 30 | inline constexpr std::tuple PackageVersion{VersionMajor, VersionMinor, VersionRevision}; 31 | 32 | #ifdef WSL_OFFICIAL_BUILD 33 | 34 | inline constexpr bool OfficialBuild = true; 35 | 36 | #else 37 | 38 | inline constexpr bool OfficialBuild = false; 39 | 40 | #endif 41 | 42 | #ifdef DEBUG 43 | 44 | inline constexpr bool Debug = true; 45 | 46 | #else 47 | 48 | inline constexpr bool Debug = false; 49 | 50 | #endif 51 | 52 | #ifdef _AMD64_ 53 | 54 | inline constexpr bool Arm64 = false; 55 | 56 | #elif _ARM64_ 57 | 58 | inline constexpr bool Arm64 = true; 59 | 60 | #else 61 | 62 | #error Unsupported compiler or build environment 63 | 64 | #endif 65 | 66 | } // namespace wsl::shared 67 | -------------------------------------------------------------------------------- /src/shared/inc/lxfsshares.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | lxfsshares.h 8 | 9 | Abstract: 10 | 11 | This file contains share names and paths that are consumed by both init 12 | and the WSL service. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | typedef struct _LXSS_SHARED_DIRECTORY 19 | { 20 | const char* Name; 21 | const char* MountPoint; 22 | } LXSS_SHARED_DIRECTORY, *PLXSS_SHARED_DIRECTORY; 23 | 24 | #define LXSS_LIB_PREFIX "/usr/lib/wsl" 25 | #define LXSS_LIB_PATH LXSS_LIB_PREFIX "/lib" 26 | #define LXSS_GPU_DRIVERS_SHARE "drivers" 27 | #define LXSS_GPU_LIB_SHARE "lib" 28 | #define LXSS_GPU_INBOX_LIB_SHARE LXSS_GPU_LIB_SHARE "_inbox" 29 | #define LXSS_GPU_PACKAGED_LIB_SHARE LXSS_GPU_LIB_SHARE "_packaged" 30 | 31 | // 32 | // Shared directories for GPU compute support. 33 | // 34 | 35 | constexpr LXSS_SHARED_DIRECTORY g_gpuShares[] = {{LXSS_GPU_DRIVERS_SHARE, LXSS_LIB_PREFIX "/drivers"}, {LXSS_GPU_LIB_SHARE, LXSS_LIB_PATH}}; 36 | -------------------------------------------------------------------------------- /src/shared/inc/retryshared.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | retryshared.h 8 | 9 | Abstract: 10 | 11 | This file contains shared retry helper functions. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wsl::shared::retry { 18 | 19 | constexpr auto AlwaysRetry = []() { return true; }; 20 | 21 | template 22 | T RetryWithTimeout(const std::function& routine, TPeriod retryPeriod, TTimeout timeout, const std::function& retryPred = AlwaysRetry) 23 | { 24 | auto stop = std::chrono::steady_clock::now() + timeout; 25 | for (;;) 26 | { 27 | try 28 | { 29 | return routine(); 30 | } 31 | catch (...) 32 | { 33 | if (!retryPred() || std::chrono::steady_clock::now() > stop) 34 | { 35 | throw; 36 | } 37 | 38 | std::this_thread::sleep_for(retryPeriod); 39 | } 40 | } 41 | } 42 | 43 | } // namespace wsl::shared::retry 44 | -------------------------------------------------------------------------------- /src/windows/common/ConsoleProgressBar.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | ConsoleProgressBar.h 8 | 9 | Abstract: 10 | 11 | This file contains the ConsoleProgressBar definition 12 | 13 | --*/ 14 | 15 | #pragma once 16 | #include "windows.h" 17 | 18 | namespace wsl::windows::common { 19 | class ConsoleProgressBar 20 | { 21 | public: 22 | ConsoleProgressBar(); 23 | 24 | HRESULT 25 | Print(_In_ uint64_t progress, _In_ uint64_t total); 26 | 27 | HRESULT 28 | Clear(); 29 | 30 | private: 31 | HRESULT 32 | PrintAndResetPosition(_In_ LPCWSTR string) const; 33 | 34 | static bool HandleIsConsole(_In_ HANDLE handle); 35 | 36 | bool m_isOutputConsole; 37 | HANDLE m_outputHandle; 38 | wil::unique_hlocal_string m_progressString; 39 | uint64_t m_previousProgress = 0; 40 | uint64_t m_previousTotal = 0; 41 | }; 42 | } // namespace wsl::windows::common 43 | -------------------------------------------------------------------------------- /src/windows/common/ConsoleProgressIndicator.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | ConsoleProgressIndicator.h 8 | 9 | Abstract: 10 | 11 | This file contains console function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "wrl.h" 19 | 20 | namespace wsl::windows::common { 21 | class ConsoleProgressIndicator 22 | { 23 | private: 24 | std::thread m_thread; 25 | wil::unique_event m_event; 26 | std::wstring m_waitMessage; 27 | std::wstring m_progressMessage; 28 | bool m_interactive{}; 29 | 30 | void IndicateProgress() const; 31 | 32 | public: 33 | ConsoleProgressIndicator(std::wstring&& inputMessage, bool animatedDots = false); 34 | ~ConsoleProgressIndicator(); 35 | 36 | void End(); 37 | 38 | void UpdateProgress(std::wstring&& progress); 39 | }; 40 | } // namespace wsl::windows::common 41 | -------------------------------------------------------------------------------- /src/windows/common/HandleConsoleProgressBar.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | HandleConsoleProgressBar.h 8 | 9 | Abstract: 10 | 11 | This file contains the definition of the HandleConsoleProgressBar class. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include "ConsoleProgressBar.h" 18 | #include "ConsoleProgressIndicator.h" 19 | 20 | namespace wsl::windows::common { 21 | class HandleConsoleProgressBar 22 | { 23 | public: 24 | enum Format 25 | { 26 | FilePointer, 27 | FileSize 28 | }; 29 | 30 | HandleConsoleProgressBar(HANDLE handle, std::wstring&& message, Format format = FilePointer); 31 | HandleConsoleProgressBar(const HandleConsoleProgressBar&) = delete; 32 | HandleConsoleProgressBar(HandleConsoleProgressBar&&) = delete; 33 | 34 | ~HandleConsoleProgressBar(); 35 | 36 | HandleConsoleProgressBar& operator=(const HandleConsoleProgressBar&) = delete; 37 | HandleConsoleProgressBar& operator=(HandleConsoleProgressBar&&) = delete; 38 | 39 | private: 40 | void UpdateProgress(HANDLE handle, LARGE_INTEGER totalBytes, ConsoleProgressBar& progressBar) const; 41 | void UpdateFileSize(HANDLE handle, ConsoleProgressIndicator& progressBar) const; 42 | 43 | wil::unique_event m_event{wil::EventOptions::ManualReset}; 44 | std::thread m_thread; 45 | std::variant m_progressBar; 46 | }; 47 | 48 | } // namespace wsl::windows::common -------------------------------------------------------------------------------- /src/windows/common/LxssPort.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | LxssPort.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for the port abstract base class. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | class LxssPort 18 | { 19 | public: 20 | virtual std::shared_ptr CreateSessionLeader(_In_ HANDLE ClientProcess) = 0; 21 | virtual void DisconnectConsole(_In_ HANDLE ClientProcess) = 0; 22 | virtual wil::cs_leave_scope_exit Lock() = 0; 23 | virtual void Receive(_Out_writes_bytes_(Length) PVOID Buffer, _In_ ULONG Length, _In_opt_ HANDLE ClientProcess = nullptr, _In_ DWORD Timeout = INFINITE) = 0; 24 | virtual void Send(_In_reads_bytes_(Length) PVOID Buffer, _In_ ULONG Length) = 0; 25 | }; 26 | -------------------------------------------------------------------------------- /src/windows/common/LxssServerPort.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | LxssServerPort.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for the server port wrapper class. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | class LxssMessagePort; 18 | 19 | class LxssServerPort 20 | { 21 | public: 22 | LxssServerPort(); 23 | 24 | LxssServerPort(_In_ wil::unique_handle&& ServerPortHandle); 25 | 26 | void RegisterLxBusServer(_In_ const wil::unique_handle& InstanceHandle, _In_ LPCSTR ServerName); 27 | 28 | HANDLE 29 | ReleaseServerPort(); 30 | 31 | std::unique_ptr WaitForConnection(_In_ ULONG TimeoutMs = LXBUS_IPC_INFINITE_TIMEOUT); 32 | 33 | NTSTATUS 34 | WaitForConnectionNoThrow(_Out_ std::unique_ptr* MessagePort, _In_ ULONG TimeoutMs = LXBUS_IPC_INFINITE_TIMEOUT) const; 35 | 36 | private: 37 | wil::unique_handle m_serverPort; 38 | }; 39 | -------------------------------------------------------------------------------- /src/windows/common/Redirector.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | Redirector.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for helpers for controlling the Plan 9 Redirector. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wsl::windows::common::redirector { 18 | 19 | class ConnectionTargetManager final 20 | { 21 | public: 22 | ConnectionTargetManager(std::wstring_view name); 23 | 24 | void AddConnectionTarget( 25 | HANDLE userToken, std::string_view aname, LX_UID_T uid, std::wstring_view unixSocketPath = {}, const GUID& instanceId = {}, ULONG port = 0); 26 | 27 | void RemoveAll(); 28 | 29 | private: 30 | bool Contains(LUID luid) const; 31 | 32 | std::wstring_view m_name; 33 | std::vector m_logonIds; 34 | wil::srwlock m_lock; 35 | }; 36 | 37 | wil::unique_hfile OpenRedirector(); 38 | 39 | void EnsureRedirectorStarted(); 40 | 41 | bool StartRedirector(); 42 | 43 | void AddConnectionTarget( 44 | std::wstring_view name, LUID logonId, std::string_view aname, LX_UID_T uid, std::wstring_view unixSocketPath, const GUID& instanceId = {}, ULONG port = 0); 45 | 46 | void RemoveConnectionTarget(std::wstring_view name, LUID logonId); 47 | 48 | void RegisterUserCallback(HANDLE handle, gsl::span outputBuffer, LPOVERLAPPED overlapped); 49 | 50 | } // namespace wsl::windows::common::redirector 51 | -------------------------------------------------------------------------------- /src/windows/common/WslClient.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslClient.h 8 | 9 | Abstract: 10 | 11 | This file contains the declaration for WSL client entry points. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wsl::windows::common { 18 | class WslClient 19 | { 20 | public: 21 | static int Main(_In_ LPCWSTR commandLine); 22 | }; 23 | } // namespace wsl::windows::common 24 | -------------------------------------------------------------------------------- /src/windows/common/WslCoreFirewallSupport.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "WslCoreConfig.h" 10 | 11 | namespace wsl::core::networking { 12 | 13 | enum class HyperVFirewallSupport 14 | { 15 | None, 16 | Version1, // initially shipped with SV2 17 | Version2 // updated from Version1 and backported down to Windows 11 22H2 18 | }; 19 | HyperVFirewallSupport GetHyperVFirewallSupportVersion(const FirewallConfiguration& firewallConfig) noexcept; 20 | 21 | std::wstring MakeLoopbackFirewallRuleId(const GUID& guid); 22 | std::wstring MakeLocalSubnetFirewallRuleId(const GUID& guid); 23 | 24 | std::vector MakeDefaultFirewallRuleConfiguration(const GUID& guid); 25 | FirewallRuleConfiguration MakeLoopbackFirewallRuleConfiguration(const std::wstring& ruleId); 26 | FirewallRuleConfiguration MakeLocalSubnetFirewallRuleConfiguration(const std::wstring& ruleId); 27 | 28 | void ConfigureHyperVFirewall(const FirewallConfiguration& firewallConfig, const std::wstring& vmCreatorFriendlyName) noexcept; 29 | 30 | void ConfigureSharedAccessFirewallRule() noexcept; 31 | 32 | HRESULT AddHyperVFirewallRule(const GUID& vmCreatorId, const wsl::core::FirewallRuleConfiguration& firewallRule) noexcept; 33 | HRESULT RemoveHyperVFirewallRule(const std::wstring& ruleId) noexcept; 34 | 35 | } // namespace wsl::core::networking 36 | -------------------------------------------------------------------------------- /src/windows/common/disk.hpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | disk.hpp 8 | 9 | Abstract: 10 | 11 | This file contains disk functions declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wsl::windows::common::disk { 18 | 19 | constexpr inline auto c_diskOperationRetry = std::chrono::milliseconds(500); 20 | 21 | wil::unique_hfile OpenDevice(_In_ LPCWSTR Name, _In_ DWORD Access = GENERIC_READ, _In_ size_t TimeoutMs = 5 * 1000); 22 | 23 | bool IsDiskOnline(_In_ HANDLE Disk); 24 | 25 | void SetOnline(_In_ HANDLE Disk, _In_ bool Online, _In_ size_t TimeoutMs = 5 * 1000); 26 | 27 | void LockVolume(_In_ HANDLE Disk); 28 | 29 | void Ioctl(_In_ HANDLE Disk, _In_ DWORD Code, _In_opt_ LPVOID InData = nullptr, _In_ DWORD InDataSize = 0, _Out_opt_ LPVOID OutData = nullptr, _In_ DWORD OutDataSize = 0); 30 | 31 | std::map ListDiskVolumes(_In_ HANDLE Disk); 32 | 33 | std::vector GetVolumeDevices(_In_ HANDLE Volume); 34 | 35 | DWORD 36 | GetDiskNumber(_In_ HANDLE Disk); 37 | 38 | std::vector ListDiskPartitions(_In_ HANDLE Disk); 39 | 40 | void ValidateDiskVolumesAreReady(_In_ HANDLE Disk); 41 | } // namespace wsl::windows::common::disk 42 | -------------------------------------------------------------------------------- /src/windows/common/hvsocket.hpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | hvsocket.hpp 8 | 9 | Abstract: 10 | 11 | This file contains hvsocket helper function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | 20 | namespace wsl::windows::common::hvsocket { 21 | 22 | wil::unique_socket Accept(_In_ SOCKET ListenSocket, _In_ int Timeout, _In_opt_ HANDLE ExitHandle = nullptr); 23 | 24 | wil::unique_socket Connect(_In_ const GUID& VmId, _In_ unsigned long Port, _In_opt_ HANDLE ExitHandle = nullptr); 25 | 26 | wil::unique_socket Create(); 27 | 28 | wil::unique_socket Listen(_In_ const GUID& VmId, _In_ unsigned long Port, _In_ int Backlog = -1); 29 | 30 | } // namespace wsl::windows::common::hvsocket 31 | -------------------------------------------------------------------------------- /src/windows/common/interop.hpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | interop.hpp 8 | 9 | Abstract: 10 | 11 | This file contains interop function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace wsl::windows::common::interop { 20 | 21 | void WorkerThread(_In_ wil::unique_handle&& ServerPortHandle); 22 | 23 | DWORD VmModeWorkerThread(_In_ wsl::shared::SocketChannel& channel, _In_ const GUID& VmId, _In_ bool IgnoreExit = false); 24 | 25 | } // namespace wsl::windows::common::interop 26 | -------------------------------------------------------------------------------- /src/windows/common/notifications.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | notifications.h 8 | 9 | Abstract: 10 | 11 | This file contains notification function definitions. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wsl::windows::common::notifications { 18 | 19 | /// 20 | /// Displays the notification that a WSL update is available. 21 | /// 22 | HRESULT DisplayUpdateNotification(const std::wstring& versionString); 23 | 24 | /// 25 | /// Displays the notification that performance will be poor due to DrvFs usage. 26 | /// 27 | HRESULT DisplayFilesystemNotification(_In_ LPCSTR binaryName); 28 | 29 | /// 30 | /// Displays the notification saying that warnings were emitted during launch. 31 | /// 32 | void DisplayWarningsNotification(); 33 | 34 | /// 35 | /// Displays the notification saying that a proxy change has been detected. 36 | /// 37 | void DisplayProxyChangeNotification(const std::wstring& message); 38 | 39 | /// 40 | /// Displays the notification saying that optional components need to be installed. 41 | /// 42 | void DisplayOptionalComponentsNotification(); 43 | 44 | } // namespace wsl::windows::common::notifications 45 | -------------------------------------------------------------------------------- /src/windows/common/socket.hpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | socket.hpp 8 | 9 | Abstract: 10 | 11 | This file contains socket helper function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | 19 | namespace wsl::windows::common::socket { 20 | 21 | void Accept(_In_ SOCKET ListenSocket, _In_ SOCKET Socket, _In_ int Timeout, _In_opt_ HANDLE ExitHandle); 22 | 23 | std::pair GetResult(_In_ SOCKET Socket, _In_ OVERLAPPED& Overlapped, _In_ DWORD Timeout, _In_ HANDLE ExitHandle); 24 | 25 | int Receive(_In_ SOCKET Socket, _In_ gsl::span Buffer, _In_opt_ HANDLE ExitHandle = nullptr, _In_ DWORD Flags = MSG_WAITALL, _In_ DWORD Timeout = INFINITE); 26 | 27 | std::vector Receive(_In_ SOCKET Socket, _In_opt_ HANDLE ExitHandle = nullptr, _In_ DWORD Timeout = INFINITE); 28 | 29 | int ReceiveNoThrow(_In_ SOCKET Socket, _In_ gsl::span Buffer, _In_opt_ HANDLE ExitHandle = nullptr, _In_ DWORD Flags = MSG_WAITALL, _In_ DWORD Timeout = INFINITE); 30 | 31 | int Send(_In_ SOCKET Socket, _In_ gsl::span Buffer, _In_opt_ HANDLE ExitHandle = nullptr); 32 | 33 | } // namespace wsl::windows::common::socket 34 | -------------------------------------------------------------------------------- /src/windows/common/svccommio.hpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | svccommio.hpp 8 | 9 | Abstract: 10 | 11 | This file contains function declarations for the SvcCommIo helper class. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include 19 | #include "wslservice.h" 20 | 21 | typedef struct _LXSS_STD_HANDLES_INFO 22 | { 23 | HANDLE InputHandle; 24 | HANDLE OutputHandle; 25 | HANDLE ErrorHandle; 26 | wil::unique_hfile ConsoleOutputHandle; 27 | BOOLEAN IsConsoleInput; 28 | BOOLEAN IsConsoleOutput; 29 | BOOLEAN IsConsoleError; 30 | DWORD SavedInputMode; 31 | DWORD SavedOutputMode; 32 | UINT SavedInputCP; 33 | UINT SavedOutputCP; 34 | } LXSS_STD_HANDLES_INFO, *PLXSS_STD_HANDLES_INFO; 35 | 36 | namespace wsl::windows::common { 37 | class SvcCommIo 38 | { 39 | public: 40 | SvcCommIo(); 41 | ~SvcCommIo(); 42 | 43 | PLXSS_STD_HANDLES GetStdHandles(); 44 | COORD GetWindowSize() const; 45 | 46 | private: 47 | void RestoreConsoleMode() const; 48 | 49 | LXSS_STD_HANDLES _stdHandles{}; 50 | LXSS_STD_HANDLES_INFO _stdHandlesInfo{}; 51 | }; 52 | } // namespace wsl::windows::common 53 | -------------------------------------------------------------------------------- /src/windows/inc/lxssclient.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | lxssclient.h 8 | 9 | Abstract: 10 | 11 | This header file contains data structures and prototypes for the LXSS 12 | client library. 13 | 14 | --*/ 15 | 16 | #pragma once 17 | 18 | NTSTATUS 19 | LxssClientInitialize(VOID); 20 | 21 | NTSTATUS 22 | LxssClientInstanceCreate(_In_ PLX_KINSTANCECREATESTART Parameters, _Out_ PHANDLE InstanceHandle); 23 | 24 | NTSTATUS 25 | LxssClientInstanceDestroy(_In_ HANDLE InstanceHandle); 26 | 27 | NTSTATUS 28 | LxssClientInstanceGetExitStatus(_In_ HANDLE InstanceHandle, _Out_ PLONG ExitStatus); 29 | 30 | NTSTATUS 31 | LxssClientInstanceStart(_In_ HANDLE InstanceHandle, _In_ HANDLE ParentProcess); 32 | 33 | NTSTATUS 34 | LxssClientInstanceStop(_In_ HANDLE InstanceHandle); 35 | 36 | NTSTATUS 37 | LxssClientMapPath( 38 | _In_ HANDLE InstanceHandle, 39 | _In_ HANDLE WindowsDataRoot, 40 | _In_ LPCSTR Source, 41 | _In_ LPCSTR Target, 42 | _In_ LPCSTR FsType, 43 | _In_ ULONG MountFlags, 44 | _In_ ULONG Uid, 45 | _In_ ULONG Gid, 46 | _In_ ULONG Mode); 47 | 48 | VOID LxssClientUninitialize(VOID); 49 | 50 | NTSTATUS 51 | LxssClientUnmapPath(_In_ HANDLE InstanceHandle, _In_ LPCSTR MountPath); 52 | -------------------------------------------------------------------------------- /src/windows/inc/traceloggingconfig.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | traceloggingconfig.h 8 | 9 | Abstract: 10 | 11 | This file contains constants for ETL logging. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include "defs.h" 18 | 19 | static_assert(!wsl::shared::OfficialBuild); 20 | 21 | #define MICROSOFT_KEYWORD_TELEMETRY 0 22 | #define MICROSOFT_KEYWORD_MEASURES 0 23 | #define MICROSOFT_KEYWORD_CRITICAL_DATA 0 24 | #define PDT_ProductAndServicePerformance 0 25 | #define PDT_ProductAndServiceUsage 0 26 | #define TelemetryPrivacyDataTag(tag) TraceLoggingUInt64((tag), "PartA_PrivTags") 27 | #define TraceLoggingOptionMicrosoftTelemetry() \ 28 | TraceLoggingOptionGroup(0x9aa7a361, 0x583f, 0x4c09, 0xb1, 0xf1, 0xce, 0xa1, 0xef, 0x58, 0x63, 0xb0) -------------------------------------------------------------------------------- /src/windows/inc/wslconfig.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslconfig.h 8 | 9 | Abstract: 10 | 11 | Header file containing command line arguments for wslconfig.exe. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #define WSLCONFIG_COMMAND_LIST L"/list" 18 | #define WSLCONFIG_COMMAND_LIST_ALL L"/all" 19 | #define WSLCONFIG_COMMAND_LIST_RUNNING L"/running" 20 | #define WSLCONFIG_COMMAND_LIST_SHORT L"/l" 21 | #define WSLCONFIG_COMMAND_SET_DEFAULT L"/setdefault" 22 | #define WSLCONFIG_COMMAND_SET_DEFAULT_SHORT L"/s" 23 | #define WSLCONFIG_COMMAND_TERMINATE L"/terminate" 24 | #define WSLCONFIG_COMMAND_TERMINATE_SHORT L"/t" 25 | #define WSLCONFIG_COMMAND_UNREGISTER_DISTRIBUTION L"/unregister" 26 | #define WSLCONFIG_COMMAND_UNREGISTER_DISTRIBUTION_SHORT L"/u" -------------------------------------------------------------------------------- /src/windows/inc/wslhost.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslhost.h 8 | 9 | Abstract: 10 | 11 | Header file containing command line arguments for wslhost.exe. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wslhost { 18 | 19 | LPCWSTR const binary_name = L"wslhost.exe"; 20 | 21 | // Arguments for NotificationActivator::Activate entrypoint. 22 | LPCWSTR const disable_notification_arg = L"--disable-notification"; 23 | LPCWSTR const docs_arg = L"--docs"; 24 | LPCWSTR const docs_arg_filesystem_url = L"https://aka.ms/wslfilesystemdocs"; 25 | LPCWSTR const event_viewer_arg = L"--event-viewer"; 26 | LPCWSTR const install_prerequisites_arg = L"--install-prerequisites"; 27 | LPCWSTR const release_notes_arg = L"--release-notes"; 28 | LPCWSTR const update_arg = L"--update"; 29 | 30 | // Arguments for wWinMain entrypoint. 31 | LPCWSTR const distro_id_option = L"--distro-id"; 32 | LPCWSTR const handle_option = L"--handle"; 33 | LPCWSTR const event_option = L"--event"; 34 | LPCWSTR const parent_option = L"--parent"; 35 | LPCWSTR const vm_id_option = L"--vm-id"; 36 | LPCWSTR const embedding_option = L"--Embedding"; 37 | } // namespace wslhost -------------------------------------------------------------------------------- /src/windows/inc/wslrelay.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslrelay.h 8 | 9 | Abstract: 10 | 11 | Header file containing command line arguments for wslrelay.exe. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | namespace wslrelay { 18 | enum RelayMode 19 | { 20 | Invalid = -1, 21 | DebugConsole, 22 | DebugConsoleRelay, 23 | PortRelay, 24 | KdRelay 25 | }; 26 | 27 | LPCWSTR const binary_name = L"wslrelay.exe"; 28 | LPCWSTR const mode_option = L"--mode"; 29 | LPCWSTR const handle_option = L"--handle"; 30 | LPCWSTR const vm_id_option = L"--vm-id"; 31 | LPCWSTR const pipe_option = L"--pipe"; 32 | LPCWSTR const exit_event_option = L"--exit-event"; 33 | LPCWSTR const port_option = L"--port"; 34 | LPCWSTR const disable_telemetry_option = L"--disable-telemetry"; 35 | } // namespace wslrelay -------------------------------------------------------------------------------- /src/windows/inc/wslversioninfo.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslversioninfo.h 8 | 9 | Abstract: 10 | 11 | This file contains version definitions for WSL binairies. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #define VER_FILEFLAGSMASK VS_FFI_FILEFLAGSMASK 18 | #define VER_FILEOS VOS_NT_WINDOWS32 19 | #define VER_PRODUCTNAME_STR "Windows Subsystem for Linux" 20 | #define VER_PRODUCTVERSION_STR WSL_PACKAGE_VERSION 21 | #define VER_FILEVERSION_STR WSL_PACKAGE_VERSION 22 | #define VER_COMPANYNAME_STR "Microsoft Corporation" 23 | #define VER_FILEVERSION WSL_PACKAGE_VERSION_MAJOR, WSL_PACKAGE_VERSION_MINOR, WSL_PACKAGE_VERSION_REVISION, 0 24 | 25 | #ifdef _WINDLL 26 | 27 | #define VER_FILETYPE VFT_DLL 28 | #define VER_FILESUBTYPE VFT2_UNKNOWN 29 | 30 | #else 31 | 32 | #define VER_FILETYPE VFT_APP 33 | #define VER_FILESUBTYPE VFT2_UNKNOWN 34 | 35 | #endif 36 | 37 | #ifdef DEBUG 38 | 39 | #define VER_FILEFLAGS VS_FF_DEBUG | VS_FF_PRIVATEBUILD 40 | 41 | #else 42 | 43 | #ifdef WSL_OFFICIAL_BUILD 44 | 45 | #define VER_FILEFLAGS 0 46 | 47 | #else 48 | 49 | #define VER_FILEFLAGS VS_FF_PRIVATEBUILD 50 | 51 | #endif 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/windows/libwsl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | DllMain.cpp 3 | WslCoreConfigInterface.cpp) 4 | 5 | add_library(libwsl SHARED ${SOURCES} libwsl.def) 6 | 7 | target_include_directories(libwsl 8 | PUBLIC ${CMAKE_CURRENT_LIST_DIR}) 9 | 10 | set_target_properties(libwsl PROPERTIES FOLDER windows) 11 | target_precompile_headers(libwsl REUSE_FROM common) 12 | 13 | target_link_libraries(libwsl 14 | ${COMMON_LINK_LIBRARIES} 15 | common 16 | configfile 17 | legacy_stdio_definitions 18 | VirtDisk.lib) -------------------------------------------------------------------------------- /src/windows/libwsl/DllMain.cpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | DllMain.cpp 8 | 9 | Abstract: 10 | 11 | This file contains the entrypoint for libwsl. 12 | 13 | --*/ 14 | 15 | #include "precomp.h" 16 | 17 | static HINSTANCE g_dllInstance; 18 | 19 | EXTERN_C BOOL STDAPICALLTYPE DllMain(_In_ HINSTANCE Instance, _In_ DWORD Reason, _In_opt_ LPVOID Reserved) 20 | { 21 | wil::DLLMain(Instance, Reason, Reserved); 22 | 23 | switch (Reason) 24 | { 25 | case DLL_PROCESS_ATTACH: 26 | g_dllInstance = Instance; 27 | WslTraceLoggingInitialize(LxssTelemetryProvider, TRUE, nullptr); 28 | 29 | // Accidentally including a Module can result in lifetime issues because it will call 30 | // CoAddRefServerProcess/CoReleaseServerProcess outside of any WRL::Module<> that may be in use in the caller, 31 | // which means the global counter is getting updated without the Module<> specific checks (e.g. last reference 32 | // has been released). 33 | FAIL_FAST_HR_IF_MSG( 34 | HRESULT_FROM_WIN32(ERROR_INVALID_STATE), 35 | Microsoft::WRL::GetModuleBase() != nullptr, 36 | "A WRL::Module has been included"); 37 | 38 | break; 39 | 40 | case DLL_PROCESS_DETACH: 41 | WslTraceLoggingUninitialize(); 42 | break; 43 | } 44 | 45 | return TRUE; 46 | } 47 | -------------------------------------------------------------------------------- /src/windows/libwsl/libwsl.def: -------------------------------------------------------------------------------- 1 | LIBRARY libwsl 2 | 3 | EXPORTS 4 | GetWslConfigFilePath 5 | CreateWslConfig 6 | FreeWslConfig 7 | GetWslConfigSetting 8 | SetWslConfigSetting -------------------------------------------------------------------------------- /src/windows/service/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_compile_definitions("PROXY_CLSID_IS={0x4EA0C6DD,0xE9FF,0x48E7,{0x99,0x4e,0x13,0xa3,0x1d,0x10,0xdc,0x60}}") 2 | add_compile_definitions("REGISTER_PROXY_DLL") 3 | 4 | add_subdirectory(exe) 5 | add_subdirectory(inc) 6 | add_subdirectory(stub) 7 | add_subdirectory(mc) -------------------------------------------------------------------------------- /src/windows/service/exe/BridgedNetworking.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | 5 | #include "INetworkingEngine.h" 6 | #include "GnsChannel.h" 7 | #include "WslCoreConfig.h" 8 | #include "WslCoreNetworkEndpointSettings.h" 9 | 10 | namespace wsl::core { 11 | 12 | class BridgedNetworking : public INetworkingEngine 13 | { 14 | public: 15 | BridgedNetworking(HCS_SYSTEM system, const Config& config); 16 | ~BridgedNetworking() override = default; 17 | 18 | void Initialize() override; 19 | void TraceLoggingRundown() noexcept override; 20 | void FillInitialConfiguration(LX_MINI_INIT_NETWORKING_CONFIGURATION& message) override; 21 | void StartPortTracker(wil::unique_socket&& socket) override; 22 | 23 | private: 24 | // Handle for the Hcn* Api. Owned by the caller (WslCoreVm), this is a non-owning copy 25 | const HCS_SYSTEM m_system{}; 26 | 27 | const Config& m_config; 28 | wsl::core::networking::EphemeralHcnEndpoint m_endpoint; 29 | }; 30 | 31 | } // namespace wsl::core 32 | -------------------------------------------------------------------------------- /src/windows/service/exe/GnsPortTrackerChannel.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include "SocketChannel.h" 10 | 11 | namespace wsl::core { 12 | class GnsPortTrackerChannel 13 | { 14 | public: 15 | GnsPortTrackerChannel( 16 | wil::unique_socket&& Socket, 17 | const std::function& Callback, 18 | const std::function& InterfaceStateCallback); 19 | 20 | ~GnsPortTrackerChannel(); 21 | 22 | GnsPortTrackerChannel(const GnsPortTrackerChannel&) = delete; 23 | GnsPortTrackerChannel(GnsPortTrackerChannel&&) = delete; 24 | 25 | GnsPortTrackerChannel& operator=(const GnsPortTrackerChannel&) = delete; 26 | GnsPortTrackerChannel& operator=(GnsPortTrackerChannel&&) = delete; 27 | 28 | void Run(); 29 | 30 | private: 31 | static SOCKADDR_INET ConvertPortRequestToSockAddr(_In_ const LX_GNS_PORT_ALLOCATION_REQUEST* portAllocationRequest); 32 | 33 | const std::function m_callback; 34 | const std::function m_interfaceStateCallback; 35 | wil::unique_event m_stopEvent = wil::unique_event{wil::EventOptions::ManualReset}; 36 | wsl::shared::SocketChannel m_channel; 37 | std::thread m_thread; 38 | }; 39 | } // namespace wsl::core 40 | -------------------------------------------------------------------------------- /src/windows/service/exe/GnsRpcServer.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | 5 | #include "helpers.hpp" 6 | #include 7 | #include 8 | #include 9 | 10 | class GnsRpcServer 11 | { 12 | public: 13 | using AdapterCallback = std::function; 14 | 15 | GnsRpcServer(); 16 | ~GnsRpcServer() noexcept; 17 | 18 | GnsRpcServer(const GnsRpcServer&) = delete; 19 | GnsRpcServer& operator=(const GnsRpcServer&) = delete; 20 | 21 | GnsRpcServer(GnsRpcServer&&) noexcept; 22 | GnsRpcServer& operator=(GnsRpcServer&&) noexcept; 23 | 24 | static std::shared_ptr GetOrCreate(); 25 | 26 | const UUID& GetServerUuid() const noexcept; 27 | 28 | private: 29 | wil::srwlock m_lock; 30 | bool m_moved = false; 31 | UUID m_serverUuid{}; 32 | }; 33 | -------------------------------------------------------------------------------- /src/windows/service/exe/GuestTelemetryLogger.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | GuestTelemetryLogger.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations used to log guest telemetry. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include "RingBuffer.h" 18 | #include "relay.hpp" 19 | 20 | class GuestTelemetryLogger : public std::enable_shared_from_this 21 | { 22 | public: 23 | GuestTelemetryLogger() = delete; 24 | ~GuestTelemetryLogger(); 25 | 26 | static std::shared_ptr Create(GUID VmId, const wil::unique_event& ExitEvent); 27 | 28 | LPCWSTR GetPipeName() const; 29 | 30 | private: 31 | GuestTelemetryLogger(GUID VmId); 32 | 33 | void Start(const wil::unique_event& ExitEvent); 34 | void ProcessInput(const std::string_view Input); 35 | 36 | std::wstring m_pipeName; 37 | wil::unique_event m_threadExit; 38 | std::thread m_thread; 39 | GUID m_runtimeId{}; 40 | RingBuffer m_ringBuffer{LX_RELAY_BUFFER_SIZE}; 41 | }; 42 | -------------------------------------------------------------------------------- /src/windows/service/exe/INetworkingEngine.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | #pragma once 4 | #include "WslCoreNetworkEndpointSettings.h" 5 | 6 | namespace wsl::core { 7 | 8 | class INetworkingEngine 9 | { 10 | public: 11 | virtual ~INetworkingEngine() = default; 12 | virtual void Initialize() = 0; 13 | virtual void TraceLoggingRundown() noexcept = 0; 14 | virtual void FillInitialConfiguration(LX_MINI_INIT_NETWORKING_CONFIGURATION& message) = 0; 15 | virtual void StartPortTracker(wil::unique_socket&& socket) = 0; 16 | }; 17 | } // namespace wsl::core 18 | -------------------------------------------------------------------------------- /src/windows/service/exe/LxssSecurity.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | Security.h 8 | 9 | Abstract: 10 | 11 | This file contains user security function declarations. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "wrl/client.h" 19 | #include "wil/resource.h" 20 | 21 | namespace Security { 22 | 23 | /// 24 | /// Initializes the job object for a instance. 25 | /// 26 | void InitializeInstanceJob(_In_ HANDLE jobHandle); 27 | 28 | /// 29 | /// Returns true if the provided token is a member of the local administrators group 30 | /// 31 | bool IsTokenLocalAdministrator(_In_ HANDLE token); 32 | } // namespace Security 33 | -------------------------------------------------------------------------------- /src/windows/service/exe/RingBuffer.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | RingBuffer.h 8 | 9 | Abstract: 10 | 11 | This file contains declarations for the RingBuffer class. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | class RingBuffer 18 | { 19 | public: 20 | RingBuffer() = delete; 21 | RingBuffer(size_t size); 22 | 23 | void Insert(std::string_view data); 24 | std::vector GetLastDelimitedStrings(char Delimiter, size_t Count) const; 25 | std::string Get() const; 26 | 27 | private: 28 | std::pair Contents() const; 29 | 30 | mutable wil::srwlock m_lock; 31 | std::vector m_buffer; 32 | size_t m_maxSize; 33 | size_t m_offset; 34 | }; -------------------------------------------------------------------------------- /src/windows/service/exe/application.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | true 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/windows/service/exe/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslservice. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "resource.h" 17 | #include "wslversioninfo.h" 18 | 19 | #define VER_INTERNALNAME_STR "wslservice.exe" 20 | #define VER_ORIGINALFILENAME_STR "wslservice.exe" 21 | 22 | #define VER_FILETYPE VFT_APP 23 | #define VER_FILESUBTYPE VFT2_UNKNOWN 24 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux Service" 25 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\Images\wsl.ico" 26 | 27 | 28 | #include 29 | -------------------------------------------------------------------------------- /src/windows/service/exe/resource.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | resource.h 8 | 9 | Abstract: 10 | 11 | This file contains resource declarations for wslservice.exe 12 | 13 | --*/ 14 | 15 | #define ID_ICON 1 16 | -------------------------------------------------------------------------------- /src/windows/service/inc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_idl(wslserviceidl "wslservice.idl" "windowsdefs.idl") 2 | set_target_properties(wslserviceidl PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/service/mc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_mc(wslservicemc wsleventschema.mc) 2 | set_target_properties(wslservicemc PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/service/mc/wsleventschema.mc: -------------------------------------------------------------------------------- 1 | MessageIdTypeDef=DWORD 2 | 3 | SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS 4 | Informational=0x1:STATUS_SEVERITY_INFORMATIONAL 5 | Warning=0x2:STATUS_SEVERITY_WARNING 6 | Error=0x3:STATUS_SEVERITY_ERROR 7 | ) 8 | 9 | LanguageNames=(Neutral=0x0000:MSG00000) 10 | 11 | MessageId=0x0 SymbolicName=MSG_WARNING 12 | Severity=Warning 13 | Facility=Application 14 | Language=Neutral 15 | %1 16 | . 17 | -------------------------------------------------------------------------------- /src/windows/service/stub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/wslservice_i_${TARGET_PLATFORM}.c 3 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/wslservice_p_${TARGET_PLATFORM}.c 4 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/dlldata_${TARGET_PLATFORM}.c 5 | ${CMAKE_CURRENT_LIST_DIR}/WslServiceProxyStub.def 6 | ${CMAKE_CURRENT_LIST_DIR}/WslServiceProxyStub.rc) 7 | 8 | set_source_files_properties(${SOURCES} PROPERTIES GENERATED TRUE) 9 | 10 | add_library(wslserviceproxystub SHARED ${SOURCES}) 11 | add_dependencies(wslserviceproxystub wslserviceidl) 12 | target_link_libraries(wslserviceproxystub ${COMMON_LINK_LIBRARIES}) 13 | set_target_properties(wslserviceproxystub PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/service/stub/WslServiceProxyStub.def: -------------------------------------------------------------------------------- 1 | LIBRARY WslServiceProxyStub.dll 2 | 3 | EXPORTS 4 | DllGetClassObject PRIVATE 5 | DllCanUnloadNow PRIVATE 6 | -------------------------------------------------------------------------------- /src/windows/service/stub/WslServiceProxyStub.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslServiceProxyStub.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslserviceproxystub.dll. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "wslversioninfo.h" 17 | 18 | #define VER_INTERNALNAME_STR "wslserviceproxystub.dll" 19 | #define VER_ORIGINALFILENAME_STR "wslserviceproxystub.dll" 20 | 21 | #define VER_FILEDESCRIPTION_STR "WSL Service ProxyStub DLL" 22 | 23 | #include 24 | -------------------------------------------------------------------------------- /src/windows/wsl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | main.cpp 3 | main.rc) 4 | 5 | set(HEADERS 6 | resource.h) 7 | 8 | add_executable(wsl ${SOURCES} ${HEADERS}) 9 | 10 | target_link_libraries(wsl 11 | ${COMMON_LINK_LIBRARIES} 12 | common 13 | runtimeobject.lib) 14 | 15 | target_precompile_headers(wsl REUSE_FROM common) 16 | set_target_properties(wsl PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wsl/main.cpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.cpp 8 | 9 | Abstract: 10 | 11 | This file contains the entry point for wsl.exe. 12 | 13 | --*/ 14 | 15 | #include "precomp.h" 16 | 17 | int __cdecl wmain() 18 | { 19 | return wsl::windows::common::WslClient::Main(GetCommandLineW()); 20 | } 21 | -------------------------------------------------------------------------------- /src/windows/wsl/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wsl. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "resource.h" 17 | #include "wslversioninfo.h" 18 | 19 | #define VER_INTERNALNAME_STR "wsl.exe" 20 | #define VER_ORIGINALFILENAME_STR "wsl.exe" 21 | 22 | #define VER_FILETYPE VFT_APP 23 | #define VER_FILESUBTYPE VFT2_UNKNOWN 24 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux" 25 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\Images\wsl.ico" 26 | 27 | #include 28 | -------------------------------------------------------------------------------- /src/windows/wsl/resource.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | resource.h 8 | 9 | Abstract: 10 | 11 | This file contains resource declarations for wsl.exe 12 | 13 | --*/ 14 | 15 | #define ID_ICON 1 16 | -------------------------------------------------------------------------------- /src/windows/wslg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | main.cpp 3 | main.rc) 4 | 5 | set(HEADERS 6 | resource.h 7 | ) 8 | 9 | add_executable(wslg WIN32 ${SOURCES} ${HEADERS}) 10 | add_dependencies(wslg 11 | common) 12 | 13 | target_link_libraries(wslg 14 | ${COMMON_LINK_LIBRARIES} 15 | common) 16 | 17 | target_precompile_headers(wslg REUSE_FROM common) 18 | set_target_properties(wslg PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wslg/main.cpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.cpp 8 | 9 | Abstract: 10 | 11 | This file contains the entry point for wslg.exe. 12 | 13 | --*/ 14 | 15 | #include "precomp.h" 16 | 17 | int WINAPI wWinMain(HINSTANCE, HINSTANCE, PWSTR, int) 18 | { 19 | return wsl::windows::common::WslClient::Main(GetCommandLineW()); 20 | } 21 | -------------------------------------------------------------------------------- /src/windows/wslg/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslg. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "resource.h" 17 | #include "wslversioninfo.h" 18 | 19 | #define VER_INTERNALNAME_STR "wslg.exe" 20 | #define VER_ORIGINALFILENAME_STR "wslg.exe" 21 | 22 | #define VER_FILETYPE VFT_APP 23 | #define VER_FILESUBTYPE VFT2_UNKNOWN 24 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux" 25 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\Images\wsl.ico" 26 | 27 | #include 28 | -------------------------------------------------------------------------------- /src/windows/wslg/resource.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | resource.h 8 | 9 | Abstract: 10 | 11 | This file contains resource declarations for wslg.exe 12 | 13 | --*/ 14 | 15 | #define ID_ICON 1 16 | -------------------------------------------------------------------------------- /src/windows/wslhost/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | main.cpp 3 | main.rc) 4 | 5 | set(HEADERS 6 | resource.h) 7 | 8 | add_executable(wslhost WIN32 ${SOURCES} ${HEADERS}) 9 | add_dependencies(wslhost 10 | common) 11 | 12 | target_link_libraries(wslhost 13 | ${COMMON_LINK_LIBRARIES} 14 | common 15 | runtimeobject.lib) 16 | 17 | target_precompile_headers(wslhost REUSE_FROM common) 18 | set_target_properties(wslhost PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wslhost/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslhost. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "resource.h" 17 | #include "wslversioninfo.h" 18 | 19 | #define VER_INTERNALNAME_STR "wslhost.exe" 20 | #define VER_ORIGINALFILENAME_STR "wslhost.exe" 21 | 22 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux" 23 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\Images\wsl.ico" 24 | 25 | #include 26 | -------------------------------------------------------------------------------- /src/windows/wslhost/resource.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | resource.h 8 | 9 | Abstract: 10 | 11 | This file contains resource declarations for wslhost.exe 12 | 13 | --*/ 14 | 15 | #define ID_ICON 1 16 | -------------------------------------------------------------------------------- /src/windows/wslinstall/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | DllMain.cpp 3 | version.rc) 4 | 5 | add_library(wslinstall SHARED ${SOURCES} wslinstall.def) 6 | 7 | target_include_directories(wslinstall PUBLIC ${CMAKE_CURRENT_LIST_DIR}) 8 | set_target_properties(wslinstall PROPERTIES FOLDER windows) 9 | target_precompile_headers(wslinstall REUSE_FROM common) 10 | 11 | target_link_libraries(wslinstall 12 | ${COMMON_LINK_LIBRARIES} 13 | common 14 | legacy_stdio_definitions 15 | Msi.lib 16 | Crypt32.lib 17 | sfc.lib) -------------------------------------------------------------------------------- /src/windows/wslinstall/version.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | version.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslinstall.dll. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "wslversioninfo.h" 17 | 18 | #define VER_INTERNALNAME_STR "wslinstall.dll" 19 | #define VER_ORIGINALFILENAME_STR "wslinstall.dll" 20 | 21 | #define VER_FILEDESCRIPTION_STR "WSL Install library" 22 | 23 | #include 24 | 25 | STRINGTABLE DISCARDABLE 26 | BEGIN 27 | 100 "WSLINSTALL" 28 | 101 "Installation logic for WSL" 29 | END 30 | -------------------------------------------------------------------------------- /src/windows/wslinstall/wslinstall.def: -------------------------------------------------------------------------------- 1 | LIBRARY wslinstall 2 | 3 | EXPORTS 4 | CleanExplorerState 5 | CleanMsixState 6 | DeprovisionMsix 7 | WslValidateInstallation 8 | InstallMsix 9 | InstallMsixAsUser 10 | RegisterLspCategories 11 | RemoveMsixAsSystem 12 | RemoveMsixAsUser 13 | RemoveRegistryKeyProtections 14 | UnregisterLspCategories 15 | CalculateWslSettingsProtocolIds -------------------------------------------------------------------------------- /src/windows/wslinstaller/exe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | ServiceMain.cpp 3 | WslInstallerFactory.cpp 4 | WslInstaller.cpp 5 | main.rc) 6 | 7 | set (HEADERS 8 | WslInstallerFactory.h 9 | WslInstaller.h) 10 | 11 | include_directories(${CMAKE_BINARY_DIR}/src/windows/wslinstaller/inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}) 12 | 13 | add_executable(wslinstaller ${SOURCES} ${HEADERS}) 14 | add_dependencies(wslinstaller wslinstalleridl) 15 | 16 | set_target_properties(wslinstaller PROPERTIES LINK_FLAGS "/merge:minATL=.rdata /include:__minATLObjMap_WslInstaller_COM") 17 | target_link_libraries(wslinstaller 18 | ${COMMON_LINK_LIBRARIES} 19 | common 20 | legacy_stdio_definitions) 21 | 22 | target_precompile_headers(wslinstaller REUSE_FROM common) 23 | set_target_properties(wslinstaller PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wslinstaller/exe/WslInstaller.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslInstaller.h 8 | 9 | Abstract: 10 | 11 | This file contains definitions for the WslInstallerService. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | #include 17 | #include 18 | 19 | class DECLSPEC_UUID("B5AEB4C3-9541-492F-AD4D-505951F6ADA4") WslInstaller 20 | : public Microsoft::WRL::RuntimeClass, IWslInstaller, IFastRundown> 21 | { 22 | HRESULT Install(UINT* ExitCode, LPWSTR* Error) override; 23 | }; 24 | 25 | struct InstallContext 26 | { 27 | wil::unique_handle Thread; 28 | HRESULT Result{}; 29 | UINT ExitCode{}; 30 | std::wstring Errors; 31 | }; 32 | 33 | std::shared_ptr LaunchInstall(); 34 | -------------------------------------------------------------------------------- /src/windows/wslinstaller/exe/WslInstallerFactory.cpp: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslInstallerFactory.cpp 8 | 9 | Abstract: 10 | 11 | This file contains the WslInstallerFactory class implementation. 12 | 13 | --*/ 14 | 15 | #include "precomp.h" 16 | 17 | #include "WslInstallerFactory.h" 18 | 19 | CoCreatableClassWithFactory(WslInstaller, WslInstallerFactory); 20 | 21 | static std::vector> g_sessions; 22 | static wil::srwlock g_mutex; 23 | extern wil::unique_event g_stopEvent; 24 | 25 | void ClearSessions() 26 | { 27 | auto lock = g_mutex.lock_exclusive(); 28 | g_sessions.clear(); 29 | } 30 | 31 | HRESULT WslInstallerFactory::CreateInstance(_In_ IUnknown* pUnkOuter, _In_ REFIID riid, _Out_ void** ppCreated) 32 | { 33 | RETURN_HR_IF_NULL(E_POINTER, ppCreated); 34 | *ppCreated = nullptr; 35 | 36 | RETURN_HR_IF(CLASS_E_NOAGGREGATION, pUnkOuter != nullptr); 37 | 38 | WSL_LOG("WslInstallerCreateInstance", TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE)); 39 | 40 | auto lock = g_mutex.lock_exclusive(); 41 | 42 | if (g_stopEvent.is_signaled()) 43 | { 44 | return S_FALSE; 45 | } 46 | 47 | const auto instance = wil::MakeOrThrow(); 48 | instance.CopyTo(riid, ppCreated); 49 | 50 | return S_OK; 51 | } -------------------------------------------------------------------------------- /src/windows/wslinstaller/exe/WslInstallerFactory.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslInstallerFactory.h 8 | 9 | Abstract: 10 | 11 | This file contains the WslInstallerFactory class definition. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include 18 | #include "WslInstaller.h" 19 | 20 | class WslInstallerFactory : public Microsoft::WRL::ClassFactory<> 21 | { 22 | public: 23 | WslInstallerFactory() = default; 24 | STDMETHODIMP CreateInstance(_In_ IUnknown* pUnkOuter, _In_ REFIID riid, _Out_ void** ppCreated) override; 25 | }; 26 | 27 | void ClearSessions(); -------------------------------------------------------------------------------- /src/windows/wslinstaller/exe/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslinstaller. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "wslversioninfo.h" 17 | 18 | #define ID_ICON 1 19 | #define VER_INTERNALNAME_STR "wslinstaller.exe" 20 | #define VER_ORIGINALFILENAME_STR "wslinstaller.exe" 21 | 22 | #define VER_FILETYPE VFT_APP 23 | #define VER_FILESUBTYPE VFT2_UNKNOWN 24 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux Installer Service" 25 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\images\wsl.ico" 26 | 27 | 28 | #include 29 | -------------------------------------------------------------------------------- /src/windows/wslinstaller/inc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_idl(wslinstalleridl wslinstallerservice.idl "") 2 | set_target_properties(wslinstalleridl PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wslinstaller/inc/wslinstallerservice.idl: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslinstalleridl.idl 8 | 9 | Abstract: 10 | 11 | This file contains the COM object definitions used to talk with the WSL 12 | service "WslInstaller" 13 | 14 | --*/ 15 | 16 | import "unknwn.idl"; 17 | import "wtypes.idl"; 18 | 19 | cpp_quote("#ifdef __cplusplus") 20 | cpp_quote("const GUID CLSID_WslInstaller = { 0xb5aeb4c3, 0x9541, 0x492f, { 0xad, 0x4d, 0x50, 0x59, 0x51, 0xf6, 0xad, 0xa4 }};") 21 | cpp_quote("class DECLSPEC_UUID(\"B5AEB4C3-9541-492F-AD4D-505951F6ADA4\") WslInstaller;") 22 | cpp_quote("#endif") 23 | 24 | [ 25 | uuid(1E912664-C599-474A-A552-DAEAF73B3164), 26 | pointer_default(unique), 27 | object 28 | ] 29 | interface IWslInstaller : IUnknown 30 | { 31 | HRESULT Install([out] UINT* ExitCode, [out] LPWSTR* ErrorMessage); 32 | }; -------------------------------------------------------------------------------- /src/windows/wslinstaller/stub/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_compile_definitions("PROXY_CLSID_IS={ 0xce1044f6, 0x36c5, 0x4599, { 0xa5, 0xa8, 0x3b, 0xbf, 0x27, 0xba, 0x54, 0x95 } }") 2 | add_compile_definitions("REGISTER_PROXY_DLL") 3 | 4 | set(SOURCES 5 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/wslinstallerservice_i_${TARGET_PLATFORM}.c 6 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/wslinstallerservice_p_${TARGET_PLATFORM}.c 7 | ${CMAKE_CURRENT_BINARY_DIR}/../inc/${TARGET_PLATFORM}/${CMAKE_BUILD_TYPE}/dlldata_${TARGET_PLATFORM}.c 8 | ${CMAKE_CURRENT_LIST_DIR}/WslInstallerProxyStub.def 9 | ${CMAKE_CURRENT_LIST_DIR}/WslInstallerProxyStub.rc) 10 | 11 | set_source_files_properties(${SOURCES} PROPERTIES GENERATED TRUE) 12 | 13 | add_library(wslinstallerproxystub SHARED ${SOURCES}) 14 | add_dependencies(wslinstallerproxystub wslinstalleridl) 15 | target_link_libraries(wslinstallerproxystub ${COMMON_LINK_LIBRARIES}) 16 | set_target_properties(wslinstallerproxystub PROPERTIES FOLDER windows) 17 | -------------------------------------------------------------------------------- /src/windows/wslinstaller/stub/WslInstallerProxyStub.def: -------------------------------------------------------------------------------- 1 | LIBRARY wslinstallerproxystub.dll 2 | 3 | EXPORTS 4 | DllGetClassObject PRIVATE 5 | DllCanUnloadNow PRIVATE 6 | -------------------------------------------------------------------------------- /src/windows/wslinstaller/stub/WslInstallerProxyStub.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | WslInstallerProxyStub.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for WslInstallerProxyStub.dll. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "wslversioninfo.h" 17 | 18 | #define VER_INTERNALNAME_STR "WslInstallerProxyStub.dll" 19 | #define VER_ORIGINALFILENAME_STR "WslInstallerProxyStub.dll" 20 | 21 | #define VER_FILEDESCRIPTION_STR "WSL Installer ProxyStub DLL" 22 | 23 | #include 24 | -------------------------------------------------------------------------------- /src/windows/wslinstaller/wslinstaller.idl: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft Corporation. All rights reserved. 4 | 5 | Module Name: 6 | 7 | wslinstaller.idl 8 | 9 | 10 | --*/ 11 | 12 | [ 13 | uuid(D72BF71C-95DA-400D-9E4A-6ABA6064FE60), 14 | pointer_default(unique), 15 | object 16 | ] 17 | interface IWslInstaller : IUnknown 18 | { 19 | HRESULT Install([out] DWORD* ExitCode); 20 | }; -------------------------------------------------------------------------------- /src/windows/wslrelay/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | localhost.cpp 3 | main.cpp 4 | main.rc) 5 | 6 | set(HEADERS 7 | localhost.h 8 | resource.h) 9 | 10 | add_executable(wslrelay WIN32 ${SOURCES} ${HEADERS}) 11 | add_dependencies(wslrelay 12 | common) 13 | 14 | target_link_libraries(wslrelay 15 | ${COMMON_LINK_LIBRARIES} 16 | common) 17 | 18 | target_precompile_headers(wslrelay REUSE_FROM common) 19 | set_target_properties(wslrelay PROPERTIES FOLDER windows) -------------------------------------------------------------------------------- /src/windows/wslrelay/main.rc: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | main.rc 8 | 9 | Abstract: 10 | 11 | This file contains resources for wslrelay. 12 | 13 | --*/ 14 | 15 | #include 16 | #include "resource.h" 17 | #include "wslversioninfo.h" 18 | 19 | #define VER_INTERNALNAME_STR "wslrelay.exe" 20 | #define VER_ORIGINALFILENAME_STR "wslrelay.exe" 21 | 22 | #define VER_FILEDESCRIPTION_STR "Windows Subsystem for Linux" 23 | ID_ICON ICON PRELOAD DISCARDABLE "..\..\..\Images\wsl.ico" 24 | 25 | #include 26 | -------------------------------------------------------------------------------- /src/windows/wslrelay/resource.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | resource.h 8 | 9 | Abstract: 10 | 11 | This file contains resource declarations for wslrelay.exe 12 | 13 | --*/ 14 | 15 | #define ID_ICON 1 16 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Activation/DefaultActivationHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml; 4 | using WslSettings.Contracts.Services; 5 | using WslSettings.ViewModels.Settings; 6 | 7 | namespace WslSettings.Activation; 8 | 9 | public class DefaultActivationHandler : ActivationHandler 10 | { 11 | public DefaultActivationHandler(INavigationService navigationService) : base(navigationService) 12 | { 13 | } 14 | 15 | protected override bool CanHandleInternal(LaunchActivatedEventArgs args) 16 | { 17 | // None of the ActivationHandlers has handled the activation. 18 | return _navigationService.Frame?.Content == null; 19 | } 20 | 21 | protected async override Task HandleInternalAsync(LaunchActivatedEventArgs args) 22 | { 23 | Navigate(IWindowService.WindowId.MainWindow, typeof(MemAndProcViewModel).FullName!, args); 24 | 25 | await Task.CompletedTask; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Activation/IActivationHandler.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Activation; 4 | 5 | public interface IActivationHandler 6 | { 7 | bool CanHandle(object args); 8 | 9 | Task HandleAsync(object args); 10 | } 11 | -------------------------------------------------------------------------------- /src/windows/wslsettings/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Behaviors/NavigationViewHeaderMode.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Behaviors; 4 | 5 | public enum NavigationViewHeaderMode 6 | { 7 | Always, 8 | Never, 9 | Minimal 10 | } 11 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Constants.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using System.Text.RegularExpressions; 4 | 5 | namespace WslSettings.Helpers; 6 | 7 | public class Constants 8 | { 9 | public static uint MB = 1024 * 1024; 10 | public static Regex WholeNumberRegex = new Regex("^[0-9]+$"); 11 | public static Regex IntegerRegex = new Regex("^((-[1-9][0-9]*)|([0-9]+))$"); 12 | public static Regex CommaSeparatedWholeNumbersOrEmptyRegex = new Regex(@"^(([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])[,])*([1-9][0-9]{0,3}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5])?$"); 13 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/IActivationService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Contracts.Services; 4 | 5 | public interface IActivationService 6 | { 7 | Task ActivateAsync(object activationArgs); 8 | } 9 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/INavigationService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using Microsoft.UI.Xaml.Navigation; 5 | 6 | namespace WslSettings.Contracts.Services; 7 | 8 | public interface INavigationService 9 | { 10 | event NavigatedEventHandler Navigated; 11 | 12 | bool CanGoBack 13 | { 14 | get; 15 | } 16 | 17 | Frame? Frame 18 | { 19 | get; set; 20 | } 21 | 22 | bool NavigateTo(string pageKey, object? parameter = null, bool clearNavigation = false); 23 | 24 | bool GoBack(); 25 | } 26 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/INavigationViewService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | 5 | namespace WslSettings.Contracts.Services; 6 | 7 | public interface INavigationViewService 8 | { 9 | IList? MenuItems 10 | { 11 | get; 12 | } 13 | 14 | object? SettingsItem 15 | { 16 | get; 17 | } 18 | 19 | void Initialize(NavigationView navigationView); 20 | 21 | void UnregisterEvents(); 22 | 23 | NavigationViewItem? GetSelectedItem(Type pageType); 24 | } 25 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/IPageService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Contracts.Services; 4 | 5 | public interface IPageService 6 | { 7 | Type GetPageType(string key); 8 | } 9 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/IWindowService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Contracts.Services; 4 | 5 | public interface IWindowService 6 | { 7 | public enum WindowId 8 | { 9 | MainWindow, 10 | OOBEWindow 11 | } 12 | 13 | WindowEx CreateOrGetWindow(WindowId windowId); 14 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/Services/IWslConfigService.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Contracts.Services; 4 | 5 | public interface IWslConfigService 6 | { 7 | IWslConfigSetting GetWslConfigSetting(WslConfigEntry wslConfigEntry, bool defaultSetting = false); 8 | uint SetWslConfigSetting(IWslConfigSetting setting); 9 | public delegate void WslConfigChangedEventHandler(); 10 | event WslConfigChangedEventHandler WslConfigChanged; 11 | } 12 | 13 | public interface IWslConfigSetting 14 | { 15 | WslConfigEntry ConfigEntry { get; } 16 | string StringValue { get; } 17 | ulong UInt64Value { get; } 18 | int Int32Value { get; } 19 | bool BoolValue { get; } 20 | NetworkingConfiguration NetworkingConfigurationValue { get; } 21 | MemoryReclaimMode MemoryReclaimModeValue { get; } 22 | uint SetValue(object? value); 23 | bool Equals(object? obj); 24 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/Contracts/ViewModels/INavigationAware.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Contracts.ViewModels; 4 | 5 | public interface INavigationAware 6 | { 7 | void OnNavigatedTo(object parameter); 8 | 9 | void OnNavigatedFrom(); 10 | } 11 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Controls/HyperlinkTextBlock.xaml: -------------------------------------------------------------------------------- 1 | 8 | 9 | 10 | 11 | 13 | 14 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Converters/BooleanToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Data; 4 | using Microsoft.UI.Xaml; 5 | 6 | namespace WslSettings.Converters 7 | { 8 | public sealed class BooleanToVisibilityConverter : IValueConverter 9 | { 10 | public object Convert(object value, Type targetType, object parameter, string language) 11 | { 12 | return (value is bool && (bool)value) ? Visibility.Visible : Visibility.Collapsed; 13 | } 14 | 15 | public object ConvertBack(object value, Type targetType, object parameter, string language) 16 | { 17 | return value is Visibility && (Visibility)value == Visibility.Visible; 18 | } 19 | } 20 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/Converters/MegabyteNumberConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Converters 4 | { 5 | public sealed class MegabyteNumberConverter : Microsoft.UI.Xaml.Data.IValueConverter 6 | { 7 | public object? Convert(object value, Type targetType, object parameter, string language) 8 | { 9 | if (value != null && UInt64.TryParse(value as string, out UInt64 parseResult)) 10 | { 11 | return (parseResult / Constants.MB).ToString(); 12 | } 13 | 14 | return null; 15 | } 16 | 17 | public object? ConvertBack(object value, Type targetType, object parameter, string language) 18 | { 19 | 20 | if (value != null && UInt64.TryParse(value as string, out UInt64 parseResult)) 21 | { 22 | return (parseResult * Constants.MB).ToString(); 23 | } 24 | 25 | return null; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Converters/MegabyteStringConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Converters 4 | { 5 | public sealed class MegabyteStringConverter : Microsoft.UI.Xaml.Data.IValueConverter 6 | { 7 | public object? Convert(object value, Type targetType, object parameter, string language) 8 | { 9 | if (value == null) 10 | { 11 | return null; 12 | } 13 | 14 | return string.Format("Settings_MegabyteStringFormat".GetLocalized(), (System.Convert.ToUInt64(value) / Constants.MB)); 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, string language) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Converters/MillisecondsStringConverter.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | namespace WslSettings.Converters 4 | { 5 | public sealed class MillisecondsStringConverter : Microsoft.UI.Xaml.Data.IValueConverter 6 | { 7 | public object? Convert(object value, Type targetType, object parameter, string language) 8 | { 9 | if (value == null || (value is ulong && (ulong)value == 0)) 10 | { 11 | return null; 12 | } 13 | 14 | return string.Format("Settings_MillisecondsStringFormat".GetLocalized(), value); 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, string language) 18 | { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Helpers/FrameExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | 5 | namespace WslSettings.Helpers; 6 | 7 | public static class FrameExtensions 8 | { 9 | public static object? GetPageViewModel(this Frame frame) => frame?.Content?.GetType().GetProperty("ViewModel")?.GetValue(frame.Content, null); 10 | } 11 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Helpers/NavigationHelper.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml; 4 | using Microsoft.UI.Xaml.Controls; 5 | 6 | namespace WslSettings.Helpers; 7 | 8 | // Helper class to set the navigation target for a NavigationViewItem. 9 | // 10 | // Usage in XAML: 11 | // 12 | // 13 | // Usage in code: 14 | // NavigationHelper.SetNavigateTo(navigationViewItem, typeof(MainViewModel).FullName); 15 | public class NavigationHelper 16 | { 17 | public static string GetNavigateTo(NavigationViewItem item) => (string)item.GetValue(NavigateToProperty); 18 | 19 | public static void SetNavigateTo(NavigationViewItem item, string value) => item.SetValue(NavigateToProperty, value); 20 | 21 | public static readonly DependencyProperty NavigateToProperty = 22 | DependencyProperty.RegisterAttached("NavigateTo", typeof(string), typeof(NavigationHelper), new PropertyMetadata(null)); 23 | } 24 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Helpers/ResourceExtensions.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.Windows.ApplicationModel.Resources; 4 | 5 | namespace WslSettings.Helpers; 6 | 7 | public static class ResourceExtensions 8 | { 9 | private static readonly ResourceLoader _resourceLoader = new(); 10 | 11 | public static string GetLocalized(this string resourceKey) => _resourceLoader.GetString(resourceKey); 12 | } 13 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Styles/FontSizes.xaml: -------------------------------------------------------------------------------- 1 |  4 | 5 | 24 6 | 7 | 16 8 | 9 | 10 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Usings.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | global using WinUIEx; 4 | global using LibWsl; 5 | global using WslSettings.Helpers; -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/DistroManagementViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class DistroManagementViewModel : ObservableRecipient 8 | { 9 | public DistroManagementViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/DockerDesktopIntegrationViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class DockerDesktopIntegrationViewModel : ObservableRecipient 8 | { 9 | public DockerDesktopIntegrationViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/GPUAccelerationViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class GPUAccelerationViewModel : ObservableRecipient 8 | { 9 | public GPUAccelerationViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/GUIAppsViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class GUIAppsViewModel : ObservableRecipient 8 | { 9 | public GUIAppsViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/GeneralViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class GeneralViewModel : ObservableRecipient 8 | { 9 | public GeneralViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/NetworkingIntegrationViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class NetworkingIntegrationViewModel : ObservableRecipient 8 | { 9 | public NetworkingIntegrationViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/VSCodeIntegrationViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class VSCodeIntegrationViewModel : ObservableRecipient 8 | { 9 | public VSCodeIntegrationViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/WelcomeToUbuntuViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class WelcomeToUbuntuViewModel : ObservableRecipient 8 | { 9 | public WelcomeToUbuntuViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/OOBE/WorkingAcrossFileSystemsViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | 5 | namespace WslSettings.ViewModels.OOBE; 6 | 7 | public partial class WorkingAcrossFileSystemsViewModel : ObservableRecipient 8 | { 9 | public WorkingAcrossFileSystemsViewModel() 10 | { 11 | } 12 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/ViewModels/Settings/AboutViewModel.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using CommunityToolkit.Mvvm.ComponentModel; 4 | using System.Reflection; 5 | 6 | namespace WslSettings.ViewModels.Settings; 7 | 8 | public partial class AboutViewModel : ObservableRecipient 9 | { 10 | public AboutViewModel() 11 | { 12 | } 13 | 14 | public string VersionDescription 15 | { 16 | get 17 | { 18 | Version version = Assembly.GetExecutingAssembly().GetName().Version!; 19 | return $"{version.Major}.{version.Minor}.{version.Build}"; 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/DistroManagementPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class DistroManagementPage : Page 8 | { 9 | public DistroManagementViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public DistroManagementPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/DockerDesktopIntegrationPage.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/DockerDesktopIntegrationPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class DockerDesktopIntegrationPage : Page 8 | { 9 | public DockerDesktopIntegrationViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public DockerDesktopIntegrationPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GPUAccelerationPage.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GPUAccelerationPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class GPUAccelerationPage : Page 8 | { 9 | public GPUAccelerationViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public GPUAccelerationPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GUIAppsPage.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GUIAppsPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class GUIAppsPage : Page 8 | { 9 | public GUIAppsViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public GUIAppsPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GeneralPage.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/GeneralPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class GeneralPage : Page 8 | { 9 | public GeneralViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public GeneralPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/NetworkingIntegrationPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class NetworkingIntegrationPage : Page 8 | { 9 | public NetworkingIntegrationViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public NetworkingIntegrationPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/VSCodeIntegrationPage.xaml: -------------------------------------------------------------------------------- 1 |  8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/VSCodeIntegrationPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class VSCodeIntegrationPage : Page 8 | { 9 | public VSCodeIntegrationViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public VSCodeIntegrationPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/OOBE/WorkingAcrossFileSystemsPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.OOBE; 5 | namespace WslSettings.Views.OOBE; 6 | 7 | public sealed partial class WorkingAcrossFileSystemsPage : Page 8 | { 9 | public WorkingAcrossFileSystemsViewModel ViewModel 10 | { 11 | get; 12 | } 13 | 14 | public WorkingAcrossFileSystemsPage() 15 | { 16 | ViewModel = App.GetService(); 17 | InitializeComponent(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Views/Settings/AboutPage.xaml.cs: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using Microsoft.UI.Xaml.Controls; 4 | using WslSettings.ViewModels.Settings; 5 | 6 | namespace WslSettings.Views.Settings; 7 | 8 | public sealed partial class AboutPage : Page 9 | { 10 | public AboutViewModel ViewModel 11 | { 12 | get; 13 | } 14 | 15 | public AboutPage() 16 | { 17 | ViewModel = App.GetService(); 18 | InitializeComponent(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Windows/MainWindow.xaml: -------------------------------------------------------------------------------- 1 |  15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /src/windows/wslsettings/Windows/OOBEWindow.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/windows/wslsettings/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | true/PM 12 | PerMonitorV2, PerMonitor 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/windows/wslsettings/directory.build.targets.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/windows/wslsettings/properties/AssemblyInfo.cs.in: -------------------------------------------------------------------------------- 1 | // Copyright (C) Microsoft Corporation. All rights reserved. 2 | 3 | using System; 4 | using System.Reflection; 5 | 6 | [assembly: System.Reflection.AssemblyTitleAttribute("Windows Subsystem for Linux Settings")] 7 | [assembly: System.Reflection.AssemblyDescriptionAttribute("$Windows Subsystem for Linux Settings")] 8 | [assembly: System.Reflection.AssemblyProductAttribute("Windows Subsystem for Linux")] 9 | [assembly: System.Reflection.AssemblyCompanyAttribute("Microsoft Corporation")] 10 | [assembly: System.Reflection.AssemblyConfigurationAttribute("")] 11 | [assembly: System.Reflection.AssemblyCopyrightAttribute("Copyright (c) Microsoft Corporation")] 12 | [assembly: System.Reflection.AssemblyTrademarkAttribute("")] 13 | [assembly: System.Reflection.AssemblyCultureAttribute("")] 14 | [assembly: System.Reflection.AssemblyFileVersionAttribute("${PACKAGE_VERSION}")] 15 | [assembly: System.Reflection.AssemblyInformationalVersionAttribute("${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_REVISION}")] 16 | [assembly: System.Reflection.AssemblyVersionAttribute("${PACKAGE_VERSION_MAJOR}.${PACKAGE_VERSION_MINOR}.${PACKAGE_VERSION_REVISION}")] 17 | [assembly: System.Runtime.Versioning.TargetPlatformAttribute("${WINDOWS_TARGET_PLATFORM_VERSION}")] 18 | [assembly: System.Runtime.Versioning.SupportedOSPlatformAttribute("${WINDOWS_TARGET_PLATFORM_MIN_VERSION}")] -------------------------------------------------------------------------------- /storebroker/Media/en-us/WSLAppList 1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/storebroker/Media/en-us/WSLAppList 1.png -------------------------------------------------------------------------------- /storebroker/Media/en-us/WSLTerminalAssetSettingsColour-Export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/storebroker/Media/en-us/WSLTerminalAssetSettingsColour-Export.png -------------------------------------------------------------------------------- /storebroker/Media/en-us/WSLTerminalPanes-Export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/storebroker/Media/en-us/WSLTerminalPanes-Export.png -------------------------------------------------------------------------------- /storebroker/Media/en-us/WSLTerminalWSLgAsset-Export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/microsoft/WSL/a630dbc613e264e1c14e1551f7737893640e6cef/storebroker/Media/en-us/WSLTerminalWSLgAsset-Export.png -------------------------------------------------------------------------------- /test/linux/unit_tests/build_tests.sh: -------------------------------------------------------------------------------- 1 | make -j8 -k -C /data/test -------------------------------------------------------------------------------- /test/linux/unit_tests/lxtcommon.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | lxtcommon.h 8 | 9 | Abstract: 10 | 11 | This is a common header file for lx tests. 12 | 13 | --*/ 14 | 15 | #ifndef _LXT_COMMON 16 | #define _LXT_COMMON 17 | 18 | #include "lxtlog.h" 19 | #include "lxtutil.h" 20 | #include "lxtevent.h" 21 | 22 | #ifndef PAGE_SIZE 23 | #define PAGE_SIZE 0x1000 24 | #endif 25 | 26 | #define LXSS_DISTRO_NAME_TEST "test_distro" 27 | 28 | #endif // _LXT_COMMON 29 | -------------------------------------------------------------------------------- /test/windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES 2 | SimpleTests.cpp 3 | UnitTests.cpp 4 | MountTests.cpp 5 | NetworkTests.cpp 6 | Plan9Tests.cpp 7 | DrvFsTests.cpp 8 | Common.cpp 9 | PluginTests.cpp 10 | PolicyTests.cpp 11 | InstallerTests.cpp) 12 | 13 | set(HEADERS 14 | Common.h 15 | PluginTests.h 16 | lxsstest.h) 17 | 18 | add_compile_definitions(INLINE_TEST_METHOD_MARKUP) 19 | 20 | add_library(wsltests SHARED ${SOURCES} ${HEADERS}) 21 | 22 | target_precompile_headers(wsltests REUSE_FROM common) 23 | target_link_libraries(wsltests 24 | common 25 | ${TAEF_LINK_LIBRARIES} 26 | ${COMMON_LINK_LIBRARIES} 27 | VirtDisk.lib 28 | Wer.lib 29 | Dbghelp.lib 30 | sfc.lib) 31 | 32 | add_dependencies(wsltests wslserviceidl) 33 | add_subdirectory(testplugin) -------------------------------------------------------------------------------- /test/windows/PluginTests.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | PluginTests.h 8 | 9 | Abstract: 10 | 11 | This file contains shared definitions used in the plugin tests. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #include "registry.hpp" 18 | #include 19 | constexpr auto c_configKey = L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Lxss\\Test"; 20 | 21 | enum class PluginTestType 22 | { 23 | Invalid, 24 | Success, 25 | FailToLoad, 26 | FailToStartVm, 27 | FailToStartDistro, 28 | FailToStopVm, 29 | FailToStopDistro, 30 | ApiErrors, 31 | PluginError, 32 | PluginRequiresUpdate, 33 | SameDistroId, 34 | ErrorMessageStartVm, 35 | ErrorMessageStartDistro, 36 | FailToStartVmWithPluginErrorMessage, 37 | InitPidIsDifferent, 38 | FailToRegisterUnregisterDistro, 39 | RunDistroCommand, 40 | GetUsername 41 | }; 42 | 43 | constexpr auto c_testType = L"TestType"; 44 | constexpr auto c_logFile = L"LogFile"; 45 | 46 | inline wil::unique_hkey OpenTestRegistryKey(REGSAM AccessMask) 47 | { 48 | return wsl::windows::common::registry::CreateKey(HKEY_LOCAL_MACHINE, c_configKey, AccessMask, nullptr, REG_OPTION_VOLATILE); 49 | } -------------------------------------------------------------------------------- /test/windows/lxsstest.h: -------------------------------------------------------------------------------- 1 | /*++ 2 | 3 | Copyright (c) Microsoft. All rights reserved. 4 | 5 | Module Name: 6 | 7 | lxsstest.h 8 | 9 | Abstract: 10 | 11 | Common definitions for lxss tests. 12 | 13 | --*/ 14 | 15 | #pragma once 16 | 17 | #define STR2WSTR_INNER(str) L##str 18 | #define STR2WSTR(str) STR2WSTR_INNER(str) 19 | 20 | // 21 | // Logging macros 22 | // 23 | 24 | #define LogError(str, ...) \ 25 | { \ 26 | WEX::Logging::Log::Error(WEX::Common::String().Format(STR2WSTR(str), __VA_ARGS__)); \ 27 | } 28 | 29 | #define LogInfo(str, ...) \ 30 | { \ 31 | WEX::Logging::Log::Comment(WEX::Common::String().Format(STR2WSTR(str), __VA_ARGS__)); \ 32 | } 33 | 34 | #define LogWarning(str, ...) \ 35 | { \ 36 | WEX::Logging::Log::Warning(WEX::Common::String().Format(STR2WSTR(str), __VA_ARGS__)); \ 37 | } 38 | 39 | #define LogPass(str, ...) \ 40 | { \ 41 | WEX::Logging::Log::Result(WEX::Logging::TestResults::Passed, WEX::Common::String().Format(STR2WSTR(str), __VA_ARGS__)); \ 42 | } 43 | 44 | #define LogSkipped(str, ...) \ 45 | { \ 46 | WEX::Logging::Log::Result(WEX::Logging::TestResults::Skipped, WEX::Common::String().Format(STR2WSTR(str), __VA_ARGS__)); \ 47 | } 48 | 49 | // 50 | // Helper macros 51 | // 52 | 53 | #define ALLOC(_size) HeapAlloc(GetProcessHeap(), 0, (_size)) 54 | #define FREE(_ptr) WI_VERIFY(HeapFree(GetProcessHeap(), 0, (_ptr)) != FALSE) 55 | -------------------------------------------------------------------------------- /test/windows/testplugin/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SOURCES Plugin.cpp) 2 | 3 | add_library(testplugin SHARED ${SOURCES}) 4 | set_target_properties(testplugin PROPERTIES EXCLUDE_FROM_ALL FALSE) 5 | include_directories(testplugin ${CMAKE_CURRENT_SOURCE_DIR}/..) 6 | target_link_libraries(testplugin ${COMMON_LINK_LIBRARIES} legacy_stdio_definitions common) 7 | target_precompile_headers(testplugin REUSE_FROM common) -------------------------------------------------------------------------------- /tools/SetupClangFormat.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | rem Copyright (c) Microsoft Corporation. 3 | rem Licensed under the MIT License. 4 | 5 | rem This script sets up git hooks for clang-format 6 | 7 | pushd %~dp0% 8 | git config --local core.hooksPath tools/hooks 9 | popd -------------------------------------------------------------------------------- /tools/bin2cpio/bin2cpio.pl: -------------------------------------------------------------------------------- 1 | # 2 | # Script to convert a binary to a CPIO image. 3 | # 4 | 5 | use strict; 6 | use File::Basename; 7 | use lib dirname (__FILE__); 8 | use CPIOImage; 9 | 10 | if($#ARGV + 1 != 2) 11 | { 12 | ErrorExit(__LINE__, "Invalid command line at line $."); 13 | } 14 | 15 | my $inputFile = $ARGV[0]; 16 | my $outputFile = $ARGV[1]; 17 | 18 | my $cpioStream = ""; 19 | CPIOImage::AddObject(\$cpioStream, $inputFile, "init"); 20 | CPIOImage::AddTrailer(\$cpioStream); 21 | CPIOImage::WriteFile(\$cpioStream, $outputFile); 22 | exit 0; 23 | 24 | sub ErrorExit($$) { 25 | my $line_number = shift; 26 | my $error_message = shift; 27 | 28 | print STDERR "$0($line_number, 1): error LX2: $error_message\n"; 29 | exit 255; 30 | } -------------------------------------------------------------------------------- /tools/build-bundle.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set "build_type=%1" 4 | if NOT DEFINED build_type set "build_type=Debug" 5 | 6 | del CMakeCache.txt &^ 7 | rd /q /s _deps &^ 8 | cmake -A arm64 . -DCMAKE_BUILD_TYPE="%build_type%" &&^ 9 | cmake --build . --config "%build_type%" -- -m &&^ 10 | del CMakeCache.txt &&^ 11 | rd /q /s _deps &&^ 12 | cmake . -A x64 -DBUILD_BUNDLE=TRUE -DCMAKE_BUILD_TYPE="%build_type%" &&^ 13 | cmake --build . --config "%build_type%" -- -m 14 | -------------------------------------------------------------------------------- /tools/create-dev-cert.ps1: -------------------------------------------------------------------------------- 1 | [CmdletBinding()] 2 | param ( 3 | [string]$OutputPath 4 | ) 5 | 6 | $ErrorActionPreference = "Stop" 7 | Set-StrictMode -Version Latest 8 | # Set PSModulePath environment variable explicitly to work with PowerShell 7 9 | $env:PSModulePath = [Environment]::GetEnvironmentVariable('PSModulePath', 'Machine') 10 | 11 | $cert = New-SelfSignedCertificate -Type Custom -Subject "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US" -KeyUsage DigitalSignature -FriendlyName "WSL Dev cert" -CertStoreLocation "Cert:\CurrentUser\My" -TextExtension @("2.5.29.37={text}1.3.6.1.5.5.7.3.3", "2.5.29.19={text}") -HashAlgorithm "SHA256" -NotAfter (Get-Date).AddYears(10) 12 | 13 | Export-PfxCertificate -cert "Cert:\CurrentUser\My\$($cert.Thumbprint)" -FilePath $OutputPath -Password (New-Object System.Security.SecureString) | Out-Null 14 | Remove-Item "Cert:\CurrentUser\My\$($cert.Thumbprint)" -DeleteKey | Out-Null 15 | 16 | Write-Host "Created new dev certificate in $OutputPath" -------------------------------------------------------------------------------- /tools/deploy/deploy-to-host.ps1: -------------------------------------------------------------------------------- 1 | #Requires -RunAsAdministrator 2 | 3 | [cmdletbinding(PositionalBinding = $false)] 4 | param ( 5 | [ValidateSet("X64", "arm64")][string]$Platform = "X64", 6 | [ValidateSet("Debug", "Release")][string]$BuildType = "Debug", 7 | [string]$BuildOutputPath = [string](Get-Location), 8 | [string]$PackageCertPath = $null, 9 | [parameter(ValueFromRemainingArguments = $true)] 10 | [string[]]$MsiArgs 11 | ) 12 | 13 | $ErrorActionPreference = "Stop" 14 | 15 | $PackagePath = "$BuildOutputPath\bin\$Platform\$BuildType\wsl.msi" 16 | 17 | # msiexec.exe doesn't like symlinks, so use the canonical path 18 | $Target = (Get-ChildItem $PackagePath)[0].Target 19 | if ($Target) 20 | { 21 | $PackagePath = $Target 22 | } 23 | 24 | Write-Host -ForegroundColor Green "Installing: $PackagePath " 25 | 26 | $MSIArguments = @( 27 | "/i" 28 | $PackagePath 29 | "/qn" 30 | "/norestart" 31 | ) 32 | 33 | if ($MsiArgs) 34 | { 35 | $MSIArguments += $MsiArgs 36 | } 37 | 38 | $exitCode = (Start-Process -Wait "msiexec.exe" -ArgumentList $MSIArguments -NoNewWindow -PassThru).ExitCode 39 | if ($exitCode -Ne 0) 40 | { 41 | Write-Host "Failed to install package: $exitCode" 42 | exit 1 43 | } 44 | 45 | Write-Host -ForegroundColor Green "Package $PackagePath installed successfully" 46 | -------------------------------------------------------------------------------- /tools/devops/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-devops==7.1.0b4 2 | click==8.1.3 3 | gitpython==3.1.41 4 | backoff==2.2.1 -------------------------------------------------------------------------------- /tools/devops/version_functions.ps1: -------------------------------------------------------------------------------- 1 | Set-StrictMode -Version Latest 2 | 3 | function Get-Current-Commit-Hash() 4 | { 5 | return ([string](git log -1 --pretty=%h)).Trim() 6 | } 7 | 8 | function Get-VersionInfo 9 | { 10 | [CmdletBinding()] 11 | param([Parameter(Mandatory = $true)]$Nightly) 12 | 13 | $ErrorActionPreference = "Stop" 14 | 15 | if ($Nightly) 16 | { 17 | $suffix = 'nightly' 18 | } 19 | else 20 | { 21 | $suffix = 'build' 22 | } 23 | 24 | $output = git.exe describe --tags --match *.*.* --abbrev=1 25 | if ($LastExitCode -ne 0) 26 | { 27 | throw "git describe exited with error status: $LastExitCode. Make sure the main branch and tags are available." 28 | } 29 | 30 | $versionInfo = $output.split('-') 31 | if ($versionInfo.Length -lt 1) 32 | { 33 | throw "Unexpected output from git describe: $output" 34 | } 35 | 36 | $version = $versionInfo[0] 37 | if ($versionInfo.Length -lt 2) 38 | { 39 | $revision = 0 # This path is taken when the commit is directly on a tag 40 | } 41 | else 42 | { 43 | $revision = $versionInfo[1] 44 | } 45 | 46 | $result = @{ 47 | 'MsixVersion' = "$version.$revision" 48 | 'NugetVersion' = "$version-$suffix{0:d3}" -f $revision 49 | } 50 | 51 | return $result 52 | } 53 | -------------------------------------------------------------------------------- /tools/hooks/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # run only on Windows 4 | if [[ "$OSTYPE" == "msys" ]]; then 5 | exec powershell.exe -NoProfile -ExecutionPolicy Bypass -Command ".\FormatSource.ps1" -Staged '$true' -Verify '$true' -NoFail '$true' 6 | fi 7 | 8 | exit 0 -------------------------------------------------------------------------------- /tools/test/CloudTest-Setup.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem Required to make cloudtest use our version of taef 4 | setx /M CloudTestWorkerCustomTaefExe "%1\taef\te.exe" 5 | 6 | mkdir %2\WexLogFileOutput 7 | mklink /D %1\WexLogFileOutput %2\WexLogFileOutput -------------------------------------------------------------------------------- /tools/test/Microsoft.WSL.TestDistro.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Microsoft.WSL.TestDistro 5 | $version$ 6 | Microsoft 7 | https://github.com/microsoft/WSL 8 | WSL Test distribution 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /tools/test/test.bat.in: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rem This script is generated by CMake. See: tools/test/test.bat.in 4 | 5 | set "Bin=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}\${CMAKE_BUILD_TYPE}" 6 | set "Tools=${CMAKE_CURRENT_LIST_DIR}\tools" 7 | path %PATH%;${TAEF_SOURCE_DIR}\build\Binaries\${TARGET_PLATFORM} 8 | 9 | powershell.exe -ExecutionPolicy Bypass "%tools%\test\run-tests.ps1" -SetupScript "%tools%\test\test-setup.ps1" -DistroPath "${TEST_DISTRO_SOURCE_DIR}test_distro.tar.xz" -TestDllPath "%bin%\wsltests.dll" -UnitTestsPath "${CMAKE_CURRENT_LIST_DIR}\test\linux\unit_tests" -Package "%bin%\installer.msix" %* || goto fail 10 | 11 | exit /b 0 12 | 13 | :fail 14 | 15 | echo "Test failed" 16 | exit /b 1 --------------------------------------------------------------------------------