From b878f2517cb4ae7cf52ed83e54204dc69d559d4d Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Thu, 10 Jun 2021 10:24:18 +0200 Subject: [PATCH] early-access version 1775 --- README.md | 2 +- src/common/host_memory.cpp | 49 +++++++++++++++++++++++----------- src/common/host_memory.h | 4 +-- src/core/hle/service/service.h | 5 +--- 4 files changed, 37 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index 7706c7b4e..4722a24dd 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1774. +This is the source code for early-access 1775. ## Legal Notice diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp index 0f8fe3a3d..7a6462737 100755 --- a/src/common/host_memory.cpp +++ b/src/common/host_memory.cpp @@ -1,17 +1,21 @@ -#ifdef __linux__ +#ifdef _WIN32 + +#include +#include +#include +#include +#include "common/dynamic_library.h" + +#elif defined(__linux__) // ^^^ Windows ^^^ vvv Linux vvv + #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include -#elif defined(_WIN32) // ^^^ Linux ^^^ vvv Windows vvv -#include -#include -#include -#include -#include "common/dynamic_library.h" -#endif // ^^^ Windows ^^^ + +#endif // ^^^ Linux ^^^ #include @@ -19,6 +23,7 @@ #include "common/assert.h" #include "common/host_memory.h" #include "common/logging/log.h" +#include "common/scope_exit.h" namespace Common { @@ -34,6 +39,12 @@ constexpr size_t HugePageSize = 0x200000; #ifndef MEM_REPLACE_PLACEHOLDER #define MEM_REPLACE_PLACEHOLDER 0x00004000 #endif +#ifndef MEM_COALESCE_PLACEHOLDERS +#define MEM_COALESCE_PLACEHOLDERS 0x00000001 +#endif +#ifndef MEM_PRESERVE_PLACEHOLDER +#define MEM_PRESERVE_PLACEHOLDER 0x00000002 +#endif using PFN_CreateFileMapping2 = _Ret_maybenull_ HANDLE(WINAPI*)( _In_ HANDLE File, _In_opt_ SECURITY_ATTRIBUTES* SecurityAttributes, _In_ ULONG DesiredAccess, @@ -333,18 +344,23 @@ private: std::unordered_map placeholder_host_pointers; ///< Placeholder backing offset }; -#elif defined(__linux__) +#elif defined(__linux__) // ^^^ Windows ^^^ vvv Linux vvv class HostMemory::Impl { public: explicit Impl(size_t backing_size_, size_t virtual_size_) : backing_size{backing_size_}, virtual_size{virtual_size_} { + bool good = false; + SCOPE_EXIT({ + if (!good) { + Release(); + } + }); // Backing memory initialization fd = memfd_create("HostMemory", 0); if (fd == -1) { LOG_CRITICAL(HW_Memory, "memfd_create failed: {}", strerror(errno)); - Release(); throw std::bad_alloc{}; } @@ -353,7 +369,6 @@ public: if (ret != 0) { LOG_CRITICAL(HW_Memory, "ftruncate failed with {}, are you out-of-memory?", strerror(errno)); - Release(); throw std::bad_alloc{}; } @@ -361,7 +376,6 @@ public: mmap(nullptr, backing_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)); if (backing_base == MAP_FAILED) { LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno)); - Release(); throw std::bad_alloc{}; } @@ -370,9 +384,10 @@ public: mmap(nullptr, virtual_size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0)); if (virtual_base == MAP_FAILED) { LOG_CRITICAL(HW_Memory, "mmap failed: {}", strerror(errno)); - Release(); throw std::bad_alloc{}; } + + good = true; } ~Impl() { @@ -397,10 +412,12 @@ public: void Protect(size_t virtual_offset, size_t length, bool read, bool write) { int flags = 0; - if (read) + if (read) { flags |= PROT_READ; - if (write) + } + if (write) { flags |= PROT_WRITE; + } int ret = mprotect(virtual_base + virtual_offset, length, flags); ASSERT_MSG(ret == 0, "mprotect failed: {}", strerror(errno)); } @@ -433,7 +450,7 @@ private: int fd{-1}; // memfd file descriptor, -1 is the error value of memfd_create }; -#else +#else // ^^^ Linux ^^^ #error Please implement the host memory for your platform diff --git a/src/common/host_memory.h b/src/common/host_memory.h index cebc36f6e..eaa7d18ab 100755 --- a/src/common/host_memory.h +++ b/src/common/host_memory.h @@ -22,8 +22,8 @@ public: * Copy constructors. They shall return a copy of the buffer without the mappings. * TODO: Implement them with COW if needed. */ - HostMemory(HostMemory& other) = delete; - HostMemory& operator=(HostMemory& other) = delete; + HostMemory(const HostMemory& other) = delete; + HostMemory& operator=(const HostMemory& other) = delete; /** * Move constructors. They will move the buffer and the mappings to the new object. diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index e078ac176..6c5bf3a95 100755 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h @@ -41,10 +41,7 @@ class ServiceManager; } /// Default number of maximum connections to a server session. -static constexpr u32 ServerSessionCountMax = 0x40; -static_assert(ServerSessionCountMax == 0x40, - "ServerSessionCountMax isn't 0x40 somehow, this assert is a reminder that this will " - "break lots of things"); +static constexpr u32 ServerSessionCountMax = 0x10000; /** * This is an non-templated base of ServiceFramework to reduce code bloat and compilation times, it