diff options
Diffstat (limited to 'src/common')
| -rw-r--r-- | src/common/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/common/bit_cast.h | 22 | ||||
| -rw-r--r-- | src/common/logging/backend.cpp | 15 | ||||
| -rw-r--r-- | src/common/logging/log.h | 1 | ||||
| -rw-r--r-- | src/common/page_table.cpp | 2 | ||||
| -rw-r--r-- | src/common/page_table.h | 14 | ||||
| -rw-r--r-- | src/common/virtual_buffer.cpp | 4 | ||||
| -rw-r--r-- | src/common/virtual_buffer.h | 36 | 
8 files changed, 80 insertions, 15 deletions
| diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 207c7a0a6..d20e6c3b5 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -102,6 +102,7 @@ add_library(common STATIC      atomic_ops.h      detached_tasks.cpp      detached_tasks.h +    bit_cast.h      bit_field.h      bit_util.h      cityhash.cpp diff --git a/src/common/bit_cast.h b/src/common/bit_cast.h new file mode 100644 index 000000000..a32a063d1 --- /dev/null +++ b/src/common/bit_cast.h @@ -0,0 +1,22 @@ +// Copyright 2020 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <cstring> +#include <type_traits> + +namespace Common { + +template <typename To, typename From> +[[nodiscard]] std::enable_if_t<sizeof(To) == sizeof(From) && std::is_trivially_copyable_v<From> && +                                   std::is_trivially_copyable_v<To>, +                               To> +BitCast(const From& src) noexcept { +    To dst; +    std::memcpy(&dst, &src, sizeof(To)); +    return dst; +} + +} // namespace Common diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 90dfa22ca..631f64d05 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -23,6 +23,7 @@  #include "common/logging/text_formatter.h"  #include "common/string_util.h"  #include "common/threadsafe_queue.h" +#include "core/settings.h"  namespace Log { @@ -152,10 +153,19 @@ FileBackend::FileBackend(const std::string& filename)  void FileBackend::Write(const Entry& entry) {      // prevent logs from going over the maximum size (in case its spamming and the user doesn't      // know) -    constexpr std::size_t MAX_BYTES_WRITTEN = 50 * 1024L * 1024L; -    if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { +    constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; +    constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; + +    if (!file.IsOpen()) { +        return; +    } + +    if (Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN_EXTENDED) { +        return; +    } else if (!Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN) {          return;      } +      bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n'));      if (entry.log_level >= Level::Error) {          file.Flush(); @@ -222,6 +232,7 @@ void DebuggerBackend::Write(const Entry& entry) {      SUB(Service, NPNS)                                                                             \      SUB(Service, NS)                                                                               \      SUB(Service, NVDRV)                                                                            \ +    SUB(Service, OLSC)                                                                             \      SUB(Service, PCIE)                                                                             \      SUB(Service, PCTL)                                                                             \      SUB(Service, PCV)                                                                              \ diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 13a4f1e30..835894918 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -95,6 +95,7 @@ enum class Class : ClassType {      Service_NPNS,      ///< The NPNS service      Service_NS,        ///< The NS services      Service_NVDRV,     ///< The NVDRV (Nvidia driver) service +    Service_OLSC,      ///< The OLSC service      Service_PCIE,      ///< The PCIe service      Service_PCTL,      ///< The PCTL (Parental control) service      Service_PCV,       ///< The PCV service diff --git a/src/common/page_table.cpp b/src/common/page_table.cpp index e5d3090d5..bccea0894 100644 --- a/src/common/page_table.cpp +++ b/src/common/page_table.cpp @@ -8,7 +8,7 @@ namespace Common {  PageTable::PageTable() = default; -PageTable::~PageTable() = default; +PageTable::~PageTable() noexcept = default;  void PageTable::Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,                         bool has_attribute) { diff --git a/src/common/page_table.h b/src/common/page_table.h index cf5eed780..9754fabf9 100644 --- a/src/common/page_table.h +++ b/src/common/page_table.h @@ -4,9 +4,7 @@  #pragma once -#include <vector> - -#include <boost/icl/interval_map.hpp> +#include <tuple>  #include "common/common_types.h"  #include "common/memory_hook.h" @@ -51,13 +49,21 @@ struct SpecialRegion {   */  struct PageTable {      PageTable(); -    ~PageTable(); +    ~PageTable() noexcept; + +    PageTable(const PageTable&) = delete; +    PageTable& operator=(const PageTable&) = delete; + +    PageTable(PageTable&&) noexcept = default; +    PageTable& operator=(PageTable&&) noexcept = default;      /**       * Resizes the page table to be able to accomodate enough pages within       * a given address space.       *       * @param address_space_width_in_bits The address size width in bits. +     * @param page_size_in_bits           The page size in bits. +     * @param has_attribute               Whether or not this page has any backing attributes.       */      void Resize(std::size_t address_space_width_in_bits, std::size_t page_size_in_bits,                  bool has_attribute); diff --git a/src/common/virtual_buffer.cpp b/src/common/virtual_buffer.cpp index b009cb500..e3ca29258 100644 --- a/src/common/virtual_buffer.cpp +++ b/src/common/virtual_buffer.cpp @@ -13,7 +13,7 @@  namespace Common { -void* AllocateMemoryPages(std::size_t size) { +void* AllocateMemoryPages(std::size_t size) noexcept {  #ifdef _WIN32      void* base{VirtualAlloc(nullptr, size, MEM_COMMIT, PAGE_READWRITE)};  #else @@ -29,7 +29,7 @@ void* AllocateMemoryPages(std::size_t size) {      return base;  } -void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) { +void FreeMemoryPages(void* base, [[maybe_unused]] std::size_t size) noexcept {      if (!base) {          return;      } diff --git a/src/common/virtual_buffer.h b/src/common/virtual_buffer.h index 125cb42f0..91d430036 100644 --- a/src/common/virtual_buffer.h +++ b/src/common/virtual_buffer.h @@ -4,29 +4,53 @@  #pragma once -#include "common/common_funcs.h" +#include <type_traits> +#include <utility>  namespace Common { -void* AllocateMemoryPages(std::size_t size); -void FreeMemoryPages(void* base, std::size_t size); +void* AllocateMemoryPages(std::size_t size) noexcept; +void FreeMemoryPages(void* base, std::size_t size) noexcept;  template <typename T> -class VirtualBuffer final : NonCopyable { +class VirtualBuffer final {  public: +    static_assert( +        std::is_trivially_constructible_v<T>, +        "T must be trivially constructible, as non-trivial constructors will not be executed " +        "with the current allocator"); +      constexpr VirtualBuffer() = default;      explicit VirtualBuffer(std::size_t count) : alloc_size{count * sizeof(T)} {          base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));      } -    ~VirtualBuffer() { +    ~VirtualBuffer() noexcept {          FreeMemoryPages(base_ptr, alloc_size);      } +    VirtualBuffer(const VirtualBuffer&) = delete; +    VirtualBuffer& operator=(const VirtualBuffer&) = delete; + +    VirtualBuffer(VirtualBuffer&& other) noexcept +        : alloc_size{std::exchange(other.alloc_size, 0)}, base_ptr{std::exchange(other.base_ptr), +                                                                   nullptr} {} + +    VirtualBuffer& operator=(VirtualBuffer&& other) noexcept { +        alloc_size = std::exchange(other.alloc_size, 0); +        base_ptr = std::exchange(other.base_ptr, nullptr); +        return *this; +    } +      void resize(std::size_t count) { +        const auto new_size = count * sizeof(T); +        if (new_size == alloc_size) { +            return; +        } +          FreeMemoryPages(base_ptr, alloc_size); -        alloc_size = count * sizeof(T); +        alloc_size = new_size;          base_ptr = reinterpret_cast<T*>(AllocateMemoryPages(alloc_size));      } | 
