diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/common/logging/backend.cpp | 25 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 7 | ||||
| -rw-r--r-- | src/common/logging/filter.cpp | 75 | ||||
| -rw-r--r-- | src/common/logging/filter.h | 6 | ||||
| -rw-r--r-- | src/common/param_package.cpp | 19 | ||||
| -rw-r--r-- | src/common/param_package.h | 2 | ||||
| -rw-r--r-- | src/core/arm/arm_interface.h | 4 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.cpp | 8 | ||||
| -rw-r--r-- | src/core/arm/dynarmic/arm_dynarmic.h | 2 | ||||
| -rw-r--r-- | src/core/arm/unicorn/arm_unicorn.cpp | 10 | ||||
| -rw-r--r-- | src/core/arm/unicorn/arm_unicorn.h | 2 | ||||
| -rw-r--r-- | src/core/file_sys/vfs.cpp | 2 | ||||
| -rw-r--r-- | src/core/file_sys/vfs.h | 27 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_offset.cpp | 5 | ||||
| -rw-r--r-- | src/core/file_sys/vfs_offset.h | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/scheduler.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 9 | ||||
| -rw-r--r-- | src/core/loader/deconstructed_rom_directory.cpp | 7 |
19 files changed, 124 insertions, 92 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ed1e93cc2..59b999935 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -3,19 +3,20 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <atomic> |
| 7 | #include <chrono> | 7 | #include <chrono> |
| 8 | #include <climits> | 8 | #include <climits> |
| 9 | #include <condition_variable> | 9 | #include <condition_variable> |
| 10 | #include <memory> | 10 | #include <memory> |
| 11 | #include <mutex> | ||
| 11 | #include <thread> | 12 | #include <thread> |
| 13 | #include <vector> | ||
| 12 | #ifdef _WIN32 | 14 | #ifdef _WIN32 |
| 13 | #include <share.h> // For _SH_DENYWR | 15 | #include <share.h> // For _SH_DENYWR |
| 14 | #else | 16 | #else |
| 15 | #define _SH_DENYWR 0 | 17 | #define _SH_DENYWR 0 |
| 16 | #endif | 18 | #endif |
| 17 | #include "common/assert.h" | 19 | #include "common/assert.h" |
| 18 | #include "common/common_funcs.h" // snprintf compatibility define | ||
| 19 | #include "common/logging/backend.h" | 20 | #include "common/logging/backend.h" |
| 20 | #include "common/logging/log.h" | 21 | #include "common/logging/log.h" |
| 21 | #include "common/logging/text_formatter.h" | 22 | #include "common/logging/text_formatter.h" |
| @@ -48,11 +49,11 @@ public: | |||
| 48 | backends.push_back(std::move(backend)); | 49 | backends.push_back(std::move(backend)); |
| 49 | } | 50 | } |
| 50 | 51 | ||
| 51 | void RemoveBackend(const std::string& backend_name) { | 52 | void RemoveBackend(std::string_view backend_name) { |
| 52 | std::lock_guard<std::mutex> lock(writing_mutex); | 53 | std::lock_guard<std::mutex> lock(writing_mutex); |
| 53 | auto it = std::remove_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { | 54 | const auto it = |
| 54 | return !strcmp(i->GetName(), backend_name.c_str()); | 55 | std::remove_if(backends.begin(), backends.end(), |
| 55 | }); | 56 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); |
| 56 | backends.erase(it, backends.end()); | 57 | backends.erase(it, backends.end()); |
| 57 | } | 58 | } |
| 58 | 59 | ||
| @@ -64,10 +65,10 @@ public: | |||
| 64 | filter = f; | 65 | filter = f; |
| 65 | } | 66 | } |
| 66 | 67 | ||
| 67 | Backend* GetBackend(const std::string& backend_name) { | 68 | Backend* GetBackend(std::string_view backend_name) { |
| 68 | auto it = std::find_if(backends.begin(), backends.end(), [&backend_name](const auto& i) { | 69 | const auto it = |
| 69 | return !strcmp(i->GetName(), backend_name.c_str()); | 70 | std::find_if(backends.begin(), backends.end(), |
| 70 | }); | 71 | [&backend_name](const auto& i) { return backend_name == i->GetName(); }); |
| 71 | if (it == backends.end()) | 72 | if (it == backends.end()) |
| 72 | return nullptr; | 73 | return nullptr; |
| 73 | return it->get(); | 74 | return it->get(); |
| @@ -265,11 +266,11 @@ void AddBackend(std::unique_ptr<Backend> backend) { | |||
| 265 | Impl::Instance().AddBackend(std::move(backend)); | 266 | Impl::Instance().AddBackend(std::move(backend)); |
| 266 | } | 267 | } |
| 267 | 268 | ||
| 268 | void RemoveBackend(const std::string& backend_name) { | 269 | void RemoveBackend(std::string_view backend_name) { |
| 269 | Impl::Instance().RemoveBackend(backend_name); | 270 | Impl::Instance().RemoveBackend(backend_name); |
| 270 | } | 271 | } |
| 271 | 272 | ||
| 272 | Backend* GetBackend(const std::string& backend_name) { | 273 | Backend* GetBackend(std::string_view backend_name) { |
| 273 | return Impl::Instance().GetBackend(backend_name); | 274 | return Impl::Instance().GetBackend(backend_name); |
| 274 | } | 275 | } |
| 275 | 276 | ||
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 57cdf6b2d..b3f4b9cef 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -4,10 +4,9 @@ | |||
| 4 | #pragma once | 4 | #pragma once |
| 5 | 5 | ||
| 6 | #include <chrono> | 6 | #include <chrono> |
| 7 | #include <cstdarg> | ||
| 8 | #include <memory> | 7 | #include <memory> |
| 9 | #include <string> | 8 | #include <string> |
| 10 | #include <utility> | 9 | #include <string_view> |
| 11 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 12 | #include "common/logging/filter.h" | 11 | #include "common/logging/filter.h" |
| 13 | #include "common/logging/log.h" | 12 | #include "common/logging/log.h" |
| @@ -106,9 +105,9 @@ private: | |||
| 106 | 105 | ||
| 107 | void AddBackend(std::unique_ptr<Backend> backend); | 106 | void AddBackend(std::unique_ptr<Backend> backend); |
| 108 | 107 | ||
| 109 | void RemoveBackend(const std::string& backend_name); | 108 | void RemoveBackend(std::string_view backend_name); |
| 110 | 109 | ||
| 111 | Backend* GetBackend(const std::string& backend_name); | 110 | Backend* GetBackend(std::string_view backend_name); |
| 112 | 111 | ||
| 113 | /** | 112 | /** |
| 114 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods | 113 | * Returns the name of the passed log class as a C-string. Subclasses are separated by periods |
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index 6ed087beb..2dd331152 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp | |||
| @@ -8,39 +8,9 @@ | |||
| 8 | #include "common/string_util.h" | 8 | #include "common/string_util.h" |
| 9 | 9 | ||
| 10 | namespace Log { | 10 | namespace Log { |
| 11 | 11 | namespace { | |
| 12 | Filter::Filter(Level default_level) { | ||
| 13 | ResetAll(default_level); | ||
| 14 | } | ||
| 15 | |||
| 16 | void Filter::ResetAll(Level level) { | ||
| 17 | class_levels.fill(level); | ||
| 18 | } | ||
| 19 | |||
| 20 | void Filter::SetClassLevel(Class log_class, Level level) { | ||
| 21 | class_levels[static_cast<size_t>(log_class)] = level; | ||
| 22 | } | ||
| 23 | |||
| 24 | void Filter::ParseFilterString(const std::string& filter_str) { | ||
| 25 | auto clause_begin = filter_str.cbegin(); | ||
| 26 | while (clause_begin != filter_str.cend()) { | ||
| 27 | auto clause_end = std::find(clause_begin, filter_str.cend(), ' '); | ||
| 28 | |||
| 29 | // If clause isn't empty | ||
| 30 | if (clause_end != clause_begin) { | ||
| 31 | ParseFilterRule(clause_begin, clause_end); | ||
| 32 | } | ||
| 33 | |||
| 34 | if (clause_end != filter_str.cend()) { | ||
| 35 | // Skip over the whitespace | ||
| 36 | ++clause_end; | ||
| 37 | } | ||
| 38 | clause_begin = clause_end; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | |||
| 42 | template <typename It> | 12 | template <typename It> |
| 43 | static Level GetLevelByName(const It begin, const It end) { | 13 | Level GetLevelByName(const It begin, const It end) { |
| 44 | for (u8 i = 0; i < static_cast<u8>(Level::Count); ++i) { | 14 | for (u8 i = 0; i < static_cast<u8>(Level::Count); ++i) { |
| 45 | const char* level_name = GetLevelName(static_cast<Level>(i)); | 15 | const char* level_name = GetLevelName(static_cast<Level>(i)); |
| 46 | if (Common::ComparePartialString(begin, end, level_name)) { | 16 | if (Common::ComparePartialString(begin, end, level_name)) { |
| @@ -51,7 +21,7 @@ static Level GetLevelByName(const It begin, const It end) { | |||
| 51 | } | 21 | } |
| 52 | 22 | ||
| 53 | template <typename It> | 23 | template <typename It> |
| 54 | static Class GetClassByName(const It begin, const It end) { | 24 | Class GetClassByName(const It begin, const It end) { |
| 55 | for (ClassType i = 0; i < static_cast<ClassType>(Class::Count); ++i) { | 25 | for (ClassType i = 0; i < static_cast<ClassType>(Class::Count); ++i) { |
| 56 | const char* level_name = GetLogClassName(static_cast<Class>(i)); | 26 | const char* level_name = GetLogClassName(static_cast<Class>(i)); |
| 57 | if (Common::ComparePartialString(begin, end, level_name)) { | 27 | if (Common::ComparePartialString(begin, end, level_name)) { |
| @@ -61,8 +31,8 @@ static Class GetClassByName(const It begin, const It end) { | |||
| 61 | return Class::Count; | 31 | return Class::Count; |
| 62 | } | 32 | } |
| 63 | 33 | ||
| 64 | bool Filter::ParseFilterRule(const std::string::const_iterator begin, | 34 | template <typename Iterator> |
| 65 | const std::string::const_iterator end) { | 35 | bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) { |
| 66 | auto level_separator = std::find(begin, end, ':'); | 36 | auto level_separator = std::find(begin, end, ':'); |
| 67 | if (level_separator == end) { | 37 | if (level_separator == end) { |
| 68 | LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: {}", | 38 | LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: {}", |
| @@ -77,7 +47,7 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, | |||
| 77 | } | 47 | } |
| 78 | 48 | ||
| 79 | if (Common::ComparePartialString(begin, level_separator, "*")) { | 49 | if (Common::ComparePartialString(begin, level_separator, "*")) { |
| 80 | ResetAll(level); | 50 | instance.ResetAll(level); |
| 81 | return true; | 51 | return true; |
| 82 | } | 52 | } |
| 83 | 53 | ||
| @@ -87,9 +57,40 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, | |||
| 87 | return false; | 57 | return false; |
| 88 | } | 58 | } |
| 89 | 59 | ||
| 90 | SetClassLevel(log_class, level); | 60 | instance.SetClassLevel(log_class, level); |
| 91 | return true; | 61 | return true; |
| 92 | } | 62 | } |
| 63 | } // Anonymous namespace | ||
| 64 | |||
| 65 | Filter::Filter(Level default_level) { | ||
| 66 | ResetAll(default_level); | ||
| 67 | } | ||
| 68 | |||
| 69 | void Filter::ResetAll(Level level) { | ||
| 70 | class_levels.fill(level); | ||
| 71 | } | ||
| 72 | |||
| 73 | void Filter::SetClassLevel(Class log_class, Level level) { | ||
| 74 | class_levels[static_cast<size_t>(log_class)] = level; | ||
| 75 | } | ||
| 76 | |||
| 77 | void Filter::ParseFilterString(std::string_view filter_view) { | ||
| 78 | auto clause_begin = filter_view.cbegin(); | ||
| 79 | while (clause_begin != filter_view.cend()) { | ||
| 80 | auto clause_end = std::find(clause_begin, filter_view.cend(), ' '); | ||
| 81 | |||
| 82 | // If clause isn't empty | ||
| 83 | if (clause_end != clause_begin) { | ||
| 84 | ParseFilterRule(*this, clause_begin, clause_end); | ||
| 85 | } | ||
| 86 | |||
| 87 | if (clause_end != filter_view.cend()) { | ||
| 88 | // Skip over the whitespace | ||
| 89 | ++clause_end; | ||
| 90 | } | ||
| 91 | clause_begin = clause_end; | ||
| 92 | } | ||
| 93 | } | ||
| 93 | 94 | ||
| 94 | bool Filter::CheckMessage(Class log_class, Level level) const { | 95 | bool Filter::CheckMessage(Class log_class, Level level) const { |
| 95 | return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); | 96 | return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); |
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h index 2a4f7c845..d5ffc5a58 100644 --- a/src/common/logging/filter.h +++ b/src/common/logging/filter.h | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <cstddef> | 8 | #include <cstddef> |
| 9 | #include <string> | 9 | #include <string_view> |
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | 11 | ||
| 12 | namespace Log { | 12 | namespace Log { |
| @@ -40,9 +40,7 @@ public: | |||
| 40 | * - `Service:Info` -- Sets the level of Service to Info. | 40 | * - `Service:Info` -- Sets the level of Service to Info. |
| 41 | * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace. | 41 | * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace. |
| 42 | */ | 42 | */ |
| 43 | void ParseFilterString(const std::string& filter_str); | 43 | void ParseFilterString(std::string_view filter_view); |
| 44 | bool ParseFilterRule(const std::string::const_iterator start, | ||
| 45 | const std::string::const_iterator end); | ||
| 46 | 44 | ||
| 47 | /// Matches class/level combination against the filter, returning true if it passed. | 45 | /// Matches class/level combination against the filter, returning true if it passed. |
| 48 | bool CheckMessage(Class log_class, Level level) const; | 46 | bool CheckMessage(Class log_class, Level level) const; |
diff --git a/src/common/param_package.cpp b/src/common/param_package.cpp index e0df430ab..9526ca0c6 100644 --- a/src/common/param_package.cpp +++ b/src/common/param_package.cpp | |||
| @@ -3,7 +3,9 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <array> | 5 | #include <array> |
| 6 | #include <utility> | ||
| 6 | #include <vector> | 7 | #include <vector> |
| 8 | |||
| 7 | #include "common/logging/log.h" | 9 | #include "common/logging/log.h" |
| 8 | #include "common/param_package.h" | 10 | #include "common/param_package.h" |
| 9 | #include "common/string_util.h" | 11 | #include "common/string_util.h" |
| @@ -12,10 +14,11 @@ namespace Common { | |||
| 12 | 14 | ||
| 13 | constexpr char KEY_VALUE_SEPARATOR = ':'; | 15 | constexpr char KEY_VALUE_SEPARATOR = ':'; |
| 14 | constexpr char PARAM_SEPARATOR = ','; | 16 | constexpr char PARAM_SEPARATOR = ','; |
| 17 | |||
| 15 | constexpr char ESCAPE_CHARACTER = '$'; | 18 | constexpr char ESCAPE_CHARACTER = '$'; |
| 16 | const std::string KEY_VALUE_SEPARATOR_ESCAPE{ESCAPE_CHARACTER, '0'}; | 19 | constexpr char KEY_VALUE_SEPARATOR_ESCAPE[] = "$0"; |
| 17 | const std::string PARAM_SEPARATOR_ESCAPE{ESCAPE_CHARACTER, '1'}; | 20 | constexpr char PARAM_SEPARATOR_ESCAPE[] = "$1"; |
| 18 | const std::string ESCAPE_CHARACTER_ESCAPE{ESCAPE_CHARACTER, '2'}; | 21 | constexpr char ESCAPE_CHARACTER_ESCAPE[] = "$2"; |
| 19 | 22 | ||
| 20 | ParamPackage::ParamPackage(const std::string& serialized) { | 23 | ParamPackage::ParamPackage(const std::string& serialized) { |
| 21 | std::vector<std::string> pairs; | 24 | std::vector<std::string> pairs; |
| @@ -35,7 +38,7 @@ ParamPackage::ParamPackage(const std::string& serialized) { | |||
| 35 | part = Common::ReplaceAll(part, ESCAPE_CHARACTER_ESCAPE, {ESCAPE_CHARACTER}); | 38 | part = Common::ReplaceAll(part, ESCAPE_CHARACTER_ESCAPE, {ESCAPE_CHARACTER}); |
| 36 | } | 39 | } |
| 37 | 40 | ||
| 38 | Set(key_value[0], key_value[1]); | 41 | Set(key_value[0], std::move(key_value[1])); |
| 39 | } | 42 | } |
| 40 | } | 43 | } |
| 41 | 44 | ||
| @@ -101,16 +104,16 @@ float ParamPackage::Get(const std::string& key, float default_value) const { | |||
| 101 | } | 104 | } |
| 102 | } | 105 | } |
| 103 | 106 | ||
| 104 | void ParamPackage::Set(const std::string& key, const std::string& value) { | 107 | void ParamPackage::Set(const std::string& key, std::string value) { |
| 105 | data[key] = value; | 108 | data.insert_or_assign(key, std::move(value)); |
| 106 | } | 109 | } |
| 107 | 110 | ||
| 108 | void ParamPackage::Set(const std::string& key, int value) { | 111 | void ParamPackage::Set(const std::string& key, int value) { |
| 109 | data[key] = std::to_string(value); | 112 | data.insert_or_assign(key, std::to_string(value)); |
| 110 | } | 113 | } |
| 111 | 114 | ||
| 112 | void ParamPackage::Set(const std::string& key, float value) { | 115 | void ParamPackage::Set(const std::string& key, float value) { |
| 113 | data[key] = std::to_string(value); | 116 | data.insert_or_assign(key, std::to_string(value)); |
| 114 | } | 117 | } |
| 115 | 118 | ||
| 116 | bool ParamPackage::Has(const std::string& key) const { | 119 | bool ParamPackage::Has(const std::string& key) const { |
diff --git a/src/common/param_package.h b/src/common/param_package.h index c4c11b221..7842cd4ef 100644 --- a/src/common/param_package.h +++ b/src/common/param_package.h | |||
| @@ -28,7 +28,7 @@ public: | |||
| 28 | std::string Get(const std::string& key, const std::string& default_value) const; | 28 | std::string Get(const std::string& key, const std::string& default_value) const; |
| 29 | int Get(const std::string& key, int default_value) const; | 29 | int Get(const std::string& key, int default_value) const; |
| 30 | float Get(const std::string& key, float default_value) const; | 30 | float Get(const std::string& key, float default_value) const; |
| 31 | void Set(const std::string& key, const std::string& value); | 31 | void Set(const std::string& key, std::string value); |
| 32 | void Set(const std::string& key, int value); | 32 | void Set(const std::string& key, int value); |
| 33 | void Set(const std::string& key, float value); | 33 | void Set(const std::string& key, float value); |
| 34 | bool Has(const std::string& key) const; | 34 | bool Has(const std::string& key) const; |
diff --git a/src/core/arm/arm_interface.h b/src/core/arm/arm_interface.h index 8416e73b0..28a99defe 100644 --- a/src/core/arm/arm_interface.h +++ b/src/core/arm/arm_interface.h | |||
| @@ -104,6 +104,10 @@ public: | |||
| 104 | 104 | ||
| 105 | virtual void SetTlsAddress(VAddr address) = 0; | 105 | virtual void SetTlsAddress(VAddr address) = 0; |
| 106 | 106 | ||
| 107 | virtual u64 GetTPIDR_EL0() const = 0; | ||
| 108 | |||
| 109 | virtual void SetTPIDR_EL0(u64 value) = 0; | ||
| 110 | |||
| 107 | /** | 111 | /** |
| 108 | * Saves the current CPU context | 112 | * Saves the current CPU context |
| 109 | * @param ctx Thread context to save | 113 | * @param ctx Thread context to save |
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp index 3572ee7b9..df47d5ee8 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.cpp +++ b/src/core/arm/dynarmic/arm_dynarmic.cpp | |||
| @@ -196,6 +196,14 @@ void ARM_Dynarmic::SetTlsAddress(u64 address) { | |||
| 196 | cb->tpidrro_el0 = address; | 196 | cb->tpidrro_el0 = address; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| 199 | u64 ARM_Dynarmic::GetTPIDR_EL0() const { | ||
| 200 | return cb->tpidr_el0; | ||
| 201 | } | ||
| 202 | |||
| 203 | void ARM_Dynarmic::SetTPIDR_EL0(u64 value) { | ||
| 204 | cb->tpidr_el0 = value; | ||
| 205 | } | ||
| 206 | |||
| 199 | void ARM_Dynarmic::SaveContext(ARM_Interface::ThreadContext& ctx) { | 207 | void ARM_Dynarmic::SaveContext(ARM_Interface::ThreadContext& ctx) { |
| 200 | ctx.cpu_registers = jit->GetRegisters(); | 208 | ctx.cpu_registers = jit->GetRegisters(); |
| 201 | ctx.sp = jit->GetSP(); | 209 | ctx.sp = jit->GetSP(); |
diff --git a/src/core/arm/dynarmic/arm_dynarmic.h b/src/core/arm/dynarmic/arm_dynarmic.h index ed724c3f1..a9891ac4f 100644 --- a/src/core/arm/dynarmic/arm_dynarmic.h +++ b/src/core/arm/dynarmic/arm_dynarmic.h | |||
| @@ -34,6 +34,8 @@ public: | |||
| 34 | void SetCPSR(u32 cpsr) override; | 34 | void SetCPSR(u32 cpsr) override; |
| 35 | VAddr GetTlsAddress() const override; | 35 | VAddr GetTlsAddress() const override; |
| 36 | void SetTlsAddress(VAddr address) override; | 36 | void SetTlsAddress(VAddr address) override; |
| 37 | void SetTPIDR_EL0(u64 value) override; | ||
| 38 | u64 GetTPIDR_EL0() const override; | ||
| 37 | 39 | ||
| 38 | void SaveContext(ThreadContext& ctx) override; | 40 | void SaveContext(ThreadContext& ctx) override; |
| 39 | void LoadContext(const ThreadContext& ctx) override; | 41 | void LoadContext(const ThreadContext& ctx) override; |
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp index d2d699e9b..44a46bf04 100644 --- a/src/core/arm/unicorn/arm_unicorn.cpp +++ b/src/core/arm/unicorn/arm_unicorn.cpp | |||
| @@ -169,6 +169,16 @@ void ARM_Unicorn::SetTlsAddress(VAddr base) { | |||
| 169 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDRRO_EL0, &base)); | 169 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDRRO_EL0, &base)); |
| 170 | } | 170 | } |
| 171 | 171 | ||
| 172 | u64 ARM_Unicorn::GetTPIDR_EL0() const { | ||
| 173 | u64 value{}; | ||
| 174 | CHECKED(uc_reg_read(uc, UC_ARM64_REG_TPIDR_EL0, &value)); | ||
| 175 | return value; | ||
| 176 | } | ||
| 177 | |||
| 178 | void ARM_Unicorn::SetTPIDR_EL0(u64 value) { | ||
| 179 | CHECKED(uc_reg_write(uc, UC_ARM64_REG_TPIDR_EL0, &value)); | ||
| 180 | } | ||
| 181 | |||
| 172 | void ARM_Unicorn::Run() { | 182 | void ARM_Unicorn::Run() { |
| 173 | if (GDBStub::IsServerEnabled()) { | 183 | if (GDBStub::IsServerEnabled()) { |
| 174 | ExecuteInstructions(std::max(4000000, 0)); | 184 | ExecuteInstructions(std::max(4000000, 0)); |
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h index a78a0acf2..af7943352 100644 --- a/src/core/arm/unicorn/arm_unicorn.h +++ b/src/core/arm/unicorn/arm_unicorn.h | |||
| @@ -28,6 +28,8 @@ public: | |||
| 28 | void SetCPSR(u32 cpsr) override; | 28 | void SetCPSR(u32 cpsr) override; |
| 29 | VAddr GetTlsAddress() const override; | 29 | VAddr GetTlsAddress() const override; |
| 30 | void SetTlsAddress(VAddr address) override; | 30 | void SetTlsAddress(VAddr address) override; |
| 31 | void SetTPIDR_EL0(u64 value) override; | ||
| 32 | u64 GetTPIDR_EL0() const override; | ||
| 31 | void SaveContext(ThreadContext& ctx) override; | 33 | void SaveContext(ThreadContext& ctx) override; |
| 32 | void LoadContext(const ThreadContext& ctx) override; | 34 | void LoadContext(const ThreadContext& ctx) override; |
| 33 | void PrepareReschedule() override; | 35 | void PrepareReschedule() override; |
diff --git a/src/core/file_sys/vfs.cpp b/src/core/file_sys/vfs.cpp index 16c8ad90b..3f690f12a 100644 --- a/src/core/file_sys/vfs.cpp +++ b/src/core/file_sys/vfs.cpp | |||
| @@ -42,7 +42,7 @@ bool VfsFile::WriteByte(u8 data, size_t offset) { | |||
| 42 | return Write(&data, 1, offset) == 1; | 42 | return Write(&data, 1, offset) == 1; |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | size_t VfsFile::WriteBytes(std::vector<u8> data, size_t offset) { | 45 | size_t VfsFile::WriteBytes(const std::vector<u8>& data, size_t offset) { |
| 46 | return Write(data.data(), data.size(), offset); | 46 | return Write(data.data(), data.size(), offset); |
| 47 | } | 47 | } |
| 48 | 48 | ||
diff --git a/src/core/file_sys/vfs.h b/src/core/file_sys/vfs.h index a5213e0cc..db3c77eac 100644 --- a/src/core/file_sys/vfs.h +++ b/src/core/file_sys/vfs.h | |||
| @@ -59,8 +59,7 @@ struct VfsFile : NonCopyable { | |||
| 59 | // Returns the number of bytes (sizeof(T)*number_elements) read successfully. | 59 | // Returns the number of bytes (sizeof(T)*number_elements) read successfully. |
| 60 | template <typename T> | 60 | template <typename T> |
| 61 | size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { | 61 | size_t ReadArray(T* data, size_t number_elements, size_t offset = 0) const { |
| 62 | static_assert(std::is_trivially_copyable<T>::value, | 62 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 63 | "Data type must be trivially copyable."); | ||
| 64 | 63 | ||
| 65 | return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset); | 64 | return Read(reinterpret_cast<u8*>(data), number_elements * sizeof(T), offset); |
| 66 | } | 65 | } |
| @@ -69,8 +68,7 @@ struct VfsFile : NonCopyable { | |||
| 69 | // Returns the number of bytes read successfully. | 68 | // Returns the number of bytes read successfully. |
| 70 | template <typename T> | 69 | template <typename T> |
| 71 | size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { | 70 | size_t ReadBytes(T* data, size_t size, size_t offset = 0) const { |
| 72 | static_assert(std::is_trivially_copyable<T>::value, | 71 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 73 | "Data type must be trivially copyable."); | ||
| 74 | return Read(reinterpret_cast<u8*>(data), size, offset); | 72 | return Read(reinterpret_cast<u8*>(data), size, offset); |
| 75 | } | 73 | } |
| 76 | 74 | ||
| @@ -78,8 +76,7 @@ struct VfsFile : NonCopyable { | |||
| 78 | // Returns the number of bytes read successfully (sizeof(T)). | 76 | // Returns the number of bytes read successfully (sizeof(T)). |
| 79 | template <typename T> | 77 | template <typename T> |
| 80 | size_t ReadObject(T* data, size_t offset = 0) const { | 78 | size_t ReadObject(T* data, size_t offset = 0) const { |
| 81 | static_assert(std::is_trivially_copyable<T>::value, | 79 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 82 | "Data type must be trivially copyable."); | ||
| 83 | return Read(reinterpret_cast<u8*>(data), sizeof(T), offset); | 80 | return Read(reinterpret_cast<u8*>(data), sizeof(T), offset); |
| 84 | } | 81 | } |
| 85 | 82 | ||
| @@ -88,33 +85,29 @@ struct VfsFile : NonCopyable { | |||
| 88 | virtual bool WriteByte(u8 data, size_t offset = 0); | 85 | virtual bool WriteByte(u8 data, size_t offset = 0); |
| 89 | // Writes a vector of bytes to offset in file and returns the number of bytes successfully | 86 | // Writes a vector of bytes to offset in file and returns the number of bytes successfully |
| 90 | // written. | 87 | // written. |
| 91 | virtual size_t WriteBytes(std::vector<u8> data, size_t offset = 0); | 88 | virtual size_t WriteBytes(const std::vector<u8>& data, size_t offset = 0); |
| 92 | 89 | ||
| 93 | // Writes an array of type T, size number_elements to offset in file. | 90 | // Writes an array of type T, size number_elements to offset in file. |
| 94 | // Returns the number of bytes (sizeof(T)*number_elements) written successfully. | 91 | // Returns the number of bytes (sizeof(T)*number_elements) written successfully. |
| 95 | template <typename T> | 92 | template <typename T> |
| 96 | size_t WriteArray(T* data, size_t number_elements, size_t offset = 0) { | 93 | size_t WriteArray(const T* data, size_t number_elements, size_t offset = 0) { |
| 97 | static_assert(std::is_trivially_copyable<T>::value, | 94 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 98 | "Data type must be trivially copyable."); | ||
| 99 | |||
| 100 | return Write(data, number_elements * sizeof(T), offset); | 95 | return Write(data, number_elements * sizeof(T), offset); |
| 101 | } | 96 | } |
| 102 | 97 | ||
| 103 | // Writes size bytes starting at memory location data to offset in file. | 98 | // Writes size bytes starting at memory location data to offset in file. |
| 104 | // Returns the number of bytes written successfully. | 99 | // Returns the number of bytes written successfully. |
| 105 | template <typename T> | 100 | template <typename T> |
| 106 | size_t WriteBytes(T* data, size_t size, size_t offset = 0) { | 101 | size_t WriteBytes(const T* data, size_t size, size_t offset = 0) { |
| 107 | static_assert(std::is_trivially_copyable<T>::value, | 102 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 108 | "Data type must be trivially copyable."); | 103 | return Write(reinterpret_cast<const u8*>(data), size, offset); |
| 109 | return Write(reinterpret_cast<u8*>(data), size, offset); | ||
| 110 | } | 104 | } |
| 111 | 105 | ||
| 112 | // Writes one object of type T to offset in file. | 106 | // Writes one object of type T to offset in file. |
| 113 | // Returns the number of bytes written successfully (sizeof(T)). | 107 | // Returns the number of bytes written successfully (sizeof(T)). |
| 114 | template <typename T> | 108 | template <typename T> |
| 115 | size_t WriteObject(const T& data, size_t offset = 0) { | 109 | size_t WriteObject(const T& data, size_t offset = 0) { |
| 116 | static_assert(std::is_trivially_copyable<T>::value, | 110 | static_assert(std::is_trivially_copyable_v<T>, "Data type must be trivially copyable."); |
| 117 | "Data type must be trivially copyable."); | ||
| 118 | return Write(&data, sizeof(T), offset); | 111 | return Write(&data, sizeof(T), offset); |
| 119 | } | 112 | } |
| 120 | 113 | ||
diff --git a/src/core/file_sys/vfs_offset.cpp b/src/core/file_sys/vfs_offset.cpp index 31fdd9aa1..217e02235 100644 --- a/src/core/file_sys/vfs_offset.cpp +++ b/src/core/file_sys/vfs_offset.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <utility> | 6 | #include <utility> |
| 6 | 7 | ||
| 7 | #include "core/file_sys/vfs_offset.h" | 8 | #include "core/file_sys/vfs_offset.h" |
| @@ -75,7 +76,7 @@ bool OffsetVfsFile::WriteByte(u8 data, size_t r_offset) { | |||
| 75 | return false; | 76 | return false; |
| 76 | } | 77 | } |
| 77 | 78 | ||
| 78 | size_t OffsetVfsFile::WriteBytes(std::vector<u8> data, size_t r_offset) { | 79 | size_t OffsetVfsFile::WriteBytes(const std::vector<u8>& data, size_t r_offset) { |
| 79 | return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); | 80 | return file->Write(data.data(), TrimToFit(data.size(), r_offset), offset + r_offset); |
| 80 | } | 81 | } |
| 81 | 82 | ||
| @@ -88,7 +89,7 @@ size_t OffsetVfsFile::GetOffset() const { | |||
| 88 | } | 89 | } |
| 89 | 90 | ||
| 90 | size_t OffsetVfsFile::TrimToFit(size_t r_size, size_t r_offset) const { | 91 | size_t OffsetVfsFile::TrimToFit(size_t r_size, size_t r_offset) const { |
| 91 | return std::max<size_t>(std::min<size_t>(size - r_offset, r_size), 0); | 92 | return std::clamp(r_size, size_t{0}, size - r_offset); |
| 92 | } | 93 | } |
| 93 | 94 | ||
| 94 | } // namespace FileSys | 95 | } // namespace FileSys |
diff --git a/src/core/file_sys/vfs_offset.h b/src/core/file_sys/vfs_offset.h index 2e16e47eb..ded4827f5 100644 --- a/src/core/file_sys/vfs_offset.h +++ b/src/core/file_sys/vfs_offset.h | |||
| @@ -28,7 +28,7 @@ struct OffsetVfsFile : public VfsFile { | |||
| 28 | std::vector<u8> ReadBytes(size_t size, size_t offset) const override; | 28 | std::vector<u8> ReadBytes(size_t size, size_t offset) const override; |
| 29 | std::vector<u8> ReadAllBytes() const override; | 29 | std::vector<u8> ReadAllBytes() const override; |
| 30 | bool WriteByte(u8 data, size_t offset) override; | 30 | bool WriteByte(u8 data, size_t offset) override; |
| 31 | size_t WriteBytes(std::vector<u8> data, size_t offset) override; | 31 | size_t WriteBytes(const std::vector<u8>& data, size_t offset) override; |
| 32 | 32 | ||
| 33 | bool Rename(const std::string& name) override; | 33 | bool Rename(const std::string& name) override; |
| 34 | 34 | ||
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp index f7e25cbf5..e307eec98 100644 --- a/src/core/hle/kernel/scheduler.cpp +++ b/src/core/hle/kernel/scheduler.cpp | |||
| @@ -56,6 +56,8 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 56 | if (previous_thread) { | 56 | if (previous_thread) { |
| 57 | previous_thread->last_running_ticks = CoreTiming::GetTicks(); | 57 | previous_thread->last_running_ticks = CoreTiming::GetTicks(); |
| 58 | cpu_core->SaveContext(previous_thread->context); | 58 | cpu_core->SaveContext(previous_thread->context); |
| 59 | // Save the TPIDR_EL0 system register in case it was modified. | ||
| 60 | previous_thread->tpidr_el0 = cpu_core->GetTPIDR_EL0(); | ||
| 59 | 61 | ||
| 60 | if (previous_thread->status == ThreadStatus::Running) { | 62 | if (previous_thread->status == ThreadStatus::Running) { |
| 61 | // This is only the case when a reschedule is triggered without the current thread | 63 | // This is only the case when a reschedule is triggered without the current thread |
| @@ -87,6 +89,7 @@ void Scheduler::SwitchContext(Thread* new_thread) { | |||
| 87 | 89 | ||
| 88 | cpu_core->LoadContext(new_thread->context); | 90 | cpu_core->LoadContext(new_thread->context); |
| 89 | cpu_core->SetTlsAddress(new_thread->GetTLSAddress()); | 91 | cpu_core->SetTlsAddress(new_thread->GetTLSAddress()); |
| 92 | cpu_core->SetTPIDR_EL0(new_thread->GetTPIDR_EL0()); | ||
| 90 | cpu_core->ClearExclusiveState(); | 93 | cpu_core->ClearExclusiveState(); |
| 91 | } else { | 94 | } else { |
| 92 | current_thread = nullptr; | 95 | current_thread = nullptr; |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index 53f2e861e..cd85c4b7c 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -312,6 +312,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 312 | thread->status = ThreadStatus::Dormant; | 312 | thread->status = ThreadStatus::Dormant; |
| 313 | thread->entry_point = entry_point; | 313 | thread->entry_point = entry_point; |
| 314 | thread->stack_top = stack_top; | 314 | thread->stack_top = stack_top; |
| 315 | thread->tpidr_el0 = 0; | ||
| 315 | thread->nominal_priority = thread->current_priority = priority; | 316 | thread->nominal_priority = thread->current_priority = priority; |
| 316 | thread->last_running_ticks = CoreTiming::GetTicks(); | 317 | thread->last_running_ticks = CoreTiming::GetTicks(); |
| 317 | thread->processor_id = processor_id; | 318 | thread->processor_id = processor_id; |
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index 47881ec20..6218960d2 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -183,6 +183,14 @@ public: | |||
| 183 | } | 183 | } |
| 184 | 184 | ||
| 185 | /* | 185 | /* |
| 186 | * Returns the value of the TPIDR_EL0 Read/Write system register for this thread. | ||
| 187 | * @returns The value of the TPIDR_EL0 register. | ||
| 188 | */ | ||
| 189 | u64 GetTPIDR_EL0() const { | ||
| 190 | return tpidr_el0; | ||
| 191 | } | ||
| 192 | |||
| 193 | /* | ||
| 186 | * Returns the address of the current thread's command buffer, located in the TLS. | 194 | * Returns the address of the current thread's command buffer, located in the TLS. |
| 187 | * @returns VAddr of the thread's command buffer. | 195 | * @returns VAddr of the thread's command buffer. |
| 188 | */ | 196 | */ |
| @@ -213,6 +221,7 @@ public: | |||
| 213 | s32 processor_id; | 221 | s32 processor_id; |
| 214 | 222 | ||
| 215 | VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread | 223 | VAddr tls_address; ///< Virtual address of the Thread Local Storage of the thread |
| 224 | u64 tpidr_el0; ///< TPIDR_EL0 read/write system register. | ||
| 216 | 225 | ||
| 217 | SharedPtr<Process> owner_process; ///< Process that owns this thread | 226 | SharedPtr<Process> owner_process; ///< Process that owns this thread |
| 218 | 227 | ||
diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 19b8667ba..394963a69 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp | |||
| @@ -83,16 +83,13 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( | |||
| 83 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; | 83 | VAddr next_load_addr{Memory::PROCESS_IMAGE_VADDR}; |
| 84 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", | 84 | for (const auto& module : {"rtld", "main", "subsdk0", "subsdk1", "subsdk2", "subsdk3", |
| 85 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { | 85 | "subsdk4", "subsdk5", "subsdk6", "subsdk7", "sdk"}) { |
| 86 | const VAddr load_addr = next_load_addr; | ||
| 87 | const FileSys::VirtualFile module_file = dir->GetFile(module); | 86 | const FileSys::VirtualFile module_file = dir->GetFile(module); |
| 88 | if (module_file != nullptr) | 87 | if (module_file != nullptr) { |
| 88 | const VAddr load_addr = next_load_addr; | ||
| 89 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr); | 89 | next_load_addr = AppLoader_NSO::LoadModule(module_file, load_addr); |
| 90 | if (next_load_addr) { | ||
| 91 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); | 90 | LOG_DEBUG(Loader, "loaded module {} @ 0x{:X}", module, load_addr); |
| 92 | // Register module with GDBStub | 91 | // Register module with GDBStub |
| 93 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); | 92 | GDBStub::RegisterModule(module, load_addr, next_load_addr - 1, false); |
| 94 | } else { | ||
| 95 | next_load_addr = load_addr; | ||
| 96 | } | 93 | } |
| 97 | } | 94 | } |
| 98 | 95 | ||