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