net: report open file and device descriptors ready in select (Cyberpunk 2077 Galaxy RNG seeding)

Co-authored-by: Artyom Zabroda <artyomzabroda@proton.me>
This commit is contained in:
nmzik
2026-10-22 17:02:46 +02:00
parent f5f4e7d48a
commit a875d1b205
4 changed files with 40 additions and 1 deletions
+20
View File
@@ -30,6 +30,7 @@
#include "common/emulatorConfig.h"
#include "common/logging/log.h"
#include "common/threads.h"
#include "kernel/fileSystem.h"
#include "kernel/pthread.h"
#include "libs/errno.h"
#include "libs/libs.h"
@@ -2577,6 +2578,7 @@ int KYTY_SYSV_ABI Select(int nfds, void* readfds, void* writefds, void* exceptfd
std::vector<std::pair<int, NativeSocket>> descriptors;
std::vector<std::shared_ptr<SocketTransport>> stream_reads;
std::vector<std::pair<void*, int>> ready_files;
int host_nfds = 0;
for (int fd = 0; fd < nfds; fd++) {
const bool read = GuestFdIsSet(readfds, fd);
@@ -2585,6 +2587,16 @@ int KYTY_SYSV_ABI Select(int nfds, void* readfds, void* writefds, void* exceptfd
if (!read && !write && !except) {
continue;
}
// FreeBSD polls files and devices ready to read and write at once.
if (!IsSocket(fd) && LibKernel::FileSystem::IsOpenDescriptor(fd)) {
if (read) {
ready_files.emplace_back(readfds, fd);
}
if (write) {
ready_files.emplace_back(writefds, fd);
}
continue;
}
NativeSocket socket = INVALID_NATIVE_SOCKET;
std::shared_ptr<SocketTransport> transport;
#if !defined(_WIN32)
@@ -2636,6 +2648,10 @@ int KYTY_SYSV_ABI Select(int nfds, void* readfds, void* writefds, void* exceptfd
host_timeout.tv_usec = static_cast<decltype(host_timeout.tv_usec)>(guest_timeout->tv_usec);
host_timeout_ptr = &host_timeout;
}
if (!ready_files.empty()) {
host_timeout = {};
host_timeout_ptr = &host_timeout;
}
int result = 0;
#if defined(_WIN32)
@@ -2672,6 +2688,10 @@ int KYTY_SYSV_ABI Select(int nfds, void* readfds, void* writefds, void* exceptfd
result++;
}
}
for (const auto& [fds, fd]: ready_files) {
GuestFdSet(fds, fd);
result++;
}
return result;
}