Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions msipackage/package.wix.in
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,6 @@
<RegistryValue Value="WSLAUserSession" Type="string" />
</RegistryKey>

<!-- WSLAVirtualMachine -->
<RegistryKey Root="HKCR" Key="CLSID\{0CFC5DC1-B6A7-45FC-8034-3FA9ED73CE30}">
<RegistryValue Name="AppId" Value="{E9B79997-57E3-4201-AECC-6A464E530DD2}" Type="string" />
<RegistryValue Value="WSLAVirtualMachine" Type="string" />
</RegistryKey>
<!-- WSLASession -->
<RegistryKey Root="HKCR" Key="CLSID\{4877FEFC-4977-4929-A958-9F36AA1892A4}">
<RegistryValue Name="AppId" Value="{E9B79997-57E3-4201-AECC-6A464E530DD2}" Type="string" />
Expand All @@ -287,14 +282,6 @@
</RegistryKey>
</RegistryKey>

<!-- IWSLAVirtualMachine-->
<RegistryKey Root="HKCR" Key="Interface\{82A7ABC8-6B50-43FC-AB96-15FBBE7E8761}">
<RegistryValue Value="IWSLAVirtualMachine" Type="string" />
<RegistryKey Key="ProxyStubClsid32">
<RegistryValue Value="{4EA0C6DD-E9FF-48E7-994E-13A31D10DC61}" Type="string" />
</RegistryKey>
</RegistryKey>

<!-- IWSLAContainer-->
<RegistryKey Root="HKCR" Key="Interface\{7577FE8D-DE85-471E-B870-11669986F332}">
<RegistryValue Value="IWSLAContainer" Type="string" />
Expand Down
57 changes: 2 additions & 55 deletions src/linux/init/WSLAInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -656,59 +656,6 @@ void HandleMessageImpl(wsl::shared::SocketChannel& Channel, const WSLA_PORT_RELA
RunLocalHostRelay(SocketAddress, ListenSocket.get());
}

void HandleMessageImpl(wsl::shared::SocketChannel& Channel, const WSLA_WAITPID& Message, const gsl::span<gsl::byte>& Buffer)
{
WSLA_WAITPID_RESULT response{};
response.State = WSLAOpenFlagsUnknown;

auto sendResponse = wil::scope_exit([&]() { Channel.SendMessage(response); });

wil::unique_fd process = syscall(SYS_pidfd_open, Message.Pid, 0);
if (!process)
{
LOG_ERROR("pidfd_open({}) failed, {}", Message.Pid, errno);
response.Errno = errno;
return;
}

pollfd pollResult{};
pollResult.fd = process.get();
pollResult.events = POLLIN | POLLERR;

int result = poll(&pollResult, 1, Message.TimeoutMs);
if (result < 0)
{
LOG_ERROR("poll failed {}", errno);
response.Errno = errno;
return;
}
else if (result == 0) // Timed out
{
response.State = WSLAOpenFlagsRunning;
response.Errno = 0;
return;
}

if (WI_IsFlagSet(pollResult.revents, POLLIN))
{
siginfo_t childState{};
auto result = waitid(P_PIDFD, process.get(), &childState, WEXITED);
if (result < 0)
{
LOG_ERROR("waitid({}) failed, {}", process.get(), errno);
response.Errno = errno;
return;
}

response.Code = childState.si_status;
response.Errno = 0;
response.State = childState.si_code == CLD_EXITED ? WSLAOpenFlagsExited : WSLAOpenFlagsSignaled;
return;
}

LOG_ERROR("Poll returned an unexpected error state on fd: {} for pid: {}", process.get(), Message.Pid);
}

void HandleMessageImpl(wsl::shared::SocketChannel& Channel, const WSLA_SIGNAL& Message, const gsl::span<gsl::byte>& Buffer)
{
auto result = kill(Message.Pid, Message.Signal);
Expand Down Expand Up @@ -866,7 +813,7 @@ void ProcessMessage(wsl::shared::SocketChannel& Channel, LX_MESSAGE_TYPE Type, c
{
try
{
HandleMessage<WSLA_GET_DISK, WSLA_MOUNT, WSLA_EXEC, WSLA_FORK, WSLA_CONNECT, WSLA_WAITPID, WSLA_SIGNAL, WSLA_TTY_RELAY, WSLA_PORT_RELAY, WSLA_OPEN, WSLA_UNMOUNT, WSLA_DETACH, WSLA_ACCEPT, WSLA_WATCH_PROCESSES, WSLA_UNIX_CONNECT>(
HandleMessage<WSLA_GET_DISK, WSLA_MOUNT, WSLA_EXEC, WSLA_FORK, WSLA_CONNECT, WSLA_SIGNAL, WSLA_TTY_RELAY, WSLA_PORT_RELAY, WSLA_OPEN, WSLA_UNMOUNT, WSLA_DETACH, WSLA_ACCEPT, WSLA_WATCH_PROCESSES, WSLA_UNIX_CONNECT>(
Channel, Type, Buffer);
}
catch (...)
Expand All @@ -882,7 +829,7 @@ void ProcessMessages(wsl::shared::SocketChannel& Channel)
while (Channel.Connected())
{
auto [Message, Range] = Channel.ReceiveMessageOrClosed<MESSAGE_HEADER>();
if (Message == nullptr || Message->MessageType == LxMessageWSLAShutdown)

Choose a reason for hiding this comment

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

Why are we removing shutdown processing here? Some race? We rely on VM terminating / channel closing?

if (Message == nullptr)
{
break;
}
Expand Down
40 changes: 0 additions & 40 deletions src/shared/inc/lxinitshared.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ typedef enum _LX_MESSAGE_TYPE
LxMessageWSLAWaitPid,
LxMessageWSLAWaitPidResponse,
LxMessageWSLASignal,
LxMessageWSLAShutdown,
LxMessageWSLARelayTty,
LxMessageWSLAMapPort,
LxMessageWSLAConnectRelay,
Expand Down Expand Up @@ -502,7 +501,6 @@ inline auto ToString(LX_MESSAGE_TYPE messageType)
X(LxMessageWSLAWaitPid)
X(LxMessageWSLAWaitPidResponse)
X(LxMessageWSLASignal)
X(LxMessageWSLAShutdown)
X(LxMessageWSLARelayTty)
X(LxMessageWSLAMapPort)
X(LxMessageWSLAConnectRelay)
Expand Down Expand Up @@ -1734,33 +1732,6 @@ enum WSLAOpenFlags
WSLAOpenFlagsSignaled
};

struct WSLA_WAITPID_RESULT
{
static inline auto Type = LxMessageWSLAWaitPidResponse;

DECLARE_MESSAGE_CTOR(WSLA_WAITPID_RESULT);

MESSAGE_HEADER Header;
WSLAOpenFlags State = WSLAOpenFlagsUnknown;
int32_t Code = -1;
int32_t Errno = -1;
PRETTY_PRINT(FIELD(Header), FIELD(State), FIELD(Code), FIELD(Errno));
};

struct WSLA_WAITPID
{
static inline auto Type = LxMessageWSLAWaitPid;
using TResponse = WSLA_WAITPID_RESULT;

DECLARE_MESSAGE_CTOR(WSLA_WAITPID);

MESSAGE_HEADER Header;
int32_t Pid = -1;
uint64_t TimeoutMs = 0;

PRETTY_PRINT(FIELD(Header), FIELD(Pid), FIELD(TimeoutMs));
};

struct WSLA_SIGNAL
{
static inline auto Type = LxMessageWSLASignal;
Expand All @@ -1775,17 +1746,6 @@ struct WSLA_SIGNAL
PRETTY_PRINT(FIELD(Header), FIELD(Pid), FIELD(Signal));
};

struct WSLA_SHUTDOWN
{
static inline auto Type = LxMessageWSLAShutdown;
using TResponse = RESULT_MESSAGE<int32_t>;

DECLARE_MESSAGE_CTOR(WSLA_SHUTDOWN);
MESSAGE_HEADER Header;

PRETTY_PRINT(FIELD(Header));
};

struct WSLA_MAP_PORT
{
static inline auto Type = LxMessageWSLAMapPort;
Expand Down
4 changes: 1 addition & 3 deletions src/windows/common/WslClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,6 @@ int WslaShell(_In_ std::wstring_view commandLine)
THROW_IF_FAILED(CoCreateInstance(__uuidof(WSLAUserSession), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&userSession)));
wsl::windows::common::security::ConfigureForCOMImpersonation(userSession.get());

wil::com_ptr<IWSLAVirtualMachine> virtualMachine;
wil::com_ptr<IWSLASession> session;

if (!rootVhdOverride.empty())
Expand All @@ -1623,8 +1622,7 @@ int WslaShell(_In_ std::wstring_view commandLine)
}
else
{
THROW_IF_FAILED(userSession->CreateSession(&sessionSettings, &session));
THROW_IF_FAILED(session->GetVirtualMachine(&virtualMachine));
THROW_IF_FAILED(userSession->CreateSession(&sessionSettings, WSLASessionFlagsNone, &session));

wsl::windows::common::security::ConfigureForCOMImpersonation(userSession.get());
}
Expand Down
24 changes: 11 additions & 13 deletions src/windows/wslaservice/exe/WSLAContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ auto ProcessPortMappings(const WSLA_CONTAINER_OPTIONS& options, WSLAVirtualMachi
{
if (e.MappedToHost)
{
LOG_IF_FAILED_MSG(
vm.MapPort(e.Family, e.HostPort, e.VmPort, true),
"Failed to unmap port (family=%i, guestPort=%u, hostPort=%u)",
e.Family,
e.VmPort,
e.HostPort);
try
{
vm.MapPort(e.Family, e.HostPort, e.VmPort, true);

Choose a reason for hiding this comment

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

nit: for readability, it would be nice at some point to have either an UnmapPort() or use enum/const to make last parameter more intuitive

}
CATCH_LOG();
}
}
});
Expand Down Expand Up @@ -116,7 +115,7 @@ auto ProcessPortMappings(const WSLA_CONTAINER_OPTIONS& options, WSLAVirtualMachi
// Map Windows <-> VM ports.
for (auto& e : *mappedPorts)
{
THROW_IF_FAILED(vm.MapPort(e.Family, e.HostPort, e.VmPort, false));
vm.MapPort(e.Family, e.HostPort, e.VmPort, false);
e.MappedToHost = true;
}

Expand Down Expand Up @@ -201,12 +200,11 @@ WSLAContainerImpl::~WSLAContainerImpl()
{
WI_ASSERT(e.MappedToHost);

LOG_IF_FAILED_MSG(
m_parentVM->MapPort(e.Family, e.HostPort, e.VmPort, true),
"Failed to delete port mapping (family=%i, guestPort=%u, hostPort=%u)",
e.Family,
e.VmPort,
e.HostPort);
try
{
m_parentVM->MapPort(e.Family, e.HostPort, e.VmPort, true);
}
CATCH_LOG();

allocatedGuestPorts.insert(e.VmPort);
}
Expand Down
2 changes: 1 addition & 1 deletion src/windows/wslaservice/exe/WSLAProcessControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void VMProcessControl::Signal(int Signal)
std::lock_guard lock{m_lock};
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), m_vm == nullptr || m_exitEvent.is_signaled());

THROW_IF_FAILED(m_vm->Signal(m_pid, Signal));
m_vm->Signal(m_pid, Signal);
}

void VMProcessControl::ResizeTty(ULONG Rows, ULONG Columns)
Expand Down
Loading