From 041ec932594de31ca2532800f8cb6f92475bbf69 Mon Sep 17 00:00:00 2001 From: Daman Mulye Date: Wed, 7 Oct 2026 16:37:15 -0700 Subject: [PATCH] feedback --- src/windows/service/exe/WslCoreVm.cpp | 20 ++++++++++++++++--- .../windows/HcsVirtualMachineBackendTests.cpp | 20 ++++++++----------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/windows/service/exe/WslCoreVm.cpp b/src/windows/service/exe/WslCoreVm.cpp index f4030d32..08e0cc5f 100644 --- a/src/windows/service/exe/WslCoreVm.cpp +++ b/src/windows/service/exe/WslCoreVm.cpp @@ -378,9 +378,23 @@ void WslCoreVm::Initialize(const GUID& VmId, const wil::shared_handle& UserToken } catch (...) { - // Reset the backend so the destructor does not attempt a graceful guest shutdown for a VM - // that never reached the running state. - m_backend.reset(); + const auto hr = wil::ResultFromCaughtException(); + auto resetBackend = wil::scope_exit([&] { m_backend.reset(); }); + if ((hr == HRESULT_FROM_WIN32(WSAENOTCONN) || hr == HRESULT_FROM_WIN32(WSAECONNRESET) || hr == HRESULT_FROM_WIN32(WSAETIMEDOUT)) && + m_vmCrashEvent.wait(1000)) + { + const auto crashLogPath = m_backend->GetCrashLogPath(); + if (crashLogPath) + { + THROW_HR_WITH_USER_ERROR( + WSL_E_VM_CRASHED, + wsl::shared::Localization::MessageWSL2Crashed() + L"\r\n" + + Localization::MessageWSL2CrashedStackTrace(crashLogPath.value())); + } + + THROW_HR_WITH_USER_ERROR(WSL_E_VM_CRASHED, wsl::shared::Localization::MessageWSL2Crashed()); + } + throw; } diff --git a/test/windows/HcsVirtualMachineBackendTests.cpp b/test/windows/HcsVirtualMachineBackendTests.cpp index b4445c6a..275efbfa 100644 --- a/test/windows/HcsVirtualMachineBackendTests.cpp +++ b/test/windows/HcsVirtualMachineBackendTests.cpp @@ -39,7 +39,7 @@ void CreateVhd(const std::filesystem::path& Path) &storageType, Path.c_str(), VIRTUAL_DISK_ACCESS_NONE, nullptr, CREATE_VIRTUAL_DISK_FLAG_SUPPORT_COMPRESSED_VOLUMES, 0, ¶meters, nullptr, &vhd)); } -std::wstring GetDacl(const std::filesystem::path& Path) +std::wstring GetDaclAces(const std::filesystem::path& Path) { PACL acl = nullptr; wil::unique_hlocal descriptor; @@ -48,7 +48,9 @@ std::wstring GetDacl(const std::filesystem::path& Path) wil::unique_hlocal_string value; THROW_IF_WIN32_BOOL_FALSE(ConvertSecurityDescriptorToStringSecurityDescriptorW( descriptor.get(), SDDL_REVISION_1, DACL_SECURITY_INFORMATION, &value, nullptr)); - return value.get(); + const std::wstring dacl{value.get()}; + const auto firstAce = dacl.find(L'('); + return firstAce == std::wstring::npos ? std::wstring{} : dacl.substr(firstAce); } // Tests require elevation, so the test process token is the elevated counterpart of @@ -235,14 +237,9 @@ class HcsVirtualMachineBackendTests const auto directory = CreateTestDirectory(); auto cleanup = wil::scope_exit_log(WI_DIAGNOSTICS_INFO, [&] { std::filesystem::remove_all(directory); }); const auto firstPath = directory / L"first.vhdx"; - const auto invalidPath = directory / L"invalid.vhdx"; CreateVhd(firstPath); - wil::unique_hfile invalidFile{CreateFileW(invalidPath.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_NEW, FILE_ATTRIBUTE_NORMAL, nullptr)}; - THROW_LAST_ERROR_IF(!invalidFile); - invalidFile.reset(); - const auto firstDacl = GetDacl(firstPath); - const auto invalidDacl = GetDacl(invalidPath); + const auto firstDaclAces = GetDaclAces(firstPath); auto request = CreateRunnableRequest(); request.Identity.UserToken = wil::shared_handle{GetElevatedTestToken().release()}; VmBootDiskRequest first; @@ -250,14 +247,13 @@ class HcsVirtualMachineBackendTests first.Disk = CreateDiskRequest(firstPath); first.GrantHostAccess = true; VmBootDiskRequest invalid; - invalid.Key = L"invalid"; - invalid.Disk = CreateDiskRequest(invalidPath); + invalid.Key = L"first"; + invalid.Disk = CreateDiskRequest(firstPath); invalid.GrantHostAccess = true; request.BootDisks = {std::move(first), std::move(invalid)}; VERIFY_ARE_NOT_EQUAL(S_OK, OperationResult([&] { HcsVirtualMachineBackend::Create(request); })); - VERIFY_ARE_EQUAL(firstDacl, GetDacl(firstPath)); - VERIFY_ARE_EQUAL(invalidDacl, GetDacl(invalidPath)); + VERIFY_ARE_EQUAL(firstDaclAces, GetDaclAces(firstPath)); } TEST_METHOD(ManagesDiskPlacementsAndLifetime)