summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/CMakeLists.txt17
-rw-r--r--src/core/arm/dynarmic/arm_dynarmic.cpp2
-rw-r--r--src/core/arm/unicorn/arm_unicorn.cpp14
-rw-r--r--src/core/arm/unicorn/arm_unicorn.h2
-rw-r--r--src/core/crypto/key_manager.cpp16
-rw-r--r--src/core/crypto/partition_data_manager.cpp7
-rw-r--r--src/core/file_sys/kernel_executable.cpp2
-rw-r--r--src/core/file_sys/program_metadata.cpp6
-rw-r--r--src/core/file_sys/program_metadata.h4
-rw-r--r--src/core/file_sys/romfs_factory.cpp4
-rw-r--r--src/core/file_sys/savedata_factory.cpp4
-rw-r--r--src/core/file_sys/vfs_libzip.cpp2
-rw-r--r--src/core/file_sys/xts_archive.cpp12
-rw-r--r--src/core/gdbstub/gdbstub.cpp3
-rw-r--r--src/core/hle/kernel/scheduler.cpp46
-rw-r--r--src/core/hle/kernel/scheduler.h36
-rw-r--r--src/core/hle/kernel/thread.cpp48
-rw-r--r--src/core/hle/kernel/vm_manager.cpp2
-rw-r--r--src/core/hle/result.h10
-rw-r--r--src/core/hle/service/acc/acc.cpp6
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp4
-rw-r--r--src/core/hle/service/am/am.cpp4
-rw-r--r--src/core/hle/service/am/applets/web_browser.cpp16
-rw-r--r--src/core/hle/service/aoc/aoc_u.cpp2
-rw-r--r--src/core/hle/service/audio/hwopus.cpp4
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp2
-rw-r--r--src/core/hle/service/filesystem/filesystem.cpp26
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp6
-rw-r--r--src/core/hle/service/mii/mii.cpp6
-rw-r--r--src/core/hle/service/nfp/nfp.cpp3
-rw-r--r--src/core/hle/service/ns/ns.cpp4
-rw-r--r--src/core/hle/service/ns/pl_u.cpp2
-rw-r--r--src/core/hle/service/time/time.cpp26
-rw-r--r--src/core/hle/service/vi/vi.cpp2
-rw-r--r--src/core/perf_stats.cpp2
35 files changed, 182 insertions, 170 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 4f6a87b0a..f2e774a6b 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -522,6 +522,23 @@ add_library(core STATIC
522 tools/freezer.h 522 tools/freezer.h
523) 523)
524 524
525if (MSVC)
526 target_compile_options(core PRIVATE
527 # 'expression' : signed/unsigned mismatch
528 /we4018
529 # 'argument' : conversion from 'type1' to 'type2', possible loss of data (floating-point)
530 /we4244
531 # 'conversion' : conversion from 'type1' to 'type2', signed/unsigned mismatch
532 /we4245
533 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data
534 /we4254
535 # 'var' : conversion from 'size_t' to 'type', possible loss of data
536 /we4267
537 # 'context' : truncation from 'type1' to 'type2'
538 /we4305
539 )
540endif()
541
525create_target_directory_groups(core) 542create_target_directory_groups(core)
526 543
527target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) 544target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
diff --git a/src/core/arm/dynarmic/arm_dynarmic.cpp b/src/core/arm/dynarmic/arm_dynarmic.cpp
index 700c4afff..a0705b2b8 100644
--- a/src/core/arm/dynarmic/arm_dynarmic.cpp
+++ b/src/core/arm/dynarmic/arm_dynarmic.cpp
@@ -67,7 +67,7 @@ public:
67 ARM_Interface::ThreadContext ctx; 67 ARM_Interface::ThreadContext ctx;
68 parent.SaveContext(ctx); 68 parent.SaveContext(ctx);
69 parent.inner_unicorn.LoadContext(ctx); 69 parent.inner_unicorn.LoadContext(ctx);
70 parent.inner_unicorn.ExecuteInstructions(static_cast<int>(num_instructions)); 70 parent.inner_unicorn.ExecuteInstructions(num_instructions);
71 parent.inner_unicorn.SaveContext(ctx); 71 parent.inner_unicorn.SaveContext(ctx);
72 parent.LoadContext(ctx); 72 parent.LoadContext(ctx);
73 num_interpreted_instructions += num_instructions; 73 num_interpreted_instructions += num_instructions;
diff --git a/src/core/arm/unicorn/arm_unicorn.cpp b/src/core/arm/unicorn/arm_unicorn.cpp
index d4f41bfc1..9698172db 100644
--- a/src/core/arm/unicorn/arm_unicorn.cpp
+++ b/src/core/arm/unicorn/arm_unicorn.cpp
@@ -67,10 +67,11 @@ ARM_Unicorn::ARM_Unicorn(System& system) : system{system} {
67 CHECKED(uc_reg_write(uc, UC_ARM64_REG_CPACR_EL1, &fpv)); 67 CHECKED(uc_reg_write(uc, UC_ARM64_REG_CPACR_EL1, &fpv));
68 68
69 uc_hook hook{}; 69 uc_hook hook{};
70 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, -1)); 70 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_INTR, (void*)InterruptHook, this, 0, UINT64_MAX));
71 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, &system, 0, -1)); 71 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_MEM_INVALID, (void*)UnmappedMemoryHook, &system, 0,
72 UINT64_MAX));
72 if (GDBStub::IsServerEnabled()) { 73 if (GDBStub::IsServerEnabled()) {
73 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, -1)); 74 CHECKED(uc_hook_add(uc, &hook, UC_HOOK_CODE, (void*)CodeHook, this, 0, UINT64_MAX));
74 last_bkpt_hit = false; 75 last_bkpt_hit = false;
75 } 76 }
76} 77}
@@ -154,9 +155,10 @@ void ARM_Unicorn::SetTPIDR_EL0(u64 value) {
154 155
155void ARM_Unicorn::Run() { 156void ARM_Unicorn::Run() {
156 if (GDBStub::IsServerEnabled()) { 157 if (GDBStub::IsServerEnabled()) {
157 ExecuteInstructions(std::max(4000000, 0)); 158 ExecuteInstructions(std::max(4000000U, 0U));
158 } else { 159 } else {
159 ExecuteInstructions(std::max(system.CoreTiming().GetDowncount(), s64{0})); 160 ExecuteInstructions(
161 std::max(std::size_t(system.CoreTiming().GetDowncount()), std::size_t{0}));
160 } 162 }
161} 163}
162 164
@@ -166,7 +168,7 @@ void ARM_Unicorn::Step() {
166 168
167MICROPROFILE_DEFINE(ARM_Jit_Unicorn, "ARM JIT", "Unicorn", MP_RGB(255, 64, 64)); 169MICROPROFILE_DEFINE(ARM_Jit_Unicorn, "ARM JIT", "Unicorn", MP_RGB(255, 64, 64));
168 170
169void ARM_Unicorn::ExecuteInstructions(int num_instructions) { 171void ARM_Unicorn::ExecuteInstructions(std::size_t num_instructions) {
170 MICROPROFILE_SCOPE(ARM_Jit_Unicorn); 172 MICROPROFILE_SCOPE(ARM_Jit_Unicorn);
171 CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions)); 173 CHECKED(uc_emu_start(uc, GetPC(), 1ULL << 63, 0, num_instructions));
172 system.CoreTiming().AddTicks(num_instructions); 174 system.CoreTiming().AddTicks(num_instructions);
diff --git a/src/core/arm/unicorn/arm_unicorn.h b/src/core/arm/unicorn/arm_unicorn.h
index fe2ffd70c..b39426ea0 100644
--- a/src/core/arm/unicorn/arm_unicorn.h
+++ b/src/core/arm/unicorn/arm_unicorn.h
@@ -34,7 +34,7 @@ public:
34 void LoadContext(const ThreadContext& ctx) override; 34 void LoadContext(const ThreadContext& ctx) override;
35 void PrepareReschedule() override; 35 void PrepareReschedule() override;
36 void ClearExclusiveState() override; 36 void ClearExclusiveState() override;
37 void ExecuteInstructions(int num_instructions); 37 void ExecuteInstructions(std::size_t num_instructions);
38 void Run() override; 38 void Run() override;
39 void Step() override; 39 void Step() override;
40 void ClearInstructionCache() override; 40 void ClearInstructionCache() override;
diff --git a/src/core/crypto/key_manager.cpp b/src/core/crypto/key_manager.cpp
index 487b57053..87e6a1fd3 100644
--- a/src/core/crypto/key_manager.cpp
+++ b/src/core/crypto/key_manager.cpp
@@ -22,6 +22,7 @@
22#include "common/file_util.h" 22#include "common/file_util.h"
23#include "common/hex_util.h" 23#include "common/hex_util.h"
24#include "common/logging/log.h" 24#include "common/logging/log.h"
25#include "common/string_util.h"
25#include "core/core.h" 26#include "core/core.h"
26#include "core/crypto/aes_util.h" 27#include "core/crypto/aes_util.h"
27#include "core/crypto/key_manager.h" 28#include "core/crypto/key_manager.h"
@@ -378,8 +379,9 @@ std::vector<Ticket> GetTicketblob(const FileUtil::IOFile& ticket_save) {
378template <size_t size> 379template <size_t size>
379static std::array<u8, size> operator^(const std::array<u8, size>& lhs, 380static std::array<u8, size> operator^(const std::array<u8, size>& lhs,
380 const std::array<u8, size>& rhs) { 381 const std::array<u8, size>& rhs) {
381 std::array<u8, size> out{}; 382 std::array<u8, size> out;
382 std::transform(lhs.begin(), lhs.end(), rhs.begin(), out.begin(), std::bit_xor<>()); 383 std::transform(lhs.begin(), lhs.end(), rhs.begin(), out.begin(),
384 [](u8 lhs, u8 rhs) { return u8(lhs ^ rhs); });
383 return out; 385 return out;
384} 386}
385 387
@@ -538,7 +540,7 @@ void KeyManager::LoadFromFile(const std::string& filename, bool is_title_keys) {
538 Key128 key = Common::HexStringToArray<16>(out[1]); 540 Key128 key = Common::HexStringToArray<16>(out[1]);
539 s128_keys[{S128KeyType::Titlekey, rights_id[1], rights_id[0]}] = key; 541 s128_keys[{S128KeyType::Titlekey, rights_id[1], rights_id[0]}] = key;
540 } else { 542 } else {
541 std::transform(out[0].begin(), out[0].end(), out[0].begin(), ::tolower); 543 out[0] = Common::ToLower(out[0]);
542 if (s128_file_id.find(out[0]) != s128_file_id.end()) { 544 if (s128_file_id.find(out[0]) != s128_file_id.end()) {
543 const auto index = s128_file_id.at(out[0]); 545 const auto index = s128_file_id.at(out[0]);
544 Key128 key = Common::HexStringToArray<16>(out[1]); 546 Key128 key = Common::HexStringToArray<16>(out[1]);
@@ -948,12 +950,10 @@ void KeyManager::DeriveETicket(PartitionDataManager& data) {
948 return; 950 return;
949 } 951 }
950 952
951 Key128 rsa_oaep_kek{}; 953 const Key128 rsa_oaep_kek = seed3 ^ mask0;
952 std::transform(seed3.begin(), seed3.end(), mask0.begin(), rsa_oaep_kek.begin(), 954 if (rsa_oaep_kek == Key128{}) {
953 std::bit_xor<>());
954
955 if (rsa_oaep_kek == Key128{})
956 return; 955 return;
956 }
957 957
958 SetKey(S128KeyType::Source, rsa_oaep_kek, 958 SetKey(S128KeyType::Source, rsa_oaep_kek,
959 static_cast<u64>(SourceKeyType::RSAOaepKekGeneration)); 959 static_cast<u64>(SourceKeyType::RSAOaepKekGeneration));
diff --git a/src/core/crypto/partition_data_manager.cpp b/src/core/crypto/partition_data_manager.cpp
index a4b09fd12..d64302f2e 100644
--- a/src/core/crypto/partition_data_manager.cpp
+++ b/src/core/crypto/partition_data_manager.cpp
@@ -204,11 +204,12 @@ static std::array<Key128, 0x20> FindEncryptedMasterKeyFromHex(const std::vector<
204 204
205FileSys::VirtualFile FindFileInDirWithNames(const FileSys::VirtualDir& dir, 205FileSys::VirtualFile FindFileInDirWithNames(const FileSys::VirtualDir& dir,
206 const std::string& name) { 206 const std::string& name) {
207 auto upper = name; 207 const auto upper = Common::ToUpper(name);
208 std::transform(upper.begin(), upper.end(), upper.begin(), [](u8 c) { return std::toupper(c); }); 208
209 for (const auto& fname : {name, name + ".bin", upper, upper + ".BIN"}) { 209 for (const auto& fname : {name, name + ".bin", upper, upper + ".BIN"}) {
210 if (dir->GetFile(fname) != nullptr) 210 if (dir->GetFile(fname) != nullptr) {
211 return dir->GetFile(fname); 211 return dir->GetFile(fname);
212 }
212 } 213 }
213 214
214 return nullptr; 215 return nullptr;
diff --git a/src/core/file_sys/kernel_executable.cpp b/src/core/file_sys/kernel_executable.cpp
index 371300684..76313679d 100644
--- a/src/core/file_sys/kernel_executable.cpp
+++ b/src/core/file_sys/kernel_executable.cpp
@@ -147,7 +147,7 @@ std::vector<u32> KIP::GetKernelCapabilities() const {
147} 147}
148 148
149s32 KIP::GetMainThreadPriority() const { 149s32 KIP::GetMainThreadPriority() const {
150 return header.main_thread_priority; 150 return static_cast<s32>(header.main_thread_priority);
151} 151}
152 152
153u32 KIP::GetMainThreadStackSize() const { 153u32 KIP::GetMainThreadStackSize() const {
diff --git a/src/core/file_sys/program_metadata.cpp b/src/core/file_sys/program_metadata.cpp
index 7310b3602..1d6c30962 100644
--- a/src/core/file_sys/program_metadata.cpp
+++ b/src/core/file_sys/program_metadata.cpp
@@ -52,14 +52,14 @@ Loader::ResultStatus ProgramMetadata::Load(VirtualFile file) {
52} 52}
53 53
54void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, 54void ProgramMetadata::LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space,
55 u8 main_thread_prio, u8 main_thread_core, 55 s32 main_thread_prio, u32 main_thread_core,
56 u32 main_thread_stack_size, u64 title_id, 56 u32 main_thread_stack_size, u64 title_id,
57 u64 filesystem_permissions, 57 u64 filesystem_permissions,
58 KernelCapabilityDescriptors capabilities) { 58 KernelCapabilityDescriptors capabilities) {
59 npdm_header.has_64_bit_instructions.Assign(is_64_bit); 59 npdm_header.has_64_bit_instructions.Assign(is_64_bit);
60 npdm_header.address_space_type.Assign(address_space); 60 npdm_header.address_space_type.Assign(address_space);
61 npdm_header.main_thread_priority = main_thread_prio; 61 npdm_header.main_thread_priority = static_cast<u8>(main_thread_prio);
62 npdm_header.main_thread_cpu = main_thread_core; 62 npdm_header.main_thread_cpu = static_cast<u8>(main_thread_core);
63 npdm_header.main_stack_size = main_thread_stack_size; 63 npdm_header.main_stack_size = main_thread_stack_size;
64 aci_header.title_id = title_id; 64 aci_header.title_id = title_id;
65 aci_file_access.permissions = filesystem_permissions; 65 aci_file_access.permissions = filesystem_permissions;
diff --git a/src/core/file_sys/program_metadata.h b/src/core/file_sys/program_metadata.h
index 88ec97d85..f8759a396 100644
--- a/src/core/file_sys/program_metadata.h
+++ b/src/core/file_sys/program_metadata.h
@@ -47,8 +47,8 @@ public:
47 Loader::ResultStatus Load(VirtualFile file); 47 Loader::ResultStatus Load(VirtualFile file);
48 48
49 // Load from parameters instead of NPDM file, used for KIP 49 // Load from parameters instead of NPDM file, used for KIP
50 void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, u8 main_thread_prio, 50 void LoadManual(bool is_64_bit, ProgramAddressSpaceType address_space, s32 main_thread_prio,
51 u8 main_thread_core, u32 main_thread_stack_size, u64 title_id, 51 u32 main_thread_core, u32 main_thread_stack_size, u64 title_id,
52 u64 filesystem_permissions, KernelCapabilityDescriptors capabilities); 52 u64 filesystem_permissions, KernelCapabilityDescriptors capabilities);
53 53
54 bool Is64BitProgram() const; 54 bool Is64BitProgram() const;
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp
index 4bd2e6183..418a39a7e 100644
--- a/src/core/file_sys/romfs_factory.cpp
+++ b/src/core/file_sys/romfs_factory.cpp
@@ -71,12 +71,12 @@ ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage,
71 71
72 if (res == nullptr) { 72 if (res == nullptr) {
73 // TODO(DarkLordZach): Find the right error code to use here 73 // TODO(DarkLordZach): Find the right error code to use here
74 return ResultCode(-1); 74 return RESULT_UNKNOWN;
75 } 75 }
76 const auto romfs = res->GetRomFS(); 76 const auto romfs = res->GetRomFS();
77 if (romfs == nullptr) { 77 if (romfs == nullptr) {
78 // TODO(DarkLordZach): Find the right error code to use here 78 // TODO(DarkLordZach): Find the right error code to use here
79 return ResultCode(-1); 79 return RESULT_UNKNOWN;
80 } 80 }
81 return MakeResult<VirtualFile>(romfs); 81 return MakeResult<VirtualFile>(romfs);
82} 82}
diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp
index e2a7eaf7b..f3def93ab 100644
--- a/src/core/file_sys/savedata_factory.cpp
+++ b/src/core/file_sys/savedata_factory.cpp
@@ -90,7 +90,7 @@ ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space,
90 // Return an error if the save data doesn't actually exist. 90 // Return an error if the save data doesn't actually exist.
91 if (out == nullptr) { 91 if (out == nullptr) {
92 // TODO(DarkLordZach): Find out correct error code. 92 // TODO(DarkLordZach): Find out correct error code.
93 return ResultCode(-1); 93 return RESULT_UNKNOWN;
94 } 94 }
95 95
96 return MakeResult<VirtualDir>(std::move(out)); 96 return MakeResult<VirtualDir>(std::move(out));
@@ -111,7 +111,7 @@ ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space,
111 // Return an error if the save data doesn't actually exist. 111 // Return an error if the save data doesn't actually exist.
112 if (out == nullptr) { 112 if (out == nullptr) {
113 // TODO(Subv): Find out correct error code. 113 // TODO(Subv): Find out correct error code.
114 return ResultCode(-1); 114 return RESULT_UNKNOWN;
115 } 115 }
116 116
117 return MakeResult<VirtualDir>(std::move(out)); 117 return MakeResult<VirtualDir>(std::move(out));
diff --git a/src/core/file_sys/vfs_libzip.cpp b/src/core/file_sys/vfs_libzip.cpp
index 8bdaa7e4a..11d1978ea 100644
--- a/src/core/file_sys/vfs_libzip.cpp
+++ b/src/core/file_sys/vfs_libzip.cpp
@@ -27,7 +27,7 @@ VirtualDir ExtractZIP(VirtualFile file) {
27 27
28 std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>(); 28 std::shared_ptr<VectorVfsDirectory> out = std::make_shared<VectorVfsDirectory>();
29 29
30 const auto num_entries = zip_get_num_entries(zip.get(), 0); 30 const auto num_entries = static_cast<std::size_t>(zip_get_num_entries(zip.get(), 0));
31 31
32 zip_stat_t stat{}; 32 zip_stat_t stat{};
33 zip_stat_init(&stat); 33 zip_stat_init(&stat);
diff --git a/src/core/file_sys/xts_archive.cpp b/src/core/file_sys/xts_archive.cpp
index 7ca375791..86e06ccb9 100644
--- a/src/core/file_sys/xts_archive.cpp
+++ b/src/core/file_sys/xts_archive.cpp
@@ -7,12 +7,13 @@
7#include <cstring> 7#include <cstring>
8#include <regex> 8#include <regex>
9#include <string> 9#include <string>
10
10#include <mbedtls/md.h> 11#include <mbedtls/md.h>
11#include <mbedtls/sha256.h> 12#include <mbedtls/sha256.h>
12#include "common/assert.h" 13
13#include "common/file_util.h" 14#include "common/file_util.h"
14#include "common/hex_util.h" 15#include "common/hex_util.h"
15#include "common/logging/log.h" 16#include "common/string_util.h"
16#include "core/crypto/aes_util.h" 17#include "core/crypto/aes_util.h"
17#include "core/crypto/xts_encryption_layer.h" 18#include "core/crypto/xts_encryption_layer.h"
18#include "core/file_sys/partition_filesystem.h" 19#include "core/file_sys/partition_filesystem.h"
@@ -53,11 +54,8 @@ NAX::NAX(VirtualFile file_) : header(std::make_unique<NAXHeader>()), file(std::m
53 return; 54 return;
54 } 55 }
55 56
56 std::string two_dir = match[1]; 57 const std::string two_dir = Common::ToUpper(match[1]);
57 std::string nca_id = match[2]; 58 const std::string nca_id = Common::ToLower(match[2]);
58 std::transform(two_dir.begin(), two_dir.end(), two_dir.begin(), ::toupper);
59 std::transform(nca_id.begin(), nca_id.end(), nca_id.begin(), ::tolower);
60
61 status = Parse(fmt::format("/registered/{}/{}.nca", two_dir, nca_id)); 59 status = Parse(fmt::format("/registered/{}/{}.nca", two_dir, nca_id));
62} 60}
63 61
diff --git a/src/core/gdbstub/gdbstub.cpp b/src/core/gdbstub/gdbstub.cpp
index 20bb50868..54ed680db 100644
--- a/src/core/gdbstub/gdbstub.cpp
+++ b/src/core/gdbstub/gdbstub.cpp
@@ -468,7 +468,8 @@ static u8 ReadByte() {
468 468
469/// Calculate the checksum of the current command buffer. 469/// Calculate the checksum of the current command buffer.
470static u8 CalculateChecksum(const u8* buffer, std::size_t length) { 470static u8 CalculateChecksum(const u8* buffer, std::size_t length) {
471 return static_cast<u8>(std::accumulate(buffer, buffer + length, 0, std::plus<u8>())); 471 return static_cast<u8>(std::accumulate(buffer, buffer + length, u8{0},
472 [](u8 lhs, u8 rhs) { return u8(lhs + rhs); }));
472} 473}
473 474
474/** 475/**
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 0e2dbf13e..16e95381b 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -35,12 +35,12 @@ void GlobalScheduler::RemoveThread(const Thread* thread) {
35 thread_list.end()); 35 thread_list.end());
36} 36}
37 37
38void GlobalScheduler::UnloadThread(s32 core) { 38void GlobalScheduler::UnloadThread(std::size_t core) {
39 Scheduler& sched = system.Scheduler(core); 39 Scheduler& sched = system.Scheduler(core);
40 sched.UnloadThread(); 40 sched.UnloadThread();
41} 41}
42 42
43void GlobalScheduler::SelectThread(u32 core) { 43void GlobalScheduler::SelectThread(std::size_t core) {
44 const auto update_thread = [](Thread* thread, Scheduler& sched) { 44 const auto update_thread = [](Thread* thread, Scheduler& sched) {
45 if (thread != sched.selected_thread) { 45 if (thread != sched.selected_thread) {
46 if (thread == nullptr) { 46 if (thread == nullptr) {
@@ -77,9 +77,9 @@ void GlobalScheduler::SelectThread(u32 core) {
77 // if we got a suggested thread, select it, else do a second pass. 77 // if we got a suggested thread, select it, else do a second pass.
78 if (winner && winner->GetPriority() > 2) { 78 if (winner && winner->GetPriority() > 2) {
79 if (winner->IsRunning()) { 79 if (winner->IsRunning()) {
80 UnloadThread(winner->GetProcessorID()); 80 UnloadThread(static_cast<u32>(winner->GetProcessorID()));
81 } 81 }
82 TransferToCore(winner->GetPriority(), core, winner); 82 TransferToCore(winner->GetPriority(), static_cast<s32>(core), winner);
83 update_thread(winner, sched); 83 update_thread(winner, sched);
84 return; 84 return;
85 } 85 }
@@ -91,9 +91,9 @@ void GlobalScheduler::SelectThread(u32 core) {
91 Thread* thread_on_core = scheduled_queue[src_core].front(); 91 Thread* thread_on_core = scheduled_queue[src_core].front();
92 Thread* to_change = *it; 92 Thread* to_change = *it;
93 if (thread_on_core->IsRunning() || to_change->IsRunning()) { 93 if (thread_on_core->IsRunning() || to_change->IsRunning()) {
94 UnloadThread(src_core); 94 UnloadThread(static_cast<u32>(src_core));
95 } 95 }
96 TransferToCore(thread_on_core->GetPriority(), core, thread_on_core); 96 TransferToCore(thread_on_core->GetPriority(), static_cast<s32>(core), thread_on_core);
97 current_thread = thread_on_core; 97 current_thread = thread_on_core;
98 break; 98 break;
99 } 99 }
@@ -154,9 +154,9 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) {
154 if (winner != nullptr) { 154 if (winner != nullptr) {
155 if (winner != yielding_thread) { 155 if (winner != yielding_thread) {
156 if (winner->IsRunning()) { 156 if (winner->IsRunning()) {
157 UnloadThread(winner->GetProcessorID()); 157 UnloadThread(static_cast<u32>(winner->GetProcessorID()));
158 } 158 }
159 TransferToCore(winner->GetPriority(), core_id, winner); 159 TransferToCore(winner->GetPriority(), s32(core_id), winner);
160 } 160 }
161 } else { 161 } else {
162 winner = next_thread; 162 winner = next_thread;
@@ -196,9 +196,9 @@ bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread
196 if (winner != nullptr) { 196 if (winner != nullptr) {
197 if (winner != yielding_thread) { 197 if (winner != yielding_thread) {
198 if (winner->IsRunning()) { 198 if (winner->IsRunning()) {
199 UnloadThread(winner->GetProcessorID()); 199 UnloadThread(static_cast<u32>(winner->GetProcessorID()));
200 } 200 }
201 TransferToCore(winner->GetPriority(), core_id, winner); 201 TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner);
202 } 202 }
203 } else { 203 } else {
204 winner = yielding_thread; 204 winner = yielding_thread;
@@ -248,7 +248,7 @@ void GlobalScheduler::PreemptThreads() {
248 248
249 if (winner != nullptr) { 249 if (winner != nullptr) {
250 if (winner->IsRunning()) { 250 if (winner->IsRunning()) {
251 UnloadThread(winner->GetProcessorID()); 251 UnloadThread(static_cast<u32>(winner->GetProcessorID()));
252 } 252 }
253 TransferToCore(winner->GetPriority(), s32(core_id), winner); 253 TransferToCore(winner->GetPriority(), s32(core_id), winner);
254 current_thread = 254 current_thread =
@@ -281,7 +281,7 @@ void GlobalScheduler::PreemptThreads() {
281 281
282 if (winner != nullptr) { 282 if (winner != nullptr) {
283 if (winner->IsRunning()) { 283 if (winner->IsRunning()) {
284 UnloadThread(winner->GetProcessorID()); 284 UnloadThread(static_cast<u32>(winner->GetProcessorID()));
285 } 285 }
286 TransferToCore(winner->GetPriority(), s32(core_id), winner); 286 TransferToCore(winner->GetPriority(), s32(core_id), winner);
287 current_thread = winner; 287 current_thread = winner;
@@ -292,30 +292,30 @@ void GlobalScheduler::PreemptThreads() {
292 } 292 }
293} 293}
294 294
295void GlobalScheduler::Suggest(u32 priority, u32 core, Thread* thread) { 295void GlobalScheduler::Suggest(u32 priority, std::size_t core, Thread* thread) {
296 suggested_queue[core].add(thread, priority); 296 suggested_queue[core].add(thread, priority);
297} 297}
298 298
299void GlobalScheduler::Unsuggest(u32 priority, u32 core, Thread* thread) { 299void GlobalScheduler::Unsuggest(u32 priority, std::size_t core, Thread* thread) {
300 suggested_queue[core].remove(thread, priority); 300 suggested_queue[core].remove(thread, priority);
301} 301}
302 302
303void GlobalScheduler::Schedule(u32 priority, u32 core, Thread* thread) { 303void GlobalScheduler::Schedule(u32 priority, std::size_t core, Thread* thread) {
304 ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); 304 ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core.");
305 scheduled_queue[core].add(thread, priority); 305 scheduled_queue[core].add(thread, priority);
306} 306}
307 307
308void GlobalScheduler::SchedulePrepend(u32 priority, u32 core, Thread* thread) { 308void GlobalScheduler::SchedulePrepend(u32 priority, std::size_t core, Thread* thread) {
309 ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core."); 309 ASSERT_MSG(thread->GetProcessorID() == s32(core), "Thread must be assigned to this core.");
310 scheduled_queue[core].add(thread, priority, false); 310 scheduled_queue[core].add(thread, priority, false);
311} 311}
312 312
313void GlobalScheduler::Reschedule(u32 priority, u32 core, Thread* thread) { 313void GlobalScheduler::Reschedule(u32 priority, std::size_t core, Thread* thread) {
314 scheduled_queue[core].remove(thread, priority); 314 scheduled_queue[core].remove(thread, priority);
315 scheduled_queue[core].add(thread, priority); 315 scheduled_queue[core].add(thread, priority);
316} 316}
317 317
318void GlobalScheduler::Unschedule(u32 priority, u32 core, Thread* thread) { 318void GlobalScheduler::Unschedule(u32 priority, std::size_t core, Thread* thread) {
319 scheduled_queue[core].remove(thread, priority); 319 scheduled_queue[core].remove(thread, priority);
320} 320}
321 321
@@ -327,14 +327,14 @@ void GlobalScheduler::TransferToCore(u32 priority, s32 destination_core, Thread*
327 } 327 }
328 thread->SetProcessorID(destination_core); 328 thread->SetProcessorID(destination_core);
329 if (source_core >= 0) { 329 if (source_core >= 0) {
330 Unschedule(priority, source_core, thread); 330 Unschedule(priority, static_cast<u32>(source_core), thread);
331 } 331 }
332 if (destination_core >= 0) { 332 if (destination_core >= 0) {
333 Unsuggest(priority, destination_core, thread); 333 Unsuggest(priority, static_cast<u32>(destination_core), thread);
334 Schedule(priority, destination_core, thread); 334 Schedule(priority, static_cast<u32>(destination_core), thread);
335 } 335 }
336 if (source_core >= 0) { 336 if (source_core >= 0) {
337 Suggest(priority, source_core, thread); 337 Suggest(priority, static_cast<u32>(source_core), thread);
338 } 338 }
339} 339}
340 340
@@ -357,7 +357,7 @@ void GlobalScheduler::Shutdown() {
357 thread_list.clear(); 357 thread_list.clear();
358} 358}
359 359
360Scheduler::Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, u32 core_id) 360Scheduler::Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, std::size_t core_id)
361 : system(system), cpu_core(cpu_core), core_id(core_id) {} 361 : system(system), cpu_core(cpu_core), core_id(core_id) {}
362 362
363Scheduler::~Scheduler() = default; 363Scheduler::~Scheduler() = default;
diff --git a/src/core/hle/kernel/scheduler.h b/src/core/hle/kernel/scheduler.h
index f2d6311b8..311849dfb 100644
--- a/src/core/hle/kernel/scheduler.h
+++ b/src/core/hle/kernel/scheduler.h
@@ -42,41 +42,34 @@ public:
42 * Add a thread to the suggested queue of a cpu core. Suggested threads may be 42 * Add a thread to the suggested queue of a cpu core. Suggested threads may be
43 * picked if no thread is scheduled to run on the core. 43 * picked if no thread is scheduled to run on the core.
44 */ 44 */
45 void Suggest(u32 priority, u32 core, Thread* thread); 45 void Suggest(u32 priority, std::size_t core, Thread* thread);
46 46
47 /** 47 /**
48 * Remove a thread to the suggested queue of a cpu core. Suggested threads may be 48 * Remove a thread to the suggested queue of a cpu core. Suggested threads may be
49 * picked if no thread is scheduled to run on the core. 49 * picked if no thread is scheduled to run on the core.
50 */ 50 */
51 void Unsuggest(u32 priority, u32 core, Thread* thread); 51 void Unsuggest(u32 priority, std::size_t core, Thread* thread);
52 52
53 /** 53 /**
54 * Add a thread to the scheduling queue of a cpu core. The thread is added at the 54 * Add a thread to the scheduling queue of a cpu core. The thread is added at the
55 * back the queue in its priority level. 55 * back the queue in its priority level.
56 */ 56 */
57 void Schedule(u32 priority, u32 core, Thread* thread); 57 void Schedule(u32 priority, std::size_t core, Thread* thread);
58 58
59 /** 59 /**
60 * Add a thread to the scheduling queue of a cpu core. The thread is added at the 60 * Add a thread to the scheduling queue of a cpu core. The thread is added at the
61 * front the queue in its priority level. 61 * front the queue in its priority level.
62 */ 62 */
63 void SchedulePrepend(u32 priority, u32 core, Thread* thread); 63 void SchedulePrepend(u32 priority, std::size_t core, Thread* thread);
64 64
65 /// Reschedule an already scheduled thread based on a new priority 65 /// Reschedule an already scheduled thread based on a new priority
66 void Reschedule(u32 priority, u32 core, Thread* thread); 66 void Reschedule(u32 priority, std::size_t core, Thread* thread);
67 67
68 /// Unschedules a thread. 68 /// Unschedules a thread.
69 void Unschedule(u32 priority, u32 core, Thread* thread); 69 void Unschedule(u32 priority, std::size_t core, Thread* thread);
70
71 /**
72 * Transfers a thread into an specific core. If the destination_core is -1
73 * it will be unscheduled from its source code and added into its suggested
74 * queue.
75 */
76 void TransferToCore(u32 priority, s32 destination_core, Thread* thread);
77 70
78 /// Selects a core and forces it to unload its current thread's context 71 /// Selects a core and forces it to unload its current thread's context
79 void UnloadThread(s32 core); 72 void UnloadThread(std::size_t core);
80 73
81 /** 74 /**
82 * Takes care of selecting the new scheduled thread in three steps: 75 * Takes care of selecting the new scheduled thread in three steps:
@@ -90,9 +83,9 @@ public:
90 * 3. Third is no suggested thread is found, we do a second pass and pick a running 83 * 3. Third is no suggested thread is found, we do a second pass and pick a running
91 * thread in another core and swap it with its current thread. 84 * thread in another core and swap it with its current thread.
92 */ 85 */
93 void SelectThread(u32 core); 86 void SelectThread(std::size_t core);
94 87
95 bool HaveReadyThreads(u32 core_id) const { 88 bool HaveReadyThreads(std::size_t core_id) const {
96 return !scheduled_queue[core_id].empty(); 89 return !scheduled_queue[core_id].empty();
97 } 90 }
98 91
@@ -145,6 +138,13 @@ public:
145 void Shutdown(); 138 void Shutdown();
146 139
147private: 140private:
141 /**
142 * Transfers a thread into an specific core. If the destination_core is -1
143 * it will be unscheduled from its source code and added into its suggested
144 * queue.
145 */
146 void TransferToCore(u32 priority, s32 destination_core, Thread* thread);
147
148 bool AskForReselectionOrMarkRedundant(Thread* current_thread, const Thread* winner); 148 bool AskForReselectionOrMarkRedundant(Thread* current_thread, const Thread* winner);
149 149
150 static constexpr u32 min_regular_priority = 2; 150 static constexpr u32 min_regular_priority = 2;
@@ -163,7 +163,7 @@ private:
163 163
164class Scheduler final { 164class Scheduler final {
165public: 165public:
166 explicit Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, u32 core_id); 166 explicit Scheduler(Core::System& system, Core::ARM_Interface& cpu_core, std::size_t core_id);
167 ~Scheduler(); 167 ~Scheduler();
168 168
169 /// Returns whether there are any threads that are ready to run. 169 /// Returns whether there are any threads that are ready to run.
@@ -220,7 +220,7 @@ private:
220 Core::ARM_Interface& cpu_core; 220 Core::ARM_Interface& cpu_core;
221 u64 last_context_switch_time = 0; 221 u64 last_context_switch_time = 0;
222 u64 idle_selection_count = 0; 222 u64 idle_selection_count = 0;
223 const u32 core_id; 223 const std::size_t core_id;
224 224
225 bool is_context_switch_pending = false; 225 bool is_context_switch_pending = false;
226}; 226};
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 962530d2d..ee7531f2d 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -77,18 +77,6 @@ void Thread::CancelWakeupTimer() {
77 callback_handle); 77 callback_handle);
78} 78}
79 79
80static std::optional<s32> GetNextProcessorId(u64 mask) {
81 for (s32 index = 0; index < Core::NUM_CPU_CORES; ++index) {
82 if (mask & (1ULL << index)) {
83 if (!Core::System::GetInstance().Scheduler(index).GetCurrentThread()) {
84 // Core is enabled and not running any threads, use this one
85 return index;
86 }
87 }
88 }
89 return {};
90}
91
92void Thread::ResumeFromWait() { 80void Thread::ResumeFromWait() {
93 ASSERT_MSG(wait_objects.empty(), "Thread is waking up while waiting for objects"); 81 ASSERT_MSG(wait_objects.empty(), "Thread is waking up while waiting for objects");
94 82
@@ -173,7 +161,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
173 if (!Memory::IsValidVirtualAddress(owner_process, entry_point)) { 161 if (!Memory::IsValidVirtualAddress(owner_process, entry_point)) {
174 LOG_ERROR(Kernel_SVC, "(name={}): invalid entry {:016X}", name, entry_point); 162 LOG_ERROR(Kernel_SVC, "(name={}): invalid entry {:016X}", name, entry_point);
175 // TODO (bunnei): Find the correct error code to use here 163 // TODO (bunnei): Find the correct error code to use here
176 return ResultCode(-1); 164 return RESULT_UNKNOWN;
177 } 165 }
178 166
179 auto& system = Core::System::GetInstance(); 167 auto& system = Core::System::GetInstance();
@@ -401,7 +389,7 @@ void Thread::SetCurrentPriority(u32 new_priority) {
401 389
402ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) { 390ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) {
403 const auto HighestSetCore = [](u64 mask, u32 max_cores) { 391 const auto HighestSetCore = [](u64 mask, u32 max_cores) {
404 for (s32 core = max_cores - 1; core >= 0; core--) { 392 for (s32 core = static_cast<s32>(max_cores - 1); core >= 0; core--) {
405 if (((mask >> core) & 1) != 0) { 393 if (((mask >> core) & 1) != 0) {
406 return core; 394 return core;
407 } 395 }
@@ -425,7 +413,7 @@ ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) {
425 if (old_affinity_mask != new_affinity_mask) { 413 if (old_affinity_mask != new_affinity_mask) {
426 const s32 old_core = processor_id; 414 const s32 old_core = processor_id;
427 if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { 415 if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) {
428 if (ideal_core < 0) { 416 if (static_cast<s32>(ideal_core) < 0) {
429 processor_id = HighestSetCore(affinity_mask, GlobalScheduler::NUM_CPU_CORES); 417 processor_id = HighestSetCore(affinity_mask, GlobalScheduler::NUM_CPU_CORES);
430 } else { 418 } else {
431 processor_id = ideal_core; 419 processor_id = ideal_core;
@@ -447,23 +435,23 @@ void Thread::AdjustSchedulingOnStatus(u32 old_flags) {
447 ThreadSchedStatus::Runnable) { 435 ThreadSchedStatus::Runnable) {
448 // In this case the thread was running, now it's pausing/exitting 436 // In this case the thread was running, now it's pausing/exitting
449 if (processor_id >= 0) { 437 if (processor_id >= 0) {
450 scheduler.Unschedule(current_priority, processor_id, this); 438 scheduler.Unschedule(current_priority, static_cast<u32>(processor_id), this);
451 } 439 }
452 440
453 for (s32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 441 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
454 if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { 442 if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) {
455 scheduler.Unsuggest(current_priority, static_cast<u32>(core), this); 443 scheduler.Unsuggest(current_priority, core, this);
456 } 444 }
457 } 445 }
458 } else if (GetSchedulingStatus() == ThreadSchedStatus::Runnable) { 446 } else if (GetSchedulingStatus() == ThreadSchedStatus::Runnable) {
459 // The thread is now set to running from being stopped 447 // The thread is now set to running from being stopped
460 if (processor_id >= 0) { 448 if (processor_id >= 0) {
461 scheduler.Schedule(current_priority, processor_id, this); 449 scheduler.Schedule(current_priority, static_cast<u32>(processor_id), this);
462 } 450 }
463 451
464 for (s32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 452 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
465 if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { 453 if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) {
466 scheduler.Suggest(current_priority, static_cast<u32>(core), this); 454 scheduler.Suggest(current_priority, core, this);
467 } 455 }
468 } 456 }
469 } 457 }
@@ -477,11 +465,11 @@ void Thread::AdjustSchedulingOnPriority(u32 old_priority) {
477 } 465 }
478 auto& scheduler = Core::System::GetInstance().GlobalScheduler(); 466 auto& scheduler = Core::System::GetInstance().GlobalScheduler();
479 if (processor_id >= 0) { 467 if (processor_id >= 0) {
480 scheduler.Unschedule(old_priority, processor_id, this); 468 scheduler.Unschedule(old_priority, static_cast<u32>(processor_id), this);
481 } 469 }
482 470
483 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 471 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
484 if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { 472 if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) {
485 scheduler.Unsuggest(old_priority, core, this); 473 scheduler.Unsuggest(old_priority, core, this);
486 } 474 }
487 } 475 }
@@ -491,14 +479,14 @@ void Thread::AdjustSchedulingOnPriority(u32 old_priority) {
491 479
492 if (processor_id >= 0) { 480 if (processor_id >= 0) {
493 if (current_thread == this) { 481 if (current_thread == this) {
494 scheduler.SchedulePrepend(current_priority, processor_id, this); 482 scheduler.SchedulePrepend(current_priority, static_cast<u32>(processor_id), this);
495 } else { 483 } else {
496 scheduler.Schedule(current_priority, processor_id, this); 484 scheduler.Schedule(current_priority, static_cast<u32>(processor_id), this);
497 } 485 }
498 } 486 }
499 487
500 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 488 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
501 if (core != processor_id && ((affinity_mask >> core) & 1) != 0) { 489 if (core != static_cast<u32>(processor_id) && ((affinity_mask >> core) & 1) != 0) {
502 scheduler.Suggest(current_priority, core, this); 490 scheduler.Suggest(current_priority, core, this);
503 } 491 }
504 } 492 }
@@ -515,7 +503,7 @@ void Thread::AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core) {
515 503
516 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 504 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
517 if (((old_affinity_mask >> core) & 1) != 0) { 505 if (((old_affinity_mask >> core) & 1) != 0) {
518 if (core == old_core) { 506 if (core == static_cast<u32>(old_core)) {
519 scheduler.Unschedule(current_priority, core, this); 507 scheduler.Unschedule(current_priority, core, this);
520 } else { 508 } else {
521 scheduler.Unsuggest(current_priority, core, this); 509 scheduler.Unsuggest(current_priority, core, this);
@@ -525,7 +513,7 @@ void Thread::AdjustSchedulingOnAffinity(u64 old_affinity_mask, s32 old_core) {
525 513
526 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) { 514 for (u32 core = 0; core < GlobalScheduler::NUM_CPU_CORES; core++) {
527 if (((affinity_mask >> core) & 1) != 0) { 515 if (((affinity_mask >> core) & 1) != 0) {
528 if (core == processor_id) { 516 if (core == static_cast<u32>(processor_id)) {
529 scheduler.Schedule(current_priority, core, this); 517 scheduler.Schedule(current_priority, core, this);
530 } else { 518 } else {
531 scheduler.Suggest(current_priority, core, this); 519 scheduler.Suggest(current_priority, core, this);
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index c7af87073..e6eee09d7 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -167,7 +167,7 @@ ResultVal<VAddr> VMManager::FindFreeRegion(VAddr begin, VAddr end, u64 size) con
167 167
168 if (vma_handle == vma_map.cend()) { 168 if (vma_handle == vma_map.cend()) {
169 // TODO(Subv): Find the correct error code here. 169 // TODO(Subv): Find the correct error code here.
170 return ResultCode(-1); 170 return RESULT_UNKNOWN;
171 } 171 }
172 172
173 const VAddr target = std::max(begin, vma_handle->second.base); 173 const VAddr target = std::max(begin, vma_handle->second.base);
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index 8a3701151..450f61fea 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -147,6 +147,14 @@ constexpr bool operator!=(const ResultCode& a, const ResultCode& b) {
147constexpr ResultCode RESULT_SUCCESS(0); 147constexpr ResultCode RESULT_SUCCESS(0);
148 148
149/** 149/**
150 * Placeholder result code used for unknown error codes.
151 *
152 * @note This should only be used when a particular error code
153 * is not known yet.
154 */
155constexpr ResultCode RESULT_UNKNOWN(UINT32_MAX);
156
157/**
150 * This is an optional value type. It holds a `ResultCode` and, if that code is a success code, 158 * This is an optional value type. It holds a `ResultCode` and, if that code is a success code,
151 * also holds a result of type `T`. If the code is an error code then trying to access the inner 159 * also holds a result of type `T`. If the code is an error code then trying to access the inner
152 * value fails, thus ensuring that the ResultCode of functions is always checked properly before 160 * value fails, thus ensuring that the ResultCode of functions is always checked properly before
@@ -183,7 +191,7 @@ class ResultVal {
183public: 191public:
184 /// Constructs an empty `ResultVal` with the given error code. The code must not be a success 192 /// Constructs an empty `ResultVal` with the given error code. The code must not be a success
185 /// code. 193 /// code.
186 ResultVal(ResultCode error_code = ResultCode(-1)) : result_code(error_code) { 194 ResultVal(ResultCode error_code = RESULT_UNKNOWN) : result_code(error_code) {
187 ASSERT(error_code.IsError()); 195 ASSERT(error_code.IsError());
188 } 196 }
189 197
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index 0c0f7ed6e..7e3e311fb 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -84,7 +84,7 @@ protected:
84 LOG_ERROR(Service_ACC, "Failed to get profile base and data for user={}", 84 LOG_ERROR(Service_ACC, "Failed to get profile base and data for user={}",
85 user_id.Format()); 85 user_id.Format());
86 IPC::ResponseBuilder rb{ctx, 2}; 86 IPC::ResponseBuilder rb{ctx, 2};
87 rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code 87 rb.Push(RESULT_UNKNOWN); // TODO(ogniK): Get actual error code
88 } 88 }
89 } 89 }
90 90
@@ -98,7 +98,7 @@ protected:
98 } else { 98 } else {
99 LOG_ERROR(Service_ACC, "Failed to get profile base for user={}", user_id.Format()); 99 LOG_ERROR(Service_ACC, "Failed to get profile base for user={}", user_id.Format());
100 IPC::ResponseBuilder rb{ctx, 2}; 100 IPC::ResponseBuilder rb{ctx, 2};
101 rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code 101 rb.Push(RESULT_UNKNOWN); // TODO(ogniK): Get actual error code
102 } 102 }
103 } 103 }
104 104
@@ -442,7 +442,7 @@ void Module::Interface::TrySelectUserWithoutInteraction(Kernel::HLERequestContex
442 const auto user_list = profile_manager->GetAllUsers(); 442 const auto user_list = profile_manager->GetAllUsers();
443 if (std::all_of(user_list.begin(), user_list.end(), 443 if (std::all_of(user_list.begin(), user_list.end(),
444 [](const auto& user) { return user.uuid == Common::INVALID_UUID; })) { 444 [](const auto& user) { return user.uuid == Common::INVALID_UUID; })) {
445 rb.Push(ResultCode(-1)); // TODO(ogniK): Find the correct error code 445 rb.Push(RESULT_UNKNOWN); // TODO(ogniK): Find the correct error code
446 rb.PushRaw<u128>(Common::INVALID_UUID); 446 rb.PushRaw<u128>(Common::INVALID_UUID);
447 return; 447 return;
448 } 448 }
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 8f9986326..3e756e59e 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -31,8 +31,8 @@ struct ProfileDataRaw {
31static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size."); 31static_assert(sizeof(ProfileDataRaw) == 0x650, "ProfileDataRaw has incorrect size.");
32 32
33// TODO(ogniK): Get actual error codes 33// TODO(ogniK): Get actual error codes
34constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, -1); 34constexpr ResultCode ERROR_TOO_MANY_USERS(ErrorModule::Account, u32(-1));
35constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); 35constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, u32(-2));
36constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); 36constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20);
37 37
38constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/"; 38constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/avators/";
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index d52ec4387..a5702e1ab 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -991,7 +991,7 @@ void ILibraryAppletCreator::CreateLibraryApplet(Kernel::HLERequestContext& ctx)
991 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", static_cast<u32>(applet_id)); 991 LOG_ERROR(Service_AM, "Applet doesn't exist! applet_id={}", static_cast<u32>(applet_id));
992 992
993 IPC::ResponseBuilder rb{ctx, 2}; 993 IPC::ResponseBuilder rb{ctx, 2};
994 rb.Push(ResultCode(-1)); 994 rb.Push(RESULT_UNKNOWN);
995 return; 995 return;
996 } 996 }
997 997
@@ -1027,7 +1027,7 @@ void ILibraryAppletCreator::CreateTransferMemoryStorage(Kernel::HLERequestContex
1027 if (transfer_mem == nullptr) { 1027 if (transfer_mem == nullptr) {
1028 LOG_ERROR(Service_AM, "shared_mem is a nullpr for handle={:08X}", handle); 1028 LOG_ERROR(Service_AM, "shared_mem is a nullpr for handle={:08X}", handle);
1029 IPC::ResponseBuilder rb{ctx, 2}; 1029 IPC::ResponseBuilder rb{ctx, 2};
1030 rb.Push(ResultCode(-1)); 1030 rb.Push(RESULT_UNKNOWN);
1031 return; 1031 return;
1032 } 1032 }
1033 1033
diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp
index 32283e819..5546ef6e8 100644
--- a/src/core/hle/service/am/applets/web_browser.cpp
+++ b/src/core/hle/service/am/applets/web_browser.cpp
@@ -337,7 +337,7 @@ void WebBrowser::ExecuteInternal() {
337void WebBrowser::InitializeShop() { 337void WebBrowser::InitializeShop() {
338 if (frontend_e_commerce == nullptr) { 338 if (frontend_e_commerce == nullptr) {
339 LOG_ERROR(Service_AM, "Missing ECommerce Applet frontend!"); 339 LOG_ERROR(Service_AM, "Missing ECommerce Applet frontend!");
340 status = ResultCode(-1); 340 status = RESULT_UNKNOWN;
341 return; 341 return;
342 } 342 }
343 343
@@ -353,7 +353,7 @@ void WebBrowser::InitializeShop() {
353 353
354 if (url == args.end()) { 354 if (url == args.end()) {
355 LOG_ERROR(Service_AM, "Missing EShop Arguments URL for initialization!"); 355 LOG_ERROR(Service_AM, "Missing EShop Arguments URL for initialization!");
356 status = ResultCode(-1); 356 status = RESULT_UNKNOWN;
357 return; 357 return;
358 } 358 }
359 359
@@ -366,7 +366,7 @@ void WebBrowser::InitializeShop() {
366 // Less is missing info, More is malformed 366 // Less is missing info, More is malformed
367 if (split_query.size() != 2) { 367 if (split_query.size() != 2) {
368 LOG_ERROR(Service_AM, "EShop Arguments has more than one question mark, malformed"); 368 LOG_ERROR(Service_AM, "EShop Arguments has more than one question mark, malformed");
369 status = ResultCode(-1); 369 status = RESULT_UNKNOWN;
370 return; 370 return;
371 } 371 }
372 372
@@ -390,7 +390,7 @@ void WebBrowser::InitializeShop() {
390 390
391 if (scene == shop_query.end()) { 391 if (scene == shop_query.end()) {
392 LOG_ERROR(Service_AM, "No scene parameter was passed via shop query!"); 392 LOG_ERROR(Service_AM, "No scene parameter was passed via shop query!");
393 status = ResultCode(-1); 393 status = RESULT_UNKNOWN;
394 return; 394 return;
395 } 395 }
396 396
@@ -406,7 +406,7 @@ void WebBrowser::InitializeShop() {
406 const auto target = target_map.find(scene->second); 406 const auto target = target_map.find(scene->second);
407 if (target == target_map.end()) { 407 if (target == target_map.end()) {
408 LOG_ERROR(Service_AM, "Scene for shop query is invalid! (scene={})", scene->second); 408 LOG_ERROR(Service_AM, "Scene for shop query is invalid! (scene={})", scene->second);
409 status = ResultCode(-1); 409 status = RESULT_UNKNOWN;
410 return; 410 return;
411 } 411 }
412 412
@@ -427,7 +427,7 @@ void WebBrowser::InitializeOffline() {
427 if (args.find(WebArgTLVType::DocumentPath) == args.end() || 427 if (args.find(WebArgTLVType::DocumentPath) == args.end() ||
428 args.find(WebArgTLVType::DocumentKind) == args.end() || 428 args.find(WebArgTLVType::DocumentKind) == args.end() ||
429 args.find(WebArgTLVType::ApplicationID) == args.end()) { 429 args.find(WebArgTLVType::ApplicationID) == args.end()) {
430 status = ResultCode(-1); 430 status = RESULT_UNKNOWN;
431 LOG_ERROR(Service_AM, "Missing necessary parameters for initialization!"); 431 LOG_ERROR(Service_AM, "Missing necessary parameters for initialization!");
432 } 432 }
433 433
@@ -476,7 +476,7 @@ void WebBrowser::InitializeOffline() {
476 476
477 offline_romfs = GetApplicationRomFS(system, title_id, type); 477 offline_romfs = GetApplicationRomFS(system, title_id, type);
478 if (offline_romfs == nullptr) { 478 if (offline_romfs == nullptr) {
479 status = ResultCode(-1); 479 status = RESULT_UNKNOWN;
480 LOG_ERROR(Service_AM, "Failed to find offline data for request!"); 480 LOG_ERROR(Service_AM, "Failed to find offline data for request!");
481 } 481 }
482 482
@@ -496,7 +496,7 @@ void WebBrowser::ExecuteShop() {
496 const auto check_optional_parameter = [this](const auto& p) { 496 const auto check_optional_parameter = [this](const auto& p) {
497 if (!p.has_value()) { 497 if (!p.has_value()) {
498 LOG_ERROR(Service_AM, "Missing one or more necessary parameters for execution!"); 498 LOG_ERROR(Service_AM, "Missing one or more necessary parameters for execution!");
499 status = ResultCode(-1); 499 status = RESULT_UNKNOWN;
500 return false; 500 return false;
501 } 501 }
502 502
diff --git a/src/core/hle/service/aoc/aoc_u.cpp b/src/core/hle/service/aoc/aoc_u.cpp
index f36ccbc49..30076a53e 100644
--- a/src/core/hle/service/aoc/aoc_u.cpp
+++ b/src/core/hle/service/aoc/aoc_u.cpp
@@ -131,7 +131,7 @@ void AOC_U::ListAddOnContent(Kernel::HLERequestContext& ctx) {
131 if (out.size() < offset) { 131 if (out.size() < offset) {
132 IPC::ResponseBuilder rb{ctx, 2}; 132 IPC::ResponseBuilder rb{ctx, 2};
133 // TODO(DarkLordZach): Find the correct error code. 133 // TODO(DarkLordZach): Find the correct error code.
134 rb.Push(ResultCode(-1)); 134 rb.Push(RESULT_UNKNOWN);
135 return; 135 return;
136 } 136 }
137 137
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index cb4a1160d..cb839e4a2 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -80,7 +80,7 @@ private:
80 LOG_ERROR(Audio, "Failed to decode opus data"); 80 LOG_ERROR(Audio, "Failed to decode opus data");
81 IPC::ResponseBuilder rb{ctx, 2}; 81 IPC::ResponseBuilder rb{ctx, 2};
82 // TODO(ogniK): Use correct error code 82 // TODO(ogniK): Use correct error code
83 rb.Push(ResultCode(-1)); 83 rb.Push(RESULT_UNKNOWN);
84 return; 84 return;
85 } 85 }
86 86
@@ -278,7 +278,7 @@ void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
278 LOG_ERROR(Audio, "Failed to create Opus decoder (error={}).", error); 278 LOG_ERROR(Audio, "Failed to create Opus decoder (error={}).", error);
279 IPC::ResponseBuilder rb{ctx, 2}; 279 IPC::ResponseBuilder rb{ctx, 2};
280 // TODO(ogniK): Use correct error code 280 // TODO(ogniK): Use correct error code
281 rb.Push(ResultCode(-1)); 281 rb.Push(RESULT_UNKNOWN);
282 return; 282 return;
283 } 283 }
284 284
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
index 1411a646f..67e39a5c4 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -114,7 +114,7 @@ void HandleDownloadDisplayResult(const AM::Applets::AppletManager& applet_manage
114 114
115 const auto& frontend{applet_manager.GetAppletFrontendSet()}; 115 const auto& frontend{applet_manager.GetAppletFrontendSet()};
116 frontend.error->ShowCustomErrorText( 116 frontend.error->ShowCustomErrorText(
117 ResultCode(-1), "There was an error while attempting to use Boxcat.", 117 RESULT_UNKNOWN, "There was an error while attempting to use Boxcat.",
118 DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {}); 118 DOWNLOAD_RESULT_LOG_MESSAGES[static_cast<std::size_t>(res)], [] {});
119} 119}
120 120
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp
index 11e5c56b7..102017d73 100644
--- a/src/core/hle/service/filesystem/filesystem.cpp
+++ b/src/core/hle/service/filesystem/filesystem.cpp
@@ -58,11 +58,11 @@ ResultCode VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64
58 auto file = dir->CreateFile(FileUtil::GetFilename(path)); 58 auto file = dir->CreateFile(FileUtil::GetFilename(path));
59 if (file == nullptr) { 59 if (file == nullptr) {
60 // TODO(DarkLordZach): Find a better error code for this 60 // TODO(DarkLordZach): Find a better error code for this
61 return ResultCode(-1); 61 return RESULT_UNKNOWN;
62 } 62 }
63 if (!file->Resize(size)) { 63 if (!file->Resize(size)) {
64 // TODO(DarkLordZach): Find a better error code for this 64 // TODO(DarkLordZach): Find a better error code for this
65 return ResultCode(-1); 65 return RESULT_UNKNOWN;
66 } 66 }
67 return RESULT_SUCCESS; 67 return RESULT_SUCCESS;
68} 68}
@@ -80,7 +80,7 @@ ResultCode VfsDirectoryServiceWrapper::DeleteFile(const std::string& path_) cons
80 } 80 }
81 if (!dir->DeleteFile(FileUtil::GetFilename(path))) { 81 if (!dir->DeleteFile(FileUtil::GetFilename(path))) {
82 // TODO(DarkLordZach): Find a better error code for this 82 // TODO(DarkLordZach): Find a better error code for this
83 return ResultCode(-1); 83 return RESULT_UNKNOWN;
84 } 84 }
85 85
86 return RESULT_SUCCESS; 86 return RESULT_SUCCESS;
@@ -94,7 +94,7 @@ ResultCode VfsDirectoryServiceWrapper::CreateDirectory(const std::string& path_)
94 auto new_dir = dir->CreateSubdirectory(FileUtil::GetFilename(path)); 94 auto new_dir = dir->CreateSubdirectory(FileUtil::GetFilename(path));
95 if (new_dir == nullptr) { 95 if (new_dir == nullptr) {
96 // TODO(DarkLordZach): Find a better error code for this 96 // TODO(DarkLordZach): Find a better error code for this
97 return ResultCode(-1); 97 return RESULT_UNKNOWN;
98 } 98 }
99 return RESULT_SUCCESS; 99 return RESULT_SUCCESS;
100} 100}
@@ -104,7 +104,7 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectory(const std::string& path_)
104 auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); 104 auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
105 if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) { 105 if (!dir->DeleteSubdirectory(FileUtil::GetFilename(path))) {
106 // TODO(DarkLordZach): Find a better error code for this 106 // TODO(DarkLordZach): Find a better error code for this
107 return ResultCode(-1); 107 return RESULT_UNKNOWN;
108 } 108 }
109 return RESULT_SUCCESS; 109 return RESULT_SUCCESS;
110} 110}
@@ -114,7 +114,7 @@ ResultCode VfsDirectoryServiceWrapper::DeleteDirectoryRecursively(const std::str
114 auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path)); 114 auto dir = GetDirectoryRelativeWrapped(backing, FileUtil::GetParentPath(path));
115 if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) { 115 if (!dir->DeleteSubdirectoryRecursive(FileUtil::GetFilename(path))) {
116 // TODO(DarkLordZach): Find a better error code for this 116 // TODO(DarkLordZach): Find a better error code for this
117 return ResultCode(-1); 117 return RESULT_UNKNOWN;
118 } 118 }
119 return RESULT_SUCCESS; 119 return RESULT_SUCCESS;
120} 120}
@@ -125,7 +125,7 @@ ResultCode VfsDirectoryServiceWrapper::CleanDirectoryRecursively(const std::stri
125 125
126 if (!dir->CleanSubdirectoryRecursive(FileUtil::GetFilename(sanitized_path))) { 126 if (!dir->CleanSubdirectoryRecursive(FileUtil::GetFilename(sanitized_path))) {
127 // TODO(DarkLordZach): Find a better error code for this 127 // TODO(DarkLordZach): Find a better error code for this
128 return ResultCode(-1); 128 return RESULT_UNKNOWN;
129 } 129 }
130 130
131 return RESULT_SUCCESS; 131 return RESULT_SUCCESS;
@@ -142,7 +142,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
142 return FileSys::ERROR_PATH_NOT_FOUND; 142 return FileSys::ERROR_PATH_NOT_FOUND;
143 if (!src->Rename(FileUtil::GetFilename(dest_path))) { 143 if (!src->Rename(FileUtil::GetFilename(dest_path))) {
144 // TODO(DarkLordZach): Find a better error code for this 144 // TODO(DarkLordZach): Find a better error code for this
145 return ResultCode(-1); 145 return RESULT_UNKNOWN;
146 } 146 }
147 return RESULT_SUCCESS; 147 return RESULT_SUCCESS;
148 } 148 }
@@ -160,7 +160,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameFile(const std::string& src_path_,
160 160
161 if (!src->GetContainingDirectory()->DeleteFile(FileUtil::GetFilename(src_path))) { 161 if (!src->GetContainingDirectory()->DeleteFile(FileUtil::GetFilename(src_path))) {
162 // TODO(DarkLordZach): Find a better error code for this 162 // TODO(DarkLordZach): Find a better error code for this
163 return ResultCode(-1); 163 return RESULT_UNKNOWN;
164 } 164 }
165 165
166 return RESULT_SUCCESS; 166 return RESULT_SUCCESS;
@@ -177,7 +177,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
177 return FileSys::ERROR_PATH_NOT_FOUND; 177 return FileSys::ERROR_PATH_NOT_FOUND;
178 if (!src->Rename(FileUtil::GetFilename(dest_path))) { 178 if (!src->Rename(FileUtil::GetFilename(dest_path))) {
179 // TODO(DarkLordZach): Find a better error code for this 179 // TODO(DarkLordZach): Find a better error code for this
180 return ResultCode(-1); 180 return RESULT_UNKNOWN;
181 } 181 }
182 return RESULT_SUCCESS; 182 return RESULT_SUCCESS;
183 } 183 }
@@ -189,7 +189,7 @@ ResultCode VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_pa
189 src_path, dest_path); 189 src_path, dest_path);
190 190
191 // TODO(DarkLordZach): Find a better error code for this 191 // TODO(DarkLordZach): Find a better error code for this
192 return ResultCode(-1); 192 return RESULT_UNKNOWN;
193} 193}
194 194
195ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, 195ResultVal<FileSys::VirtualFile> VfsDirectoryServiceWrapper::OpenFile(const std::string& path_,
@@ -287,7 +287,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFSCurrentProcess()
287 287
288 if (romfs_factory == nullptr) { 288 if (romfs_factory == nullptr) {
289 // TODO(bunnei): Find a better error code for this 289 // TODO(bunnei): Find a better error code for this
290 return ResultCode(-1); 290 return RESULT_UNKNOWN;
291 } 291 }
292 292
293 return romfs_factory->OpenCurrentProcess(system.CurrentProcess()->GetTitleID()); 293 return romfs_factory->OpenCurrentProcess(system.CurrentProcess()->GetTitleID());
@@ -300,7 +300,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFS(
300 300
301 if (romfs_factory == nullptr) { 301 if (romfs_factory == nullptr) {
302 // TODO(bunnei): Find a better error code for this 302 // TODO(bunnei): Find a better error code for this
303 return ResultCode(-1); 303 return RESULT_UNKNOWN;
304 } 304 }
305 305
306 return romfs_factory->Open(title_id, storage_id, type); 306 return romfs_factory->Open(title_id, storage_id, type);
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index cbd5466c1..92162d3e1 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -785,7 +785,7 @@ void FSP_SRV::OpenFileSystemWithPatch(Kernel::HLERequestContext& ctx) {
785 static_cast<u8>(type), title_id); 785 static_cast<u8>(type), title_id);
786 786
787 IPC::ResponseBuilder rb{ctx, 2, 0, 0}; 787 IPC::ResponseBuilder rb{ctx, 2, 0, 0};
788 rb.Push(ResultCode(-1)); 788 rb.Push(RESULT_UNKNOWN);
789} 789}
790 790
791void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { 791void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) {
@@ -891,7 +891,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
891 // TODO (bunnei): Find the right error code to use here 891 // TODO (bunnei): Find the right error code to use here
892 LOG_CRITICAL(Service_FS, "no file system interface available!"); 892 LOG_CRITICAL(Service_FS, "no file system interface available!");
893 IPC::ResponseBuilder rb{ctx, 2}; 893 IPC::ResponseBuilder rb{ctx, 2};
894 rb.Push(ResultCode(-1)); 894 rb.Push(RESULT_UNKNOWN);
895 return; 895 return;
896 } 896 }
897 897
@@ -928,7 +928,7 @@ void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) {
928 "could not open data storage with title_id={:016X}, storage_id={:02X}", title_id, 928 "could not open data storage with title_id={:016X}, storage_id={:02X}", title_id,
929 static_cast<u8>(storage_id)); 929 static_cast<u8>(storage_id));
930 IPC::ResponseBuilder rb{ctx, 2}; 930 IPC::ResponseBuilder rb{ctx, 2};
931 rb.Push(ResultCode(-1)); 931 rb.Push(RESULT_UNKNOWN);
932 return; 932 return;
933 } 933 }
934 934
diff --git a/src/core/hle/service/mii/mii.cpp b/src/core/hle/service/mii/mii.cpp
index 0b3923ad9..0ffc5009e 100644
--- a/src/core/hle/service/mii/mii.cpp
+++ b/src/core/hle/service/mii/mii.cpp
@@ -242,7 +242,7 @@ private:
242 const auto index = db.IndexOf(uuid); 242 const auto index = db.IndexOf(uuid);
243 if (index > MAX_MIIS) { 243 if (index > MAX_MIIS) {
244 // TODO(DarkLordZach): Find a better error code 244 // TODO(DarkLordZach): Find a better error code
245 rb.Push(ResultCode(-1)); 245 rb.Push(RESULT_UNKNOWN);
246 rb.Push(index); 246 rb.Push(index);
247 } else { 247 } else {
248 rb.Push(RESULT_SUCCESS); 248 rb.Push(RESULT_SUCCESS);
@@ -268,7 +268,7 @@ private:
268 268
269 IPC::ResponseBuilder rb{ctx, 2}; 269 IPC::ResponseBuilder rb{ctx, 2};
270 // TODO(DarkLordZach): Find a better error code 270 // TODO(DarkLordZach): Find a better error code
271 rb.Push(success ? RESULT_SUCCESS : ResultCode(-1)); 271 rb.Push(success ? RESULT_SUCCESS : RESULT_UNKNOWN);
272 } 272 }
273 273
274 void AddOrReplace(Kernel::HLERequestContext& ctx) { 274 void AddOrReplace(Kernel::HLERequestContext& ctx) {
@@ -282,7 +282,7 @@ private:
282 282
283 IPC::ResponseBuilder rb{ctx, 2}; 283 IPC::ResponseBuilder rb{ctx, 2};
284 // TODO(DarkLordZach): Find a better error code 284 // TODO(DarkLordZach): Find a better error code
285 rb.Push(success ? RESULT_SUCCESS : ResultCode(-1)); 285 rb.Push(success ? RESULT_SUCCESS : RESULT_UNKNOWN);
286 } 286 }
287 287
288 void Delete(Kernel::HLERequestContext& ctx) { 288 void Delete(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index 795d7b716..3bf753dee 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -16,10 +16,7 @@
16#include "core/hle/service/nfp/nfp_user.h" 16#include "core/hle/service/nfp/nfp_user.h"
17 17
18namespace Service::NFP { 18namespace Service::NFP {
19
20namespace ErrCodes { 19namespace ErrCodes {
21[[maybe_unused]] constexpr ResultCode ERR_TAG_FAILED(ErrorModule::NFP,
22 -1); // TODO(ogniK): Find the actual error code
23constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152); 20constexpr ResultCode ERR_NO_APPLICATION_AREA(ErrorModule::NFP, 152);
24} // namespace ErrCodes 21} // namespace ErrCodes
25 22
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp
index 15c156ce1..eeba0aa19 100644
--- a/src/core/hle/service/ns/ns.cpp
+++ b/src/core/hle/service/ns/ns.cpp
@@ -271,7 +271,7 @@ void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestC
271 "output buffer is too small! (actual={:016X}, expected_min=0x4000)", size); 271 "output buffer is too small! (actual={:016X}, expected_min=0x4000)", size);
272 IPC::ResponseBuilder rb{ctx, 2}; 272 IPC::ResponseBuilder rb{ctx, 2};
273 // TODO(DarkLordZach): Find a better error code for this. 273 // TODO(DarkLordZach): Find a better error code for this.
274 rb.Push(ResultCode(-1)); 274 rb.Push(RESULT_UNKNOWN);
275 return; 275 return;
276 } 276 }
277 277
@@ -291,7 +291,7 @@ void IApplicationManagerInterface::GetApplicationControlData(Kernel::HLERequestC
291 0x4000 + control.second->GetSize()); 291 0x4000 + control.second->GetSize());
292 IPC::ResponseBuilder rb{ctx, 2}; 292 IPC::ResponseBuilder rb{ctx, 2};
293 // TODO(DarkLordZach): Find a better error code for this. 293 // TODO(DarkLordZach): Find a better error code for this.
294 rb.Push(ResultCode(-1)); 294 rb.Push(RESULT_UNKNOWN);
295 return; 295 return;
296 } 296 }
297 297
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 23477315f..db433305f 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -97,7 +97,7 @@ void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output,
97 const auto key = Common::swap32(EXPECTED_RESULT ^ EXPECTED_MAGIC); 97 const auto key = Common::swap32(EXPECTED_RESULT ^ EXPECTED_MAGIC);
98 std::vector<u32> transformed_font(input.size() + 2); 98 std::vector<u32> transformed_font(input.size() + 2);
99 transformed_font[0] = Common::swap32(EXPECTED_MAGIC); 99 transformed_font[0] = Common::swap32(EXPECTED_MAGIC);
100 transformed_font[1] = Common::swap32(input.size() * sizeof(u32)) ^ key; 100 transformed_font[1] = Common::swap32(static_cast<u32>(input.size() * sizeof(u32))) ^ key;
101 std::transform(input.begin(), input.end(), transformed_font.begin() + 2, 101 std::transform(input.begin(), input.end(), transformed_font.begin() + 2,
102 [key](u32 in) { return in ^ key; }); 102 [key](u32 in) { return in ^ key; });
103 std::memcpy(output.data() + offset, transformed_font.data(), 103 std::memcpy(output.data() + offset, transformed_font.data(),
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp
index 1b9ab8401..62efe021e 100644
--- a/src/core/hle/service/time/time.cpp
+++ b/src/core/hle/service/time/time.cpp
@@ -34,12 +34,12 @@ static void PosixToCalendar(u64 posix_time, CalendarTime& calendar_time,
34 additional_info = {}; 34 additional_info = {};
35 return; 35 return;
36 } 36 }
37 calendar_time.year = tm->tm_year + 1900; 37 calendar_time.year = static_cast<u16_le>(tm->tm_year + 1900);
38 calendar_time.month = tm->tm_mon + 1; 38 calendar_time.month = static_cast<u8>(tm->tm_mon + 1);
39 calendar_time.day = tm->tm_mday; 39 calendar_time.day = static_cast<u8>(tm->tm_mday);
40 calendar_time.hour = tm->tm_hour; 40 calendar_time.hour = static_cast<u8>(tm->tm_hour);
41 calendar_time.minute = tm->tm_min; 41 calendar_time.minute = static_cast<u8>(tm->tm_min);
42 calendar_time.second = tm->tm_sec; 42 calendar_time.second = static_cast<u8>(tm->tm_sec);
43 43
44 additional_info.day_of_week = tm->tm_wday; 44 additional_info.day_of_week = tm->tm_wday;
45 additional_info.day_of_year = tm->tm_yday; 45 additional_info.day_of_year = tm->tm_yday;
@@ -322,7 +322,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
322 if (tm == nullptr) { 322 if (tm == nullptr) {
323 LOG_ERROR(Service_Time, "tm is a nullptr"); 323 LOG_ERROR(Service_Time, "tm is a nullptr");
324 IPC::ResponseBuilder rb{ctx, 2}; 324 IPC::ResponseBuilder rb{ctx, 2};
325 rb.Push(ResultCode(-1)); // TODO(ogniK): Find appropriate error code 325 rb.Push(RESULT_UNKNOWN); // TODO(ogniK): Find appropriate error code
326 return; 326 return;
327 } 327 }
328 328
@@ -331,12 +331,12 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) {
331 const SteadyClockTimePoint steady_clock_time_point{static_cast<u64_le>(ms.count() / 1000), {}}; 331 const SteadyClockTimePoint steady_clock_time_point{static_cast<u64_le>(ms.count() / 1000), {}};
332 332
333 CalendarTime calendar_time{}; 333 CalendarTime calendar_time{};
334 calendar_time.year = tm->tm_year + 1900; 334 calendar_time.year = static_cast<u16_le>(tm->tm_year + 1900);
335 calendar_time.month = tm->tm_mon + 1; 335 calendar_time.month = static_cast<u8>(tm->tm_mon + 1);
336 calendar_time.day = tm->tm_mday; 336 calendar_time.day = static_cast<u8>(tm->tm_mday);
337 calendar_time.hour = tm->tm_hour; 337 calendar_time.hour = static_cast<u8>(tm->tm_hour);
338 calendar_time.minute = tm->tm_min; 338 calendar_time.minute = static_cast<u8>(tm->tm_min);
339 calendar_time.second = tm->tm_sec; 339 calendar_time.second = static_cast<u8>(tm->tm_sec);
340 340
341 ClockSnapshot clock_snapshot{}; 341 ClockSnapshot clock_snapshot{};
342 clock_snapshot.system_posix_time = time_since_epoch; 342 clock_snapshot.system_posix_time = time_since_epoch;
diff --git a/src/core/hle/service/vi/vi.cpp b/src/core/hle/service/vi/vi.cpp
index 611cecc20..abfc3a801 100644
--- a/src/core/hle/service/vi/vi.cpp
+++ b/src/core/hle/service/vi/vi.cpp
@@ -541,7 +541,7 @@ private:
541 } else { 541 } else {
542 // Wait the current thread until a buffer becomes available 542 // Wait the current thread until a buffer becomes available
543 ctx.SleepClientThread( 543 ctx.SleepClientThread(
544 "IHOSBinderDriver::DequeueBuffer", -1, 544 "IHOSBinderDriver::DequeueBuffer", UINT64_MAX,
545 [=](Kernel::SharedPtr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx, 545 [=](Kernel::SharedPtr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
546 Kernel::ThreadWakeupReason reason) { 546 Kernel::ThreadWakeupReason reason) {
547 // Repeat TransactParcel DequeueBuffer when a buffer is available 547 // Repeat TransactParcel DequeueBuffer when a buffer is available
diff --git a/src/core/perf_stats.cpp b/src/core/perf_stats.cpp
index d2c69d1a0..f1ae9d4df 100644
--- a/src/core/perf_stats.cpp
+++ b/src/core/perf_stats.cpp
@@ -81,7 +81,7 @@ double PerfStats::GetMeanFrametime() {
81 return 0; 81 return 0;
82 } 82 }
83 const double sum = std::accumulate(perf_history.begin() + IgnoreFrames, 83 const double sum = std::accumulate(perf_history.begin() + IgnoreFrames,
84 perf_history.begin() + current_index, 0); 84 perf_history.begin() + current_index, 0.0);
85 return sum / (current_index - IgnoreFrames); 85 return sum / (current_index - IgnoreFrames);
86} 86}
87 87