diff --git a/Utilities/VirtualMemory.cpp b/Utilities/VirtualMemory.cpp index 7eb31d2749..dfda9152e7 100644 --- a/Utilities/VirtualMemory.cpp +++ b/Utilities/VirtualMemory.cpp @@ -12,6 +12,14 @@ #include #endif +#if 0 +#include +static int memfd_create(const char *name, unsigned int flags) +{ + return syscall(__NR_memfd_create, name, flags); +} +#endif + namespace utils { // Convert memory protection (internal) @@ -115,21 +123,27 @@ namespace utils { #ifdef _WIN32 m_handle = ::CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, m_size, NULL); + verify(HERE), m_handle != INVALID_HANDLE_VALUE; //#elif __linux__ -// m_file = ::memfd_create("mem1", 0); -// ::ftruncate(m_file, m_size); +// m_file = ::memfd_create("", 0); +// verify(HERE), m_file >= 0; +// verify(HERE), ::ftruncate(m_file, m_size) >= 0; #else while ((m_file = ::shm_open("/rpcs3-mem1", O_RDWR | O_CREAT | O_EXCL, S_IWUSR | S_IRUSR)) == -1) { - if (errno != EEXIST) - return; + if (m_file == -1 && errno == EMFILE) + { + fmt::throw_exception("Too many open files. Raise the limit and try again."); + } + + verify(HERE), errno == EEXIST; } - ::shm_unlink("/rpcs3-mem1"); - ::ftruncate(m_file, m_size); + verify(HERE), ::shm_unlink("/rpcs3-mem1") >= 0; + verify(HERE), ::ftruncate(m_file, m_size) >= 0; #endif - m_ptr = this->map(nullptr); + m_ptr = verify(HERE, this->map(nullptr)); } shm::~shm() diff --git a/rpcs3/main.cpp b/rpcs3/main.cpp index 509b814760..3e326306e2 100644 --- a/rpcs3/main.cpp +++ b/rpcs3/main.cpp @@ -13,6 +13,11 @@ #include #endif +#ifdef __linux__ +#include +#include +#endif + inline std::string sstr(const QString& _in) { return _in.toStdString(); } template @@ -85,6 +90,14 @@ int main(int argc, char** argv) qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1"); #endif +#ifdef __linux__ + struct ::rlimit rlim; + rlim.rlim_cur = 4096; + rlim.rlim_max = 4096; + if (::setrlimit(RLIMIT_NOFILE, &rlim) != 0) + std::fprintf(stderr, "Failed to set max open file limit (4096)."); +#endif + QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps); QCoreApplication::setAttribute(Qt::AA_DisableWindowContextHelpButton);