summaryrefslogtreecommitdiff
path: root/src/core/hle
diff options
context:
space:
mode:
authorGravatar Lioncash2020-10-15 14:49:45 -0400
committerGravatar Lioncash2020-10-17 19:50:39 -0400
commitbe1954e04cb5a0c3a526f78ed5490a5e65310280 (patch)
tree267db7ae4be88dbbc288fa605e35d4a2a13839f6 /src/core/hle
parentMerge pull request #4787 from lioncash/conversion (diff)
downloadyuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.gz
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.tar.xz
yuzu-be1954e04cb5a0c3a526f78ed5490a5e65310280.zip
core: Fix clang build
Recent changes to the build system that made more warnings be flagged as errors caused building via clang to break. Fixes #4795
Diffstat (limited to 'src/core/hle')
-rw-r--r--src/core/hle/ipc_helpers.h4
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp4
-rw-r--r--src/core/hle/kernel/handle_table.cpp2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp2
-rw-r--r--src/core/hle/kernel/kernel.cpp2
-rw-r--r--src/core/hle/kernel/memory/address_space_info.cpp2
-rw-r--r--src/core/hle/kernel/memory/memory_manager.cpp4
-rw-r--r--src/core/hle/kernel/memory/page_heap.cpp17
-rw-r--r--src/core/hle/kernel/memory/page_heap.h18
-rw-r--r--src/core/hle/kernel/memory/page_table.cpp6
-rw-r--r--src/core/hle/kernel/physical_core.h2
-rw-r--r--src/core/hle/kernel/process.cpp17
-rw-r--r--src/core/hle/kernel/resource_limit.cpp4
-rw-r--r--src/core/hle/kernel/scheduler.cpp72
-rw-r--r--src/core/hle/kernel/svc.cpp7
-rw-r--r--src/core/hle/kernel/svc_wrap.h17
-rw-r--r--src/core/hle/kernel/synchronization.cpp4
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/kernel/thread.h6
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp13
-rw-r--r--src/core/hle/service/am/am.cpp2
-rw-r--r--src/core/hle/service/am/applets/controller.cpp26
-rw-r--r--src/core/hle/service/audio/audout_u.cpp7
-rw-r--r--src/core/hle/service/audio/hwopus.cpp29
-rw-r--r--src/core/hle/service/bcat/backend/backend.h8
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp9
-rw-r--r--src/core/hle/service/bcat/module.cpp3
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/debug_pad.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/gesture.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/keyboard.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/mouse.cpp8
-rw-r--r--src/core/hle/service/hid/controllers/npad.cpp69
-rw-r--r--src/core/hle/service/hid/controllers/stubbed.cpp12
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.cpp9
-rw-r--r--src/core/hle/service/hid/controllers/touchscreen.h2
-rw-r--r--src/core/hle/service/hid/controllers/xpad.cpp8
-rw-r--r--src/core/hle/service/ldr/ldr.cpp4
-rw-r--r--src/core/hle/service/mii/manager.cpp20
-rw-r--r--src/core/hle/service/nfp/nfp.cpp2
-rw-r--r--src/core/hle/service/ns/ns.cpp2
-rw-r--r--src/core/hle/service/ns/pl_u.cpp12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp48
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp12
-rw-r--r--src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp8
-rw-r--r--src/core/hle/service/nvdrv/interface.cpp8
-rw-r--r--src/core/hle/service/nvflinger/nvflinger.cpp2
-rw-r--r--src/core/hle/service/service.cpp4
-rw-r--r--src/core/hle/service/set/set.cpp6
-rw-r--r--src/core/hle/service/sockets/bsd.cpp72
-rw-r--r--src/core/hle/service/sockets/bsd.h3
-rw-r--r--src/core/hle/service/sockets/sockets_translate.cpp1
-rw-r--r--src/core/hle/service/time/time_zone_manager.cpp118
-rw-r--r--src/core/hle/service/time/time_zone_service.cpp4
54 files changed, 433 insertions, 322 deletions
diff --git a/src/core/hle/ipc_helpers.h b/src/core/hle/ipc_helpers.h
index 1c354037d..fcb86c822 100644
--- a/src/core/hle/ipc_helpers.h
+++ b/src/core/hle/ipc_helpers.h
@@ -233,7 +233,7 @@ void ResponseBuilder::PushRaw(const T& value) {
233 static_assert(std::is_trivially_copyable_v<T>, 233 static_assert(std::is_trivially_copyable_v<T>,
234 "It's undefined behavior to use memcpy with non-trivially copyable objects"); 234 "It's undefined behavior to use memcpy with non-trivially copyable objects");
235 std::memcpy(cmdbuf + index, &value, sizeof(T)); 235 std::memcpy(cmdbuf + index, &value, sizeof(T));
236 index += (sizeof(T) + 3) / 4; // round up to word length 236 index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length
237} 237}
238 238
239template <> 239template <>
@@ -390,7 +390,7 @@ void RequestParser::PopRaw(T& value) {
390 static_assert(std::is_trivially_copyable_v<T>, 390 static_assert(std::is_trivially_copyable_v<T>,
391 "It's undefined behavior to use memcpy with non-trivially copyable objects"); 391 "It's undefined behavior to use memcpy with non-trivially copyable objects");
392 std::memcpy(&value, cmdbuf + index, sizeof(T)); 392 std::memcpy(&value, cmdbuf + index, sizeof(T));
393 index += (sizeof(T) + 3) / 4; // round up to word length 393 index += static_cast<std::ptrdiff_t>((sizeof(T) + 3) / 4); // round up to word length
394} 394}
395 395
396template <typename T> 396template <typename T>
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index b882eaa0f..b6ebc5329 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -108,7 +108,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a
108 auto& monitor = system.Monitor(); 108 auto& monitor = system.Monitor();
109 s32 updated_value; 109 s32 updated_value;
110 do { 110 do {
111 updated_value = monitor.ExclusiveRead32(current_core, address); 111 updated_value = static_cast<s32>(monitor.ExclusiveRead32(current_core, address));
112 112
113 if (updated_value != value) { 113 if (updated_value != value) {
114 return ERR_INVALID_STATE; 114 return ERR_INVALID_STATE;
@@ -129,7 +129,7 @@ ResultCode AddressArbiter::ModifyByWaitingCountAndSignalToAddressIfEqual(VAddr a
129 updated_value = value; 129 updated_value = value;
130 } 130 }
131 } 131 }
132 } while (!monitor.ExclusiveWrite32(current_core, address, updated_value)); 132 } while (!monitor.ExclusiveWrite32(current_core, address, static_cast<u32>(updated_value)));
133 133
134 WakeThreads(waiting_threads, num_to_wake); 134 WakeThreads(waiting_threads, num_to_wake);
135 return RESULT_SUCCESS; 135 return RESULT_SUCCESS;
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 3e745c18b..fe4988f84 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -68,7 +68,7 @@ ResultVal<Handle> HandleTable::Create(std::shared_ptr<Object> obj) {
68 generations[slot] = generation; 68 generations[slot] = generation;
69 objects[slot] = std::move(obj); 69 objects[slot] = std::move(obj);
70 70
71 Handle handle = generation | (slot << 15); 71 const auto handle = static_cast<Handle>(generation | static_cast<u16>(slot << 15));
72 return MakeResult<Handle>(handle); 72 return MakeResult<Handle>(handle);
73} 73}
74 74
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 81f85643b..0a2de4270 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -58,7 +58,7 @@ std::shared_ptr<WritableEvent> HLERequestContext::SleepClientThread(
58 58
59 { 59 {
60 Handle event_handle = InvalidHandle; 60 Handle event_handle = InvalidHandle;
61 SchedulerLockAndSleep lock(kernel, event_handle, thread.get(), timeout); 61 SchedulerLockAndSleep lock(kernel, event_handle, thread.get(), static_cast<s64>(timeout));
62 thread->SetHLECallback( 62 thread->SetHLECallback(
63 [context = *this, callback](std::shared_ptr<Thread> thread) mutable -> bool { 63 [context = *this, callback](std::shared_ptr<Thread> thread) mutable -> bool {
64 ThreadWakeupReason reason = thread->GetSignalingResult() == RESULT_TIMEOUT 64 ThreadWakeupReason reason = thread->GetSignalingResult() == RESULT_TIMEOUT
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index f2b0fe2fd..c04b23eff 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -168,7 +168,7 @@ struct KernelCore::Impl {
168 const auto type = 168 const auto type =
169 static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND); 169 static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_SUSPEND);
170 auto thread_res = 170 auto thread_res =
171 Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<u32>(i), 0, 171 Thread::Create(system, type, std::move(name), 0, 0, 0, static_cast<s32>(i), 0,
172 nullptr, std::move(init_func), init_func_parameter); 172 nullptr, std::move(init_func), init_func_parameter);
173 173
174 suspend_threads[i] = std::move(thread_res).Unwrap(); 174 suspend_threads[i] = std::move(thread_res).Unwrap();
diff --git a/src/core/hle/kernel/memory/address_space_info.cpp b/src/core/hle/kernel/memory/address_space_info.cpp
index e4288cab4..6cf43ba24 100644
--- a/src/core/hle/kernel/memory/address_space_info.cpp
+++ b/src/core/hle/kernel/memory/address_space_info.cpp
@@ -96,6 +96,7 @@ u64 AddressSpaceInfo::GetAddressSpaceStart(std::size_t width, Type type) {
96 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address; 96 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].address;
97 } 97 }
98 UNREACHABLE(); 98 UNREACHABLE();
99 return 0;
99} 100}
100 101
101std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) { 102std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type) {
@@ -112,6 +113,7 @@ std::size_t AddressSpaceInfo::GetAddressSpaceSize(std::size_t width, Type type)
112 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size; 113 return AddressSpaceInfos[AddressSpaceIndices39Bit[index]].size;
113 } 114 }
114 UNREACHABLE(); 115 UNREACHABLE();
116 return 0;
115} 117}
116 118
117} // namespace Kernel::Memory 119} // namespace Kernel::Memory
diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp
index acf13585c..a96157c37 100644
--- a/src/core/hle/kernel/memory/memory_manager.cpp
+++ b/src/core/hle/kernel/memory/memory_manager.cpp
@@ -71,7 +71,7 @@ VAddr MemoryManager::AllocateContinuous(std::size_t num_pages, std::size_t align
71 } 71 }
72 72
73 // If we allocated more than we need, free some 73 // If we allocated more than we need, free some
74 const auto allocated_pages{PageHeap::GetBlockNumPages(heap_index)}; 74 const auto allocated_pages{PageHeap::GetBlockNumPages(static_cast<u32>(heap_index))};
75 if (allocated_pages > num_pages) { 75 if (allocated_pages > num_pages) {
76 chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages); 76 chosen_manager.Free(allocated_block + num_pages * PageSize, allocated_pages - num_pages);
77 } 77 }
@@ -112,7 +112,7 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa
112 112
113 // Keep allocating until we've allocated all our pages 113 // Keep allocating until we've allocated all our pages
114 for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) { 114 for (s32 index{heap_index}; index >= 0 && num_pages > 0; index--) {
115 const auto pages_per_alloc{PageHeap::GetBlockNumPages(index)}; 115 const auto pages_per_alloc{PageHeap::GetBlockNumPages(static_cast<u32>(index))};
116 116
117 while (num_pages >= pages_per_alloc) { 117 while (num_pages >= pages_per_alloc) {
118 // Allocate a block 118 // Allocate a block
diff --git a/src/core/hle/kernel/memory/page_heap.cpp b/src/core/hle/kernel/memory/page_heap.cpp
index 0ab1f7205..7890b8c1a 100644
--- a/src/core/hle/kernel/memory/page_heap.cpp
+++ b/src/core/hle/kernel/memory/page_heap.cpp
@@ -33,11 +33,12 @@ void PageHeap::Initialize(VAddr address, std::size_t size, std::size_t metadata_
33} 33}
34 34
35VAddr PageHeap::AllocateBlock(s32 index) { 35VAddr PageHeap::AllocateBlock(s32 index) {
36 const std::size_t needed_size{blocks[index].GetSize()}; 36 const auto u_index = static_cast<std::size_t>(index);
37 const auto needed_size{blocks[u_index].GetSize()};
37 38
38 for (s32 i{index}; i < static_cast<s32>(MemoryBlockPageShifts.size()); i++) { 39 for (auto i = u_index; i < MemoryBlockPageShifts.size(); i++) {
39 if (const VAddr addr{blocks[i].PopBlock()}; addr) { 40 if (const VAddr addr = blocks[i].PopBlock(); addr != 0) {
40 if (const std::size_t allocated_size{blocks[i].GetSize()}; 41 if (const std::size_t allocated_size = blocks[i].GetSize();
41 allocated_size > needed_size) { 42 allocated_size > needed_size) {
42 Free(addr + needed_size, (allocated_size - needed_size) / PageSize); 43 Free(addr + needed_size, (allocated_size - needed_size) / PageSize);
43 } 44 }
@@ -50,7 +51,7 @@ VAddr PageHeap::AllocateBlock(s32 index) {
50 51
51void PageHeap::FreeBlock(VAddr block, s32 index) { 52void PageHeap::FreeBlock(VAddr block, s32 index) {
52 do { 53 do {
53 block = blocks[index++].PushBlock(block); 54 block = blocks[static_cast<std::size_t>(index++)].PushBlock(block);
54 } while (block != 0); 55 } while (block != 0);
55} 56}
56 57
@@ -69,7 +70,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
69 VAddr after_start{end}; 70 VAddr after_start{end};
70 VAddr after_end{end}; 71 VAddr after_end{end};
71 while (big_index >= 0) { 72 while (big_index >= 0) {
72 const std::size_t block_size{blocks[big_index].GetSize()}; 73 const std::size_t block_size{blocks[static_cast<std::size_t>(big_index)].GetSize()};
73 const VAddr big_start{Common::AlignUp((start), block_size)}; 74 const VAddr big_start{Common::AlignUp((start), block_size)};
74 const VAddr big_end{Common::AlignDown((end), block_size)}; 75 const VAddr big_end{Common::AlignDown((end), block_size)};
75 if (big_start < big_end) { 76 if (big_start < big_end) {
@@ -87,7 +88,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
87 88
88 // Free space before the big blocks 89 // Free space before the big blocks
89 for (s32 i{big_index - 1}; i >= 0; i--) { 90 for (s32 i{big_index - 1}; i >= 0; i--) {
90 const std::size_t block_size{blocks[i].GetSize()}; 91 const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()};
91 while (before_start + block_size <= before_end) { 92 while (before_start + block_size <= before_end) {
92 before_end -= block_size; 93 before_end -= block_size;
93 FreeBlock(before_end, i); 94 FreeBlock(before_end, i);
@@ -96,7 +97,7 @@ void PageHeap::Free(VAddr addr, std::size_t num_pages) {
96 97
97 // Free space after the big blocks 98 // Free space after the big blocks
98 for (s32 i{big_index - 1}; i >= 0; i--) { 99 for (s32 i{big_index - 1}; i >= 0; i--) {
99 const std::size_t block_size{blocks[i].GetSize()}; 100 const std::size_t block_size{blocks[static_cast<size_t>(i)].GetSize()};
100 while (after_start + block_size <= after_end) { 101 while (after_start + block_size <= after_end) {
101 FreeBlock(after_start, i); 102 FreeBlock(after_start, i);
102 after_start += block_size; 103 after_start += block_size;
diff --git a/src/core/hle/kernel/memory/page_heap.h b/src/core/hle/kernel/memory/page_heap.h
index 22b0de860..92a2bce04 100644
--- a/src/core/hle/kernel/memory/page_heap.h
+++ b/src/core/hle/kernel/memory/page_heap.h
@@ -34,7 +34,9 @@ public:
34 34
35 static constexpr s32 GetBlockIndex(std::size_t num_pages) { 35 static constexpr s32 GetBlockIndex(std::size_t num_pages) {
36 for (s32 i{static_cast<s32>(NumMemoryBlockPageShifts) - 1}; i >= 0; i--) { 36 for (s32 i{static_cast<s32>(NumMemoryBlockPageShifts) - 1}; i >= 0; i--) {
37 if (num_pages >= (static_cast<std::size_t>(1) << MemoryBlockPageShifts[i]) / PageSize) { 37 const auto shift_index = static_cast<std::size_t>(i);
38 if (num_pages >=
39 (static_cast<std::size_t>(1) << MemoryBlockPageShifts[shift_index]) / PageSize) {
38 return i; 40 return i;
39 } 41 }
40 } 42 }
@@ -86,7 +88,7 @@ private:
86 88
87 // Set the bitmap pointers 89 // Set the bitmap pointers
88 for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) { 90 for (s32 depth{GetHighestDepthIndex()}; depth >= 0; depth--) {
89 bit_storages[depth] = storage; 91 bit_storages[static_cast<std::size_t>(depth)] = storage;
90 size = Common::AlignUp(size, 64) / 64; 92 size = Common::AlignUp(size, 64) / 64;
91 storage += size; 93 storage += size;
92 } 94 }
@@ -99,7 +101,7 @@ private:
99 s32 depth{}; 101 s32 depth{};
100 102
101 do { 103 do {
102 const u64 v{bit_storages[depth][offset]}; 104 const u64 v{bit_storages[static_cast<std::size_t>(depth)][offset]};
103 if (v == 0) { 105 if (v == 0) {
104 // Non-zero depth indicates that a previous level had a free block 106 // Non-zero depth indicates that a previous level had a free block
105 ASSERT(depth == 0); 107 ASSERT(depth == 0);
@@ -125,7 +127,7 @@ private:
125 constexpr bool ClearRange(std::size_t offset, std::size_t count) { 127 constexpr bool ClearRange(std::size_t offset, std::size_t count) {
126 const s32 depth{GetHighestDepthIndex()}; 128 const s32 depth{GetHighestDepthIndex()};
127 const auto bit_ind{offset / 64}; 129 const auto bit_ind{offset / 64};
128 u64* bits{bit_storages[depth]}; 130 u64* bits{bit_storages[static_cast<std::size_t>(depth)]};
129 if (count < 64) { 131 if (count < 64) {
130 const auto shift{offset % 64}; 132 const auto shift{offset % 64};
131 ASSERT(shift + count <= 64); 133 ASSERT(shift + count <= 64);
@@ -177,11 +179,11 @@ private:
177 const auto which{offset % 64}; 179 const auto which{offset % 64};
178 const u64 mask{1ULL << which}; 180 const u64 mask{1ULL << which};
179 181
180 u64* bit{std::addressof(bit_storages[depth][ind])}; 182 u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])};
181 const u64 v{*bit}; 183 const u64 v{*bit};
182 ASSERT((v & mask) == 0); 184 ASSERT((v & mask) == 0);
183 *bit = v | mask; 185 *bit = v | mask;
184 if (v) { 186 if (v != 0) {
185 break; 187 break;
186 } 188 }
187 offset = ind; 189 offset = ind;
@@ -195,12 +197,12 @@ private:
195 const auto which{offset % 64}; 197 const auto which{offset % 64};
196 const u64 mask{1ULL << which}; 198 const u64 mask{1ULL << which};
197 199
198 u64* bit{std::addressof(bit_storages[depth][ind])}; 200 u64* bit{std::addressof(bit_storages[static_cast<std::size_t>(depth)][ind])};
199 u64 v{*bit}; 201 u64 v{*bit};
200 ASSERT((v & mask) != 0); 202 ASSERT((v & mask) != 0);
201 v &= ~mask; 203 v &= ~mask;
202 *bit = v; 204 *bit = v;
203 if (v) { 205 if (v != 0) {
204 break; 206 break;
205 } 207 }
206 offset = ind; 208 offset = ind;
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp
index a3fadb533..4f759d078 100644
--- a/src/core/hle/kernel/memory/page_table.cpp
+++ b/src/core/hle/kernel/memory/page_table.cpp
@@ -414,7 +414,8 @@ ResultCode PageTable::MapPhysicalMemory(VAddr addr, std::size_t size) {
414 const std::size_t remaining_pages{remaining_size / PageSize}; 414 const std::size_t remaining_pages{remaining_size / PageSize};
415 415
416 if (process->GetResourceLimit() && 416 if (process->GetResourceLimit() &&
417 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, remaining_size)) { 417 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory,
418 static_cast<s64>(remaining_size))) {
418 return ERR_RESOURCE_LIMIT_EXCEEDED; 419 return ERR_RESOURCE_LIMIT_EXCEEDED;
419 } 420 }
420 421
@@ -778,7 +779,8 @@ ResultVal<VAddr> PageTable::SetHeapSize(std::size_t size) {
778 779
779 auto process{system.Kernel().CurrentProcess()}; 780 auto process{system.Kernel().CurrentProcess()};
780 if (process->GetResourceLimit() && delta != 0 && 781 if (process->GetResourceLimit() && delta != 0 &&
781 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory, delta)) { 782 !process->GetResourceLimit()->Reserve(ResourceType::PhysicalMemory,
783 static_cast<s64>(delta))) {
782 return ERR_RESOURCE_LIMIT_EXCEEDED; 784 return ERR_RESOURCE_LIMIT_EXCEEDED;
783 } 785 }
784 786
diff --git a/src/core/hle/kernel/physical_core.h b/src/core/hle/kernel/physical_core.h
index d7a7a951c..6cb59d0fc 100644
--- a/src/core/hle/kernel/physical_core.h
+++ b/src/core/hle/kernel/physical_core.h
@@ -34,7 +34,7 @@ public:
34 PhysicalCore& operator=(const PhysicalCore&) = delete; 34 PhysicalCore& operator=(const PhysicalCore&) = delete;
35 35
36 PhysicalCore(PhysicalCore&&) = default; 36 PhysicalCore(PhysicalCore&&) = default;
37 PhysicalCore& operator=(PhysicalCore&&) = default; 37 PhysicalCore& operator=(PhysicalCore&&) = delete;
38 38
39 void Idle(); 39 void Idle();
40 /// Interrupt this physical core. 40 /// Interrupt this physical core.
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index ff9d9248b..0b39f2955 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -137,9 +137,10 @@ std::shared_ptr<ResourceLimit> Process::GetResourceLimit() const {
137} 137}
138 138
139u64 Process::GetTotalPhysicalMemoryAvailable() const { 139u64 Process::GetTotalPhysicalMemoryAvailable() const {
140 const u64 capacity{resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory) + 140 const u64 capacity{
141 page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size + 141 static_cast<u64>(resource_limit->GetCurrentResourceValue(ResourceType::PhysicalMemory)) +
142 main_thread_stack_size}; 142 page_table->GetTotalHeapSize() + GetSystemResourceSize() + image_size +
143 main_thread_stack_size};
143 144
144 if (capacity < memory_usage_capacity) { 145 if (capacity < memory_usage_capacity) {
145 return capacity; 146 return capacity;
@@ -279,12 +280,12 @@ ResultCode Process::LoadFromMetadata(const FileSys::ProgramMetadata& metadata,
279 // Set initial resource limits 280 // Set initial resource limits
280 resource_limit->SetLimitValue( 281 resource_limit->SetLimitValue(
281 ResourceType::PhysicalMemory, 282 ResourceType::PhysicalMemory,
282 kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)); 283 static_cast<s64>(kernel.MemoryManager().GetSize(Memory::MemoryManager::Pool::Application)));
283 resource_limit->SetLimitValue(ResourceType::Threads, 608); 284 resource_limit->SetLimitValue(ResourceType::Threads, 608);
284 resource_limit->SetLimitValue(ResourceType::Events, 700); 285 resource_limit->SetLimitValue(ResourceType::Events, 700);
285 resource_limit->SetLimitValue(ResourceType::TransferMemory, 128); 286 resource_limit->SetLimitValue(ResourceType::TransferMemory, 128);
286 resource_limit->SetLimitValue(ResourceType::Sessions, 894); 287 resource_limit->SetLimitValue(ResourceType::Sessions, 894);
287 ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, code_size)); 288 ASSERT(resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(code_size)));
288 289
289 // Create TLS region 290 // Create TLS region
290 tls_region_address = CreateTLSRegion(); 291 tls_region_address = CreateTLSRegion();
@@ -300,9 +301,9 @@ void Process::Run(s32 main_thread_priority, u64 stack_size) {
300 301
301 ChangeStatus(ProcessStatus::Running); 302 ChangeStatus(ProcessStatus::Running);
302 303
303 SetupMainThread(system, *this, main_thread_priority, main_thread_stack_top); 304 SetupMainThread(system, *this, static_cast<u32>(main_thread_priority), main_thread_stack_top);
304 resource_limit->Reserve(ResourceType::Threads, 1); 305 resource_limit->Reserve(ResourceType::Threads, 1);
305 resource_limit->Reserve(ResourceType::PhysicalMemory, main_thread_stack_size); 306 resource_limit->Reserve(ResourceType::PhysicalMemory, static_cast<s64>(main_thread_stack_size));
306} 307}
307 308
308void Process::PrepareForTermination() { 309void Process::PrepareForTermination() {
@@ -363,7 +364,7 @@ VAddr Process::CreateTLSRegion() {
363 ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize, 364 ->AllocateAndMapMemory(1, Memory::PageSize, true, start, size / Memory::PageSize,
364 Memory::MemoryState::ThreadLocal, 365 Memory::MemoryState::ThreadLocal,
365 Memory::MemoryPermission::ReadAndWrite, tls_map_addr) 366 Memory::MemoryPermission::ReadAndWrite, tls_map_addr)
366 .ValueOr(0)}; 367 .ValueOr(0U)};
367 368
368 ASSERT(tls_page_addr); 369 ASSERT(tls_page_addr);
369 370
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index 212e442f4..e94093f24 100644
--- a/src/core/hle/kernel/resource_limit.cpp
+++ b/src/core/hle/kernel/resource_limit.cpp
@@ -43,8 +43,8 @@ void ResourceLimit::Release(ResourceType resource, u64 amount) {
43void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) { 43void ResourceLimit::Release(ResourceType resource, u64 used_amount, u64 available_amount) {
44 const std::size_t index{ResourceTypeToIndex(resource)}; 44 const std::size_t index{ResourceTypeToIndex(resource)};
45 45
46 current[index] -= used_amount; 46 current[index] -= static_cast<s64>(used_amount);
47 available[index] -= available_amount; 47 available[index] -= static_cast<s64>(available_amount);
48} 48}
49 49
50std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) { 50std::shared_ptr<ResourceLimit> ResourceLimit::Create(KernelCore& kernel) {
diff --git a/src/core/hle/kernel/scheduler.cpp b/src/core/hle/kernel/scheduler.cpp
index 6b7db5372..4a9a762f3 100644
--- a/src/core/hle/kernel/scheduler.cpp
+++ b/src/core/hle/kernel/scheduler.cpp
@@ -89,9 +89,11 @@ u32 GlobalScheduler::SelectThreads() {
89 while (iter != suggested_queue[core_id].end()) { 89 while (iter != suggested_queue[core_id].end()) {
90 suggested = *iter; 90 suggested = *iter;
91 iter++; 91 iter++;
92 s32 suggested_core_id = suggested->GetProcessorID(); 92 const s32 suggested_core_id = suggested->GetProcessorID();
93 Thread* top_thread = 93 Thread* top_thread = suggested_core_id >= 0
94 suggested_core_id >= 0 ? top_threads[suggested_core_id] : nullptr; 94 ? top_threads[static_cast<u32>(suggested_core_id)]
95 : nullptr;
96
95 if (top_thread != suggested) { 97 if (top_thread != suggested) {
96 if (top_thread != nullptr && 98 if (top_thread != nullptr &&
97 top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) { 99 top_thread->GetPriority() < THREADPRIO_MAX_CORE_MIGRATION) {
@@ -102,16 +104,19 @@ u32 GlobalScheduler::SelectThreads() {
102 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested); 104 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), suggested);
103 break; 105 break;
104 } 106 }
107
105 suggested = nullptr; 108 suggested = nullptr;
106 migration_candidates[num_candidates++] = suggested_core_id; 109 migration_candidates[num_candidates++] = suggested_core_id;
107 } 110 }
111
108 // Step 3: Select a suggested thread from another core 112 // Step 3: Select a suggested thread from another core
109 if (suggested == nullptr) { 113 if (suggested == nullptr) {
110 for (std::size_t i = 0; i < num_candidates; i++) { 114 for (std::size_t i = 0; i < num_candidates; i++) {
111 s32 candidate_core = migration_candidates[i]; 115 const auto candidate_core = static_cast<u32>(migration_candidates[i]);
112 suggested = top_threads[candidate_core]; 116 suggested = top_threads[candidate_core];
113 auto it = scheduled_queue[candidate_core].begin(); 117 auto it = scheduled_queue[candidate_core].begin();
114 it++; 118 ++it;
119
115 Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr; 120 Thread* next = it != scheduled_queue[candidate_core].end() ? *it : nullptr;
116 if (next != nullptr) { 121 if (next != nullptr) {
117 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id), 122 TransferToCore(suggested->GetPriority(), static_cast<s32>(core_id),
@@ -128,7 +133,8 @@ u32 GlobalScheduler::SelectThreads() {
128 133
129 idle_cores &= ~(1U << core_id); 134 idle_cores &= ~(1U << core_id);
130 } 135 }
131 u32 cores_needing_context_switch{}; 136
137 u32 cores_needing_context_switch = 0;
132 for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) { 138 for (u32 core = 0; core < Core::Hardware::NUM_CPU_CORES; core++) {
133 Scheduler& sched = kernel.Scheduler(core); 139 Scheduler& sched = kernel.Scheduler(core);
134 ASSERT(top_threads[core] == nullptr || 140 ASSERT(top_threads[core] == nullptr ||
@@ -186,13 +192,16 @@ bool GlobalScheduler::YieldThreadAndBalanceLoad(Thread* yielding_thread) {
186 for (auto& thread : suggested_queue[core_id]) { 192 for (auto& thread : suggested_queue[core_id]) {
187 const s32 source_core = thread->GetProcessorID(); 193 const s32 source_core = thread->GetProcessorID();
188 if (source_core >= 0) { 194 if (source_core >= 0) {
189 if (current_threads[source_core] != nullptr) { 195 const auto sanitized_source_core = static_cast<u32>(source_core);
190 if (thread == current_threads[source_core] || 196
191 current_threads[source_core]->GetPriority() < min_regular_priority) { 197 if (current_threads[sanitized_source_core] != nullptr) {
198 if (thread == current_threads[sanitized_source_core] ||
199 current_threads[sanitized_source_core]->GetPriority() < min_regular_priority) {
192 continue; 200 continue;
193 } 201 }
194 } 202 }
195 } 203 }
204
196 if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() || 205 if (next_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks() ||
197 next_thread->GetPriority() < thread->GetPriority()) { 206 next_thread->GetPriority() < thread->GetPriority()) {
198 if (thread->GetPriority() <= priority) { 207 if (thread->GetPriority() <= priority) {
@@ -240,17 +249,25 @@ bool GlobalScheduler::YieldThreadAndWaitForLoadBalancing(Thread* yielding_thread
240 for (std::size_t i = 0; i < current_threads.size(); i++) { 249 for (std::size_t i = 0; i < current_threads.size(); i++) {
241 current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front(); 250 current_threads[i] = scheduled_queue[i].empty() ? nullptr : scheduled_queue[i].front();
242 } 251 }
252
243 for (auto& thread : suggested_queue[core_id]) { 253 for (auto& thread : suggested_queue[core_id]) {
244 const s32 source_core = thread->GetProcessorID(); 254 const s32 source_core = thread->GetProcessorID();
245 if (source_core < 0 || thread == current_threads[source_core]) { 255 if (source_core < 0) {
256 continue;
257 }
258
259 const auto sanitized_source_core = static_cast<u32>(source_core);
260 if (thread == current_threads[sanitized_source_core]) {
246 continue; 261 continue;
247 } 262 }
248 if (current_threads[source_core] == nullptr || 263
249 current_threads[source_core]->GetPriority() >= min_regular_priority) { 264 if (current_threads[sanitized_source_core] == nullptr ||
265 current_threads[sanitized_source_core]->GetPriority() >= min_regular_priority) {
250 winner = thread; 266 winner = thread;
251 } 267 }
252 break; 268 break;
253 } 269 }
270
254 if (winner != nullptr) { 271 if (winner != nullptr) {
255 if (winner != yielding_thread) { 272 if (winner != yielding_thread) {
256 TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner); 273 TransferToCore(winner->GetPriority(), static_cast<s32>(core_id), winner);
@@ -292,17 +309,22 @@ void GlobalScheduler::PreemptThreads() {
292 if (thread->GetPriority() != priority) { 309 if (thread->GetPriority() != priority) {
293 continue; 310 continue;
294 } 311 }
312
295 if (source_core >= 0) { 313 if (source_core >= 0) {
296 Thread* next_thread = scheduled_queue[source_core].empty() 314 const auto sanitized_source_core = static_cast<u32>(source_core);
315 Thread* next_thread = scheduled_queue[sanitized_source_core].empty()
297 ? nullptr 316 ? nullptr
298 : scheduled_queue[source_core].front(); 317 : scheduled_queue[sanitized_source_core].front();
318
299 if (next_thread != nullptr && next_thread->GetPriority() < 2) { 319 if (next_thread != nullptr && next_thread->GetPriority() < 2) {
300 break; 320 break;
301 } 321 }
322
302 if (next_thread == thread) { 323 if (next_thread == thread) {
303 continue; 324 continue;
304 } 325 }
305 } 326 }
327
306 if (current_thread != nullptr && 328 if (current_thread != nullptr &&
307 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { 329 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) {
308 winner = thread; 330 winner = thread;
@@ -322,17 +344,22 @@ void GlobalScheduler::PreemptThreads() {
322 if (thread->GetPriority() < priority) { 344 if (thread->GetPriority() < priority) {
323 continue; 345 continue;
324 } 346 }
347
325 if (source_core >= 0) { 348 if (source_core >= 0) {
326 Thread* next_thread = scheduled_queue[source_core].empty() 349 const auto sanitized_source_core = static_cast<u32>(source_core);
350 Thread* next_thread = scheduled_queue[sanitized_source_core].empty()
327 ? nullptr 351 ? nullptr
328 : scheduled_queue[source_core].front(); 352 : scheduled_queue[sanitized_source_core].front();
353
329 if (next_thread != nullptr && next_thread->GetPriority() < 2) { 354 if (next_thread != nullptr && next_thread->GetPriority() < 2) {
330 break; 355 break;
331 } 356 }
357
332 if (next_thread == thread) { 358 if (next_thread == thread) {
333 continue; 359 continue;
334 } 360 }
335 } 361 }
362
336 if (current_thread != nullptr && 363 if (current_thread != nullptr &&
337 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) { 364 current_thread->GetLastRunningTicks() >= thread->GetLastRunningTicks()) {
338 winner = thread; 365 winner = thread;
@@ -352,11 +379,11 @@ void GlobalScheduler::PreemptThreads() {
352 379
353void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule, 380void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule,
354 Core::EmuThreadHandle global_thread) { 381 Core::EmuThreadHandle global_thread) {
355 u32 current_core = global_thread.host_handle; 382 const u32 current_core = global_thread.host_handle;
356 bool must_context_switch = global_thread.guest_handle != InvalidHandle && 383 bool must_context_switch = global_thread.guest_handle != InvalidHandle &&
357 (current_core < Core::Hardware::NUM_CPU_CORES); 384 (current_core < Core::Hardware::NUM_CPU_CORES);
358 while (cores_pending_reschedule != 0) { 385 while (cores_pending_reschedule != 0) {
359 u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule); 386 const u32 core = Common::CountTrailingZeroes32(cores_pending_reschedule);
360 ASSERT(core < Core::Hardware::NUM_CPU_CORES); 387 ASSERT(core < Core::Hardware::NUM_CPU_CORES);
361 if (!must_context_switch || core != current_core) { 388 if (!must_context_switch || core != current_core) {
362 auto& phys_core = kernel.PhysicalCore(core); 389 auto& phys_core = kernel.PhysicalCore(core);
@@ -366,6 +393,7 @@ void GlobalScheduler::EnableInterruptAndSchedule(u32 cores_pending_reschedule,
366 } 393 }
367 cores_pending_reschedule &= ~(1U << core); 394 cores_pending_reschedule &= ~(1U << core);
368 } 395 }
396
369 if (must_context_switch) { 397 if (must_context_switch) {
370 auto& core_scheduler = kernel.CurrentScheduler(); 398 auto& core_scheduler = kernel.CurrentScheduler();
371 kernel.ExitSVCProfile(); 399 kernel.ExitSVCProfile();
@@ -803,9 +831,11 @@ void Scheduler::Initialize() {
803 std::string name = "Idle Thread Id:" + std::to_string(core_id); 831 std::string name = "Idle Thread Id:" + std::to_string(core_id);
804 std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc(); 832 std::function<void(void*)> init_func = Core::CpuManager::GetIdleThreadStartFunc();
805 void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater(); 833 void* init_func_parameter = system.GetCpuManager().GetStartFuncParamater();
806 ThreadType type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE); 834 const auto type = static_cast<ThreadType>(THREADTYPE_KERNEL | THREADTYPE_HLE | THREADTYPE_IDLE);
807 auto thread_res = Thread::Create(system, type, name, 0, 64, 0, static_cast<u32>(core_id), 0, 835 auto thread_res =
808 nullptr, std::move(init_func), init_func_parameter); 836 Thread::Create(system, type, std::move(name), 0, 64, 0, static_cast<s32>(core_id), 0,
837 nullptr, std::move(init_func), init_func_parameter);
838
809 idle_thread = std::move(thread_res).Unwrap(); 839 idle_thread = std::move(thread_res).Unwrap();
810} 840}
811 841
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index bafd1ced7..b8623e831 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -482,7 +482,8 @@ static ResultCode WaitSynchronization(Core::System& system, Handle* index, VAddr
482static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address, 482static ResultCode WaitSynchronization32(Core::System& system, u32 timeout_low, u32 handles_address,
483 s32 handle_count, u32 timeout_high, Handle* index) { 483 s32 handle_count, u32 timeout_high, Handle* index) {
484 const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)}; 484 const s64 nano_seconds{(static_cast<s64>(timeout_high) << 32) | static_cast<s64>(timeout_low)};
485 return WaitSynchronization(system, index, handles_address, handle_count, nano_seconds); 485 return WaitSynchronization(system, index, handles_address, static_cast<u32>(handle_count),
486 nano_seconds);
486} 487}
487 488
488/// Resumes a thread waiting on WaitSynchronization 489/// Resumes a thread waiting on WaitSynchronization
@@ -2002,7 +2003,7 @@ static ResultCode GetThreadCoreMask(Core::System& system, Handle thread_handle,
2002 return ERR_INVALID_HANDLE; 2003 return ERR_INVALID_HANDLE;
2003 } 2004 }
2004 2005
2005 *core = thread->GetIdealCore(); 2006 *core = static_cast<u32>(thread->GetIdealCore());
2006 *mask = thread->GetAffinityMask(); 2007 *mask = thread->GetAffinityMask();
2007 2008
2008 return RESULT_SUCCESS; 2009 return RESULT_SUCCESS;
@@ -2070,7 +2071,7 @@ static ResultCode SetThreadCoreMask(Core::System& system, Handle thread_handle,
2070 return ERR_INVALID_HANDLE; 2071 return ERR_INVALID_HANDLE;
2071 } 2072 }
2072 2073
2073 return thread->SetCoreAndAffinityMask(core, affinity_mask); 2074 return thread->SetCoreAndAffinityMask(static_cast<s32>(core), affinity_mask);
2074} 2075}
2075 2076
2076static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core, 2077static ResultCode SetThreadCoreMask32(Core::System& system, Handle thread_handle, u32 core,
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h
index 0b6dd9df0..9284a4c84 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -11,11 +11,11 @@
11 11
12namespace Kernel { 12namespace Kernel {
13 13
14static inline u64 Param(const Core::System& system, int n) { 14static inline u64 Param(const Core::System& system, std::size_t n) {
15 return system.CurrentArmInterface().GetReg(n); 15 return system.CurrentArmInterface().GetReg(n);
16} 16}
17 17
18static inline u32 Param32(const Core::System& system, int n) { 18static inline u32 Param32(const Core::System& system, std::size_t n) {
19 return static_cast<u32>(system.CurrentArmInterface().GetReg(n)); 19 return static_cast<u32>(system.CurrentArmInterface().GetReg(n));
20} 20}
21 21
@@ -29,7 +29,7 @@ static inline void FuncReturn(Core::System& system, u64 result) {
29} 29}
30 30
31static inline void FuncReturn32(Core::System& system, u32 result) { 31static inline void FuncReturn32(Core::System& system, u32 result) {
32 system.CurrentArmInterface().SetReg(0, (u64)result); 32 system.CurrentArmInterface().SetReg(0, static_cast<u64>(result));
33} 33}
34 34
35//////////////////////////////////////////////////////////////////////////////////////////////////// 35////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -386,9 +386,10 @@ template <ResultCode func(Core::System&, Handle*, u32, u32, u32, u32, s32)>
386void SvcWrap32(Core::System& system) { 386void SvcWrap32(Core::System& system) {
387 Handle param_1 = 0; 387 Handle param_1 = 0;
388 388
389 const u32 retval = func(system, &param_1, Param32(system, 0), Param32(system, 1), 389 const u32 retval =
390 Param32(system, 2), Param32(system, 3), Param32(system, 4)) 390 func(system, &param_1, Param32(system, 0), Param32(system, 1), Param32(system, 2),
391 .raw; 391 Param32(system, 3), static_cast<s32>(Param32(system, 4)))
392 .raw;
392 393
393 system.CurrentArmInterface().SetReg(1, param_1); 394 system.CurrentArmInterface().SetReg(1, param_1);
394 FuncReturn(system, retval); 395 FuncReturn(system, retval);
@@ -542,8 +543,8 @@ void SvcWrap32(Core::System& system) {
542template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)> 543template <ResultCode func(Core::System&, u32, u32, s32, u32, Handle*)>
543void SvcWrap32(Core::System& system) { 544void SvcWrap32(Core::System& system) {
544 u32 param_1 = 0; 545 u32 param_1 = 0;
545 const u32 retval = func(system, Param32(system, 0), Param32(system, 1), Param32(system, 2), 546 const u32 retval = func(system, Param32(system, 0), Param32(system, 1),
546 Param32(system, 3), &param_1) 547 static_cast<s32>(Param32(system, 2)), Param32(system, 3), &param_1)
547 .raw; 548 .raw;
548 system.CurrentArmInterface().SetReg(1, param_1); 549 system.CurrentArmInterface().SetReg(1, param_1);
549 FuncReturn(system, retval); 550 FuncReturn(system, retval);
diff --git a/src/core/hle/kernel/synchronization.cpp b/src/core/hle/kernel/synchronization.cpp
index 8b875d853..653f722b3 100644
--- a/src/core/hle/kernel/synchronization.cpp
+++ b/src/core/hle/kernel/synchronization.cpp
@@ -51,7 +51,7 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor(
51 // We found a ready object, acquire it and set the result value 51 // We found a ready object, acquire it and set the result value
52 SynchronizationObject* object = itr->get(); 52 SynchronizationObject* object = itr->get();
53 object->Acquire(thread); 53 object->Acquire(thread);
54 const u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); 54 const auto index = static_cast<u32>(std::distance(sync_objects.begin(), itr));
55 lock.CancelSleep(); 55 lock.CancelSleep();
56 return {RESULT_SUCCESS, index}; 56 return {RESULT_SUCCESS, index};
57 } 57 }
@@ -105,7 +105,7 @@ std::pair<ResultCode, Handle> Synchronization::WaitFor(
105 }); 105 });
106 ASSERT(itr != sync_objects.end()); 106 ASSERT(itr != sync_objects.end());
107 signaling_object->Acquire(thread); 107 signaling_object->Acquire(thread);
108 const u32 index = static_cast<s32>(std::distance(sync_objects.begin(), itr)); 108 const auto index = static_cast<u32>(std::distance(sync_objects.begin(), itr));
109 return {signaling_result, index}; 109 return {signaling_result, index};
110 } 110 }
111 return {signaling_result, -1}; 111 return {signaling_result, -1};
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index d132aba34..323e740e9 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -525,7 +525,7 @@ ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) {
525 if (old_affinity_mask != new_affinity_mask) { 525 if (old_affinity_mask != new_affinity_mask) {
526 const s32 old_core = processor_id; 526 const s32 old_core = processor_id;
527 if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) { 527 if (processor_id >= 0 && ((affinity_mask >> processor_id) & 1) == 0) {
528 if (static_cast<s32>(ideal_core) < 0) { 528 if (ideal_core < 0) {
529 processor_id = HighestSetCore(affinity_mask, Core::Hardware::NUM_CPU_CORES); 529 processor_id = HighestSetCore(affinity_mask, Core::Hardware::NUM_CPU_CORES);
530 } else { 530 } else {
531 processor_id = ideal_core; 531 processor_id = ideal_core;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index 8daf79fac..21b22ca45 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -470,7 +470,7 @@ public:
470 470
471 bool InvokeHLECallback(std::shared_ptr<Thread> thread); 471 bool InvokeHLECallback(std::shared_ptr<Thread> thread);
472 472
473 u32 GetIdealCore() const { 473 s32 GetIdealCore() const {
474 return ideal_core; 474 return ideal_core;
475 } 475 }
476 476
@@ -654,8 +654,8 @@ private:
654 654
655 Scheduler* scheduler = nullptr; 655 Scheduler* scheduler = nullptr;
656 656
657 u32 ideal_core{0xFFFFFFFF}; 657 s32 ideal_core = -1;
658 u64 affinity_mask{0x1}; 658 u64 affinity_mask = 1;
659 659
660 s32 ideal_core_override = -1; 660 s32 ideal_core_override = -1;
661 u64 affinity_mask_override = 0x1; 661 u64 affinity_mask_override = 0x1;
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index 9b829e957..9c302043a 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -41,12 +41,15 @@ constexpr char ACC_SAVE_AVATORS_BASE_PATH[] = "/system/save/8000000000000010/su/
41ProfileManager::ProfileManager() { 41ProfileManager::ProfileManager() {
42 ParseUserSaveFile(); 42 ParseUserSaveFile();
43 43
44 if (user_count == 0) 44 if (user_count == 0) {
45 CreateNewUser(UUID::Generate(), "yuzu"); 45 CreateNewUser(UUID::Generate(), "yuzu");
46 }
46 47
47 auto current = std::clamp<int>(Settings::values.current_user, 0, MAX_USERS - 1); 48 auto current = static_cast<size_t>(
48 if (UserExistsIndex(current)) 49 std::clamp(Settings::values.current_user, 0, static_cast<s32>(MAX_USERS - 1)));
50 if (UserExistsIndex(current)) {
49 current = 0; 51 current = 0;
52 }
50 53
51 OpenUser(*GetUser(current)); 54 OpenUser(*GetUser(current));
52} 55}
@@ -189,8 +192,8 @@ std::size_t ProfileManager::GetUserCount() const {
189/// booting 192/// booting
190 193
191std::size_t ProfileManager::GetOpenUserCount() const { 194std::size_t ProfileManager::GetOpenUserCount() const {
192 return std::count_if(profiles.begin(), profiles.end(), 195 return static_cast<std::size_t>(std::count_if(profiles.begin(), profiles.end(),
193 [](const ProfileInfo& p) { return p.is_open; }); 196 [](const ProfileInfo& p) { return p.is_open; }));
194} 197}
195 198
196/// Checks if a user id exists in our profile manager 199/// Checks if a user id exists in our profile manager
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index d7a81f64a..995b7e5c6 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -1311,7 +1311,7 @@ void IApplicationFunctions::PopLaunchParameter(Kernel::HLERequestContext& ctx) {
1311 params.is_account_selected = 1; 1311 params.is_account_selected = 1;
1312 1312
1313 Account::ProfileManager profile_manager{}; 1313 Account::ProfileManager profile_manager{};
1314 const auto uuid = profile_manager.GetUser(Settings::values.current_user); 1314 const auto uuid = profile_manager.GetUser(static_cast<u32>(Settings::values.current_user));
1315 ASSERT(uuid); 1315 ASSERT(uuid);
1316 params.current_user = uuid->uuid; 1316 params.current_user = uuid->uuid;
1317 1317
diff --git a/src/core/hle/service/am/applets/controller.cpp b/src/core/hle/service/am/applets/controller.cpp
index 2151da783..17788d7a5 100644
--- a/src/core/hle/service/am/applets/controller.cpp
+++ b/src/core/hle/service/am/applets/controller.cpp
@@ -178,23 +178,23 @@ void Controller::Execute() {
178} 178}
179 179
180void Controller::ConfigurationComplete() { 180void Controller::ConfigurationComplete() {
181 ControllerSupportResultInfo result_info{};
182
183 const auto& players = Settings::values.players; 181 const auto& players = Settings::values.players;
184 182
185 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters. 183 const s8 player_count =
186 // Otherwise, only count connected players from P1-P8. 184 is_single_mode
187 result_info.player_count = 185 ? 1
188 is_single_mode ? 1 186 : static_cast<s8>(std::count_if(players.begin(), players.end() - 2,
189 : static_cast<s8>(std::count_if( 187 [](const auto& player) { return player.connected; }));
190 players.begin(), players.end() - 2,
191 [](Settings::PlayerInput player) { return player.connected; }));
192 188
193 result_info.selected_id = HID::Controller_NPad::IndexToNPad( 189 const auto index = static_cast<u32>(std::distance(
194 std::distance(players.begin(), 190 players.begin(), std::find_if(players.begin(), players.end(),
195 std::find_if(players.begin(), players.end(), 191 [](const auto& player) { return player.connected; })));
196 [](Settings::PlayerInput player) { return player.connected; })));
197 192
193 // If enable_single_mode is enabled, player_count is 1 regardless of any other parameters.
194 // Otherwise, only count connected players from P1-P8.
195 ControllerSupportResultInfo result_info{};
196 result_info.player_count = player_count;
197 result_info.selected_id = HID::Controller_NPad::IndexToNPad(index);
198 result_info.result = 0; 198 result_info.result = 0;
199 199
200 LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}", 200 LOG_DEBUG(Service_HID, "Result Info: player_count={}, selected_id={}, result={}",
diff --git a/src/core/hle/service/audio/audout_u.cpp b/src/core/hle/service/audio/audout_u.cpp
index 9b4910e53..a345a68e6 100644
--- a/src/core/hle/service/audio/audout_u.cpp
+++ b/src/core/hle/service/audio/audout_u.cpp
@@ -69,9 +69,10 @@ public:
69 buffer_event = 69 buffer_event =
70 Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased"); 70 Kernel::WritableEvent::CreateEventPair(system.Kernel(), "IAudioOutBufferReleased");
71 71
72 stream = audio_core.OpenStream(system.CoreTiming(), audio_params.sample_rate, 72 stream =
73 audio_params.channel_count, std::move(unique_name), 73 audio_core.OpenStream(system.CoreTiming(), static_cast<u32>(audio_params.sample_rate),
74 [this] { buffer_event.writable->Signal(); }); 74 audio_params.channel_count, std::move(unique_name),
75 [this] { buffer_event.writable->Signal(); });
75 } 76 }
76 77
77private: 78private:
diff --git a/src/core/hle/service/audio/hwopus.cpp b/src/core/hle/service/audio/hwopus.cpp
index f1d81602c..16a6deb7e 100644
--- a/src/core/hle/service/audio/hwopus.cpp
+++ b/src/core/hle/service/audio/hwopus.cpp
@@ -50,8 +50,8 @@ public:
50 Enabled, 50 Enabled,
51 }; 51 };
52 52
53 explicit OpusDecoderState(OpusDecoderPtr decoder, u32 sample_rate, u32 channel_count) 53 explicit OpusDecoderState(OpusDecoderPtr decoder_, s32 sample_rate_, u32 channel_count_)
54 : decoder{std::move(decoder)}, sample_rate{sample_rate}, channel_count{channel_count} {} 54 : decoder{std::move(decoder_)}, sample_rate{sample_rate_}, channel_count{channel_count_} {}
55 55
56 // Decodes interleaved Opus packets. Optionally allows reporting time taken to 56 // Decodes interleaved Opus packets. Optionally allows reporting time taken to
57 // perform the decoding, as well as any relevant extra behavior. 57 // perform the decoding, as well as any relevant extra behavior.
@@ -113,15 +113,16 @@ private:
113 return false; 113 return false;
114 } 114 }
115 115
116 const auto frame = input.data() + sizeof(OpusPacketHeader); 116 const auto* const frame = input.data() + sizeof(OpusPacketHeader);
117 const auto decoded_sample_count = opus_packet_get_nb_samples( 117 const auto decoded_sample_count = opus_packet_get_nb_samples(
118 frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), 118 frame, static_cast<opus_int32>(input.size() - sizeof(OpusPacketHeader)), sample_rate);
119 static_cast<opus_int32>(sample_rate)); 119 const auto decoded_size =
120 if (decoded_sample_count * channel_count * sizeof(u16) > raw_output_sz) { 120 static_cast<u32>(decoded_sample_count) * channel_count * sizeof(u16);
121 if (decoded_size > raw_output_sz) {
121 LOG_ERROR( 122 LOG_ERROR(
122 Audio, 123 Audio,
123 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}", 124 "Decoded data does not fit into the output data, decoded_sz={}, raw_output_sz={}",
124 decoded_sample_count * channel_count * sizeof(u16), raw_output_sz); 125 decoded_size, raw_output_sz);
125 return false; 126 return false;
126 } 127 }
127 128
@@ -137,11 +138,11 @@ private:
137 } 138 }
138 139
139 const auto end_time = std::chrono::high_resolution_clock::now() - start_time; 140 const auto end_time = std::chrono::high_resolution_clock::now() - start_time;
140 sample_count = out_sample_count; 141 sample_count = static_cast<u32>(out_sample_count);
141 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size); 142 consumed = static_cast<u32>(sizeof(OpusPacketHeader) + hdr.size);
142 if (out_performance_time != nullptr) { 143 if (out_performance_time != nullptr) {
143 *out_performance_time = 144 *out_performance_time = static_cast<u64>(
144 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count(); 145 std::chrono::duration_cast<std::chrono::milliseconds>(end_time).count());
145 } 146 }
146 147
147 return true; 148 return true;
@@ -154,7 +155,7 @@ private:
154 } 155 }
155 156
156 OpusDecoderPtr decoder; 157 OpusDecoderPtr decoder;
157 u32 sample_rate; 158 s32 sample_rate;
158 u32 channel_count; 159 u32 channel_count;
159}; 160};
160 161
@@ -212,7 +213,7 @@ std::size_t WorkerBufferSize(u32 channel_count) {
212 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 213 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
213 constexpr int num_streams = 1; 214 constexpr int num_streams = 1;
214 const int num_stereo_streams = channel_count == 2 ? 1 : 0; 215 const int num_stereo_streams = channel_count == 2 ? 1 : 0;
215 return opus_multistream_decoder_get_size(num_streams, num_stereo_streams); 216 return static_cast<size_t>(opus_multistream_decoder_get_size(num_streams, num_stereo_streams));
216} 217}
217 218
218// Creates the mapping table that maps the input channels to the particular 219// Creates the mapping table that maps the input channels to the particular
@@ -244,7 +245,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
244 "Invalid sample rate"); 245 "Invalid sample rate");
245 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count"); 246 ASSERT_MSG(channel_count == 1 || channel_count == 2, "Invalid channel count");
246 247
247 const u32 worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count)); 248 const auto worker_buffer_sz = static_cast<u32>(WorkerBufferSize(channel_count));
248 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz); 249 LOG_DEBUG(Audio, "worker_buffer_sz={}", worker_buffer_sz);
249 250
250 IPC::ResponseBuilder rb{ctx, 3}; 251 IPC::ResponseBuilder rb{ctx, 3};
@@ -254,7 +255,7 @@ void HwOpus::GetWorkBufferSize(Kernel::HLERequestContext& ctx) {
254 255
255void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) { 256void HwOpus::OpenOpusDecoder(Kernel::HLERequestContext& ctx) {
256 IPC::RequestParser rp{ctx}; 257 IPC::RequestParser rp{ctx};
257 const auto sample_rate = rp.Pop<u32>(); 258 const auto sample_rate = rp.Pop<s32>();
258 const auto channel_count = rp.Pop<u32>(); 259 const auto channel_count = rp.Pop<u32>();
259 const auto buffer_sz = rp.Pop<u32>(); 260 const auto buffer_sz = rp.Pop<u32>();
260 261
diff --git a/src/core/hle/service/bcat/backend/backend.h b/src/core/hle/service/bcat/backend/backend.h
index 48bbbe66f..1e5e93290 100644
--- a/src/core/hle/service/bcat/backend/backend.h
+++ b/src/core/hle/service/bcat/backend/backend.h
@@ -53,10 +53,10 @@ struct DeliveryCacheProgressImpl {
53 ResultCode result = RESULT_SUCCESS; 53 ResultCode result = RESULT_SUCCESS;
54 DirectoryName current_directory; 54 DirectoryName current_directory;
55 FileName current_file; 55 FileName current_file;
56 s64 current_downloaded_bytes; ///< Bytes downloaded on current file. 56 u64 current_downloaded_bytes; ///< Bytes downloaded on current file.
57 s64 current_total_bytes; ///< Bytes total on current file. 57 u64 current_total_bytes; ///< Bytes total on current file.
58 s64 total_downloaded_bytes; ///< Bytes downloaded on overall download. 58 u64 total_downloaded_bytes; ///< Bytes downloaded on overall download.
59 s64 total_bytes; ///< Bytes total on overall download. 59 u64 total_bytes; ///< Bytes total on overall download.
60 INSERT_PADDING_BYTES( 60 INSERT_PADDING_BYTES(
61 0x198); ///< Appears to be unused in official code, possibly reserved for future use. 61 0x198); ///< Appears to be unused in official code, possibly reserved for future use.
62}; 62};
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
index 589e288df..bd7ea75c2 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -3,7 +3,16 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <fmt/ostream.h> 5#include <fmt/ostream.h>
6
7#if defined(__GNUC__)
8#pragma GCC diagnostic push
9#pragma GCC diagnostic ignored "-Wsign-conversion"
10#endif
6#include <httplib.h> 11#include <httplib.h>
12#if defined(__GNUC__)
13#pragma GCC diagnostic pop
14#endif
15
7#include <mbedtls/sha256.h> 16#include <mbedtls/sha256.h>
8#include <nlohmann/json.hpp> 17#include <nlohmann/json.hpp>
9#include "common/hex_util.h" 18#include "common/hex_util.h"
diff --git a/src/core/hle/service/bcat/module.cpp b/src/core/hle/service/bcat/module.cpp
index db0e06ca1..5a7e9f930 100644
--- a/src/core/hle/service/bcat/module.cpp
+++ b/src/core/hle/service/bcat/module.cpp
@@ -454,7 +454,8 @@ private:
454 write_size = std::min<u64>(write_size, files.size()); 454 write_size = std::min<u64>(write_size, files.size());
455 std::vector<DeliveryCacheDirectoryEntry> entries(write_size); 455 std::vector<DeliveryCacheDirectoryEntry> entries(write_size);
456 std::transform( 456 std::transform(
457 files.begin(), files.begin() + write_size, entries.begin(), [](const auto& file) { 457 files.begin(), files.begin() + static_cast<s64>(write_size), entries.begin(),
458 [](const auto& file) {
458 FileName name{}; 459 FileName name{};
459 std::memcpy(name.data(), file->GetName().data(), 460 std::memcpy(name.data(), file->GetName().data(),
460 std::min(file->GetName().size(), name.size())); 461 std::min(file->GetName().size(), name.size()));
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 649128be4..993686f1d 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -94,7 +94,8 @@ private:
94 } 94 }
95 95
96 // Read the data from the Storage backend 96 // Read the data from the Storage backend
97 std::vector<u8> output = backend->ReadBytes(length, offset); 97 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset));
98
98 // Write the data to memory 99 // Write the data to memory
99 ctx.WriteBuffer(output); 100 ctx.WriteBuffer(output);
100 101
@@ -151,7 +152,7 @@ private:
151 } 152 }
152 153
153 // Read the data from the Storage backend 154 // Read the data from the Storage backend
154 std::vector<u8> output = backend->ReadBytes(length, offset); 155 const auto output = backend->ReadBytes(static_cast<u64>(length), static_cast<u64>(offset));
155 156
156 // Write the data to memory 157 // Write the data to memory
157 ctx.WriteBuffer(output); 158 ctx.WriteBuffer(output);
@@ -194,7 +195,8 @@ private:
194 // Write the data to the Storage backend 195 // Write the data to the Storage backend
195 const auto write_size = 196 const auto write_size =
196 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); 197 static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
197 const std::size_t written = backend->Write(data.data(), write_size, offset); 198 const std::size_t written =
199 backend->Write(data.data(), write_size, static_cast<u64>(offset));
198 200
199 ASSERT_MSG(static_cast<s64>(written) == length, 201 ASSERT_MSG(static_cast<s64>(written) == length,
200 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, 202 "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,
diff --git a/src/core/hle/service/hid/controllers/debug_pad.cpp b/src/core/hle/service/hid/controllers/debug_pad.cpp
index ad251ed4a..c2c1470a5 100644
--- a/src/core/hle/service/hid/controllers/debug_pad.cpp
+++ b/src/core/hle/service/hid/controllers/debug_pad.cpp
@@ -23,7 +23,7 @@ void Controller_DebugPad::OnRelease() {}
23 23
24void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 24void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
25 std::size_t size) { 25 std::size_t size) {
26 shared_memory.header.timestamp = core_timing.GetCPUTicks(); 26 shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
27 shared_memory.header.total_entry_count = 17; 27 shared_memory.header.total_entry_count = 17;
28 28
29 if (!IsControllerActivated()) { 29 if (!IsControllerActivated()) {
@@ -33,9 +33,11 @@ void Controller_DebugPad::OnUpdate(const Core::Timing::CoreTiming& core_timing,
33 } 33 }
34 shared_memory.header.entry_count = 16; 34 shared_memory.header.entry_count = 16;
35 35
36 const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 36 const auto& last_entry =
37 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
38 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 39 auto& cur_entry =
40 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
39 41
40 cur_entry.sampling_number = last_entry.sampling_number + 1; 42 cur_entry.sampling_number = last_entry.sampling_number + 1;
41 cur_entry.sampling_number2 = cur_entry.sampling_number; 43 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/gesture.cpp b/src/core/hle/service/hid/controllers/gesture.cpp
index b7b7bfeae..0618b2a05 100644
--- a/src/core/hle/service/hid/controllers/gesture.cpp
+++ b/src/core/hle/service/hid/controllers/gesture.cpp
@@ -19,7 +19,7 @@ void Controller_Gesture::OnRelease() {}
19 19
20void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
21 std::size_t size) { 21 std::size_t size) {
22 shared_memory.header.timestamp = core_timing.GetCPUTicks(); 22 shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
23 shared_memory.header.total_entry_count = 17; 23 shared_memory.header.total_entry_count = 17;
24 24
25 if (!IsControllerActivated()) { 25 if (!IsControllerActivated()) {
@@ -29,9 +29,11 @@ void Controller_Gesture::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
29 } 29 }
30 shared_memory.header.entry_count = 16; 30 shared_memory.header.entry_count = 16;
31 31
32 const auto& last_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 32 const auto& last_entry =
33 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
34 auto& cur_entry = shared_memory.gesture_states[shared_memory.header.last_entry_index]; 35 auto& cur_entry =
36 shared_memory.gesture_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 37
36 cur_entry.sampling_number = last_entry.sampling_number + 1; 38 cur_entry.sampling_number = last_entry.sampling_number + 1;
37 cur_entry.sampling_number2 = cur_entry.sampling_number; 39 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/keyboard.cpp b/src/core/hle/service/hid/controllers/keyboard.cpp
index 59b694cd4..0624be316 100644
--- a/src/core/hle/service/hid/controllers/keyboard.cpp
+++ b/src/core/hle/service/hid/controllers/keyboard.cpp
@@ -21,7 +21,7 @@ void Controller_Keyboard::OnRelease() {}
21 21
22void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 22void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
23 std::size_t size) { 23 std::size_t size) {
24 shared_memory.header.timestamp = core_timing.GetCPUTicks(); 24 shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
25 shared_memory.header.total_entry_count = 17; 25 shared_memory.header.total_entry_count = 17;
26 26
27 if (!IsControllerActivated()) { 27 if (!IsControllerActivated()) {
@@ -31,9 +31,11 @@ void Controller_Keyboard::OnUpdate(const Core::Timing::CoreTiming& core_timing,
31 } 31 }
32 shared_memory.header.entry_count = 16; 32 shared_memory.header.entry_count = 16;
33 33
34 const auto& last_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 34 const auto& last_entry =
35 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 36 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
36 auto& cur_entry = shared_memory.pad_states[shared_memory.header.last_entry_index]; 37 auto& cur_entry =
38 shared_memory.pad_states[static_cast<u64>(shared_memory.header.last_entry_index)];
37 39
38 cur_entry.sampling_number = last_entry.sampling_number + 1; 40 cur_entry.sampling_number = last_entry.sampling_number + 1;
39 cur_entry.sampling_number2 = cur_entry.sampling_number; 41 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/mouse.cpp b/src/core/hle/service/hid/controllers/mouse.cpp
index ac40989c5..10e2373bc 100644
--- a/src/core/hle/service/hid/controllers/mouse.cpp
+++ b/src/core/hle/service/hid/controllers/mouse.cpp
@@ -19,7 +19,7 @@ void Controller_Mouse::OnRelease() {}
19 19
20void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
21 std::size_t size) { 21 std::size_t size) {
22 shared_memory.header.timestamp = core_timing.GetCPUTicks(); 22 shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
23 shared_memory.header.total_entry_count = 17; 23 shared_memory.header.total_entry_count = 17;
24 24
25 if (!IsControllerActivated()) { 25 if (!IsControllerActivated()) {
@@ -29,9 +29,11 @@ void Controller_Mouse::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
29 } 29 }
30 shared_memory.header.entry_count = 16; 30 shared_memory.header.entry_count = 16;
31 31
32 auto& last_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; 32 auto& last_entry =
33 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
33 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 34 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
34 auto& cur_entry = shared_memory.mouse_states[shared_memory.header.last_entry_index]; 35 auto& cur_entry =
36 shared_memory.mouse_states[static_cast<u64>(shared_memory.header.last_entry_index)];
35 37
36 cur_entry.sampling_number = last_entry.sampling_number + 1; 38 cur_entry.sampling_number = last_entry.sampling_number + 1;
37 cur_entry.sampling_number2 = cur_entry.sampling_number; 39 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/npad.cpp b/src/core/hle/service/hid/controllers/npad.cpp
index e311bc18c..2422c0190 100644
--- a/src/core/hle/service/hid/controllers/npad.cpp
+++ b/src/core/hle/service/hid/controllers/npad.cpp
@@ -341,26 +341,29 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
341 } 341 }
342 for (std::size_t i = 0; i < shared_memory_entries.size(); i++) { 342 for (std::size_t i = 0; i < shared_memory_entries.size(); i++) {
343 auto& npad = shared_memory_entries[i]; 343 auto& npad = shared_memory_entries[i];
344 const std::array<NPadGeneric*, 7> controller_npads{&npad.main_controller_states, 344 const std::array controller_npads{
345 &npad.handheld_states, 345 &npad.main_controller_states,
346 &npad.dual_states, 346 &npad.handheld_states,
347 &npad.left_joy_states, 347 &npad.dual_states,
348 &npad.right_joy_states, 348 &npad.left_joy_states,
349 &npad.pokeball_states, 349 &npad.right_joy_states,
350 &npad.libnx}; 350 &npad.pokeball_states,
351 &npad.libnx,
352 };
351 353
352 for (auto* main_controller : controller_npads) { 354 for (auto* main_controller : controller_npads) {
353 main_controller->common.entry_count = 16; 355 main_controller->common.entry_count = 16;
354 main_controller->common.total_entry_count = 17; 356 main_controller->common.total_entry_count = 17;
355 357
356 const auto& last_entry = 358 const auto& last_entry =
357 main_controller->npad[main_controller->common.last_entry_index]; 359 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)];
358 360
359 main_controller->common.timestamp = core_timing.GetCPUTicks(); 361 main_controller->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
360 main_controller->common.last_entry_index = 362 main_controller->common.last_entry_index =
361 (main_controller->common.last_entry_index + 1) % 17; 363 (main_controller->common.last_entry_index + 1) % 17;
362 364
363 auto& cur_entry = main_controller->npad[main_controller->common.last_entry_index]; 365 auto& cur_entry =
366 main_controller->npad[static_cast<u64>(main_controller->common.last_entry_index)];
364 367
365 cur_entry.timestamp = last_entry.timestamp + 1; 368 cur_entry.timestamp = last_entry.timestamp + 1;
366 cur_entry.timestamp2 = cur_entry.timestamp; 369 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -371,22 +374,29 @@ void Controller_NPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
371 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) { 374 if (controller_type == NPadControllerType::None || !connected_controllers[i].is_connected) {
372 continue; 375 continue;
373 } 376 }
374 const u32 npad_index = static_cast<u32>(i); 377 const auto npad_index = static_cast<u32>(i);
375 378
376 RequestPadStateUpdate(npad_index); 379 RequestPadStateUpdate(npad_index);
377 auto& pad_state = npad_pad_states[npad_index]; 380 auto& pad_state = npad_pad_states[npad_index];
378 381
379 auto& main_controller = 382 auto& main_controller =
380 npad.main_controller_states.npad[npad.main_controller_states.common.last_entry_index]; 383 npad.main_controller_states
384 .npad[static_cast<u64>(npad.main_controller_states.common.last_entry_index)];
381 auto& handheld_entry = 385 auto& handheld_entry =
382 npad.handheld_states.npad[npad.handheld_states.common.last_entry_index]; 386 npad.handheld_states
383 auto& dual_entry = npad.dual_states.npad[npad.dual_states.common.last_entry_index]; 387 .npad[static_cast<u64>(npad.handheld_states.common.last_entry_index)];
384 auto& left_entry = npad.left_joy_states.npad[npad.left_joy_states.common.last_entry_index]; 388 auto& dual_entry =
389 npad.dual_states.npad[static_cast<u64>(npad.dual_states.common.last_entry_index)];
390 auto& left_entry =
391 npad.left_joy_states
392 .npad[static_cast<u64>(npad.left_joy_states.common.last_entry_index)];
385 auto& right_entry = 393 auto& right_entry =
386 npad.right_joy_states.npad[npad.right_joy_states.common.last_entry_index]; 394 npad.right_joy_states
395 .npad[static_cast<u64>(npad.right_joy_states.common.last_entry_index)];
387 auto& pokeball_entry = 396 auto& pokeball_entry =
388 npad.pokeball_states.npad[npad.pokeball_states.common.last_entry_index]; 397 npad.pokeball_states
389 auto& libnx_entry = npad.libnx.npad[npad.libnx.common.last_entry_index]; 398 .npad[static_cast<u64>(npad.pokeball_states.common.last_entry_index)];
399 auto& libnx_entry = npad.libnx.npad[static_cast<u64>(npad.libnx.common.last_entry_index)];
390 400
391 libnx_entry.connection_status.raw = 0; 401 libnx_entry.connection_status.raw = 0;
392 libnx_entry.connection_status.IsConnected.Assign(1); 402 libnx_entry.connection_status.IsConnected.Assign(1);
@@ -500,13 +510,14 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
500 sixaxis_sensor->common.total_entry_count = 17; 510 sixaxis_sensor->common.total_entry_count = 17;
501 511
502 const auto& last_entry = 512 const auto& last_entry =
503 sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; 513 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)];
504 514
505 sixaxis_sensor->common.timestamp = core_timing.GetCPUTicks(); 515 sixaxis_sensor->common.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
506 sixaxis_sensor->common.last_entry_index = 516 sixaxis_sensor->common.last_entry_index =
507 (sixaxis_sensor->common.last_entry_index + 1) % 17; 517 (sixaxis_sensor->common.last_entry_index + 1) % 17;
508 518
509 auto& cur_entry = sixaxis_sensor->sixaxis[sixaxis_sensor->common.last_entry_index]; 519 auto& cur_entry =
520 sixaxis_sensor->sixaxis[static_cast<u64>(sixaxis_sensor->common.last_entry_index)];
510 521
511 cur_entry.timestamp = last_entry.timestamp + 1; 522 cur_entry.timestamp = last_entry.timestamp + 1;
512 cur_entry.timestamp2 = cur_entry.timestamp; 523 cur_entry.timestamp2 = cur_entry.timestamp;
@@ -529,17 +540,21 @@ void Controller_NPad::OnMotionUpdate(const Core::Timing::CoreTiming& core_timing
529 } 540 }
530 541
531 auto& full_sixaxis_entry = 542 auto& full_sixaxis_entry =
532 npad.sixaxis_full.sixaxis[npad.sixaxis_full.common.last_entry_index]; 543 npad.sixaxis_full.sixaxis[static_cast<u64>(npad.sixaxis_full.common.last_entry_index)];
533 auto& handheld_sixaxis_entry = 544 auto& handheld_sixaxis_entry =
534 npad.sixaxis_handheld.sixaxis[npad.sixaxis_handheld.common.last_entry_index]; 545 npad.sixaxis_handheld
546 .sixaxis[static_cast<u64>(npad.sixaxis_handheld.common.last_entry_index)];
535 auto& dual_left_sixaxis_entry = 547 auto& dual_left_sixaxis_entry =
536 npad.sixaxis_dual_left.sixaxis[npad.sixaxis_dual_left.common.last_entry_index]; 548 npad.sixaxis_dual_left
549 .sixaxis[static_cast<u64>(npad.sixaxis_dual_left.common.last_entry_index)];
537 auto& dual_right_sixaxis_entry = 550 auto& dual_right_sixaxis_entry =
538 npad.sixaxis_dual_right.sixaxis[npad.sixaxis_dual_right.common.last_entry_index]; 551 npad.sixaxis_dual_right
552 .sixaxis[static_cast<u64>(npad.sixaxis_dual_right.common.last_entry_index)];
539 auto& left_sixaxis_entry = 553 auto& left_sixaxis_entry =
540 npad.sixaxis_left.sixaxis[npad.sixaxis_left.common.last_entry_index]; 554 npad.sixaxis_left.sixaxis[static_cast<u64>(npad.sixaxis_left.common.last_entry_index)];
541 auto& right_sixaxis_entry = 555 auto& right_sixaxis_entry =
542 npad.sixaxis_right.sixaxis[npad.sixaxis_right.common.last_entry_index]; 556 npad.sixaxis_right
557 .sixaxis[static_cast<u64>(npad.sixaxis_right.common.last_entry_index)];
543 558
544 switch (controller_type) { 559 switch (controller_type) {
545 case NPadControllerType::None: 560 case NPadControllerType::None:
diff --git a/src/core/hle/service/hid/controllers/stubbed.cpp b/src/core/hle/service/hid/controllers/stubbed.cpp
index e7483bfa2..f9cb61667 100644
--- a/src/core/hle/service/hid/controllers/stubbed.cpp
+++ b/src/core/hle/service/hid/controllers/stubbed.cpp
@@ -22,12 +22,12 @@ void Controller_Stubbed::OnUpdate(const Core::Timing::CoreTiming& core_timing, u
22 return; 22 return;
23 } 23 }
24 24
25 CommonHeader header{}; 25 const CommonHeader header{
26 header.timestamp = core_timing.GetCPUTicks(); 26 .timestamp = static_cast<s64>(core_timing.GetCPUTicks()),
27 header.total_entry_count = 17; 27 .total_entry_count = 17,
28 header.entry_count = 0; 28 .last_entry_index = 0,
29 header.last_entry_index = 0; 29 .entry_count = 0,
30 30 };
31 std::memcpy(data + common_offset, &header, sizeof(CommonHeader)); 31 std::memcpy(data + common_offset, &header, sizeof(CommonHeader));
32} 32}
33 33
diff --git a/src/core/hle/service/hid/controllers/touchscreen.cpp b/src/core/hle/service/hid/controllers/touchscreen.cpp
index 0df395e85..06f4134a2 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.cpp
+++ b/src/core/hle/service/hid/controllers/touchscreen.cpp
@@ -22,7 +22,7 @@ void Controller_Touchscreen::OnRelease() {}
22 22
23void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 23void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
24 std::size_t size) { 24 std::size_t size) {
25 shared_memory.header.timestamp = core_timing.GetCPUTicks(); 25 shared_memory.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
26 shared_memory.header.total_entry_count = 17; 26 shared_memory.header.total_entry_count = 17;
27 27
28 if (!IsControllerActivated()) { 28 if (!IsControllerActivated()) {
@@ -33,9 +33,12 @@ void Controller_Touchscreen::OnUpdate(const Core::Timing::CoreTiming& core_timin
33 shared_memory.header.entry_count = 16; 33 shared_memory.header.entry_count = 16;
34 34
35 const auto& last_entry = 35 const auto& last_entry =
36 shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; 36 shared_memory
37 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
37 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17; 38 shared_memory.header.last_entry_index = (shared_memory.header.last_entry_index + 1) % 17;
38 auto& cur_entry = shared_memory.shared_memory_entries[shared_memory.header.last_entry_index]; 39 auto& cur_entry =
40 shared_memory
41 .shared_memory_entries[static_cast<u64>(shared_memory.header.last_entry_index)];
39 42
40 cur_entry.sampling_number = last_entry.sampling_number + 1; 43 cur_entry.sampling_number = last_entry.sampling_number + 1;
41 cur_entry.sampling_number2 = cur_entry.sampling_number; 44 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/hid/controllers/touchscreen.h b/src/core/hle/service/hid/controllers/touchscreen.h
index 4d9042adc..746acbd1c 100644
--- a/src/core/hle/service/hid/controllers/touchscreen.h
+++ b/src/core/hle/service/hid/controllers/touchscreen.h
@@ -69,6 +69,6 @@ private:
69 TouchScreenSharedMemory shared_memory{}; 69 TouchScreenSharedMemory shared_memory{};
70 std::unique_ptr<Input::TouchDevice> touch_device; 70 std::unique_ptr<Input::TouchDevice> touch_device;
71 std::unique_ptr<Input::TouchDevice> touch_btn_device; 71 std::unique_ptr<Input::TouchDevice> touch_btn_device;
72 s64_le last_touch{}; 72 u64_le last_touch{};
73}; 73};
74} // namespace Service::HID 74} // namespace Service::HID
diff --git a/src/core/hle/service/hid/controllers/xpad.cpp b/src/core/hle/service/hid/controllers/xpad.cpp
index 2503ef241..60417abb8 100644
--- a/src/core/hle/service/hid/controllers/xpad.cpp
+++ b/src/core/hle/service/hid/controllers/xpad.cpp
@@ -20,7 +20,7 @@ void Controller_XPad::OnRelease() {}
20void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data, 20void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8* data,
21 std::size_t size) { 21 std::size_t size) {
22 for (auto& xpad_entry : shared_memory.shared_memory_entries) { 22 for (auto& xpad_entry : shared_memory.shared_memory_entries) {
23 xpad_entry.header.timestamp = core_timing.GetCPUTicks(); 23 xpad_entry.header.timestamp = static_cast<s64>(core_timing.GetCPUTicks());
24 xpad_entry.header.total_entry_count = 17; 24 xpad_entry.header.total_entry_count = 17;
25 25
26 if (!IsControllerActivated()) { 26 if (!IsControllerActivated()) {
@@ -30,9 +30,11 @@ void Controller_XPad::OnUpdate(const Core::Timing::CoreTiming& core_timing, u8*
30 } 30 }
31 xpad_entry.header.entry_count = 16; 31 xpad_entry.header.entry_count = 16;
32 32
33 const auto& last_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; 33 const auto& last_entry =
34 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
34 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17; 35 xpad_entry.header.last_entry_index = (xpad_entry.header.last_entry_index + 1) % 17;
35 auto& cur_entry = xpad_entry.pad_states[xpad_entry.header.last_entry_index]; 36 auto& cur_entry =
37 xpad_entry.pad_states[static_cast<u64>(xpad_entry.header.last_entry_index)];
36 38
37 cur_entry.sampling_number = last_entry.sampling_number + 1; 39 cur_entry.sampling_number = last_entry.sampling_number + 1;
38 cur_entry.sampling_number2 = cur_entry.sampling_number; 40 cur_entry.sampling_number2 = cur_entry.sampling_number;
diff --git a/src/core/hle/service/ldr/ldr.cpp b/src/core/hle/service/ldr/ldr.cpp
index d8cd10e31..9ad5bbf0d 100644
--- a/src/core/hle/service/ldr/ldr.cpp
+++ b/src/core/hle/service/ldr/ldr.cpp
@@ -23,7 +23,7 @@ namespace Service::LDR {
23 23
24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2}; 24constexpr ResultCode ERROR_INSUFFICIENT_ADDRESS_SPACE{ErrorModule::RO, 2};
25 25
26constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51}; 26[[maybe_unused]] constexpr ResultCode ERROR_INVALID_MEMORY_STATE{ErrorModule::Loader, 51};
27constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52}; 27constexpr ResultCode ERROR_INVALID_NRO{ErrorModule::Loader, 52};
28constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53}; 28constexpr ResultCode ERROR_INVALID_NRR{ErrorModule::Loader, 53};
29constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54}; 29constexpr ResultCode ERROR_MISSING_NRR_HASH{ErrorModule::Loader, 54};
@@ -33,7 +33,7 @@ constexpr ResultCode ERROR_ALREADY_LOADED{ErrorModule::Loader, 57};
33constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81}; 33constexpr ResultCode ERROR_INVALID_ALIGNMENT{ErrorModule::Loader, 81};
34constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82}; 34constexpr ResultCode ERROR_INVALID_SIZE{ErrorModule::Loader, 82};
35constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84}; 35constexpr ResultCode ERROR_INVALID_NRO_ADDRESS{ErrorModule::Loader, 84};
36constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85}; 36[[maybe_unused]] constexpr ResultCode ERROR_INVALID_NRR_ADDRESS{ErrorModule::Loader, 85};
37constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87}; 37constexpr ResultCode ERROR_NOT_INITIALIZED{ErrorModule::Loader, 87};
38 38
39constexpr std::size_t MAXIMUM_LOADED_RO{0x40}; 39constexpr std::size_t MAXIMUM_LOADED_RO{0x40};
diff --git a/src/core/hle/service/mii/manager.cpp b/src/core/hle/service/mii/manager.cpp
index 8e433eb41..5930765bc 100644
--- a/src/core/hle/service/mii/manager.cpp
+++ b/src/core/hle/service/mii/manager.cpp
@@ -240,10 +240,10 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
240 bf.eye_type.Assign( 240 bf.eye_type.Assign(
241 eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]); 241 eye_type_info.values[GetRandomValue<std::size_t>(eye_type_info.values_count)]);
242 242
243 const auto eye_rotate_1{gender != Gender::Male ? 4 : 2}; 243 const auto eye_rotate_1{gender != Gender::Male ? 4U : 2U};
244 const auto eye_rotate_2{gender != Gender::Male ? 3 : 4}; 244 const auto eye_rotate_2{gender != Gender::Male ? 3U : 4U};
245 const auto eye_rotate_offset{32 - EyeRotateLookup[eye_rotate_1] + eye_rotate_2}; 245 const auto eye_rotate_offset{32U - EyeRotateLookup[eye_rotate_1] + eye_rotate_2};
246 const auto eye_rotate{32 - EyeRotateLookup[bf.eye_type]}; 246 const auto eye_rotate{32U - EyeRotateLookup[bf.eye_type]};
247 247
248 bf.eye_color.Assign( 248 bf.eye_color.Assign(
249 EyeColorLookup[eye_color_info 249 EyeColorLookup[eye_color_info
@@ -257,11 +257,11 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
257 bf.eyebrow_type.Assign( 257 bf.eyebrow_type.Assign(
258 eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]); 258 eyebrow_type_info.values[GetRandomValue<std::size_t>(eyebrow_type_info.values_count)]);
259 259
260 const auto eyebrow_rotate_1{race == Race::Asian ? 6 : 0}; 260 const auto eyebrow_rotate_1{race == Race::Asian ? 6U : 0U};
261 const auto eyebrow_y{race == Race::Asian ? 9 : 10}; 261 const auto eyebrow_y{race == Race::Asian ? 9U : 10U};
262 const auto eyebrow_rotate_offset{32 - EyebrowRotateLookup[eyebrow_rotate_1] + 6}; 262 const auto eyebrow_rotate_offset{32U - EyebrowRotateLookup[eyebrow_rotate_1] + 6};
263 const auto eyebrow_rotate{ 263 const auto eyebrow_rotate{
264 32 - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]}; 264 32U - EyebrowRotateLookup[static_cast<std::size_t>(bf.eyebrow_type.Value())]};
265 265
266 bf.eyebrow_color.Assign(bf.hair_color); 266 bf.eyebrow_color.Assign(bf.hair_color);
267 bf.eyebrow_scale.Assign(4); 267 bf.eyebrow_scale.Assign(4);
@@ -270,14 +270,14 @@ MiiStoreData BuildRandomStoreData(Age age, Gender gender, Race race, const Commo
270 bf.eyebrow_x.Assign(2); 270 bf.eyebrow_x.Assign(2);
271 bf.eyebrow_y.Assign(axis_y + eyebrow_y); 271 bf.eyebrow_y.Assign(axis_y + eyebrow_y);
272 272
273 const auto nose_scale{gender == Gender::Female ? 3 : 4}; 273 const auto nose_scale{gender == Gender::Female ? 3U : 4U};
274 274
275 bf.nose_type.Assign( 275 bf.nose_type.Assign(
276 nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]); 276 nose_type_info.values[GetRandomValue<std::size_t>(nose_type_info.values_count)]);
277 bf.nose_scale.Assign(nose_scale); 277 bf.nose_scale.Assign(nose_scale);
278 bf.nose_y.Assign(axis_y + 9); 278 bf.nose_y.Assign(axis_y + 9);
279 279
280 const auto mouth_color{gender == Gender::Female ? GetRandomValue<int>(4) : 0}; 280 const auto mouth_color{gender == Gender::Female ? GetRandomValue<u32>(4) : 0U};
281 281
282 bf.mouth_type.Assign( 282 bf.mouth_type.Assign(
283 mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]); 283 mouth_type_info.values[GetRandomValue<std::size_t>(mouth_type_info.values_count)]);
diff --git a/src/core/hle/service/nfp/nfp.cpp b/src/core/hle/service/nfp/nfp.cpp
index a0469ffbd..0dd23ec9e 100644
--- a/src/core/hle/service/nfp/nfp.cpp
+++ b/src/core/hle/service/nfp/nfp.cpp
@@ -217,7 +217,7 @@ private:
217 const auto& amiibo = nfp_interface.GetAmiiboBuffer(); 217 const auto& amiibo = nfp_interface.GetAmiiboBuffer();
218 const TagInfo tag_info{ 218 const TagInfo tag_info{
219 .uuid = amiibo.uuid, 219 .uuid = amiibo.uuid,
220 .uuid_length = static_cast<u8>(tag_info.uuid.size()), 220 .uuid_length = static_cast<u8>(amiibo.uuid.size()),
221 .padding_1 = {}, 221 .padding_1 = {},
222 .protocol = 1, // TODO(ogniK): Figure out actual values 222 .protocol = 1, // TODO(ogniK): Figure out actual values
223 .tag_type = 2, 223 .tag_type = 2,
diff --git a/src/core/hle/service/ns/ns.cpp b/src/core/hle/service/ns/ns.cpp
index 58ee1f712..3edee6303 100644
--- a/src/core/hle/service/ns/ns.cpp
+++ b/src/core/hle/service/ns/ns.cpp
@@ -368,7 +368,7 @@ ResultVal<u8> IApplicationManagerInterface::GetApplicationDesiredLanguage(
368 368
369 // Get language code from settings 369 // Get language code from settings
370 const auto language_code = 370 const auto language_code =
371 Set::GetLanguageCodeFromIndex(Settings::values.language_index.GetValue()); 371 Set::GetLanguageCodeFromIndex(static_cast<u32>(Settings::values.language_index.GetValue()));
372 372
373 // Convert to application language, get priority list 373 // Convert to application language, get priority list
374 const auto application_language = ConvertToApplicationLanguage(language_code); 374 const auto application_language = ConvertToApplicationLanguage(language_code);
diff --git a/src/core/hle/service/ns/pl_u.cpp b/src/core/hle/service/ns/pl_u.cpp
index 40838a225..5ccec2637 100644
--- a/src/core/hle/service/ns/pl_u.cpp
+++ b/src/core/hle/service/ns/pl_u.cpp
@@ -50,19 +50,9 @@ constexpr std::array<std::pair<FontArchives, const char*>, 7> SHARED_FONTS{
50 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"), 50 std::make_pair(FontArchives::Extension, "nintendo_ext2_003.bfttf"),
51}; 51};
52 52
53constexpr std::array<const char*, 7> SHARED_FONTS_TTF{
54 "FontStandard.ttf",
55 "FontChineseSimplified.ttf",
56 "FontExtendedChineseSimplified.ttf",
57 "FontChineseTraditional.ttf",
58 "FontKorean.ttf",
59 "FontNintendoExtended.ttf",
60 "FontNintendoExtended2.ttf",
61};
62
63// The below data is specific to shared font data dumped from Switch on f/w 2.2 53// The below data is specific to shared font data dumped from Switch on f/w 2.2
64// Virtual address and offsets/sizes likely will vary by dump 54// Virtual address and offsets/sizes likely will vary by dump
65constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL}; 55[[maybe_unused]] constexpr VAddr SHARED_FONT_MEM_VADDR{0x00000009d3016000ULL};
66constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be 56constexpr u32 EXPECTED_RESULT{0x7f9a0218}; // What we expect the decrypted bfttf first 4 bytes to be
67constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be 57constexpr u32 EXPECTED_MAGIC{0x36f81a1e}; // What we expect the encrypted bfttf first 4 bytes to be
68constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000}; 58constexpr u64 SHARED_FONT_MEM_SIZE{0x1100000};
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
index 39bd2a45b..85e921ceb 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_as_gpu.cpp
@@ -139,7 +139,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
139 139
140 const auto object{nvmap_dev->GetObject(params.nvmap_handle)}; 140 const auto object{nvmap_dev->GetObject(params.nvmap_handle)};
141 if (!object) { 141 if (!object) {
142 LOG_CRITICAL(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle); 142 LOG_ERROR(Service_NVDRV, "invalid nvmap_handle={:X}", params.nvmap_handle);
143 std::memcpy(output.data(), &params, output.size()); 143 std::memcpy(output.data(), &params, output.size());
144 return NvErrCodes::InvalidInput; 144 return NvErrCodes::InvalidInput;
145 } 145 }
@@ -151,21 +151,24 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
151 auto& gpu = system.GPU(); 151 auto& gpu = system.GPU();
152 152
153 u64 page_size{params.page_size}; 153 u64 page_size{params.page_size};
154 if (!page_size) { 154 if (page_size == 0) {
155 page_size = object->align; 155 page_size = object->align;
156 } 156 }
157 157
158 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) { 158 if ((params.flags & AddressSpaceFlags::Remap) != AddressSpaceFlags::None) {
159 if (const auto buffer_map{FindBufferMap(params.offset)}; buffer_map) { 159 const auto buffer_map = FindBufferMap(static_cast<GPUVAddr>(params.offset));
160 const auto cpu_addr{static_cast<VAddr>(buffer_map->CpuAddr() + params.buffer_offset)}; 160
161 if (buffer_map) {
162 const auto cpu_addr{
163 static_cast<VAddr>(buffer_map->CpuAddr() + static_cast<u64>(params.buffer_offset))};
161 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)}; 164 const auto gpu_addr{static_cast<GPUVAddr>(params.offset + params.buffer_offset)};
162 165
163 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) { 166 if (!gpu.MemoryManager().Map(cpu_addr, gpu_addr, params.mapping_size)) {
164 LOG_CRITICAL(Service_NVDRV, 167 LOG_ERROR(Service_NVDRV,
165 "remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, " 168 "Remap failed, flags={:X}, nvmap_handle={:X}, buffer_offset={}, "
166 "mapping_size = {}, offset={}", 169 "mapping_size = {}, offset={}",
167 params.flags, params.nvmap_handle, params.buffer_offset, 170 params.flags, params.nvmap_handle, params.buffer_offset,
168 params.mapping_size, params.offset); 171 params.mapping_size, params.offset);
169 172
170 std::memcpy(output.data(), &params, output.size()); 173 std::memcpy(output.data(), &params, output.size());
171 return NvErrCodes::InvalidInput; 174 return NvErrCodes::InvalidInput;
@@ -174,7 +177,7 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
174 std::memcpy(output.data(), &params, output.size()); 177 std::memcpy(output.data(), &params, output.size());
175 return NvErrCodes::Success; 178 return NvErrCodes::Success;
176 } else { 179 } else {
177 LOG_CRITICAL(Service_NVDRV, "address not mapped offset={}", params.offset); 180 LOG_ERROR(Service_NVDRV, "Address not mapped. offset={}", params.offset);
178 181
179 std::memcpy(output.data(), &params, output.size()); 182 std::memcpy(output.data(), &params, output.size());
180 return NvErrCodes::InvalidInput; 183 return NvErrCodes::InvalidInput;
@@ -184,25 +187,27 @@ u32 nvhost_as_gpu::MapBufferEx(const std::vector<u8>& input, std::vector<u8>& ou
184 // We can only map objects that have already been assigned a CPU address. 187 // We can only map objects that have already been assigned a CPU address.
185 ASSERT(object->status == nvmap::Object::Status::Allocated); 188 ASSERT(object->status == nvmap::Object::Status::Allocated);
186 189
187 const auto physical_address{object->addr + params.buffer_offset}; 190 const auto physical_address{object->addr + static_cast<VAddr>(params.buffer_offset)};
188 u64 size{params.mapping_size}; 191 u64 size{params.mapping_size};
189 if (!size) { 192 if (size == 0) {
190 size = object->size; 193 size = object->size;
191 } 194 }
192 195
193 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None}; 196 const bool is_alloc{(params.flags & AddressSpaceFlags::FixedOffset) == AddressSpaceFlags::None};
194 if (is_alloc) { 197 if (is_alloc) {
195 params.offset = gpu.MemoryManager().MapAllocate(physical_address, size, page_size); 198 params.offset =
199 static_cast<s64>(gpu.MemoryManager().MapAllocate(physical_address, size, page_size));
196 } else { 200 } else {
197 params.offset = gpu.MemoryManager().Map(physical_address, params.offset, size); 201 params.offset = static_cast<s64>(
202 gpu.MemoryManager().Map(physical_address, static_cast<GPUVAddr>(params.offset), size));
198 } 203 }
199 204
200 auto result{NvErrCodes::Success}; 205 auto result{NvErrCodes::Success};
201 if (!params.offset) { 206 if (params.offset == 0) {
202 LOG_CRITICAL(Service_NVDRV, "failed to map size={}", size); 207 LOG_ERROR(Service_NVDRV, "Failed to map size={}", size);
203 result = NvErrCodes::InvalidInput; 208 result = NvErrCodes::InvalidInput;
204 } else { 209 } else {
205 AddBufferMap(params.offset, size, physical_address, is_alloc); 210 AddBufferMap(static_cast<GPUVAddr>(params.offset), size, physical_address, is_alloc);
206 } 211 }
207 212
208 std::memcpy(output.data(), &params, output.size()); 213 std::memcpy(output.data(), &params, output.size());
@@ -213,12 +218,13 @@ u32 nvhost_as_gpu::UnmapBuffer(const std::vector<u8>& input, std::vector<u8>& ou
213 IoctlUnmapBuffer params{}; 218 IoctlUnmapBuffer params{};
214 std::memcpy(&params, input.data(), input.size()); 219 std::memcpy(&params, input.data(), input.size());
215 220
216 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", params.offset); 221 const auto offset = static_cast<GPUVAddr>(params.offset);
222 LOG_DEBUG(Service_NVDRV, "called, offset=0x{:X}", offset);
217 223
218 if (const auto size{RemoveBufferMap(params.offset)}; size) { 224 if (const auto size{RemoveBufferMap(offset)}; size) {
219 system.GPU().MemoryManager().Unmap(params.offset, *size); 225 system.GPU().MemoryManager().Unmap(offset, *size);
220 } else { 226 } else {
221 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", params.offset); 227 LOG_ERROR(Service_NVDRV, "invalid offset=0x{:X}", offset);
222 } 228 }
223 229
224 std::memcpy(output.data(), &params, output.size()); 230 std::memcpy(output.data(), &params, output.size());
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
index b27ee0502..07d851d0e 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_ctrl.cpp
@@ -63,8 +63,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
63 return NvResult::BadParameter; 63 return NvResult::BadParameter;
64 } 64 }
65 65
66 u32 event_id = params.value & 0x00FF; 66 const u32 event_id = params.value & 0x00FF;
67
68 if (event_id >= MaxNvEvents) { 67 if (event_id >= MaxNvEvents) {
69 std::memcpy(output.data(), &params, sizeof(params)); 68 std::memcpy(output.data(), &params, sizeof(params));
70 return NvResult::BadParameter; 69 return NvResult::BadParameter;
@@ -78,16 +77,17 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
78 event.writable->Signal(); 77 event.writable->Signal();
79 return NvResult::Success; 78 return NvResult::Success;
80 } 79 }
80
81 auto lock = gpu.LockSync(); 81 auto lock = gpu.LockSync();
82 const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id); 82 const u32 current_syncpoint_value = gpu.GetSyncpointValue(params.syncpt_id);
83 const s32 diff = current_syncpoint_value - params.threshold; 83 const s32 diff = static_cast<s32>(current_syncpoint_value - params.threshold);
84 if (diff >= 0) { 84 if (diff >= 0) {
85 event.writable->Signal(); 85 event.writable->Signal();
86 params.value = current_syncpoint_value; 86 params.value = current_syncpoint_value;
87 std::memcpy(output.data(), &params, sizeof(params)); 87 std::memcpy(output.data(), &params, sizeof(params));
88 return NvResult::Success; 88 return NvResult::Success;
89 } 89 }
90 const u32 target_value = current_syncpoint_value - diff; 90 const u32 target_value = current_syncpoint_value - static_cast<u32>(diff);
91 91
92 if (!is_async) { 92 if (!is_async) {
93 params.value = 0; 93 params.value = 0;
@@ -98,7 +98,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
98 return NvResult::Timeout; 98 return NvResult::Timeout;
99 } 99 }
100 100
101 EventState status = events_interface.status[event_id]; 101 const EventState status = events_interface.status[event_id];
102 if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) { 102 if (event_id < MaxNvEvents || status == EventState::Free || status == EventState::Registered) {
103 events_interface.SetEventStatus(event_id, EventState::Waiting); 103 events_interface.SetEventStatus(event_id, EventState::Waiting);
104 events_interface.assigned_syncpt[event_id] = params.syncpt_id; 104 events_interface.assigned_syncpt[event_id] = params.syncpt_id;
@@ -114,7 +114,7 @@ u32 nvhost_ctrl::IocCtrlEventWait(const std::vector<u8>& input, std::vector<u8>&
114 if (!is_async && ctrl.fresh_call) { 114 if (!is_async && ctrl.fresh_call) {
115 ctrl.must_delay = true; 115 ctrl.must_delay = true;
116 ctrl.timeout = params.timeout; 116 ctrl.timeout = params.timeout;
117 ctrl.event_id = event_id; 117 ctrl.event_id = static_cast<s32>(event_id);
118 return NvResult::Timeout; 118 return NvResult::Timeout;
119 } 119 }
120 std::memcpy(output.data(), &params, sizeof(params)); 120 std::memcpy(output.data(), &params, sizeof(params));
diff --git a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
index f1966ac0e..5e51b37be 100644
--- a/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
+++ b/src/core/hle/service/nvdrv/devices/nvhost_gpu.cpp
@@ -127,7 +127,7 @@ u32 nvhost_gpu::AllocGPFIFOEx2(const std::vector<u8>& input, std::vector<u8>& ou
127 params.unk3); 127 params.unk3);
128 128
129 auto& gpu = system.GPU(); 129 auto& gpu = system.GPU();
130 params.fence_out.id = assigned_syncpoints; 130 params.fence_out.id = static_cast<s32>(assigned_syncpoints);
131 params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints); 131 params.fence_out.value = gpu.GetSyncpointValue(assigned_syncpoints);
132 assigned_syncpoints++; 132 assigned_syncpoints++;
133 std::memcpy(output.data(), &params, output.size()); 133 std::memcpy(output.data(), &params, output.size());
@@ -166,7 +166,8 @@ u32 nvhost_gpu::SubmitGPFIFO(const std::vector<u8>& input, std::vector<u8>& outp
166 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 166 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);
167 167
168 auto& gpu = system.GPU(); 168 auto& gpu = system.GPU();
169 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); 169 const u32 current_syncpoint_value =
170 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
170 if (params.flags.increment.Value()) { 171 if (params.flags.increment.Value()) {
171 params.fence_out.value += current_syncpoint_value; 172 params.fence_out.value += current_syncpoint_value;
172 } else { 173 } else {
@@ -200,7 +201,8 @@ u32 nvhost_gpu::KickoffPB(const std::vector<u8>& input, std::vector<u8>& output,
200 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0); 201 UNIMPLEMENTED_IF(params.flags.add_increment.Value() != 0);
201 202
202 auto& gpu = system.GPU(); 203 auto& gpu = system.GPU();
203 u32 current_syncpoint_value = gpu.GetSyncpointValue(params.fence_out.id); 204 const u32 current_syncpoint_value =
205 gpu.GetSyncpointValue(static_cast<u32>(params.fence_out.id));
204 if (params.flags.increment.Value()) { 206 if (params.flags.increment.Value()) {
205 params.fence_out.value += current_syncpoint_value; 207 params.fence_out.value += current_syncpoint_value;
206 } else { 208 } else {
diff --git a/src/core/hle/service/nvdrv/interface.cpp b/src/core/hle/service/nvdrv/interface.cpp
index 88fbfa9b0..2f4f73487 100644
--- a/src/core/hle/service/nvdrv/interface.cpp
+++ b/src/core/hle/service/nvdrv/interface.cpp
@@ -61,9 +61,9 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) {
61 if (ctrl.must_delay) { 61 if (ctrl.must_delay) {
62 ctrl.fresh_call = false; 62 ctrl.fresh_call = false;
63 ctx.SleepClientThread( 63 ctx.SleepClientThread(
64 "NVServices::DelayedResponse", ctrl.timeout, 64 "NVServices::DelayedResponse", static_cast<u64>(ctrl.timeout),
65 [=, this](std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx_, 65 [=, this](std::shared_ptr<Kernel::Thread>, Kernel::HLERequestContext& ctx_,
66 Kernel::ThreadWakeupReason reason) { 66 Kernel::ThreadWakeupReason) {
67 IoctlCtrl ctrl2{ctrl}; 67 IoctlCtrl ctrl2{ctrl};
68 std::vector<u8> tmp_output = output; 68 std::vector<u8> tmp_output = output;
69 std::vector<u8> tmp_output2 = output2; 69 std::vector<u8> tmp_output2 = output2;
@@ -77,7 +77,7 @@ void NVDRV::IoctlBase(Kernel::HLERequestContext& ctx, IoctlVersion version) {
77 rb.Push(RESULT_SUCCESS); 77 rb.Push(RESULT_SUCCESS);
78 rb.Push(ioctl_result); 78 rb.Push(ioctl_result);
79 }, 79 },
80 nvdrv->GetEventWriteable(ctrl.event_id)); 80 nvdrv->GetEventWriteable(static_cast<u32>(ctrl.event_id)));
81 } else { 81 } else {
82 ctx.WriteBuffer(output); 82 ctx.WriteBuffer(output);
83 if (version == IoctlVersion::Version3) { 83 if (version == IoctlVersion::Version3) {
diff --git a/src/core/hle/service/nvflinger/nvflinger.cpp b/src/core/hle/service/nvflinger/nvflinger.cpp
index c64673dba..621a429bc 100644
--- a/src/core/hle/service/nvflinger/nvflinger.cpp
+++ b/src/core/hle/service/nvflinger/nvflinger.cpp
@@ -247,7 +247,7 @@ void NVFlinger::Compose() {
247 guard->unlock(); 247 guard->unlock();
248 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) { 248 for (u32 fence_id = 0; fence_id < multi_fence.num_fences; fence_id++) {
249 const auto& fence = multi_fence.fences[fence_id]; 249 const auto& fence = multi_fence.fences[fence_id];
250 gpu.WaitFence(fence.id, fence.value); 250 gpu.WaitFence(static_cast<u32>(fence.id), fence.value);
251 } 251 }
252 guard->lock(); 252 guard->lock();
253 253
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp
index ba9159ee0..bc7476a5b 100644
--- a/src/core/hle/service/service.cpp
+++ b/src/core/hle/service/service.cpp
@@ -80,10 +80,10 @@ namespace Service {
80 std::string_view port_name, 80 std::string_view port_name,
81 const u32* cmd_buff) { 81 const u32* cmd_buff) {
82 // Number of params == bits 0-5 + bits 6-11 82 // Number of params == bits 0-5 + bits 6-11
83 int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); 83 const u32 num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F);
84 84
85 std::string function_string = fmt::format("function '{}': port={}", name, port_name); 85 std::string function_string = fmt::format("function '{}': port={}", name, port_name);
86 for (int i = 1; i <= num_params; ++i) { 86 for (u32 i = 1; i <= num_params; ++i) {
87 function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]); 87 function_string += fmt::format(", cmd_buff[{}]=0x{:X}", i, cmd_buff[i]);
88 } 88 }
89 return function_string; 89 return function_string;
diff --git a/src/core/hle/service/set/set.cpp b/src/core/hle/service/set/set.cpp
index e64777668..82a7aecc7 100644
--- a/src/core/hle/service/set/set.cpp
+++ b/src/core/hle/service/set/set.cpp
@@ -91,7 +91,8 @@ void GetAvailableLanguageCodesImpl(Kernel::HLERequestContext& ctx, std::size_t m
91} 91}
92 92
93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) { 93void GetKeyCodeMapImpl(Kernel::HLERequestContext& ctx) {
94 const auto language_code = available_language_codes[Settings::values.language_index.GetValue()]; 94 const auto language_code =
95 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())];
95 const auto key_code = 96 const auto key_code =
96 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(), 97 std::find_if(language_to_layout.cbegin(), language_to_layout.cend(),
97 [=](const auto& element) { return element.first == language_code; }); 98 [=](const auto& element) { return element.first == language_code; });
@@ -167,7 +168,8 @@ void SET::GetLanguageCode(Kernel::HLERequestContext& ctx) {
167 168
168 IPC::ResponseBuilder rb{ctx, 4}; 169 IPC::ResponseBuilder rb{ctx, 4};
169 rb.Push(RESULT_SUCCESS); 170 rb.Push(RESULT_SUCCESS);
170 rb.PushEnum(available_language_codes[Settings::values.language_index.GetValue()]); 171 rb.PushEnum(
172 available_language_codes[static_cast<u32>(Settings::values.language_index.GetValue())]);
171} 173}
172 174
173void SET::GetRegionCode(Kernel::HLERequestContext& ctx) { 175void SET::GetRegionCode(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/sockets/bsd.cpp b/src/core/hle/service/sockets/bsd.cpp
index a74be9370..7cb70064c 100644
--- a/src/core/hle/service/sockets/bsd.cpp
+++ b/src/core/hle/service/sockets/bsd.cpp
@@ -437,9 +437,9 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
437 UNIMPLEMENTED_MSG("SOCK_RAW errno management"); 437 UNIMPLEMENTED_MSG("SOCK_RAW errno management");
438 } 438 }
439 439
440 [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000) != 0; 440 [[maybe_unused]] const bool unk_flag = (static_cast<u32>(type) & 0x20000000U) != 0;
441 UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type"); 441 UNIMPLEMENTED_IF_MSG(unk_flag, "Unknown flag in type");
442 type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000); 442 type = static_cast<Type>(static_cast<u32>(type) & ~0x20000000U);
443 443
444 const s32 fd = FindFreeFileDescriptorHandle(); 444 const s32 fd = FindFreeFileDescriptorHandle();
445 if (fd < 0) { 445 if (fd < 0) {
@@ -447,7 +447,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
447 return {-1, Errno::MFILE}; 447 return {-1, Errno::MFILE};
448 } 448 }
449 449
450 FileDescriptor& descriptor = file_descriptors[fd].emplace(); 450 FileDescriptor& descriptor = GetFileDescriptor(fd).emplace();
451 // ENONMEM might be thrown here 451 // ENONMEM might be thrown here
452 452
453 LOG_INFO(Service, "New socket fd={}", fd); 453 LOG_INFO(Service, "New socket fd={}", fd);
@@ -461,7 +461,7 @@ std::pair<s32, Errno> BSD::SocketImpl(Domain domain, Type type, Protocol protoco
461 461
462std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer, 462std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u8> read_buffer,
463 s32 nfds, s32 timeout) { 463 s32 nfds, s32 timeout) {
464 if (write_buffer.size() < nfds * sizeof(PollFD)) { 464 if (write_buffer.size() < static_cast<size_t>(nfds) * sizeof(PollFD)) {
465 return {-1, Errno::INVAL}; 465 return {-1, Errno::INVAL};
466 } 466 }
467 467
@@ -471,7 +471,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
471 } 471 }
472 472
473 const size_t length = std::min(read_buffer.size(), write_buffer.size()); 473 const size_t length = std::min(read_buffer.size(), write_buffer.size());
474 std::vector<PollFD> fds(nfds); 474 std::vector<PollFD> fds(static_cast<size_t>(nfds));
475 std::memcpy(fds.data(), read_buffer.data(), length); 475 std::memcpy(fds.data(), read_buffer.data(), length);
476 476
477 if (timeout >= 0) { 477 if (timeout >= 0) {
@@ -497,7 +497,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
497 return {0, Errno::SUCCESS}; 497 return {0, Errno::SUCCESS};
498 } 498 }
499 499
500 const std::optional<FileDescriptor>& descriptor = file_descriptors[pollfd.fd]; 500 const std::optional<FileDescriptor>& descriptor = GetFileDescriptor(pollfd.fd);
501 if (!descriptor) { 501 if (!descriptor) {
502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd); 502 LOG_ERROR(Service, "File descriptor handle={} is not allocated", pollfd.fd);
503 pollfd.revents = POLL_NVAL; 503 pollfd.revents = POLL_NVAL;
@@ -508,7 +508,7 @@ std::pair<s32, Errno> BSD::PollImpl(std::vector<u8>& write_buffer, std::vector<u
508 std::vector<Network::PollFD> host_pollfds(fds.size()); 508 std::vector<Network::PollFD> host_pollfds(fds.size());
509 std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) { 509 std::transform(fds.begin(), fds.end(), host_pollfds.begin(), [this](PollFD pollfd) {
510 Network::PollFD result; 510 Network::PollFD result;
511 result.socket = file_descriptors[pollfd.fd]->socket.get(); 511 result.socket = GetFileDescriptor(pollfd.fd)->socket.get();
512 result.events = TranslatePollEventsToHost(pollfd.events); 512 result.events = TranslatePollEventsToHost(pollfd.events);
513 result.revents = 0; 513 result.revents = 0;
514 return result; 514 return result;
@@ -536,13 +536,13 @@ std::pair<s32, Errno> BSD::AcceptImpl(s32 fd, std::vector<u8>& write_buffer) {
536 return {-1, Errno::MFILE}; 536 return {-1, Errno::MFILE};
537 } 537 }
538 538
539 FileDescriptor& descriptor = *file_descriptors[fd]; 539 FileDescriptor& descriptor = *GetFileDescriptor(fd);
540 auto [result, bsd_errno] = descriptor.socket->Accept(); 540 auto [result, bsd_errno] = descriptor.socket->Accept();
541 if (bsd_errno != Network::Errno::SUCCESS) { 541 if (bsd_errno != Network::Errno::SUCCESS) {
542 return {-1, Translate(bsd_errno)}; 542 return {-1, Translate(bsd_errno)};
543 } 543 }
544 544
545 FileDescriptor& new_descriptor = file_descriptors[new_fd].emplace(); 545 FileDescriptor& new_descriptor = GetFileDescriptor(new_fd).emplace();
546 new_descriptor.socket = std::move(result.socket); 546 new_descriptor.socket = std::move(result.socket);
547 new_descriptor.is_connection_based = descriptor.is_connection_based; 547 new_descriptor.is_connection_based = descriptor.is_connection_based;
548 548
@@ -561,7 +561,7 @@ Errno BSD::BindImpl(s32 fd, const std::vector<u8>& addr) {
561 SockAddrIn addr_in; 561 SockAddrIn addr_in;
562 std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); 562 std::memcpy(&addr_in, addr.data(), sizeof(addr_in));
563 563
564 return Translate(file_descriptors[fd]->socket->Bind(Translate(addr_in))); 564 return Translate(GetFileDescriptor(fd)->socket->Bind(Translate(addr_in)));
565} 565}
566 566
567Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) { 567Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) {
@@ -573,7 +573,7 @@ Errno BSD::ConnectImpl(s32 fd, const std::vector<u8>& addr) {
573 SockAddrIn addr_in; 573 SockAddrIn addr_in;
574 std::memcpy(&addr_in, addr.data(), sizeof(addr_in)); 574 std::memcpy(&addr_in, addr.data(), sizeof(addr_in));
575 575
576 return Translate(file_descriptors[fd]->socket->Connect(Translate(addr_in))); 576 return Translate(GetFileDescriptor(fd)->socket->Connect(Translate(addr_in)));
577} 577}
578 578
579Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) { 579Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
@@ -581,7 +581,7 @@ Errno BSD::GetPeerNameImpl(s32 fd, std::vector<u8>& write_buffer) {
581 return Errno::BADF; 581 return Errno::BADF;
582 } 582 }
583 583
584 const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetPeerName(); 584 const auto [addr_in, bsd_errno] = GetFileDescriptor(fd)->socket->GetPeerName();
585 if (bsd_errno != Network::Errno::SUCCESS) { 585 if (bsd_errno != Network::Errno::SUCCESS) {
586 return Translate(bsd_errno); 586 return Translate(bsd_errno);
587 } 587 }
@@ -597,7 +597,7 @@ Errno BSD::GetSockNameImpl(s32 fd, std::vector<u8>& write_buffer) {
597 return Errno::BADF; 597 return Errno::BADF;
598 } 598 }
599 599
600 const auto [addr_in, bsd_errno] = file_descriptors[fd]->socket->GetSockName(); 600 const auto [addr_in, bsd_errno] = GetFileDescriptor(fd)->socket->GetSockName();
601 if (bsd_errno != Network::Errno::SUCCESS) { 601 if (bsd_errno != Network::Errno::SUCCESS) {
602 return Translate(bsd_errno); 602 return Translate(bsd_errno);
603 } 603 }
@@ -612,7 +612,7 @@ Errno BSD::ListenImpl(s32 fd, s32 backlog) {
612 if (!IsFileDescriptorValid(fd)) { 612 if (!IsFileDescriptorValid(fd)) {
613 return Errno::BADF; 613 return Errno::BADF;
614 } 614 }
615 return Translate(file_descriptors[fd]->socket->Listen(backlog)); 615 return Translate(GetFileDescriptor(fd)->socket->Listen(backlog));
616} 616}
617 617
618std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) { 618std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
@@ -620,14 +620,14 @@ std::pair<s32, Errno> BSD::FcntlImpl(s32 fd, FcntlCmd cmd, s32 arg) {
620 return {-1, Errno::BADF}; 620 return {-1, Errno::BADF};
621 } 621 }
622 622
623 FileDescriptor& descriptor = *file_descriptors[fd]; 623 FileDescriptor& descriptor = *GetFileDescriptor(fd);
624 624
625 switch (cmd) { 625 switch (cmd) {
626 case FcntlCmd::GETFL: 626 case FcntlCmd::GETFL:
627 ASSERT(arg == 0); 627 ASSERT(arg == 0);
628 return {descriptor.flags, Errno::SUCCESS}; 628 return {descriptor.flags, Errno::SUCCESS};
629 case FcntlCmd::SETFL: { 629 case FcntlCmd::SETFL: {
630 const bool enable = (arg & FLAG_O_NONBLOCK) != 0; 630 const bool enable = (static_cast<u32>(arg) & FLAG_O_NONBLOCK) != 0;
631 const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable)); 631 const Errno bsd_errno = Translate(descriptor.socket->SetNonBlock(enable));
632 if (bsd_errno != Errno::SUCCESS) { 632 if (bsd_errno != Errno::SUCCESS) {
633 return {-1, bsd_errno}; 633 return {-1, bsd_errno};
@@ -648,7 +648,7 @@ Errno BSD::SetSockOptImpl(s32 fd, u32 level, OptName optname, size_t optlen, con
648 return Errno::BADF; 648 return Errno::BADF;
649 } 649 }
650 650
651 Network::Socket* const socket = file_descriptors[fd]->socket.get(); 651 Network::Socket* const socket = GetFileDescriptor(fd)->socket.get();
652 652
653 if (optname == OptName::LINGER) { 653 if (optname == OptName::LINGER) {
654 ASSERT(optlen == sizeof(Linger)); 654 ASSERT(optlen == sizeof(Linger));
@@ -689,14 +689,14 @@ Errno BSD::ShutdownImpl(s32 fd, s32 how) {
689 return Errno::BADF; 689 return Errno::BADF;
690 } 690 }
691 const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how)); 691 const Network::ShutdownHow host_how = Translate(static_cast<ShutdownHow>(how));
692 return Translate(file_descriptors[fd]->socket->Shutdown(host_how)); 692 return Translate(GetFileDescriptor(fd)->socket->Shutdown(host_how));
693} 693}
694 694
695std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) { 695std::pair<s32, Errno> BSD::RecvImpl(s32 fd, u32 flags, std::vector<u8>& message) {
696 if (!IsFileDescriptorValid(fd)) { 696 if (!IsFileDescriptorValid(fd)) {
697 return {-1, Errno::BADF}; 697 return {-1, Errno::BADF};
698 } 698 }
699 return Translate(file_descriptors[fd]->socket->Recv(flags, message)); 699 return Translate(GetFileDescriptor(fd)->socket->Recv(flags, message));
700} 700}
701 701
702std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message, 702std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& message,
@@ -705,7 +705,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
705 return {-1, Errno::BADF}; 705 return {-1, Errno::BADF};
706 } 706 }
707 707
708 FileDescriptor& descriptor = *file_descriptors[fd]; 708 FileDescriptor& descriptor = *GetFileDescriptor(fd);
709 709
710 Network::SockAddrIn addr_in{}; 710 Network::SockAddrIn addr_in{};
711 Network::SockAddrIn* p_addr_in = nullptr; 711 Network::SockAddrIn* p_addr_in = nullptr;
@@ -719,7 +719,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
719 // Apply flags 719 // Apply flags
720 if ((flags & FLAG_MSG_DONTWAIT) != 0) { 720 if ((flags & FLAG_MSG_DONTWAIT) != 0) {
721 flags &= ~FLAG_MSG_DONTWAIT; 721 flags &= ~FLAG_MSG_DONTWAIT;
722 if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { 722 if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) {
723 descriptor.socket->SetNonBlock(true); 723 descriptor.socket->SetNonBlock(true);
724 } 724 }
725 } 725 }
@@ -727,7 +727,7 @@ std::pair<s32, Errno> BSD::RecvFromImpl(s32 fd, u32 flags, std::vector<u8>& mess
727 const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in)); 727 const auto [ret, bsd_errno] = Translate(descriptor.socket->RecvFrom(flags, message, p_addr_in));
728 728
729 // Restore original state 729 // Restore original state
730 if ((descriptor.flags & FLAG_O_NONBLOCK) == 0) { 730 if ((static_cast<u32>(descriptor.flags) & FLAG_O_NONBLOCK) == 0) {
731 descriptor.socket->SetNonBlock(false); 731 descriptor.socket->SetNonBlock(false);
732 } 732 }
733 733
@@ -748,7 +748,7 @@ std::pair<s32, Errno> BSD::SendImpl(s32 fd, u32 flags, const std::vector<u8>& me
748 if (!IsFileDescriptorValid(fd)) { 748 if (!IsFileDescriptorValid(fd)) {
749 return {-1, Errno::BADF}; 749 return {-1, Errno::BADF};
750 } 750 }
751 return Translate(file_descriptors[fd]->socket->Send(message, flags)); 751 return Translate(GetFileDescriptor(fd)->socket->Send(message, flags));
752} 752}
753 753
754std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message, 754std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>& message,
@@ -767,7 +767,8 @@ std::pair<s32, Errno> BSD::SendToImpl(s32 fd, u32 flags, const std::vector<u8>&
767 p_addr_in = &addr_in; 767 p_addr_in = &addr_in;
768 } 768 }
769 769
770 return Translate(file_descriptors[fd]->socket->SendTo(flags, message, p_addr_in)); 770 const auto& descriptor = GetFileDescriptor(fd);
771 return Translate(descriptor->socket->SendTo(flags, message, p_addr_in));
771} 772}
772 773
773Errno BSD::CloseImpl(s32 fd) { 774Errno BSD::CloseImpl(s32 fd) {
@@ -775,20 +776,21 @@ Errno BSD::CloseImpl(s32 fd) {
775 return Errno::BADF; 776 return Errno::BADF;
776 } 777 }
777 778
778 const Errno bsd_errno = Translate(file_descriptors[fd]->socket->Close()); 779 auto& descriptor = GetFileDescriptor(fd);
780 const Errno bsd_errno = Translate(descriptor->socket->Close());
779 if (bsd_errno != Errno::SUCCESS) { 781 if (bsd_errno != Errno::SUCCESS) {
780 return bsd_errno; 782 return bsd_errno;
781 } 783 }
782 784
783 LOG_INFO(Service, "Close socket fd={}", fd); 785 LOG_INFO(Service, "Close socket fd={}", fd);
784 786
785 file_descriptors[fd].reset(); 787 descriptor.reset();
786 return bsd_errno; 788 return bsd_errno;
787} 789}
788 790
789s32 BSD::FindFreeFileDescriptorHandle() noexcept { 791s32 BSD::FindFreeFileDescriptorHandle() noexcept {
790 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) { 792 for (s32 fd = 0; fd < static_cast<s32>(file_descriptors.size()); ++fd) {
791 if (!file_descriptors[fd]) { 793 if (!GetFileDescriptor(fd)) {
792 return fd; 794 return fd;
793 } 795 }
794 } 796 }
@@ -800,7 +802,7 @@ bool BSD::IsFileDescriptorValid(s32 fd) const noexcept {
800 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd); 802 LOG_ERROR(Service, "Invalid file descriptor handle={}", fd);
801 return false; 803 return false;
802 } 804 }
803 if (!file_descriptors[fd]) { 805 if (!GetFileDescriptor(fd)) {
804 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd); 806 LOG_ERROR(Service, "File descriptor handle={} is not allocated", fd);
805 return false; 807 return false;
806 } 808 }
@@ -813,10 +815,12 @@ bool BSD::IsBlockingSocket(s32 fd) const noexcept {
813 if (fd > static_cast<s32>(MAX_FD) || fd < 0) { 815 if (fd > static_cast<s32>(MAX_FD) || fd < 0) {
814 return false; 816 return false;
815 } 817 }
816 if (!file_descriptors[fd]) { 818
819 const auto& descriptor = GetFileDescriptor(fd);
820 if (!descriptor) {
817 return false; 821 return false;
818 } 822 }
819 return (file_descriptors[fd]->flags & FLAG_O_NONBLOCK) != 0; 823 return (static_cast<u32>(descriptor->flags) & FLAG_O_NONBLOCK) != 0;
820} 824}
821 825
822void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept { 826void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept {
@@ -827,6 +831,14 @@ void BSD::BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) co
827 rb.PushEnum(bsd_errno); 831 rb.PushEnum(bsd_errno);
828} 832}
829 833
834std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) {
835 return file_descriptors[static_cast<u32>(fd)];
836}
837
838const std::optional<BSD::FileDescriptor>& BSD::GetFileDescriptor(s32 fd) const {
839 return file_descriptors[static_cast<u32>(fd)];
840}
841
830BSD::BSD(Core::System& system, const char* name) 842BSD::BSD(Core::System& system, const char* name)
831 : ServiceFramework(name), worker_pool{system, this} { 843 : ServiceFramework(name), worker_pool{system, this} {
832 // clang-format off 844 // clang-format off
diff --git a/src/core/hle/service/sockets/bsd.h b/src/core/hle/service/sockets/bsd.h
index 357531951..ac9523d83 100644
--- a/src/core/hle/service/sockets/bsd.h
+++ b/src/core/hle/service/sockets/bsd.h
@@ -167,6 +167,9 @@ private:
167 167
168 void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept; 168 void BuildErrnoResponse(Kernel::HLERequestContext& ctx, Errno bsd_errno) const noexcept;
169 169
170 std::optional<FileDescriptor>& GetFileDescriptor(s32 fd);
171 const std::optional<FileDescriptor>& GetFileDescriptor(s32 fd) const;
172
170 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors; 173 std::array<std::optional<FileDescriptor>, MAX_FD> file_descriptors;
171 174
172 BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork, 175 BlockingWorkerPool<BSD, PollWork, AcceptWork, ConnectWork, RecvWork, RecvFromWork, SendWork,
diff --git a/src/core/hle/service/sockets/sockets_translate.cpp b/src/core/hle/service/sockets/sockets_translate.cpp
index 2e626fd86..50c2a455d 100644
--- a/src/core/hle/service/sockets/sockets_translate.cpp
+++ b/src/core/hle/service/sockets/sockets_translate.cpp
@@ -64,6 +64,7 @@ Network::Type Translate(Type type) {
64 return Network::Type::DGRAM; 64 return Network::Type::DGRAM;
65 default: 65 default:
66 UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type)); 66 UNIMPLEMENTED_MSG("Unimplemented type={}", static_cast<int>(type));
67 return {};
67 } 68 }
68} 69}
69 70
diff --git a/src/core/hle/service/time/time_zone_manager.cpp b/src/core/hle/service/time/time_zone_manager.cpp
index bdf0439f2..df0ed924d 100644
--- a/src/core/hle/service/time/time_zone_manager.cpp
+++ b/src/core/hle/service/time/time_zone_manager.cpp
@@ -117,7 +117,8 @@ static constexpr int GetMonthLength(bool is_leap_year, int month) {
117 constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; 117 constexpr std::array<int, 12> month_lengths{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
118 constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30, 118 constexpr std::array<int, 12> month_lengths_leap{31, 29, 31, 30, 31, 30,
119 31, 31, 30, 31, 30, 31}; 119 31, 31, 30, 31, 30, 31};
120 return is_leap_year ? month_lengths_leap[month] : month_lengths[month]; 120 const auto month_index = static_cast<u32>(month);
121 return is_leap_year ? month_lengths_leap[month_index] : month_lengths[month_index];
121} 122}
122 123
123static constexpr bool IsDigit(char value) { 124static constexpr bool IsDigit(char value) {
@@ -320,7 +321,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
320 int dest_len{}; 321 int dest_len{};
321 int dest_offset{}; 322 int dest_offset{};
322 const char* dest_name{name + offset}; 323 const char* dest_name{name + offset};
323 if (rule.chars.size() < std::size_t(char_count)) { 324 if (rule.chars.size() < static_cast<std::size_t>(char_count)) {
324 return {}; 325 return {};
325 } 326 }
326 327
@@ -343,7 +344,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
343 return {}; 344 return {};
344 } 345 }
345 char_count += dest_len + 1; 346 char_count += dest_len + 1;
346 if (rule.chars.size() < std::size_t(char_count)) { 347 if (rule.chars.size() < static_cast<std::size_t>(char_count)) {
347 return {}; 348 return {};
348 } 349 }
349 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') { 350 if (name[offset] != '\0' && name[offset] != ',' && name[offset] != ';') {
@@ -386,7 +387,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
386 rule.default_type = 0; 387 rule.default_type = 0;
387 388
388 s64 jan_first{}; 389 s64 jan_first{};
389 int time_count{}; 390 u32 time_count{};
390 int jan_offset{}; 391 int jan_offset{};
391 int year_beginning{epoch_year}; 392 int year_beginning{epoch_year};
392 do { 393 do {
@@ -414,7 +415,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
414 if (is_reversed || 415 if (is_reversed ||
415 (start_time < end_time && 416 (start_time < end_time &&
416 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) { 417 (end_time - start_time < (year_seconds + (std_offset - dest_offset))))) {
417 if (rule.ats.size() - 2 < std::size_t(time_count)) { 418 if (rule.ats.size() - 2 < time_count) {
418 break; 419 break;
419 } 420 }
420 421
@@ -438,7 +439,7 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
438 } 439 }
439 jan_offset = 0; 440 jan_offset = 0;
440 } 441 }
441 rule.time_count = time_count; 442 rule.time_count = static_cast<s32>(time_count);
442 if (time_count == 0) { 443 if (time_count == 0) {
443 rule.type_count = 1; 444 rule.type_count = 1;
444 } else if (years_per_repeat < year - year_beginning) { 445 } else if (years_per_repeat < year - year_beginning) {
@@ -451,26 +452,30 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
451 } 452 }
452 453
453 s64 their_std_offset{}; 454 s64 their_std_offset{};
454 for (int index{}; index < rule.time_count; ++index) { 455 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) {
455 const s8 type{rule.types[index]}; 456 const s8 type{rule.types[index]};
456 if (rule.ttis[type].is_standard_time_daylight) { 457 const auto& tti = rule.ttis[static_cast<u8>(type)];
457 their_std_offset = -rule.ttis[type].gmt_offset; 458
459 if (tti.is_standard_time_daylight) {
460 their_std_offset = -tti.gmt_offset;
458 } 461 }
459 } 462 }
460 463
461 s64 their_offset{their_std_offset}; 464 s64 their_offset{their_std_offset};
462 for (int index{}; index < rule.time_count; ++index) { 465 for (u32 index = 0; index < static_cast<u32>(rule.time_count); ++index) {
463 const s8 type{rule.types[index]}; 466 const s8 type{rule.types[index]};
464 rule.types[index] = rule.ttis[type].is_dst ? 1 : 0; 467 const auto& tti = rule.ttis[static_cast<u8>(type)];
465 if (!rule.ttis[type].is_gmt) { 468
466 if (!rule.ttis[type].is_standard_time_daylight) { 469 rule.types[index] = tti.is_dst ? 1 : 0;
470 if (!tti.is_gmt) {
471 if (!tti.is_standard_time_daylight) {
467 rule.ats[index] += dest_offset - their_std_offset; 472 rule.ats[index] += dest_offset - their_std_offset;
468 } else { 473 } else {
469 rule.ats[index] += std_offset - their_std_offset; 474 rule.ats[index] += std_offset - their_std_offset;
470 } 475 }
471 } 476 }
472 their_offset = -rule.ttis[type].gmt_offset; 477 their_offset = -tti.gmt_offset;
473 if (!rule.ttis[type].is_dst) { 478 if (!tti.is_dst) {
474 their_std_offset = their_offset; 479 their_std_offset = their_offset;
475 } 480 }
476 } 481 }
@@ -494,16 +499,16 @@ static bool ParsePosixName(const char* name, TimeZoneRule& rule) {
494 } 499 }
495 500
496 rule.char_count = char_count; 501 rule.char_count = char_count;
497 for (int index{}; index < std_len; ++index) { 502 for (std::size_t index = 0; index < static_cast<std::size_t>(std_len); ++index) {
498 rule.chars[index] = std_name[index]; 503 rule.chars[index] = std_name[index];
499 } 504 }
500 505
501 rule.chars[std_len++] = '\0'; 506 rule.chars[static_cast<size_t>(std_len++)] = '\0';
502 if (dest_len != 0) { 507 if (dest_len != 0) {
503 for (int index{}; index < dest_len; ++index) { 508 for (int index = 0; index < dest_len; ++index) {
504 rule.chars[std_len + index] = dest_name[index]; 509 rule.chars[static_cast<std::size_t>(std_len + index)] = dest_name[index];
505 } 510 }
506 rule.chars[std_len + dest_len] = '\0'; 511 rule.chars[static_cast<std::size_t>(std_len + dest_len)] = '\0';
507 } 512 }
508 513
509 return true; 514 return true;
@@ -531,33 +536,33 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
531 536
532 int time_count{}; 537 int time_count{};
533 u64 read_offset = sizeof(TzifHeader); 538 u64 read_offset = sizeof(TzifHeader);
534 for (int index{}; index < time_zone_rule.time_count; ++index) { 539 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) {
535 s64_be at{}; 540 s64_be at{};
536 vfs_file->ReadObject<s64_be>(&at, read_offset); 541 vfs_file->ReadObject<s64_be>(&at, read_offset);
537 time_zone_rule.types[index] = 1; 542 time_zone_rule.types[index] = 1;
538 if (time_count != 0 && at <= time_zone_rule.ats[time_count - 1]) { 543 if (time_count != 0 && at <= time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) {
539 if (at < time_zone_rule.ats[time_count - 1]) { 544 if (at < time_zone_rule.ats[static_cast<size_t>(time_count) - 1]) {
540 return {}; 545 return {};
541 } 546 }
542 time_zone_rule.types[index - 1] = 0; 547 time_zone_rule.types[index - 1] = 0;
543 time_count--; 548 time_count--;
544 } 549 }
545 time_zone_rule.ats[time_count++] = at; 550 time_zone_rule.ats[static_cast<size_t>(time_count++)] = at;
546 read_offset += sizeof(s64_be); 551 read_offset += sizeof(s64_be);
547 } 552 }
548 time_count = 0; 553 time_count = 0;
549 for (int index{}; index < time_zone_rule.time_count; ++index) { 554 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.time_count); ++index) {
550 const u8 type{*vfs_file->ReadByte(read_offset)}; 555 const auto type{static_cast<s8>(*vfs_file->ReadByte(read_offset))};
551 read_offset += sizeof(u8); 556 read_offset += sizeof(s8);
552 if (time_zone_rule.time_count <= type) { 557 if (time_zone_rule.time_count <= type) {
553 return {}; 558 return {};
554 } 559 }
555 if (time_zone_rule.types[index] != 0) { 560 if (time_zone_rule.types[index] != 0) {
556 time_zone_rule.types[time_count++] = type; 561 time_zone_rule.types[static_cast<size_t>(time_count++)] = type;
557 } 562 }
558 } 563 }
559 time_zone_rule.time_count = time_count; 564 time_zone_rule.time_count = time_count;
560 for (int index{}; index < time_zone_rule.type_count; ++index) { 565 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
561 TimeTypeInfo& ttis{time_zone_rule.ttis[index]}; 566 TimeTypeInfo& ttis{time_zone_rule.ttis[index]};
562 u32_be gmt_offset{}; 567 u32_be gmt_offset{};
563 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset); 568 vfs_file->ReadObject<u32_be>(&gmt_offset, read_offset);
@@ -579,10 +584,11 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
579 ttis.abbreviation_list_index = abbreviation_list_index; 584 ttis.abbreviation_list_index = abbreviation_list_index;
580 } 585 }
581 586
582 vfs_file->ReadArray(time_zone_rule.chars.data(), time_zone_rule.char_count, read_offset); 587 vfs_file->ReadArray(time_zone_rule.chars.data(), static_cast<u32>(time_zone_rule.char_count),
583 time_zone_rule.chars[time_zone_rule.char_count] = '\0'; 588 read_offset);
584 read_offset += time_zone_rule.char_count; 589 time_zone_rule.chars[static_cast<u32>(time_zone_rule.char_count)] = '\0';
585 for (int index{}; index < time_zone_rule.type_count; ++index) { 590 read_offset += static_cast<u64>(time_zone_rule.char_count);
591 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
586 if (header.ttis_std_count == 0) { 592 if (header.ttis_std_count == 0) {
587 time_zone_rule.ttis[index].is_standard_time_daylight = false; 593 time_zone_rule.ttis[index].is_standard_time_daylight = false;
588 } else { 594 } else {
@@ -595,7 +601,7 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
595 } 601 }
596 } 602 }
597 603
598 for (int index{}; index < time_zone_rule.type_count; ++index) { 604 for (size_t index = 0; index < static_cast<size_t>(time_zone_rule.type_count); ++index) {
599 if (header.ttis_std_count == 0) { 605 if (header.ttis_std_count == 0) {
600 time_zone_rule.ttis[index].is_gmt = false; 606 time_zone_rule.ttis[index].is_gmt = false;
601 } else { 607 } else {
@@ -619,13 +625,14 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
619 } 625 }
620 626
621 std::array<char, time_zone_name_max + 1> temp_name{}; 627 std::array<char, time_zone_name_max + 1> temp_name{};
622 vfs_file->ReadArray(temp_name.data(), bytes_read, read_offset); 628 vfs_file->ReadArray(temp_name.data(), static_cast<size_t>(bytes_read), read_offset);
623 if (bytes_read > 2 && temp_name[0] == '\n' && temp_name[bytes_read - 1] == '\n' && 629 if (bytes_read > 2 && temp_name[0] == '\n' &&
624 std::size_t(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) { 630 temp_name[static_cast<u64>(bytes_read - 1)] == '\n' &&
625 temp_name[bytes_read - 1] = '\0'; 631 static_cast<std::size_t>(time_zone_rule.type_count) + 2 <= time_zone_rule.ttis.size()) {
632 temp_name[static_cast<u64>(bytes_read - 1)] = '\0';
626 633
627 std::array<char, time_zone_name_max> name{}; 634 std::array<char, time_zone_name_max> name{};
628 std::memcpy(name.data(), temp_name.data() + 1, std::size_t(bytes_read - 1)); 635 std::memcpy(name.data(), temp_name.data() + 1, static_cast<std::size_t>(bytes_read - 1));
629 636
630 TimeZoneRule temp_rule; 637 TimeZoneRule temp_rule;
631 if (ParsePosixName(name.data(), temp_rule)) { 638 if (ParsePosixName(name.data(), temp_rule)) {
@@ -642,24 +649,24 @@ static bool ParseTimeZoneBinary(TimeZoneRule& time_zone_rule, FileSys::VirtualFi
642 s32 default_type{}; 649 s32 default_type{};
643 650
644 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) { 651 for (default_type = 0; default_type < time_zone_rule.time_count; default_type++) {
645 if (time_zone_rule.types[default_type] == 0) { 652 if (time_zone_rule.types[static_cast<u32>(default_type)] == 0) {
646 break; 653 break;
647 } 654 }
648 } 655 }
649 656
650 default_type = default_type < time_zone_rule.time_count ? -1 : 0; 657 default_type = default_type < time_zone_rule.time_count ? -1 : 0;
651 if (default_type < 0 && time_zone_rule.time_count > 0 && 658 if (default_type < 0 && time_zone_rule.time_count > 0 &&
652 time_zone_rule.ttis[time_zone_rule.types[0]].is_dst) { 659 time_zone_rule.ttis[static_cast<u8>(time_zone_rule.types[0])].is_dst) {
653 default_type = time_zone_rule.types[0]; 660 default_type = time_zone_rule.types[0];
654 while (--default_type >= 0) { 661 while (--default_type >= 0) {
655 if (!time_zone_rule.ttis[default_type].is_dst) { 662 if (!time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) {
656 break; 663 break;
657 } 664 }
658 } 665 }
659 } 666 }
660 if (default_type < 0) { 667 if (default_type < 0) {
661 default_type = 0; 668 default_type = 0;
662 while (time_zone_rule.ttis[default_type].is_dst) { 669 while (time_zone_rule.ttis[static_cast<u32>(default_type)].is_dst) {
663 if (++default_type >= time_zone_rule.type_count) { 670 if (++default_type >= time_zone_rule.type_count) {
664 default_type = 0; 671 default_type = 0;
665 break; 672 break;
@@ -749,12 +756,12 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
749 CalendarTimeInternal& calendar_time, 756 CalendarTimeInternal& calendar_time,
750 CalendarAdditionalInfo& calendar_additional_info) { 757 CalendarAdditionalInfo& calendar_additional_info) {
751 if ((rules.go_ahead && time < rules.ats[0]) || 758 if ((rules.go_ahead && time < rules.ats[0]) ||
752 (rules.go_back && time > rules.ats[rules.time_count - 1])) { 759 (rules.go_back && time > rules.ats[static_cast<size_t>(rules.time_count - 1)])) {
753 s64 seconds{}; 760 s64 seconds{};
754 if (time < rules.ats[0]) { 761 if (time < rules.ats[0]) {
755 seconds = rules.ats[0] - time; 762 seconds = rules.ats[0] - time;
756 } else { 763 } else {
757 seconds = time - rules.ats[rules.time_count - 1]; 764 seconds = time - rules.ats[static_cast<size_t>(rules.time_count - 1)];
758 } 765 }
759 seconds--; 766 seconds--;
760 767
@@ -767,7 +774,8 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
767 } else { 774 } else {
768 new_time -= seconds; 775 new_time -= seconds;
769 } 776 }
770 if (new_time < rules.ats[0] && new_time > rules.ats[rules.time_count - 1]) { 777 if (new_time < rules.ats[0] &&
778 new_time > rules.ats[static_cast<size_t>(rules.time_count - 1)]) {
771 return ERROR_TIME_NOT_FOUND; 779 return ERROR_TIME_NOT_FOUND;
772 } 780 }
773 if (const ResultCode result{ 781 if (const ResultCode result{
@@ -791,25 +799,27 @@ static ResultCode ToCalendarTimeInternal(const TimeZoneRule& rules, s64 time,
791 s32 low{1}; 799 s32 low{1};
792 s32 high{rules.time_count}; 800 s32 high{rules.time_count};
793 while (low < high) { 801 while (low < high) {
794 s32 mid{(low + high) >> 1}; 802 const s32 mid{(low + high) >> 1};
795 if (time < rules.ats[mid]) { 803 if (time < rules.ats[static_cast<size_t>(mid)]) {
796 high = mid; 804 high = mid;
797 } else { 805 } else {
798 low = mid + 1; 806 low = mid + 1;
799 } 807 }
800 } 808 }
801 tti_index = rules.types[low - 1]; 809 tti_index = rules.types[static_cast<size_t>(low - 1)];
802 } 810 }
803 811
804 if (const ResultCode result{CreateCalendarTime(time, rules.ttis[tti_index].gmt_offset, 812 if (const ResultCode result{
805 calendar_time, calendar_additional_info)}; 813 CreateCalendarTime(time, rules.ttis[static_cast<u32>(tti_index)].gmt_offset,
814 calendar_time, calendar_additional_info)};
806 result != RESULT_SUCCESS) { 815 result != RESULT_SUCCESS) {
807 return result; 816 return result;
808 } 817 }
809 818
810 calendar_additional_info.is_dst = rules.ttis[tti_index].is_dst; 819 const auto& tti = rules.ttis[static_cast<size_t>(tti_index)];
811 const char* time_zone{&rules.chars[rules.ttis[tti_index].abbreviation_list_index]}; 820 calendar_additional_info.is_dst = tti.is_dst;
812 for (int index{}; time_zone[index] != '\0'; ++index) { 821 const char* time_zone{&rules.chars[static_cast<size_t>(tti.abbreviation_list_index)]};
822 for (size_t index = 0; time_zone[index] != '\0'; ++index) {
813 calendar_additional_info.timezone_name[index] = time_zone[index]; 823 calendar_additional_info.timezone_name[index] = time_zone[index];
814 } 824 }
815 return RESULT_SUCCESS; 825 return RESULT_SUCCESS;
diff --git a/src/core/hle/service/time/time_zone_service.cpp b/src/core/hle/service/time/time_zone_service.cpp
index ff3a10b3e..8a0227021 100644
--- a/src/core/hle/service/time/time_zone_service.cpp
+++ b/src/core/hle/service/time/time_zone_service.cpp
@@ -49,12 +49,12 @@ void ITimeZoneService::LoadTimeZoneRule(Kernel::HLERequestContext& ctx) {
49 const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()}; 49 const auto raw_location_name{rp.PopRaw<std::array<u8, 0x24>>()};
50 50
51 std::string location_name; 51 std::string location_name;
52 for (const auto& byte : raw_location_name) { 52 for (const auto byte : raw_location_name) {
53 // Strip extra bytes 53 // Strip extra bytes
54 if (byte == '\0') { 54 if (byte == '\0') {
55 break; 55 break;
56 } 56 }
57 location_name.push_back(byte); 57 location_name.push_back(static_cast<char>(byte));
58 } 58 }
59 59
60 LOG_DEBUG(Service_Time, "called, location_name={}", location_name); 60 LOG_DEBUG(Service_Time, "called, location_name={}", location_name);