mirror of
https://github.com/aphrody-labs/WSL.git
synced 2026-10-14 05:39:06 +00:00
feedback
This commit is contained in:
1 parent
5c611949be
commit
041ec93259
2 files changed
+25
-15
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in new issue
Block a user