mirror of
https://github.com/microsoft/WSL.git
synced 2025-12-11 04:35:57 -06:00
cleanup: remove old WSLA* files from the WSL service folder (#13763)
Co-authored-by: Ben Hillis <benhill@ntdev.microsoft.com>
This commit is contained in:
parent
4017d23ac9
commit
955cb899ea
@ -53,8 +53,6 @@ set(HEADERS
|
||||
WslCoreTcpIpStateTracking.h
|
||||
WslCoreVm.h)
|
||||
|
||||
include_directories(${CMAKE_SOURCE_DIR}/src/windows/wslaclient)
|
||||
|
||||
add_executable(wslservice ${SOURCES} ${HEADERS})
|
||||
add_dependencies(wslservice wslserviceidl wslservicemc)
|
||||
add_compile_definitions(__WRL_CLASSIC_COM__)
|
||||
|
||||
@ -18,7 +18,6 @@ Abstract:
|
||||
#include "WslCoreFilesystem.h"
|
||||
#include "LxssIpTables.h"
|
||||
#include "LxssUserSessionFactory.h"
|
||||
#include "WSLAUserSessionFactory.h"
|
||||
#include <ctime>
|
||||
|
||||
using namespace wsl::windows::common::registry;
|
||||
|
||||
@ -1,87 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
WSLAUserSession.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
TODO
|
||||
|
||||
--*/
|
||||
#include "WSLAUserSession.h"
|
||||
|
||||
using wsl::windows::service::wsla::WSLAUserSessionImpl;
|
||||
|
||||
WSLAUserSessionImpl::WSLAUserSessionImpl(HANDLE Token, wil::unique_tokeninfo_ptr<TOKEN_USER>&& TokenInfo) :
|
||||
m_tokenInfo(std::move(TokenInfo))
|
||||
{
|
||||
}
|
||||
|
||||
WSLAUserSessionImpl::~WSLAUserSessionImpl()
|
||||
{
|
||||
// Manually signal the VM termination events. This prevents being stuck on an API call that holds the VM lock.
|
||||
{
|
||||
std::lock_guard lock(m_virtualMachinesLock);
|
||||
|
||||
for (auto* e : m_virtualMachines)
|
||||
{
|
||||
e->OnSessionTerminating();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WSLAUserSessionImpl::OnVmTerminated(WSLAVirtualMachine* machine)
|
||||
{
|
||||
std::lock_guard lock(m_virtualMachinesLock);
|
||||
auto pred = [machine](const auto* e) { return machine == e; };
|
||||
|
||||
// Remove any stale VM reference.
|
||||
m_virtualMachines.erase(std::remove_if(m_virtualMachines.begin(), m_virtualMachines.end(), pred), m_virtualMachines.end());
|
||||
}
|
||||
|
||||
HRESULT WSLAUserSessionImpl::CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine)
|
||||
{
|
||||
auto vm = wil::MakeOrThrow<WSLAVirtualMachine>(*Settings, GetUserSid(), this);
|
||||
|
||||
{
|
||||
std::lock_guard lock(m_virtualMachinesLock);
|
||||
m_virtualMachines.emplace_back(vm.Get());
|
||||
}
|
||||
|
||||
vm->Start();
|
||||
THROW_IF_FAILED(vm.CopyTo(__uuidof(IWSLAVirtualMachine), (void**)VirtualMachine));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
PSID WSLAUserSessionImpl::GetUserSid() const
|
||||
{
|
||||
return m_tokenInfo->User.Sid;
|
||||
}
|
||||
|
||||
wsl::windows::service::wsla::WSLAUserSession::WSLAUserSession(std::weak_ptr<WSLAUserSessionImpl>&& Session) :
|
||||
m_session(std::move(Session))
|
||||
{
|
||||
}
|
||||
|
||||
HRESULT wsl::windows::service::wsla::WSLAUserSession::GetVersion(_Out_ WSL_VERSION* Version)
|
||||
{
|
||||
Version->Major = WSL_PACKAGE_VERSION_MAJOR;
|
||||
Version->Minor = WSL_PACKAGE_VERSION_MINOR;
|
||||
Version->Revision = WSL_PACKAGE_VERSION_REVISION;
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT wsl::windows::service::wsla::WSLAUserSession::CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine)
|
||||
try
|
||||
{
|
||||
auto session = m_session.lock();
|
||||
RETURN_HR_IF(RPC_E_DISCONNECTED, !session);
|
||||
|
||||
return session->CreateVirtualMachine(Settings, VirtualMachine);
|
||||
}
|
||||
CATCH_RETURN();
|
||||
@ -1,56 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
WSLAUserSession.h
|
||||
|
||||
Abstract:
|
||||
|
||||
TODO
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
#include "WSLAVirtualMachine.h"
|
||||
|
||||
namespace wsl::windows::service::wsla {
|
||||
|
||||
class WSLAUserSessionImpl
|
||||
{
|
||||
public:
|
||||
WSLAUserSessionImpl(HANDLE Token, wil::unique_tokeninfo_ptr<TOKEN_USER>&& TokenInfo);
|
||||
WSLAUserSessionImpl(WSLAUserSessionImpl&&) = default;
|
||||
WSLAUserSessionImpl& operator=(WSLAUserSessionImpl&&) = default;
|
||||
|
||||
~WSLAUserSessionImpl();
|
||||
|
||||
PSID GetUserSid() const;
|
||||
|
||||
HRESULT CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine);
|
||||
|
||||
void OnVmTerminated(WSLAVirtualMachine* machine);
|
||||
|
||||
private:
|
||||
wil::unique_tokeninfo_ptr<TOKEN_USER> m_tokenInfo;
|
||||
|
||||
std::recursive_mutex m_virtualMachinesLock;
|
||||
std::vector<WSLAVirtualMachine*> m_virtualMachines;
|
||||
};
|
||||
|
||||
class DECLSPEC_UUID("a9b7a1b9-0671-405c-95f1-e0612cb4ce8f") WSLAUserSession
|
||||
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLAUserSession, IFastRundown>
|
||||
{
|
||||
public:
|
||||
WSLAUserSession(std::weak_ptr<WSLAUserSessionImpl>&& Session);
|
||||
WSLAUserSession(const WSLAUserSession&) = delete;
|
||||
WSLAUserSession& operator=(const WSLAUserSession&) = delete;
|
||||
|
||||
IFACEMETHOD(GetVersion)(_Out_ WSL_VERSION* Version) override;
|
||||
IFACEMETHOD(CreateVirtualMachine)(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine) override;
|
||||
|
||||
private:
|
||||
std::weak_ptr<WSLAUserSessionImpl> m_session;
|
||||
};
|
||||
|
||||
} // namespace wsl::windows::service::wsla
|
||||
@ -1,82 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
WSLAUserSessionFactory.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
TODO
|
||||
|
||||
--*/
|
||||
#include "precomp.h"
|
||||
|
||||
#include "WSLAUserSessionFactory.h"
|
||||
#include "WSLAUserSession.h"
|
||||
|
||||
using wsl::windows::service::wsla::WSLAUserSessionFactory;
|
||||
using wsl::windows::service::wsla::WSLAUserSessionImpl;
|
||||
|
||||
CoCreatableClassWithFactory(WSLAUserSession, WSLAUserSessionFactory);
|
||||
|
||||
static std::mutex g_mutex;
|
||||
static std::optional<std::vector<std::shared_ptr<WSLAUserSessionImpl>>> g_sessions =
|
||||
std::make_optional<std::vector<std::shared_ptr<WSLAUserSessionImpl>>>();
|
||||
|
||||
HRESULT WSLAUserSessionFactory::CreateInstance(_In_ IUnknown* pUnkOuter, _In_ REFIID riid, _Out_ void** ppCreated)
|
||||
{
|
||||
RETURN_HR_IF_NULL(E_POINTER, ppCreated);
|
||||
*ppCreated = nullptr;
|
||||
|
||||
RETURN_HR_IF(CLASS_E_NOAGGREGATION, pUnkOuter != nullptr);
|
||||
|
||||
WSL_LOG("WSLAUserSessionFactory", TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
|
||||
|
||||
try
|
||||
{
|
||||
const wil::unique_handle userToken = wsl::windows::common::security::GetUserToken(TokenImpersonation);
|
||||
|
||||
// Get the session ID and SID of the client process.
|
||||
DWORD sessionId{};
|
||||
DWORD length = 0;
|
||||
THROW_IF_WIN32_BOOL_FALSE(::GetTokenInformation(userToken.get(), TokenSessionId, &sessionId, sizeof(sessionId), &length));
|
||||
|
||||
auto tokenInfo = wil::get_token_information<TOKEN_USER>(userToken.get());
|
||||
|
||||
std::lock_guard lock{g_mutex};
|
||||
|
||||
THROW_HR_IF(CO_E_SERVER_STOPPING, !g_sessions.has_value());
|
||||
|
||||
auto session = std::find_if(g_sessions->begin(), g_sessions->end(), [&tokenInfo](auto it) {
|
||||
return EqualSid(it->GetUserSid(), &tokenInfo->User.Sid);
|
||||
});
|
||||
|
||||
if (session == g_sessions->end())
|
||||
{
|
||||
session = g_sessions->insert(g_sessions->end(), std::make_shared<WSLAUserSessionImpl>(userToken.get(), std::move(tokenInfo)));
|
||||
}
|
||||
|
||||
auto comInstance = wil::MakeOrThrow<WSLAUserSession>(std::weak_ptr<WSLAUserSessionImpl>(*session));
|
||||
|
||||
THROW_IF_FAILED(comInstance.CopyTo(riid, ppCreated));
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
const auto result = wil::ResultFromCaughtException();
|
||||
|
||||
// Note: S_FALSE will cause COM to retry if the service is stopping.
|
||||
return result == CO_E_SERVER_STOPPING ? S_FALSE : result;
|
||||
}
|
||||
|
||||
WSL_LOG("WSLAUserSessionFactory", TraceLoggingLevel(WINEVENT_LEVEL_VERBOSE));
|
||||
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
void wsl::windows::service::wsla::ClearWslaSessionsAndBlockNewInstances()
|
||||
{
|
||||
std::lock_guard lock{g_mutex};
|
||||
g_sessions.reset();
|
||||
}
|
||||
@ -1,28 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
WSLAUserSessionFactory.h
|
||||
|
||||
Abstract:
|
||||
|
||||
TODO
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
#include <wil/resource.h>
|
||||
|
||||
namespace wsl::windows::service::wsla {
|
||||
|
||||
class WSLAUserSessionFactory : public Microsoft::WRL::ClassFactory<>
|
||||
{
|
||||
public:
|
||||
WSLAUserSessionFactory() = default;
|
||||
|
||||
STDMETHODIMP CreateInstance(_In_ IUnknown* pUnkOuter, _In_ REFIID riid, _Out_ void** ppCreated) override;
|
||||
};
|
||||
|
||||
void ClearWslaSessionsAndBlockNewInstances();
|
||||
} // namespace wsl::windows::service::wsla
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,106 +0,0 @@
|
||||
/*++
|
||||
|
||||
Copyright (c) Microsoft. All rights reserved.
|
||||
|
||||
Module Name:
|
||||
|
||||
WSLAVirtualMachine.h
|
||||
|
||||
Abstract:
|
||||
|
||||
TODO
|
||||
|
||||
--*/
|
||||
#pragma once
|
||||
#include "wslservice.h"
|
||||
#include "INetworkingEngine.h"
|
||||
#include "hcs.hpp"
|
||||
#include "Dmesg.h"
|
||||
#include "WSLAApi.h"
|
||||
|
||||
namespace wsl::windows::service::wsla {
|
||||
|
||||
class WSLAUserSessionImpl;
|
||||
|
||||
class DECLSPEC_UUID("0CFC5DC1-B6A7-45FC-8034-3FA9ED73CE30") WSLAVirtualMachine
|
||||
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLAVirtualMachine, IFastRundown>
|
||||
|
||||
{
|
||||
public:
|
||||
WSLAVirtualMachine(const VIRTUAL_MACHINE_SETTINGS& Settings, PSID Sid, WSLAUserSessionImpl* UserSession);
|
||||
~WSLAVirtualMachine();
|
||||
|
||||
void Start();
|
||||
void OnSessionTerminating();
|
||||
|
||||
IFACEMETHOD(AttachDisk(_In_ PCWSTR Path, _In_ BOOL ReadOnly, _Out_ LPSTR* Device, _Out_ ULONG* Lun)) override;
|
||||
IFACEMETHOD(Mount(_In_ LPCSTR Source, _In_ LPCSTR Target, _In_ LPCSTR Type, _In_ LPCSTR Options, _In_ ULONG Flags)) override;
|
||||
IFACEMETHOD(CreateLinuxProcess(
|
||||
_In_ const WSLA_CREATE_PROCESS_OPTIONS* Options, _In_ ULONG FdCount, _In_ WSLA_PROCESS_FD* Fd, _Out_ ULONG* Handles, _Out_ WSLA_CREATE_PROCESS_RESULT* Result)) override;
|
||||
IFACEMETHOD(WaitPid(_In_ LONG Pid, _In_ ULONGLONG TimeoutMs, _Out_ ULONG* State, _Out_ int* Code)) override;
|
||||
IFACEMETHOD(Signal(_In_ LONG Pid, _In_ int Signal)) override;
|
||||
IFACEMETHOD(Shutdown(ULONGLONG _In_ TimeoutMs)) override;
|
||||
IFACEMETHOD(RegisterCallback(_In_ ITerminationCallback* callback)) override;
|
||||
IFACEMETHOD(GetDebugShellPipe(_Out_ LPWSTR* pipePath)) override;
|
||||
IFACEMETHOD(MapPort(_In_ int Family, _In_ short WindowsPort, _In_ short LinuxPort, _In_ BOOL Remove)) override;
|
||||
IFACEMETHOD(Unmount(_In_ const char* Path)) override;
|
||||
IFACEMETHOD(DetachDisk(_In_ ULONG Lun)) override;
|
||||
IFACEMETHOD(MountWindowsFolder(_In_ LPCWSTR WindowsPath, _In_ LPCSTR LinuxPath, _In_ BOOL ReadOnly)) override;
|
||||
IFACEMETHOD(UnmountWindowsFolder(_In_ LPCSTR LinuxPath)) override;
|
||||
IFACEMETHOD(MountGpuLibraries(_In_ LPCSTR LibrariesMountPoint, _In_ LPCSTR DriversMountpoint, _In_ DWORD Flags)) override;
|
||||
|
||||
private:
|
||||
static int32_t MountImpl(wsl::shared::SocketChannel& Channel, LPCSTR Source, _In_ LPCSTR Target, _In_ LPCSTR Type, _In_ LPCSTR Options, _In_ ULONG Flags);
|
||||
static void CALLBACK s_OnExit(_In_ HCS_EVENT* Event, _In_opt_ void* Context);
|
||||
static bool ParseTtyInformation(const WSLA_PROCESS_FD* Fds, ULONG FdCount, const WSLA_PROCESS_FD** TtyInput, const WSLA_PROCESS_FD** TtyOutput);
|
||||
|
||||
void ConfigureNetworking();
|
||||
void OnExit(_In_ const HCS_EVENT* Event);
|
||||
|
||||
std::tuple<int32_t, int32_t, wsl::shared::SocketChannel> Fork(enum WSLA_FORK::ForkType Type);
|
||||
std::tuple<int32_t, int32_t, wsl::shared::SocketChannel> Fork(wsl::shared::SocketChannel& Channel, enum WSLA_FORK::ForkType Type);
|
||||
int32_t ExpectClosedChannelOrError(wsl::shared::SocketChannel& Channel);
|
||||
|
||||
wil::unique_socket ConnectSocket(wsl::shared::SocketChannel& Channel, int32_t Fd);
|
||||
void OpenLinuxFile(wsl::shared::SocketChannel& Channel, const char* Path, uint32_t Flags, int32_t Fd);
|
||||
void LaunchPortRelay();
|
||||
|
||||
std::vector<wil::unique_socket> CreateLinuxProcessImpl(
|
||||
_In_ const WSLA_CREATE_PROCESS_OPTIONS* Options, _In_ ULONG FdCount, _In_ WSLA_PROCESS_FD* Fd, _Out_ WSLA_CREATE_PROCESS_RESULT* Result);
|
||||
|
||||
HRESULT MountWindowsFolderImpl(_In_ LPCWSTR WindowsPath, _In_ LPCSTR LinuxPath, _In_ BOOL ReadOnly, _In_ WslMountFlags Flags);
|
||||
|
||||
struct AttachedDisk
|
||||
{
|
||||
std::filesystem::path Path;
|
||||
std::string Device;
|
||||
bool AccessGranted = false;
|
||||
};
|
||||
|
||||
VIRTUAL_MACHINE_SETTINGS m_settings;
|
||||
GUID m_vmId{};
|
||||
std::wstring m_vmIdString;
|
||||
wsl::windows::common::helpers::WindowsVersion m_windowsVersion = wsl::windows::common::helpers::GetWindowsVersion();
|
||||
int m_coldDiscardShiftSize{};
|
||||
bool m_running = false;
|
||||
PSID m_userSid{};
|
||||
std::wstring m_debugShellPipe;
|
||||
|
||||
wsl::windows::common::hcs::unique_hcs_system m_computeSystem;
|
||||
std::shared_ptr<DmesgCollector> m_dmesgCollector;
|
||||
wil::unique_event m_vmExitEvent{wil::EventOptions::ManualReset};
|
||||
wil::unique_event m_vmTerminatingEvent{wil::EventOptions::ManualReset};
|
||||
wil::com_ptr<ITerminationCallback> m_terminationCallback;
|
||||
std::unique_ptr<wsl::core::INetworkingEngine> m_networkEngine;
|
||||
|
||||
wsl::shared::SocketChannel m_initChannel;
|
||||
wil::unique_handle m_portRelayChannelRead;
|
||||
wil::unique_handle m_portRelayChannelWrite;
|
||||
|
||||
std::map<ULONG, AttachedDisk> m_attachedDisks;
|
||||
std::map<std::string, std::wstring> m_plan9Mounts;
|
||||
std::recursive_mutex m_lock;
|
||||
std::mutex m_portRelaylock;
|
||||
WSLAUserSessionImpl* m_userSession;
|
||||
};
|
||||
} // namespace wsl::windows::service::wsla
|
||||
@ -159,7 +159,6 @@ cpp_quote("const GUID CLSID_LxssUserSessionInBox = {0x4f476546, 0xb412, 0x4579,
|
||||
cpp_quote("#ifdef __cplusplus")
|
||||
cpp_quote("class DECLSPEC_UUID(\"a9b7a1b9-0671-405c-95f1-e0612cb4ce7e\") LxssUserSession;")
|
||||
cpp_quote("class DECLSPEC_UUID(\"4f476546-b412-4579-b64c-123df331e3d6\") LxssUserSessionInBox;")
|
||||
cpp_quote("class DECLSPEC_UUID(\"a9b7a1b9-0671-405c-95f1-e0612cb4ce8f\") WSLAUserSession;")
|
||||
|
||||
cpp_quote("#endif")
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user