Windows: full module parity and runtime-qualified test suite

- Net/IO: Winsock sockets (UdpSocket, TlsClientStream, WebSocketClient),
  HttpServer port with a loopback wake socket replacing eventfd, and the
  select-based IO backend built on Windows (ws2_32).
- Net: implement StaticFileResolver::open_safe and OpenedStaticFile on
  Windows (reparse-point rejection plus canonical containment check on the
  opened handle) and widen native handles to intptr_t.
- Plugin: hot reload works on Windows by loading a fresh copy while the old
  DLL stays mapped; enable the reload, discovery and FSM service reload
  tests and retire the plugin file by rename instead of replacement.
- Update: activation pointer as a directory junction on Windows.
- Stacktrace: portable path comparison for wide native strings.
- Docs/targets: every module allowlisted on Windows; record the Wine run
  (2000 tests, 1977 passed, 23 skipped, 0 failed).
- CMake: add -Wa,-mbig-obj for GNU MinGW targets (COFF section limit).
- Async: fix the FuturePool stopped-after-close test to wait for the
  executor to release its admission slot instead of racing it.

Windows and Linux suites both pass: Windows 2000/1977/23 skips/0 failed,
Linux 2027/2023/4 skips/0 failed.
This commit is contained in:
faumaray committed 2026-12-06 14:56:26 +03:00
1 parent 1b1947340f
commit b3c959b920
32 files changed
+1836 -401

No files matched your search

+165 -11
View File
@@ -26,10 +26,38 @@
#include <unistd.h>
#endif
#ifdef _WIN32
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>
#include <winioctl.h>
#include <cstring>
#include <vector>
#endif
namespace Void::Update
{
namespace
{
#ifdef _WIN32
// MinGW's headers do not declare REPARSE_DATA_BUFFER; only the mount
// point layout is needed here.
struct MountPointReparseBuffer {
ULONG ReparseTag;
USHORT ReparseDataLength;
USHORT Reserved;
USHORT SubstituteNameOffset;
USHORT SubstituteNameLength;
USHORT PrintNameOffset;
USHORT PrintNameLength;
WCHAR PathBuffer[1];
};
#endif
[[nodiscard]] Void::Result::Error
filesystem_error(std::string_view operation,
const std::filesystem::path& path,
@@ -97,6 +125,124 @@ namespace Void::Update
}
return data;
}
// The activation pointer is a directory junction: unlike a symbolic
// link it needs no SeCreateSymbolicLinkPrivilege (Developer Mode or an
// elevated process), so it works on a stock Windows installation.
[[nodiscard]] Void::Result::Result<void>
create_activation_junction(const std::filesystem::path& path,
const std::filesystem::path& target)
{
std::error_code error;
std::filesystem::remove(path, error);
if (!::CreateDirectoryW(path.c_str(), nullptr)) {
return Void::Result::fail(std::format(
"VersionStore: create junction directory '{}': {}",
path.string(), std::system_category().message(
static_cast<int>(::GetLastError()))));
}
const HANDLE handle = ::CreateFileW(
path.c_str(), GENERIC_WRITE, 0, nullptr, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
nullptr);
if (handle == INVALID_HANDLE_VALUE) {
return Void::Result::fail(std::format(
"VersionStore: open junction '{}': {}", path.string(),
std::system_category().message(
static_cast<int>(::GetLastError()))));
}
const auto absolute = std::filesystem::absolute(target).native();
const std::wstring substitute = L"\\??\\" + absolute;
const std::size_t substitute_bytes = substitute.size() * sizeof(wchar_t);
const std::size_t print_bytes = absolute.size() * sizeof(wchar_t);
const std::size_t data_size = 8 + substitute_bytes + 2 +
print_bytes + 2;
std::vector<std::byte> buffer(
offsetof(MountPointReparseBuffer, PathBuffer) + data_size);
auto* reparse =
reinterpret_cast<MountPointReparseBuffer*>(buffer.data());
reparse->ReparseTag = IO_REPARSE_TAG_MOUNT_POINT;
reparse->ReparseDataLength =
static_cast<USHORT>(data_size);
reparse->Reserved = 0;
reparse->SubstituteNameOffset = 0;
reparse->SubstituteNameLength =
static_cast<USHORT>(substitute_bytes);
reparse->PrintNameOffset =
static_cast<USHORT>(substitute_bytes + sizeof(wchar_t));
reparse->PrintNameLength =
static_cast<USHORT>(print_bytes);
std::memcpy(
reparse->PathBuffer, substitute.data(),
substitute_bytes);
reparse->PathBuffer[substitute.size()] = L'\0';
std::memcpy(reparse->PathBuffer +
substitute.size() + 1,
absolute.data(), print_bytes);
reparse->PathBuffer[substitute.size() + 1 + absolute.size()] = L'\0';
DWORD returned = 0;
const BOOL ok = ::DeviceIoControl(
handle, FSCTL_SET_REPARSE_POINT, buffer.data(),
static_cast<DWORD>(buffer.size()), nullptr, 0, &returned,
nullptr);
const int code = ok ? 0 : static_cast<int>(::GetLastError());
(void)::CloseHandle(handle);
if (!ok) {
return Void::Result::fail(std::format(
"VersionStore: set junction '{}': {}", path.string(),
std::system_category().message(code)));
}
return {};
}
[[nodiscard]] Void::Result::Result<std::filesystem::path>
read_activation_junction(const std::filesystem::path& path)
{
const HANDLE handle = ::CreateFileW(
path.c_str(), 0,
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
nullptr, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT,
nullptr);
if (handle == INVALID_HANDLE_VALUE) {
return Void::Result::fail(std::format(
"VersionStore: open pointer '{}': {}", path.string(),
std::system_category().message(
static_cast<int>(::GetLastError()))));
}
std::vector<std::byte> buffer(MAXIMUM_REPARSE_DATA_BUFFER_SIZE);
DWORD returned = 0;
const BOOL ok = ::DeviceIoControl(
handle, FSCTL_GET_REPARSE_POINT, nullptr, 0, buffer.data(),
static_cast<DWORD>(buffer.size()), &returned, nullptr);
const int code = ok ? 0 : static_cast<int>(::GetLastError());
(void)::CloseHandle(handle);
if (!ok) {
return Void::Result::fail(std::format(
"VersionStore: read pointer '{}': {}", path.string(),
std::system_category().message(code)));
}
auto* reparse =
reinterpret_cast<MountPointReparseBuffer*>(buffer.data());
if (reparse->ReparseTag != IO_REPARSE_TAG_MOUNT_POINT) {
return Void::Result::fail(std::format(
"VersionStore: pointer '{}' is not a junction",
path.string()));
}
const std::size_t offset =
reparse->SubstituteNameOffset /
sizeof(wchar_t);
const std::size_t length =
reparse->SubstituteNameLength /
sizeof(wchar_t);
std::wstring target(
reparse->PathBuffer + offset, length);
constexpr std::wstring_view prefix = L"\\??\\";
if (target.starts_with(prefix)) {
target.erase(0, prefix.size());
}
return std::filesystem::path{target};
}
#endif
#ifndef _WIN32
@@ -640,15 +786,7 @@ namespace Void::Update
atomic_link(const std::filesystem::path& path,
const std::filesystem::path& target)
{
std::error_code error;
std::filesystem::remove(path, error);
error.clear();
std::filesystem::create_directory_symlink(target, path, error);
if (error) {
return std::unexpected{
filesystem_error("create symlink", path, error)};
}
return {};
return create_activation_junction(path, target);
}
[[nodiscard]]
@@ -1843,22 +1981,38 @@ namespace Void::Update
VersionStore::currentVersion() const
{
std::error_code error;
std::filesystem::path target;
const auto status =
std::filesystem::symlink_status(m_root / "current", error);
if (error == std::errc::no_such_file_or_directory ||
status.type() == std::filesystem::file_type::not_found) {
return std::optional<Semver::Version>{};
}
#ifdef _WIN32
// The activation pointer is a junction on Windows, which the filesystem
// reports as a directory; resolve it to its target.
if (error || !std::filesystem::is_directory(status)) {
return Void::Result::fail(
"VersionStore: current is not a valid pointer");
}
auto resolved = read_activation_junction(m_root / "current");
if (!resolved) {
return std::unexpected{resolved.error()};
}
// Normalize to the relative form the shared checks below expect; the
// published-directory check verifies it under this store.
target = std::filesystem::path{"versions"} / resolved->filename();
#else
if (error || !std::filesystem::is_symlink(status)) {
return Void::Result::fail(
"VersionStore: current is not a valid symlink");
}
const auto target =
std::filesystem::read_symlink(m_root / "current", error);
target = std::filesystem::read_symlink(m_root / "current", error);
if (error || target.parent_path() != "versions") {
return Void::Result::fail(
"VersionStore: current symlink target is invalid");
}
#endif
auto version = Semver::parse_strict(target.filename().string());
if (!version) {
return Void::Result::fail(