Skip to content

Commit 7f91c00

Browse files
author
Pooja Trivedi
committed
Merge branch 'wsl-for-apps' into user/ptrivedi/cont-mgr
2 parents 90ba76b + cedbb94 commit 7f91c00

File tree

11 files changed

+116
-133
lines changed

11 files changed

+116
-133
lines changed

.github/CODEOWNERS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# File containing policy for file ownership
22

33
# Reviewers for all files in the repository
4-
* @microsoft/wsl-maintainers
4+
* @microsoft/wsl-maintainers
5+
* @microsoft/wsla-team

msipackage/package.wix.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,11 @@
263263
<RegistryValue Name="AppId" Value="{E9B79997-57E3-4201-AECC-6A464E530DD2}" Type="string" />
264264
<RegistryValue Value="WSLAVirtualMachine" Type="string" />
265265
</RegistryKey>
266-
267266
<!-- WSLASession -->
268267
<RegistryKey Root="HKCR" Key="CLSID\{4877FEFC-4977-4929-A958-9F36AA1892A4}">
269268
<RegistryValue Name="AppId" Value="{E9B79997-57E3-4201-AECC-6A464E530DD2}" Type="string" />
270269
<RegistryValue Value="WSLASession" Type="string" />
271270
</RegistryKey>
272-
273271
<!-- IWSLAUserSession-->
274272
<RegistryKey Root="HKCR" Key="Interface\{82A7ABC8-6B50-43FC-AB96-15FBBE7E8760}">
275273
<RegistryValue Value="IWSLAUserSession" Type="string" />
@@ -301,7 +299,6 @@
301299
<RegistryValue Value="{4EA0C6DD-E9FF-48E7-994E-13A31D10DC61}" Type="string" />
302300
</RegistryKey>
303301
</RegistryKey>
304-
305302
<File Id="wslaservice.exe" Source="${BIN}/wslaservice.exe" KeyPath="yes" />
306303
<File Id="wslaserviceproxystub.dll" Name="wslaserviceproxystub.dll" Source="${BIN}/wslaserviceproxystub.dll" />
307304

src/windows/wslaclient/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ add_library(wslaclient SHARED ${SOURCES} ${HEADERS} wslaclient.def)
55
set_target_properties(wslaclient PROPERTIES EXCLUDE_FROM_ALL FALSE)
66
add_dependencies(wslaclient wslaserviceidl)
77
target_link_libraries(wslaclient ${COMMON_LINK_LIBRARIES} legacy_stdio_definitions common)
8-
target_precompile_headers(wslaclient REUSE_FROM common)
8+
target_precompile_headers(wslaclient REUSE_FROM common)
9+
set_target_properties(wslaclient PROPERTIES FOLDER windows)

src/windows/wslaclient/DllMain.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,6 @@ Module Name:
1818
#include "wslrelay.h"
1919
#include "wslInstall.h"
2020

21-
/* namespace {
22-
23-
void ConfigureComSecurity(IUnknown* Instance)
24-
{
25-
wil::com_ptr_nothrow<IClientSecurity> clientSecurity;
26-
THROW_IF_FAILED(Instance->QueryInterface(IID_PPV_ARGS(&clientSecurity)));
27-
28-
// Get the current proxy blanket settings.
29-
DWORD authnSvc, authzSvc, authnLvl, capabilites;
30-
THROW_IF_FAILED(clientSecurity->QueryBlanket(Instance, &authnSvc, &authzSvc, NULL, &authnLvl, NULL, NULL, &capabilites));
31-
32-
// Make sure that dynamic cloaking is used.
33-
WI_ClearFlag(capabilites, EOAC_STATIC_CLOAKING);
34-
WI_SetFlag(capabilites, EOAC_DYNAMIC_CLOAKING);
35-
THROW_IF_FAILED(clientSecurity->SetBlanket(Instance, authnSvc, authzSvc, NULL, authnLvl, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, capabilites));
36-
}
37-
} // namespace */
38-
3921
class DECLSPEC_UUID("7BC4E198-6531-4FA6-ADE2-5EF3D2A04DFF") CallbackInstance
4022
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, ITerminationCallback, IFastRundown>
4123
{
@@ -74,7 +56,6 @@ try
7456
wil::com_ptr<IWSLAUserSession> session;
7557

7658
THROW_IF_FAILED(CoCreateInstance(__uuidof(WSLAUserSession), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&session)));
77-
// ConfigureComSecurity(session.get());
7859
wsl::windows::common::security::ConfigureForCOMImpersonation(session.get());
7960

8061
/* wil::com_ptr<IWSLAVirtualMachine> virtualMachineInstance;
@@ -92,7 +73,6 @@ try
9273
settings.EnableGPU = UserSettings->GPU.Enable;
9374
9475
THROW_IF_FAILED(session->CreateVirtualMachine(&settings, &virtualMachineInstance));
95-
// ConfigureComSecurity(virtualMachineInstance.get());
9676
wsl::windows::common::security::ConfigureForCOMImpersonation(virtualMachineInstance.get());
9777
9878
// Register termination callback, if specified
@@ -439,4 +419,4 @@ try
439419
{
440420
return reinterpret_cast<IWSLAVirtualMachine*>(VirtualMachine)->MountGpuLibraries(LibrariesMountPoint, DriversMountpoint, static_cast<DWORD>(Flags));
441421
}
442-
CATCH_RETURN();
422+
CATCH_RETURN();
Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
1-
#include "C:/Users/trivedipooja/source/repos/WSL/src/windows/common/CMakeFiles/common.dir/Debug/cmake_pch.hxx"
2-
#include "WSLASession.h"
1+
/*++
32
4-
using wsl::windows::service::wsla::WSLASessionImpl;
5-
using wsl::windows::service::wsla::WSLASession;
3+
Copyright (c) Microsoft. All rights reserved.
64
7-
WSLASessionImpl::WSLASessionImpl()
8-
{
9-
}
5+
Module Name:
106
7+
WSLASession.cpp
118
12-
WSLASessionImpl::~WSLASessionImpl()
13-
{
14-
}
9+
Abstract:
1510
16-
wsl::windows::service::wsla::WSLASession::WSLASession(std::weak_ptr<WSLASessionImpl>&& Session) :
17-
m_wslaSession(std::move(Session))
18-
{
19-
}
11+
This file contains the implementation of the WSLASession COM class.
12+
13+
--*/
14+
15+
#include "WSLASession.h"
16+
17+
using wsl::windows::service::wsla::WSLASession;
2018

2119
HRESULT WSLASession::GetDisplayName(LPWSTR* DisplayName)
2220
{
@@ -26,4 +24,4 @@ HRESULT WSLASession::GetDisplayName(LPWSTR* DisplayName)
2624

2725
WSLASession::WSLASession(const WSLA_SESSION_CONFIGURATION& SessionConfiguration) : m_sessionConfig(SessionConfiguration)
2826
{
29-
}
27+
}

src/windows/wslaservice/exe/WSLASession.h

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,6 @@ Module Name:
1111
TODO
1212
1313
--*/
14-
#pragma once
15-
#include "wslaservice.h"
16-
#include "INetworkingEngine.h"
17-
#include "hcs.hpp"
18-
#include "Dmesg.h"
19-
#include "WSLAApi.h"
20-
#include "WSLAVirtualMachine.h"
21-
22-
namespace wsl::windows::service::wsla {
23-
24-
class WSLAUserSessionImpl;
25-
26-
class WSLASessionImpl
27-
{
28-
public:
29-
WSLASessionImpl();
30-
//WSLASessionImpl(WSLASessionImpl&&) = default;
31-
//WSLASessionImpl& operator=(WSLASessionImpl&&) = default;
32-
33-
~WSLASessionImpl();
34-
35-
/* HRESULT CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine);
36-
void OnVmTerminated(WSLAVirtualMachine* machine);
37-
38-
void OnUserSessionTerminating(); */
39-
40-
41-
private:
42-
WSLAVirtualMachine* m_vm;
43-
// WSLAContainerManager m_containerManager;
44-
};
4514

4615
class DECLSPEC_UUID("4877FEFC-4977-4929-A958-9F36AA1892A4") WSLASession
4716
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLASession, IFastRundown>
@@ -72,4 +41,4 @@ class DECLSPEC_UUID("4877FEFC-4977-4929-A958-9F36AA1892A4") WSLASession
7241
WSLAUserSessionImpl* m_userSession;
7342
std::weak_ptr<WSLASessionImpl> m_wslaSession;
7443
};
75-
} // namespace wsl::windows::service::wsla
44+
} // namespace wsl::windows::service::wsla

src/windows/wslaservice/exe/WSLAUserSession.cpp

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ WSLAUserSessionImpl::~WSLAUserSessionImpl()
2929

3030
for (auto* e : m_wslaSessions)
3131
{
32-
//e->OnSessionTerminating();
32+
e->OnSessionTerminating();
3333
}
3434
}
3535
}
@@ -55,6 +55,29 @@ HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::CreateSession(
5555

5656
// session->Start();
5757
THROW_IF_FAILED(session.CopyTo(__uuidof(IWSLASession), (void**)WslaSession));
58+
return S_OK;
59+
}
60+
61+
void WSLAUserSessionImpl::OnVmTerminated(WSLAVirtualMachine* machine)
62+
{
63+
std::lock_guard lock(m_lock);
64+
auto pred = [machine](const auto* e) { return machine == e; };
65+
66+
// Remove any stale VM reference.
67+
m_virtualMachines.erase(std::remove_if(m_virtualMachines.begin(), m_virtualMachines.end(), pred), m_virtualMachines.end());
68+
}
69+
70+
HRESULT WSLAUserSessionImpl::CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine)
71+
{
72+
auto vm = wil::MakeOrThrow<WSLAVirtualMachine>(*Settings, GetUserSid(), this);
73+
74+
{
75+
std::lock_guard lock(m_lock);
76+
m_virtualMachines.emplace_back(vm.Get());
77+
}
78+
79+
vm->Start();
80+
THROW_IF_FAILED(vm.CopyTo(__uuidof(IWSLAVirtualMachine), (void**)VirtualMachine));
5881

5982
return S_OK;
6083
}
@@ -64,6 +87,20 @@ PSID WSLAUserSessionImpl::GetUserSid() const
6487
return m_tokenInfo->User.Sid;
6588
}
6689

90+
HRESULT wsl::windows::service::wsla::WSLAUserSessionImpl::CreateSession(const WSLA_SESSION_SETTINGS* Settings, IWSLASession** Session)
91+
{
92+
auto session = wil::MakeOrThrow<WSLASession>(*Settings);
93+
94+
{
95+
std::lock_guard lock(m_lock);
96+
m_sessions.emplace_back(session.Get());
97+
}
98+
99+
THROW_IF_FAILED(session.CopyTo(__uuidof(IWSLASession), (void**)Session));
100+
101+
return S_OK;
102+
}
103+
67104
wsl::windows::service::wsla::WSLAUserSession::WSLAUserSession(std::weak_ptr<WSLAUserSessionImpl>&& Session) :
68105
m_session(std::move(Session))
69106
{
@@ -87,4 +124,4 @@ try
87124

88125
return session->CreateSession(Settings, VmSettings, WslaSession);
89126
}
90-
CATCH_RETURN();
127+
CATCH_RETURN();

src/windows/wslaservice/exe/WSLAUserSession.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ Module Name:
1111
TODO
1212
1313
--*/
14+
1415
#pragma once
16+
#include "WSLAVirtualMachine.h"
1517
#include "WSLASession.h"
16-
//#include "wslaservice.idl" // For WSLA_SESSION_CONFIGURATION and IWSLASession
1718

1819
namespace wsl::windows::service::wsla {
1920

@@ -28,6 +29,7 @@ class WSLAUserSessionImpl
2829

2930
PSID GetUserSid() const;
3031

32+
HRESULT CreateVirtualMachine(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine);
3133
HRESULT CreateSession(const WSLA_SESSION_CONFIGURATION* WslaSessionConfig, const VIRTUAL_MACHINE_SETTINGS* VmSettings, IWSLASession** WslaSession);
3234

3335
/* HRESULT ReleaseSession(const IWSLASession* WslaSession);
@@ -40,20 +42,21 @@ class WSLAUserSessionImpl
4042
wil::unique_tokeninfo_ptr<TOKEN_USER> m_tokenInfo;
4143

4244
std::recursive_mutex m_wslaSessionsLock;
43-
std::vector<WSLASession*> m_wslaSessions;
44-
45-
// std::vector<Microsoft::WRL::ComPtr<WSLASession>> m_wslaSessions;
45+
// TODO-WSLA: Consider using a weak_ptr to easily destroy when the last client reference is released.
46+
std::vector<Microsoft::WRL::ComPtr<WSLASession>> m_wslaSessions;
47+
std::vector<WSLAVirtualMachine*> m_virtualMachines;
4648
};
4749

4850
class DECLSPEC_UUID("a9b7a1b9-0671-405c-95f1-e0612cb4ce8f") WSLAUserSession
4951
: public Microsoft::WRL::RuntimeClass<Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::ClassicCom>, IWSLAUserSession, IFastRundown>
5052
{
5153
public:
5254
WSLAUserSession(std::weak_ptr<WSLAUserSessionImpl>&& Session);
53-
//WSLAUserSession(const WSLAUserSession&) = delete;
54-
//WSLAUserSession& operator=(const WSLAUserSession&) = delete;
55+
WSLAUserSession(const WSLAUserSession&) = delete;
56+
WSLAUserSession& operator=(const WSLAUserSession&) = delete;
5557

5658
IFACEMETHOD(GetVersion)(_Out_ WSL_VERSION* Version) override;
59+
IFACEMETHOD(CreateVirtualMachine)(const VIRTUAL_MACHINE_SETTINGS* Settings, IWSLAVirtualMachine** VirtualMachine) override;
5760
IFACEMETHOD(CreateSession)(const WSLA_SESSION_CONFIGURATION* WslaSessionConfig, const VIRTUAL_MACHINE_SETTINGS* VmSettings, IWSLASession** WslaSession);
5861
//IFACEMETHOD(ReleaseSession)(_In_ const IWSLASession* WslaSession) override;
5962
//IFACEMETHOD(ListSessions)(_Out_ std::vector<WSLASession*>& Sessions) override;

src/windows/wslaservice/exe/WSLAVirtualMachine.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ WSLAVirtualMachine::~WSLAVirtualMachine()
6464

6565
if (m_userSession != nullptr)
6666
{
67-
// m_userSession->OnVmTerminated(this);
67+
m_userSession->OnVmTerminated(this);
6868
}
6969
}
7070

@@ -1049,4 +1049,4 @@ try
10491049
RETURN_IF_FAILED(Mount("none", LibrariesMountPoint, "overlay", options.c_str(), Flags));
10501050
return S_OK;
10511051
}
1052-
CATCH_RETURN();
1052+
CATCH_RETURN();

0 commit comments

Comments
 (0)