summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/CMakeLists.txt4
-rw-r--r--src/core/hle/kernel/handle_table.cpp2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp11
-rw-r--r--src/core/hle/kernel/hle_ipc.h11
-rw-r--r--src/core/hle/kernel/memory/address_space_info.cpp16
-rw-r--r--src/core/hle/kernel/memory/address_space_info.h5
-rw-r--r--src/core/hle/kernel/memory/memory_block.h4
-rw-r--r--src/core/hle/kernel/memory/memory_block_manager.cpp3
-rw-r--r--src/core/hle/kernel/memory/memory_block_manager.h1
-rw-r--r--src/core/hle/kernel/memory/memory_manager.cpp8
-rw-r--r--src/core/hle/kernel/memory/memory_manager.h1
-rw-r--r--src/core/hle/kernel/memory/page_heap.cpp4
-rw-r--r--src/core/hle/kernel/memory/page_heap.h4
-rw-r--r--src/core/hle/kernel/memory/page_linked_list.h1
-rw-r--r--src/core/hle/kernel/memory/page_table.cpp1
-rw-r--r--src/core/hle/kernel/memory/page_table.h3
-rw-r--r--src/core/hle/kernel/memory/slab_heap.h5
-rw-r--r--src/core/hle/kernel/memory/system_control.cpp2
-rw-r--r--src/core/hle/kernel/mutex.cpp5
-rw-r--r--src/core/hle/kernel/process_capability.cpp30
-rw-r--r--src/core/hle/kernel/readable_event.cpp13
-rw-r--r--src/core/hle/kernel/resource_limit.cpp2
-rw-r--r--src/core/hle/kernel/server_session.cpp4
-rw-r--r--src/core/hle/kernel/svc.cpp7
-rw-r--r--src/core/hle/kernel/thread.cpp2
-rw-r--r--src/core/hle/service/acc/acc.cpp13
-rw-r--r--src/core/hle/service/am/am.cpp33
-rw-r--r--src/core/hle/service/am/am.h6
-rw-r--r--src/core/hle/service/am/applet_ae.cpp2
-rw-r--r--src/core/hle/service/audio/audin_u.cpp70
-rw-r--r--src/core/hle/service/audio/audin_u.h29
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp2
-rw-r--r--src/core/hle/service/hid/hid.cpp11
-rw-r--r--src/core/hle/service/hid/hid.h1
-rw-r--r--src/core/reporter.cpp3
-rw-r--r--src/core/settings.cpp1
36 files changed, 249 insertions, 71 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt
index 8546d3602..47418006b 100644
--- a/src/core/CMakeLists.txt
+++ b/src/core/CMakeLists.txt
@@ -606,11 +606,11 @@ endif()
606create_target_directory_groups(core) 606create_target_directory_groups(core)
607 607
608target_link_libraries(core PUBLIC common PRIVATE audio_core video_core) 608target_link_libraries(core PUBLIC common PRIVATE audio_core video_core)
609target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt json-headers mbedtls opus unicorn) 609target_link_libraries(core PUBLIC Boost::boost PRIVATE fmt::fmt nlohmann_json::nlohmann_json mbedtls Opus::Opus unicorn)
610 610
611if (YUZU_ENABLE_BOXCAT) 611if (YUZU_ENABLE_BOXCAT)
612 target_compile_definitions(core PRIVATE -DYUZU_ENABLE_BOXCAT) 612 target_compile_definitions(core PRIVATE -DYUZU_ENABLE_BOXCAT)
613 target_link_libraries(core PRIVATE httplib json-headers zip) 613 target_link_libraries(core PRIVATE httplib nlohmann_json::nlohmann_json zip)
614endif() 614endif()
615 615
616if (ENABLE_WEB_SERVICE) 616if (ENABLE_WEB_SERVICE)
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index e441a27fc..35448b576 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -30,6 +30,7 @@ HandleTable::~HandleTable() = default;
30 30
31ResultCode HandleTable::SetSize(s32 handle_table_size) { 31ResultCode HandleTable::SetSize(s32 handle_table_size) {
32 if (static_cast<u32>(handle_table_size) > MAX_COUNT) { 32 if (static_cast<u32>(handle_table_size) > MAX_COUNT) {
33 LOG_ERROR(Kernel, "Handle table size {} is greater than {}", handle_table_size, MAX_COUNT);
33 return ERR_OUT_OF_MEMORY; 34 return ERR_OUT_OF_MEMORY;
34 } 35 }
35 36
@@ -80,6 +81,7 @@ ResultVal<Handle> HandleTable::Duplicate(Handle handle) {
80 81
81ResultCode HandleTable::Close(Handle handle) { 82ResultCode HandleTable::Close(Handle handle) {
82 if (!IsValid(handle)) { 83 if (!IsValid(handle)) {
84 LOG_ERROR(Kernel, "Handle is not valid! handle={:08X}", handle);
83 return ERR_INVALID_HANDLE; 85 return ERR_INVALID_HANDLE;
84 } 86 }
85 87
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 91d94025c..ba0eac4c2 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -13,7 +13,6 @@
13#include "common/common_funcs.h" 13#include "common/common_funcs.h"
14#include "common/common_types.h" 14#include "common/common_types.h"
15#include "common/logging/log.h" 15#include "common/logging/log.h"
16#include "core/core.h"
17#include "core/hle/ipc_helpers.h" 16#include "core/hle/ipc_helpers.h"
18#include "core/hle/kernel/handle_table.h" 17#include "core/hle/kernel/handle_table.h"
19#include "core/hle/kernel/hle_ipc.h" 18#include "core/hle/kernel/hle_ipc.h"
@@ -57,7 +56,6 @@ std::shared_ptr<WritableEvent> HLERequestContext::SleepClientThread(
57 return true; 56 return true;
58 }); 57 });
59 58
60 auto& kernel = Core::System::GetInstance().Kernel();
61 if (!writable_event) { 59 if (!writable_event) {
62 // Create event if not provided 60 // Create event if not provided
63 const auto pair = WritableEvent::CreateEventPair(kernel, "HLE Pause Event: " + reason); 61 const auto pair = WritableEvent::CreateEventPair(kernel, "HLE Pause Event: " + reason);
@@ -79,9 +77,11 @@ std::shared_ptr<WritableEvent> HLERequestContext::SleepClientThread(
79 return writable_event; 77 return writable_event;
80} 78}
81 79
82HLERequestContext::HLERequestContext(std::shared_ptr<Kernel::ServerSession> server_session, 80HLERequestContext::HLERequestContext(KernelCore& kernel, Core::Memory::Memory& memory,
81 std::shared_ptr<ServerSession> server_session,
83 std::shared_ptr<Thread> thread) 82 std::shared_ptr<Thread> thread)
84 : server_session(std::move(server_session)), thread(std::move(thread)) { 83 : server_session(std::move(server_session)),
84 thread(std::move(thread)), kernel{kernel}, memory{memory} {
85 cmd_buf[0] = 0; 85 cmd_buf[0] = 0;
86} 86}
87 87
@@ -216,7 +216,6 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(const HandleTabl
216ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) { 216ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(Thread& thread) {
217 auto& owner_process = *thread.GetOwnerProcess(); 217 auto& owner_process = *thread.GetOwnerProcess();
218 auto& handle_table = owner_process.GetHandleTable(); 218 auto& handle_table = owner_process.GetHandleTable();
219 auto& memory = Core::System::GetInstance().Memory();
220 219
221 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf; 220 std::array<u32, IPC::COMMAND_BUFFER_LENGTH> dst_cmdbuf;
222 memory.ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(), 221 memory.ReadBlock(owner_process, thread.GetTLSAddress(), dst_cmdbuf.data(),
@@ -286,7 +285,6 @@ std::vector<u8> HLERequestContext::ReadBuffer(std::size_t buffer_index) const {
286 std::vector<u8> buffer; 285 std::vector<u8> buffer;
287 const bool is_buffer_a{BufferDescriptorA().size() > buffer_index && 286 const bool is_buffer_a{BufferDescriptorA().size() > buffer_index &&
288 BufferDescriptorA()[buffer_index].Size()}; 287 BufferDescriptorA()[buffer_index].Size()};
289 auto& memory = Core::System::GetInstance().Memory();
290 288
291 if (is_buffer_a) { 289 if (is_buffer_a) {
292 ASSERT_MSG(BufferDescriptorA().size() > buffer_index, 290 ASSERT_MSG(BufferDescriptorA().size() > buffer_index,
@@ -319,7 +317,6 @@ std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
319 size = buffer_size; // TODO(bunnei): This needs to be HW tested 317 size = buffer_size; // TODO(bunnei): This needs to be HW tested
320 } 318 }
321 319
322 auto& memory = Core::System::GetInstance().Memory();
323 if (is_buffer_b) { 320 if (is_buffer_b) {
324 ASSERT_MSG(BufferDescriptorB().size() > buffer_index, 321 ASSERT_MSG(BufferDescriptorB().size() > buffer_index,
325 "BufferDescriptorB invalid buffer_index {}", buffer_index); 322 "BufferDescriptorB invalid buffer_index {}", buffer_index);
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index af3330297..b31673928 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -19,6 +19,10 @@
19 19
20union ResultCode; 20union ResultCode;
21 21
22namespace Core::Memory {
23class Memory;
24}
25
22namespace Service { 26namespace Service {
23class ServiceFrameworkBase; 27class ServiceFrameworkBase;
24} 28}
@@ -28,6 +32,7 @@ namespace Kernel {
28class Domain; 32class Domain;
29class HandleTable; 33class HandleTable;
30class HLERequestContext; 34class HLERequestContext;
35class KernelCore;
31class Process; 36class Process;
32class ServerSession; 37class ServerSession;
33class Thread; 38class Thread;
@@ -98,7 +103,8 @@ protected:
98 */ 103 */
99class HLERequestContext { 104class HLERequestContext {
100public: 105public:
101 explicit HLERequestContext(std::shared_ptr<ServerSession> session, 106 explicit HLERequestContext(KernelCore& kernel, Core::Memory::Memory& memory,
107 std::shared_ptr<ServerSession> session,
102 std::shared_ptr<Thread> thread); 108 std::shared_ptr<Thread> thread);
103 ~HLERequestContext(); 109 ~HLERequestContext();
104 110
@@ -305,6 +311,9 @@ private:
305 311
306 std::vector<std::shared_ptr<SessionRequestHandler>> domain_request_handlers; 312 std::vector<std::shared_ptr<SessionRequestHandler>> domain_request_handlers;
307 bool is_thread_waiting{}; 313 bool is_thread_waiting{};
314
315 KernelCore& kernel;
316 Core::Memory::Memory& memory;
308}; 317};
309 318
310} // namespace Kernel 319} // namespace Kernel
diff --git a/src/core/hle/kernel/memory/address_space_info.cpp b/src/core/hle/kernel/memory/address_space_info.cpp
index 27fae05e7..a523a2502 100644
--- a/src/core/hle/kernel/memory/address_space_info.cpp
+++ b/src/core/hle/kernel/memory/address_space_info.cpp
@@ -2,8 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#include <array> 8#include <array>
9 9
@@ -49,18 +49,18 @@ constexpr bool IsAllowedIndexForAddress(std::size_t index) {
49 return index < std::size(AddressSpaceInfos) && AddressSpaceInfos[index].GetAddress() != Invalid; 49 return index < std::size(AddressSpaceInfos) && AddressSpaceInfos[index].GetAddress() != Invalid;
50} 50}
51 51
52constexpr std::size_t 52constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)>
53 AddressSpaceIndices32Bit[static_cast<std::size_t>(AddressSpaceInfo::Type::Count)]{ 53 AddressSpaceIndices32Bit{
54 0, 1, 0, 2, 0, 3, 54 0, 1, 0, 2, 0, 3,
55 }; 55 };
56 56
57constexpr std::size_t 57constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)>
58 AddressSpaceIndices36Bit[static_cast<std::size_t>(AddressSpaceInfo::Type::Count)]{ 58 AddressSpaceIndices36Bit{
59 4, 5, 4, 6, 4, 7, 59 4, 5, 4, 6, 4, 7,
60 }; 60 };
61 61
62constexpr std::size_t 62constexpr std::array<std::size_t, static_cast<std::size_t>(AddressSpaceInfo::Type::Count)>
63 AddressSpaceIndices39Bit[static_cast<std::size_t>(AddressSpaceInfo::Type::Count)]{ 63 AddressSpaceIndices39Bit{
64 9, 8, 8, 10, 12, 11, 64 9, 8, 8, 10, 12, 11,
65 }; 65 };
66 66
diff --git a/src/core/hle/kernel/memory/address_space_info.h b/src/core/hle/kernel/memory/address_space_info.h
index cc9a6421e..c479890be 100644
--- a/src/core/hle/kernel/memory/address_space_info.h
+++ b/src/core/hle/kernel/memory/address_space_info.h
@@ -2,12 +2,11 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#pragma once 8#pragma once
9 9
10#include "common/common_funcs.h"
11#include "common/common_types.h" 10#include "common/common_types.h"
12 11
13namespace Kernel::Memory { 12namespace Kernel::Memory {
diff --git a/src/core/hle/kernel/memory/memory_block.h b/src/core/hle/kernel/memory/memory_block.h
index 9db1f7b39..9d7839d08 100644
--- a/src/core/hle/kernel/memory/memory_block.h
+++ b/src/core/hle/kernel/memory/memory_block.h
@@ -2,8 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#pragma once 8#pragma once
9 9
diff --git a/src/core/hle/kernel/memory/memory_block_manager.cpp b/src/core/hle/kernel/memory/memory_block_manager.cpp
index 900395c37..0732fa5a1 100644
--- a/src/core/hle/kernel/memory/memory_block_manager.cpp
+++ b/src/core/hle/kernel/memory/memory_block_manager.cpp
@@ -67,7 +67,6 @@ void MemoryBlockManager::Update(VAddr addr, std::size_t num_pages, MemoryState p
67 MemoryPermission prev_perm, MemoryAttribute prev_attribute, 67 MemoryPermission prev_perm, MemoryAttribute prev_attribute,
68 MemoryState state, MemoryPermission perm, 68 MemoryState state, MemoryPermission perm,
69 MemoryAttribute attribute) { 69 MemoryAttribute attribute) {
70 const std::size_t prev_count{memory_block_tree.size()};
71 const VAddr end_addr{addr + num_pages * PageSize}; 70 const VAddr end_addr{addr + num_pages * PageSize};
72 iterator node{memory_block_tree.begin()}; 71 iterator node{memory_block_tree.begin()};
73 72
@@ -109,7 +108,6 @@ void MemoryBlockManager::Update(VAddr addr, std::size_t num_pages, MemoryState p
109 108
110void MemoryBlockManager::Update(VAddr addr, std::size_t num_pages, MemoryState state, 109void MemoryBlockManager::Update(VAddr addr, std::size_t num_pages, MemoryState state,
111 MemoryPermission perm, MemoryAttribute attribute) { 110 MemoryPermission perm, MemoryAttribute attribute) {
112 const std::size_t prev_count{memory_block_tree.size()};
113 const VAddr end_addr{addr + num_pages * PageSize}; 111 const VAddr end_addr{addr + num_pages * PageSize};
114 iterator node{memory_block_tree.begin()}; 112 iterator node{memory_block_tree.begin()};
115 113
@@ -145,7 +143,6 @@ void MemoryBlockManager::Update(VAddr addr, std::size_t num_pages, MemoryState s
145 143
146void MemoryBlockManager::UpdateLock(VAddr addr, std::size_t num_pages, LockFunc&& lock_func, 144void MemoryBlockManager::UpdateLock(VAddr addr, std::size_t num_pages, LockFunc&& lock_func,
147 MemoryPermission perm) { 145 MemoryPermission perm) {
148 const std::size_t prev_count{memory_block_tree.size()};
149 const VAddr end_addr{addr + num_pages * PageSize}; 146 const VAddr end_addr{addr + num_pages * PageSize};
150 iterator node{memory_block_tree.begin()}; 147 iterator node{memory_block_tree.begin()};
151 148
diff --git a/src/core/hle/kernel/memory/memory_block_manager.h b/src/core/hle/kernel/memory/memory_block_manager.h
index 9451b5df6..6e1d41075 100644
--- a/src/core/hle/kernel/memory/memory_block_manager.h
+++ b/src/core/hle/kernel/memory/memory_block_manager.h
@@ -6,7 +6,6 @@
6 6
7#include <functional> 7#include <functional>
8#include <list> 8#include <list>
9#include <memory>
10 9
11#include "common/common_types.h" 10#include "common/common_types.h"
12#include "core/hle/kernel/memory/memory_block.h" 11#include "core/hle/kernel/memory/memory_block.h"
diff --git a/src/core/hle/kernel/memory/memory_manager.cpp b/src/core/hle/kernel/memory/memory_manager.cpp
index 3cd4f9e85..6b432e1b2 100644
--- a/src/core/hle/kernel/memory/memory_manager.cpp
+++ b/src/core/hle/kernel/memory/memory_manager.cpp
@@ -104,9 +104,9 @@ ResultCode MemoryManager::Allocate(PageLinkedList& page_list, std::size_t num_pa
104 // Ensure that we don't leave anything un-freed 104 // Ensure that we don't leave anything un-freed
105 auto group_guard = detail::ScopeExit([&] { 105 auto group_guard = detail::ScopeExit([&] {
106 for (const auto& it : page_list.Nodes()) { 106 for (const auto& it : page_list.Nodes()) {
107 const auto num_pages{std::min( 107 const auto min_num_pages{std::min(
108 it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; 108 it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)};
109 chosen_manager.Free(it.GetAddress(), num_pages); 109 chosen_manager.Free(it.GetAddress(), min_num_pages);
110 } 110 }
111 }); 111 });
112 112
@@ -165,9 +165,9 @@ ResultCode MemoryManager::Free(PageLinkedList& page_list, std::size_t num_pages,
165 165
166 // Free all of the pages 166 // Free all of the pages
167 for (const auto& it : page_list.Nodes()) { 167 for (const auto& it : page_list.Nodes()) {
168 const auto num_pages{std::min( 168 const auto min_num_pages{std::min(
169 it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)}; 169 it.GetNumPages(), (chosen_manager.GetEndAddress() - it.GetAddress()) / PageSize)};
170 chosen_manager.Free(it.GetAddress(), num_pages); 170 chosen_manager.Free(it.GetAddress(), min_num_pages);
171 } 171 }
172 172
173 return RESULT_SUCCESS; 173 return RESULT_SUCCESS;
diff --git a/src/core/hle/kernel/memory/memory_manager.h b/src/core/hle/kernel/memory/memory_manager.h
index b078d7a5e..3cf444857 100644
--- a/src/core/hle/kernel/memory/memory_manager.h
+++ b/src/core/hle/kernel/memory/memory_manager.h
@@ -7,7 +7,6 @@
7#include <array> 7#include <array>
8#include <mutex> 8#include <mutex>
9 9
10#include "common/common_funcs.h"
11#include "common/common_types.h" 10#include "common/common_types.h"
12#include "core/hle/kernel/memory/page_heap.h" 11#include "core/hle/kernel/memory/page_heap.h"
13#include "core/hle/result.h" 12#include "core/hle/result.h"
diff --git a/src/core/hle/kernel/memory/page_heap.cpp b/src/core/hle/kernel/memory/page_heap.cpp
index efcbb3cad..0ab1f7205 100644
--- a/src/core/hle/kernel/memory/page_heap.cpp
+++ b/src/core/hle/kernel/memory/page_heap.cpp
@@ -2,8 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#include "core/core.h" 8#include "core/core.h"
9#include "core/hle/kernel/memory/page_heap.h" 9#include "core/hle/kernel/memory/page_heap.h"
diff --git a/src/core/hle/kernel/memory/page_heap.h b/src/core/hle/kernel/memory/page_heap.h
index 380c3f5a1..22b0de860 100644
--- a/src/core/hle/kernel/memory/page_heap.h
+++ b/src/core/hle/kernel/memory/page_heap.h
@@ -2,8 +2,8 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#pragma once 8#pragma once
9 9
diff --git a/src/core/hle/kernel/memory/page_linked_list.h b/src/core/hle/kernel/memory/page_linked_list.h
index 0668d00c6..45dc13eaf 100644
--- a/src/core/hle/kernel/memory/page_linked_list.h
+++ b/src/core/hle/kernel/memory/page_linked_list.h
@@ -7,7 +7,6 @@
7#include <list> 7#include <list>
8 8
9#include "common/assert.h" 9#include "common/assert.h"
10#include "common/common_funcs.h"
11#include "common/common_types.h" 10#include "common/common_types.h"
12#include "core/hle/kernel/memory/memory_types.h" 11#include "core/hle/kernel/memory/memory_types.h"
13#include "core/hle/result.h" 12#include "core/hle/result.h"
diff --git a/src/core/hle/kernel/memory/page_table.cpp b/src/core/hle/kernel/memory/page_table.cpp
index 3281611f8..5d6aac00f 100644
--- a/src/core/hle/kernel/memory/page_table.cpp
+++ b/src/core/hle/kernel/memory/page_table.cpp
@@ -6,7 +6,6 @@
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/scope_exit.h" 7#include "common/scope_exit.h"
8#include "core/core.h" 8#include "core/core.h"
9#include "core/device_memory.h"
10#include "core/hle/kernel/errors.h" 9#include "core/hle/kernel/errors.h"
11#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
12#include "core/hle/kernel/memory/address_space_info.h" 11#include "core/hle/kernel/memory/address_space_info.h"
diff --git a/src/core/hle/kernel/memory/page_table.h b/src/core/hle/kernel/memory/page_table.h
index a867aa050..ce0d38849 100644
--- a/src/core/hle/kernel/memory/page_table.h
+++ b/src/core/hle/kernel/memory/page_table.h
@@ -4,16 +4,15 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <list>
8#include <memory> 7#include <memory>
9#include <mutex> 8#include <mutex>
10 9
11#include "common/common_funcs.h"
12#include "common/common_types.h" 10#include "common/common_types.h"
13#include "common/page_table.h" 11#include "common/page_table.h"
14#include "core/file_sys/program_metadata.h" 12#include "core/file_sys/program_metadata.h"
15#include "core/hle/kernel/memory/memory_block.h" 13#include "core/hle/kernel/memory/memory_block.h"
16#include "core/hle/kernel/memory/memory_manager.h" 14#include "core/hle/kernel/memory/memory_manager.h"
15#include "core/hle/result.h"
17 16
18namespace Core { 17namespace Core {
19class System; 18class System;
diff --git a/src/core/hle/kernel/memory/slab_heap.h b/src/core/hle/kernel/memory/slab_heap.h
index be95fc3f7..465eaddb3 100644
--- a/src/core/hle/kernel/memory/slab_heap.h
+++ b/src/core/hle/kernel/memory/slab_heap.h
@@ -2,15 +2,14 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5// This file references various implementation details from Atmosphère, an open-source firmware for 5// This file references various implementation details from Atmosphere, an open-source firmware for
6// the Nintendo Switch. Copyright 2018-2020 Atmosphère-NX. 6// the Nintendo Switch. Copyright 2018-2020 Atmosphere-NX.
7 7
8#pragma once 8#pragma once
9 9
10#include <atomic> 10#include <atomic>
11 11
12#include "common/assert.h" 12#include "common/assert.h"
13#include "common/common_funcs.h"
14#include "common/common_types.h" 13#include "common/common_types.h"
15 14
16namespace Kernel::Memory { 15namespace Kernel::Memory {
diff --git a/src/core/hle/kernel/memory/system_control.cpp b/src/core/hle/kernel/memory/system_control.cpp
index 9cae3c6cb..2f98e9c4c 100644
--- a/src/core/hle/kernel/memory/system_control.cpp
+++ b/src/core/hle/kernel/memory/system_control.cpp
@@ -2,8 +2,6 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#pragma once
6
7#include <random> 5#include <random>
8 6
9#include "core/hle/kernel/memory/system_control.h" 7#include "core/hle/kernel/memory/system_control.h"
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index eff4e45b0..7869eb32b 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -7,6 +7,7 @@
7#include <vector> 7#include <vector>
8 8
9#include "common/assert.h" 9#include "common/assert.h"
10#include "common/logging/log.h"
10#include "core/core.h" 11#include "core/core.h"
11#include "core/hle/kernel/errors.h" 12#include "core/hle/kernel/errors.h"
12#include "core/hle/kernel/handle_table.h" 13#include "core/hle/kernel/handle_table.h"
@@ -67,6 +68,7 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
67 Handle requesting_thread_handle) { 68 Handle requesting_thread_handle) {
68 // The mutex address must be 4-byte aligned 69 // The mutex address must be 4-byte aligned
69 if ((address % sizeof(u32)) != 0) { 70 if ((address % sizeof(u32)) != 0) {
71 LOG_ERROR(Kernel, "Address is not 4-byte aligned! address={:016X}", address);
70 return ERR_INVALID_ADDRESS; 72 return ERR_INVALID_ADDRESS;
71 } 73 }
72 74
@@ -88,6 +90,8 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
88 } 90 }
89 91
90 if (holding_thread == nullptr) { 92 if (holding_thread == nullptr) {
93 LOG_ERROR(Kernel, "Holding thread does not exist! thread_handle={:08X}",
94 holding_thread_handle);
91 return ERR_INVALID_HANDLE; 95 return ERR_INVALID_HANDLE;
92 } 96 }
93 97
@@ -109,6 +113,7 @@ ResultCode Mutex::TryAcquire(VAddr address, Handle holding_thread_handle,
109ResultCode Mutex::Release(VAddr address) { 113ResultCode Mutex::Release(VAddr address) {
110 // The mutex address must be 4-byte aligned 114 // The mutex address must be 4-byte aligned
111 if ((address % sizeof(u32)) != 0) { 115 if ((address % sizeof(u32)) != 0) {
116 LOG_ERROR(Kernel, "Address is not 4-byte aligned! address={:016X}", address);
112 return ERR_INVALID_ADDRESS; 117 return ERR_INVALID_ADDRESS;
113 } 118 }
114 119
diff --git a/src/core/hle/kernel/process_capability.cpp b/src/core/hle/kernel/process_capability.cpp
index 48e5ae682..63880f13d 100644
--- a/src/core/hle/kernel/process_capability.cpp
+++ b/src/core/hle/kernel/process_capability.cpp
@@ -3,6 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/bit_util.h" 5#include "common/bit_util.h"
6#include "common/logging/log.h"
6#include "core/hle/kernel/errors.h" 7#include "core/hle/kernel/errors.h"
7#include "core/hle/kernel/handle_table.h" 8#include "core/hle/kernel/handle_table.h"
8#include "core/hle/kernel/memory/page_table.h" 9#include "core/hle/kernel/memory/page_table.h"
@@ -119,22 +120,30 @@ ResultCode ProcessCapabilities::ParseCapabilities(const u32* capabilities,
119 // The MapPhysical type uses two descriptor flags for its parameters. 120 // The MapPhysical type uses two descriptor flags for its parameters.
120 // If there's only one, then there's a problem. 121 // If there's only one, then there's a problem.
121 if (i >= num_capabilities) { 122 if (i >= num_capabilities) {
123 LOG_ERROR(Kernel, "Invalid combination! i={}", i);
122 return ERR_INVALID_COMBINATION; 124 return ERR_INVALID_COMBINATION;
123 } 125 }
124 126
125 const auto size_flags = capabilities[i]; 127 const auto size_flags = capabilities[i];
126 if (GetCapabilityType(size_flags) != CapabilityType::MapPhysical) { 128 if (GetCapabilityType(size_flags) != CapabilityType::MapPhysical) {
129 LOG_ERROR(Kernel, "Invalid capability type! size_flags={}", size_flags);
127 return ERR_INVALID_COMBINATION; 130 return ERR_INVALID_COMBINATION;
128 } 131 }
129 132
130 const auto result = HandleMapPhysicalFlags(descriptor, size_flags, page_table); 133 const auto result = HandleMapPhysicalFlags(descriptor, size_flags, page_table);
131 if (result.IsError()) { 134 if (result.IsError()) {
135 LOG_ERROR(Kernel, "Failed to map physical flags! descriptor={}, size_flags={}",
136 descriptor, size_flags);
132 return result; 137 return result;
133 } 138 }
134 } else { 139 } else {
135 const auto result = 140 const auto result =
136 ParseSingleFlagCapability(set_flags, set_svc_bits, descriptor, page_table); 141 ParseSingleFlagCapability(set_flags, set_svc_bits, descriptor, page_table);
137 if (result.IsError()) { 142 if (result.IsError()) {
143 LOG_ERROR(
144 Kernel,
145 "Failed to parse capability flag! set_flags={}, set_svc_bits={}, descriptor={}",
146 set_flags, set_svc_bits, descriptor);
138 return result; 147 return result;
139 } 148 }
140 } 149 }
@@ -162,6 +171,9 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s
162 const u32 flag_length = GetFlagBitOffset(type); 171 const u32 flag_length = GetFlagBitOffset(type);
163 const u32 set_flag = 1U << flag_length; 172 const u32 set_flag = 1U << flag_length;
164 if ((set_flag & set_flags & InitializeOnceMask) != 0) { 173 if ((set_flag & set_flags & InitializeOnceMask) != 0) {
174 LOG_ERROR(Kernel,
175 "Attempted to initialize flags that may only be initialized once. set_flags={}",
176 set_flags);
165 return ERR_INVALID_COMBINATION; 177 return ERR_INVALID_COMBINATION;
166 } 178 }
167 set_flags |= set_flag; 179 set_flags |= set_flag;
@@ -187,6 +199,7 @@ ResultCode ProcessCapabilities::ParseSingleFlagCapability(u32& set_flags, u32& s
187 break; 199 break;
188 } 200 }
189 201
202 LOG_ERROR(Kernel, "Invalid capability type! type={}", static_cast<u32>(type));
190 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 203 return ERR_INVALID_CAPABILITY_DESCRIPTOR;
191} 204}
192 205
@@ -208,23 +221,31 @@ void ProcessCapabilities::Clear() {
208 221
209ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) { 222ResultCode ProcessCapabilities::HandlePriorityCoreNumFlags(u32 flags) {
210 if (priority_mask != 0 || core_mask != 0) { 223 if (priority_mask != 0 || core_mask != 0) {
224 LOG_ERROR(Kernel, "Core or priority mask are not zero! priority_mask={}, core_mask={}",
225 priority_mask, core_mask);
211 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 226 return ERR_INVALID_CAPABILITY_DESCRIPTOR;
212 } 227 }
213 228
214 const u32 core_num_min = (flags >> 16) & 0xFF; 229 const u32 core_num_min = (flags >> 16) & 0xFF;
215 const u32 core_num_max = (flags >> 24) & 0xFF; 230 const u32 core_num_max = (flags >> 24) & 0xFF;
216 if (core_num_min > core_num_max) { 231 if (core_num_min > core_num_max) {
232 LOG_ERROR(Kernel, "Core min is greater than core max! core_num_min={}, core_num_max={}",
233 core_num_min, core_num_max);
217 return ERR_INVALID_COMBINATION; 234 return ERR_INVALID_COMBINATION;
218 } 235 }
219 236
220 const u32 priority_min = (flags >> 10) & 0x3F; 237 const u32 priority_min = (flags >> 10) & 0x3F;
221 const u32 priority_max = (flags >> 4) & 0x3F; 238 const u32 priority_max = (flags >> 4) & 0x3F;
222 if (priority_min > priority_max) { 239 if (priority_min > priority_max) {
240 LOG_ERROR(Kernel,
241 "Priority min is greater than priority max! priority_min={}, priority_max={}",
242 core_num_min, priority_max);
223 return ERR_INVALID_COMBINATION; 243 return ERR_INVALID_COMBINATION;
224 } 244 }
225 245
226 // The switch only has 4 usable cores. 246 // The switch only has 4 usable cores.
227 if (core_num_max >= 4) { 247 if (core_num_max >= 4) {
248 LOG_ERROR(Kernel, "Invalid max cores specified! core_num_max={}", core_num_max);
228 return ERR_INVALID_PROCESSOR_ID; 249 return ERR_INVALID_PROCESSOR_ID;
229 } 250 }
230 251
@@ -259,6 +280,7 @@ ResultCode ProcessCapabilities::HandleSyscallFlags(u32& set_svc_bits, u32 flags)
259 } 280 }
260 281
261 if (svc_number >= svc_capabilities.size()) { 282 if (svc_number >= svc_capabilities.size()) {
283 LOG_ERROR(Kernel, "Process svc capability is out of range! svc_number={}", svc_number);
262 return ERR_OUT_OF_RANGE; 284 return ERR_OUT_OF_RANGE;
263 } 285 }
264 286
@@ -295,6 +317,8 @@ ResultCode ProcessCapabilities::HandleInterruptFlags(u32 flags) {
295 // emulate that, it's sufficient to mark every interrupt as defined. 317 // emulate that, it's sufficient to mark every interrupt as defined.
296 318
297 if (interrupt >= interrupt_capabilities.size()) { 319 if (interrupt >= interrupt_capabilities.size()) {
320 LOG_ERROR(Kernel, "Process interrupt capability is out of range! svc_number={}",
321 interrupt);
298 return ERR_OUT_OF_RANGE; 322 return ERR_OUT_OF_RANGE;
299 } 323 }
300 324
@@ -307,6 +331,7 @@ ResultCode ProcessCapabilities::HandleInterruptFlags(u32 flags) {
307ResultCode ProcessCapabilities::HandleProgramTypeFlags(u32 flags) { 331ResultCode ProcessCapabilities::HandleProgramTypeFlags(u32 flags) {
308 const u32 reserved = flags >> 17; 332 const u32 reserved = flags >> 17;
309 if (reserved != 0) { 333 if (reserved != 0) {
334 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
310 return ERR_RESERVED_VALUE; 335 return ERR_RESERVED_VALUE;
311 } 336 }
312 337
@@ -324,6 +349,9 @@ ResultCode ProcessCapabilities::HandleKernelVersionFlags(u32 flags) {
324 const u32 major_version = kernel_version >> 19; 349 const u32 major_version = kernel_version >> 19;
325 350
326 if (major_version != 0 || flags < 0x80000) { 351 if (major_version != 0 || flags < 0x80000) {
352 LOG_ERROR(Kernel,
353 "Kernel version is non zero or flags are too small! major_version={}, flags={}",
354 major_version, flags);
327 return ERR_INVALID_CAPABILITY_DESCRIPTOR; 355 return ERR_INVALID_CAPABILITY_DESCRIPTOR;
328 } 356 }
329 357
@@ -334,6 +362,7 @@ ResultCode ProcessCapabilities::HandleKernelVersionFlags(u32 flags) {
334ResultCode ProcessCapabilities::HandleHandleTableFlags(u32 flags) { 362ResultCode ProcessCapabilities::HandleHandleTableFlags(u32 flags) {
335 const u32 reserved = flags >> 26; 363 const u32 reserved = flags >> 26;
336 if (reserved != 0) { 364 if (reserved != 0) {
365 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
337 return ERR_RESERVED_VALUE; 366 return ERR_RESERVED_VALUE;
338 } 367 }
339 368
@@ -344,6 +373,7 @@ ResultCode ProcessCapabilities::HandleHandleTableFlags(u32 flags) {
344ResultCode ProcessCapabilities::HandleDebugFlags(u32 flags) { 373ResultCode ProcessCapabilities::HandleDebugFlags(u32 flags) {
345 const u32 reserved = flags >> 19; 374 const u32 reserved = flags >> 19;
346 if (reserved != 0) { 375 if (reserved != 0) {
376 LOG_ERROR(Kernel, "Reserved value is non-zero! reserved={}", reserved);
347 return ERR_RESERVED_VALUE; 377 return ERR_RESERVED_VALUE;
348 } 378 }
349 379
diff --git a/src/core/hle/kernel/readable_event.cpp b/src/core/hle/kernel/readable_event.cpp
index 9d3d3a81b..00860fcbd 100644
--- a/src/core/hle/kernel/readable_event.cpp
+++ b/src/core/hle/kernel/readable_event.cpp
@@ -4,6 +4,7 @@
4 4
5#include <algorithm> 5#include <algorithm>
6#include "common/assert.h" 6#include "common/assert.h"
7#include "common/logging/log.h"
7#include "core/hle/kernel/errors.h" 8#include "core/hle/kernel/errors.h"
8#include "core/hle/kernel/object.h" 9#include "core/hle/kernel/object.h"
9#include "core/hle/kernel/readable_event.h" 10#include "core/hle/kernel/readable_event.h"
@@ -23,10 +24,12 @@ void ReadableEvent::Acquire(Thread* thread) {
23} 24}
24 25
25void ReadableEvent::Signal() { 26void ReadableEvent::Signal() {
26 if (!is_signaled) { 27 if (is_signaled) {
27 is_signaled = true; 28 return;
28 SynchronizationObject::Signal(); 29 }
29 }; 30
31 is_signaled = true;
32 SynchronizationObject::Signal();
30} 33}
31 34
32void ReadableEvent::Clear() { 35void ReadableEvent::Clear() {
@@ -35,6 +38,8 @@ void ReadableEvent::Clear() {
35 38
36ResultCode ReadableEvent::Reset() { 39ResultCode ReadableEvent::Reset() {
37 if (!is_signaled) { 40 if (!is_signaled) {
41 LOG_ERROR(Kernel, "Handle is not signaled! object_id={}, object_type={}, object_name={}",
42 GetObjectId(), GetTypeName(), GetName());
38 return ERR_INVALID_STATE; 43 return ERR_INVALID_STATE;
39 } 44 }
40 45
diff --git a/src/core/hle/kernel/resource_limit.cpp b/src/core/hle/kernel/resource_limit.cpp
index 96e5b9892..d9beaa3a4 100644
--- a/src/core/hle/kernel/resource_limit.cpp
+++ b/src/core/hle/kernel/resource_limit.cpp
@@ -69,6 +69,8 @@ ResultCode ResourceLimit::SetLimitValue(ResourceType resource, s64 value) {
69 limit[index] = value; 69 limit[index] = value;
70 return RESULT_SUCCESS; 70 return RESULT_SUCCESS;
71 } else { 71 } else {
72 LOG_ERROR(Kernel, "Limit value is too large! resource={}, value={}, index={}",
73 static_cast<u32>(resource), value, index);
72 return ERR_INVALID_STATE; 74 return ERR_INVALID_STATE;
73 } 75 }
74} 76}
diff --git a/src/core/hle/kernel/server_session.cpp b/src/core/hle/kernel/server_session.cpp
index 0f102ca44..25438b86b 100644
--- a/src/core/hle/kernel/server_session.cpp
+++ b/src/core/hle/kernel/server_session.cpp
@@ -137,8 +137,8 @@ ResultCode ServerSession::HandleDomainSyncRequest(Kernel::HLERequestContext& con
137ResultCode ServerSession::QueueSyncRequest(std::shared_ptr<Thread> thread, 137ResultCode ServerSession::QueueSyncRequest(std::shared_ptr<Thread> thread,
138 Core::Memory::Memory& memory) { 138 Core::Memory::Memory& memory) {
139 u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(thread->GetTLSAddress()))}; 139 u32* cmd_buf{reinterpret_cast<u32*>(memory.GetPointer(thread->GetTLSAddress()))};
140 std::shared_ptr<Kernel::HLERequestContext> context{ 140 auto context =
141 std::make_shared<Kernel::HLERequestContext>(SharedFrom(this), std::move(thread))}; 141 std::make_shared<HLERequestContext>(kernel, memory, SharedFrom(this), std::move(thread));
142 142
143 context->PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf); 143 context->PopulateFromIncomingCommandBuffer(kernel.CurrentProcess()->GetHandleTable(), cmd_buf);
144 request_queue.Push(std::move(context)); 144 request_queue.Push(std::move(context));
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index 41ef2caf6..4ae4529f5 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -685,6 +685,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
685 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource: 685 case GetInfoType::TotalPhysicalMemoryAvailableWithoutSystemResource:
686 case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: { 686 case GetInfoType::TotalPhysicalMemoryUsedWithoutSystemResource: {
687 if (info_sub_id != 0) { 687 if (info_sub_id != 0) {
688 LOG_ERROR(Kernel_SVC, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,
689 info_sub_id);
688 return ERR_INVALID_ENUM_VALUE; 690 return ERR_INVALID_ENUM_VALUE;
689 } 691 }
690 692
@@ -692,6 +694,8 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
692 system.Kernel().CurrentProcess()->GetHandleTable(); 694 system.Kernel().CurrentProcess()->GetHandleTable();
693 const auto process = current_process_handle_table.Get<Process>(static_cast<Handle>(handle)); 695 const auto process = current_process_handle_table.Get<Process>(static_cast<Handle>(handle));
694 if (!process) { 696 if (!process) {
697 LOG_ERROR(Kernel_SVC, "Process is not valid! info_id={}, info_sub_id={}, handle={:08X}",
698 info_id, info_sub_id, handle);
695 return ERR_INVALID_HANDLE; 699 return ERR_INVALID_HANDLE;
696 } 700 }
697 701
@@ -783,10 +787,13 @@ static ResultCode GetInfo(Core::System& system, u64* result, u64 info_id, u64 ha
783 787
784 case GetInfoType::RegisterResourceLimit: { 788 case GetInfoType::RegisterResourceLimit: {
785 if (handle != 0) { 789 if (handle != 0) {
790 LOG_ERROR(Kernel, "Handle is non zero! handle={:08X}", handle);
786 return ERR_INVALID_HANDLE; 791 return ERR_INVALID_HANDLE;
787 } 792 }
788 793
789 if (info_sub_id != 0) { 794 if (info_sub_id != 0) {
795 LOG_ERROR(Kernel, "Info sub id is non zero! info_id={}, info_sub_id={}", info_id,
796 info_sub_id);
790 return ERR_INVALID_COMBINATION; 797 return ERR_INVALID_COMBINATION;
791 } 798 }
792 799
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index a919750a6..db7f379ac 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -423,6 +423,8 @@ ResultCode Thread::SetCoreAndAffinityMask(s32 new_core, u64 new_affinity_mask) {
423 if (new_core == THREADPROCESSORID_DONT_UPDATE) { 423 if (new_core == THREADPROCESSORID_DONT_UPDATE) {
424 new_core = use_override ? ideal_core_override : ideal_core; 424 new_core = use_override ? ideal_core_override : ideal_core;
425 if ((new_affinity_mask & (1ULL << new_core)) == 0) { 425 if ((new_affinity_mask & (1ULL << new_core)) == 0) {
426 LOG_ERROR(Kernel, "New affinity mask is incorrect! new_core={}, new_affinity_mask={}",
427 new_core, new_affinity_mask);
426 return ERR_INVALID_COMBINATION; 428 return ERR_INVALID_COMBINATION;
427 } 429 }
428 } 430 }
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp
index 9a7992f58..630a8b048 100644
--- a/src/core/hle/service/acc/acc.cpp
+++ b/src/core/hle/service/acc/acc.cpp
@@ -228,7 +228,8 @@ public:
228 228
229class IManagerForApplication final : public ServiceFramework<IManagerForApplication> { 229class IManagerForApplication final : public ServiceFramework<IManagerForApplication> {
230public: 230public:
231 IManagerForApplication() : ServiceFramework("IManagerForApplication") { 231 explicit IManagerForApplication(Common::UUID user_id)
232 : ServiceFramework("IManagerForApplication"), user_id(user_id) {
232 // clang-format off 233 // clang-format off
233 static const FunctionInfo functions[] = { 234 static const FunctionInfo functions[] = {
234 {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"}, 235 {0, &IManagerForApplication::CheckAvailability, "CheckAvailability"},
@@ -254,12 +255,14 @@ private:
254 } 255 }
255 256
256 void GetAccountId(Kernel::HLERequestContext& ctx) { 257 void GetAccountId(Kernel::HLERequestContext& ctx) {
257 LOG_WARNING(Service_ACC, "(STUBBED) called"); 258 LOG_DEBUG(Service_ACC, "called");
258 // Should return a nintendo account ID 259
259 IPC::ResponseBuilder rb{ctx, 4}; 260 IPC::ResponseBuilder rb{ctx, 4};
260 rb.Push(RESULT_SUCCESS); 261 rb.Push(RESULT_SUCCESS);
261 rb.PushRaw<u64>(1); 262 rb.PushRaw<u64>(user_id.GetNintendoID());
262 } 263 }
264
265 Common::UUID user_id;
263}; 266};
264 267
265void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) { 268void Module::Interface::GetUserCount(Kernel::HLERequestContext& ctx) {
@@ -382,7 +385,7 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo
382 LOG_DEBUG(Service_ACC, "called"); 385 LOG_DEBUG(Service_ACC, "called");
383 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 386 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
384 rb.Push(RESULT_SUCCESS); 387 rb.Push(RESULT_SUCCESS);
385 rb.PushIpcInterface<IManagerForApplication>(); 388 rb.PushIpcInterface<IManagerForApplication>(profile_manager->GetLastOpenedUser());
386} 389}
387 390
388void Module::Interface::IsUserAccountSwitchLocked(Kernel::HLERequestContext& ctx) { 391void Module::Interface::IsUserAccountSwitchLocked(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp
index 9450de6e9..4df74c4f9 100644
--- a/src/core/hle/service/am/am.cpp
+++ b/src/core/hle/service/am/am.cpp
@@ -1335,12 +1335,23 @@ void IApplicationFunctions::SetTerminateResult(Kernel::HLERequestContext& ctx) {
1335} 1335}
1336 1336
1337void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) { 1337void IApplicationFunctions::GetDisplayVersion(Kernel::HLERequestContext& ctx) {
1338 LOG_WARNING(Service_AM, "(STUBBED) called"); 1338 LOG_DEBUG(Service_AM, "called");
1339
1340 std::array<u8, 0x10> version_string{};
1341
1342 FileSys::PatchManager pm{system.CurrentProcess()->GetTitleID()};
1343 const auto res = pm.GetControlMetadata();
1344 if (res.first != nullptr) {
1345 const auto& version = res.first->GetVersionString();
1346 std::copy(version.begin(), version.end(), version_string.begin());
1347 } else {
1348 constexpr u128 default_version = {1, 0};
1349 std::memcpy(version_string.data(), default_version.data(), sizeof(u128));
1350 }
1339 1351
1340 IPC::ResponseBuilder rb{ctx, 6}; 1352 IPC::ResponseBuilder rb{ctx, 6};
1341 rb.Push(RESULT_SUCCESS); 1353 rb.Push(RESULT_SUCCESS);
1342 rb.Push<u64>(1); 1354 rb.PushRaw(version_string);
1343 rb.Push<u64>(0);
1344} 1355}
1345 1356
1346void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) { 1357void IApplicationFunctions::GetDesiredLanguage(Kernel::HLERequestContext& ctx) {
@@ -1514,14 +1525,15 @@ void InstallInterfaces(SM::ServiceManager& service_manager,
1514 std::make_shared<TCAP>()->InstallAsService(service_manager); 1525 std::make_shared<TCAP>()->InstallAsService(service_manager);
1515} 1526}
1516 1527
1517IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions") { 1528IHomeMenuFunctions::IHomeMenuFunctions(Kernel::KernelCore& kernel)
1529 : ServiceFramework("IHomeMenuFunctions"), kernel(kernel) {
1518 // clang-format off 1530 // clang-format off
1519 static const FunctionInfo functions[] = { 1531 static const FunctionInfo functions[] = {
1520 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"}, 1532 {10, &IHomeMenuFunctions::RequestToGetForeground, "RequestToGetForeground"},
1521 {11, nullptr, "LockForeground"}, 1533 {11, nullptr, "LockForeground"},
1522 {12, nullptr, "UnlockForeground"}, 1534 {12, nullptr, "UnlockForeground"},
1523 {20, nullptr, "PopFromGeneralChannel"}, 1535 {20, nullptr, "PopFromGeneralChannel"},
1524 {21, nullptr, "GetPopFromGeneralChannelEvent"}, 1536 {21, &IHomeMenuFunctions::GetPopFromGeneralChannelEvent, "GetPopFromGeneralChannelEvent"},
1525 {30, nullptr, "GetHomeButtonWriterLockAccessor"}, 1537 {30, nullptr, "GetHomeButtonWriterLockAccessor"},
1526 {31, nullptr, "GetWriterLockAccessorEx"}, 1538 {31, nullptr, "GetWriterLockAccessorEx"},
1527 {100, nullptr, "PopRequestLaunchApplicationForDebug"}, 1539 {100, nullptr, "PopRequestLaunchApplicationForDebug"},
@@ -1531,6 +1543,9 @@ IHomeMenuFunctions::IHomeMenuFunctions() : ServiceFramework("IHomeMenuFunctions"
1531 // clang-format on 1543 // clang-format on
1532 1544
1533 RegisterHandlers(functions); 1545 RegisterHandlers(functions);
1546
1547 pop_from_general_channel_event = Kernel::WritableEvent::CreateEventPair(
1548 kernel, "IHomeMenuFunctions:PopFromGeneralChannelEvent");
1534} 1549}
1535 1550
1536IHomeMenuFunctions::~IHomeMenuFunctions() = default; 1551IHomeMenuFunctions::~IHomeMenuFunctions() = default;
@@ -1542,6 +1557,14 @@ void IHomeMenuFunctions::RequestToGetForeground(Kernel::HLERequestContext& ctx)
1542 rb.Push(RESULT_SUCCESS); 1557 rb.Push(RESULT_SUCCESS);
1543} 1558}
1544 1559
1560void IHomeMenuFunctions::GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx) {
1561 LOG_WARNING(Service_AM, "(STUBBED) called");
1562
1563 IPC::ResponseBuilder rb{ctx, 2, 1};
1564 rb.Push(RESULT_SUCCESS);
1565 rb.PushCopyObjects(pop_from_general_channel_event.readable);
1566}
1567
1545IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") { 1568IGlobalStateController::IGlobalStateController() : ServiceFramework("IGlobalStateController") {
1546 // clang-format off 1569 // clang-format off
1547 static const FunctionInfo functions[] = { 1570 static const FunctionInfo functions[] = {
diff --git a/src/core/hle/service/am/am.h b/src/core/hle/service/am/am.h
index dfa701d73..469f7f814 100644
--- a/src/core/hle/service/am/am.h
+++ b/src/core/hle/service/am/am.h
@@ -292,11 +292,15 @@ private:
292 292
293class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> { 293class IHomeMenuFunctions final : public ServiceFramework<IHomeMenuFunctions> {
294public: 294public:
295 IHomeMenuFunctions(); 295 explicit IHomeMenuFunctions(Kernel::KernelCore& kernel);
296 ~IHomeMenuFunctions() override; 296 ~IHomeMenuFunctions() override;
297 297
298private: 298private:
299 void RequestToGetForeground(Kernel::HLERequestContext& ctx); 299 void RequestToGetForeground(Kernel::HLERequestContext& ctx);
300 void GetPopFromGeneralChannelEvent(Kernel::HLERequestContext& ctx);
301
302 Kernel::EventPair pop_from_general_channel_event;
303 Kernel::KernelCore& kernel;
300}; 304};
301 305
302class IGlobalStateController final : public ServiceFramework<IGlobalStateController> { 306class IGlobalStateController final : public ServiceFramework<IGlobalStateController> {
diff --git a/src/core/hle/service/am/applet_ae.cpp b/src/core/hle/service/am/applet_ae.cpp
index e454b77d8..9df286d17 100644
--- a/src/core/hle/service/am/applet_ae.cpp
+++ b/src/core/hle/service/am/applet_ae.cpp
@@ -202,7 +202,7 @@ private:
202 202
203 IPC::ResponseBuilder rb{ctx, 2, 0, 1}; 203 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
204 rb.Push(RESULT_SUCCESS); 204 rb.Push(RESULT_SUCCESS);
205 rb.PushIpcInterface<IHomeMenuFunctions>(); 205 rb.PushIpcInterface<IHomeMenuFunctions>(system.Kernel());
206 } 206 }
207 207
208 void GetGlobalStateController(Kernel::HLERequestContext& ctx) { 208 void GetGlobalStateController(Kernel::HLERequestContext& ctx) {
diff --git a/src/core/hle/service/audio/audin_u.cpp b/src/core/hle/service/audio/audin_u.cpp
index d7f1d348d..3e2299426 100644
--- a/src/core/hle/service/audio/audin_u.cpp
+++ b/src/core/hle/service/audio/audin_u.cpp
@@ -2,6 +2,9 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include "common/logging/log.h"
6#include "core/hle/ipc_helpers.h"
7#include "core/hle/kernel/hle_ipc.h"
5#include "core/hle/service/audio/audin_u.h" 8#include "core/hle/service/audio/audin_u.h"
6 9
7namespace Service::Audio { 10namespace Service::Audio {
@@ -36,11 +39,12 @@ public:
36AudInU::AudInU() : ServiceFramework("audin:u") { 39AudInU::AudInU() : ServiceFramework("audin:u") {
37 // clang-format off 40 // clang-format off
38 static const FunctionInfo functions[] = { 41 static const FunctionInfo functions[] = {
39 {0, nullptr, "ListAudioIns"}, 42 {0, &AudInU::ListAudioIns, "ListAudioIns"},
40 {1, nullptr, "OpenAudioIn"}, 43 {1, &AudInU::OpenAudioIn, "OpenAudioIn"},
41 {2, nullptr, "Unknown"}, 44 {2, &AudInU::ListAudioIns, "ListAudioInsAuto"},
42 {3, nullptr, "OpenAudioInAuto"}, 45 {3, &AudInU::OpenAudioIn, "OpenAudioInAuto"},
43 {4, nullptr, "ListAudioInsAuto"}, 46 {4, &AudInU::ListAudioInsAutoFiltered, "ListAudioInsAutoFiltered"},
47 {5, &AudInU::OpenAudioInProtocolSpecified, "OpenAudioInProtocolSpecified"},
44 }; 48 };
45 // clang-format on 49 // clang-format on
46 50
@@ -49,4 +53,60 @@ AudInU::AudInU() : ServiceFramework("audin:u") {
49 53
50AudInU::~AudInU() = default; 54AudInU::~AudInU() = default;
51 55
56void AudInU::ListAudioIns(Kernel::HLERequestContext& ctx) {
57 LOG_DEBUG(Service_Audio, "called");
58 const std::size_t count = ctx.GetWriteBufferSize() / sizeof(AudioInDeviceName);
59
60 const std::size_t device_count = std::min(count, audio_device_names.size());
61 std::vector<AudioInDeviceName> device_names;
62 device_names.reserve(device_count);
63
64 for (std::size_t i = 0; i < device_count; i++) {
65 const auto& device_name = audio_device_names[i];
66 auto& entry = device_names.emplace_back();
67 device_name.copy(entry.data(), device_name.size());
68 }
69
70 ctx.WriteBuffer(device_names);
71
72 IPC::ResponseBuilder rb{ctx, 3};
73 rb.Push(RESULT_SUCCESS);
74 rb.Push(static_cast<u32>(device_names.size()));
75}
76
77void AudInU::ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx) {
78 LOG_DEBUG(Service_Audio, "called");
79 constexpr u32 device_count = 0;
80
81 // Since we don't actually use any other audio input devices, we return 0 devices. Filtered
82 // device listing just omits the default input device
83
84 IPC::ResponseBuilder rb{ctx, 3};
85 rb.Push(RESULT_SUCCESS);
86 rb.Push(static_cast<u32>(device_count));
87}
88
89void AudInU::OpenInOutImpl(Kernel::HLERequestContext& ctx) {
90 AudInOutParams params{};
91 params.channel_count = 2;
92 params.sample_format = SampleFormat::PCM16;
93 params.sample_rate = 48000;
94 params.state = State::Started;
95
96 IPC::ResponseBuilder rb{ctx, 6, 0, 1};
97 rb.Push(RESULT_SUCCESS);
98 rb.PushRaw<AudInOutParams>(params);
99 rb.PushIpcInterface<IAudioIn>();
100}
101
102void AudInU::OpenAudioIn(Kernel::HLERequestContext& ctx) {
103 LOG_WARNING(Service_Audio, "(STUBBED) called");
104 OpenInOutImpl(ctx);
105}
106
107void AudInU::OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx) {
108 LOG_WARNING(Service_Audio, "(STUBBED) called");
109 OpenInOutImpl(ctx);
110}
111
52} // namespace Service::Audio 112} // namespace Service::Audio
diff --git a/src/core/hle/service/audio/audin_u.h b/src/core/hle/service/audio/audin_u.h
index 0538b9560..a599f4a64 100644
--- a/src/core/hle/service/audio/audin_u.h
+++ b/src/core/hle/service/audio/audin_u.h
@@ -16,6 +16,35 @@ class AudInU final : public ServiceFramework<AudInU> {
16public: 16public:
17 explicit AudInU(); 17 explicit AudInU();
18 ~AudInU() override; 18 ~AudInU() override;
19
20private:
21 enum class SampleFormat : u32_le {
22 PCM16 = 2,
23 };
24
25 enum class State : u32_le {
26 Started = 0,
27 Stopped = 1,
28 };
29
30 struct AudInOutParams {
31 u32_le sample_rate{};
32 u32_le channel_count{};
33 SampleFormat sample_format{};
34 State state{};
35 };
36 static_assert(sizeof(AudInOutParams) == 0x10, "AudInOutParams is an invalid size");
37
38 using AudioInDeviceName = std::array<char, 256>;
39 static constexpr std::array<std::string_view, 1> audio_device_names{{
40 "BuiltInHeadset",
41 }};
42
43 void ListAudioIns(Kernel::HLERequestContext& ctx);
44 void ListAudioInsAutoFiltered(Kernel::HLERequestContext& ctx);
45 void OpenInOutImpl(Kernel::HLERequestContext& ctx);
46 void OpenAudioIn(Kernel::HLERequestContext& ctx);
47 void OpenAudioInProtocolSpecified(Kernel::HLERequestContext& ctx);
19}; 48};
20 49
21} // namespace Service::Audio 50} // namespace Service::Audio
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
index 5febe8fc1..d29e78d7e 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -4,8 +4,8 @@
4 4
5#include <fmt/ostream.h> 5#include <fmt/ostream.h>
6#include <httplib.h> 6#include <httplib.h>
7#include <json.hpp>
8#include <mbedtls/sha256.h> 7#include <mbedtls/sha256.h>
8#include <nlohmann/json.hpp>
9#include "common/hex_util.h" 9#include "common/hex_util.h"
10#include "common/logging/backend.h" 10#include "common/logging/backend.h"
11#include "common/logging/log.h" 11#include "common/logging/log.h"
diff --git a/src/core/hle/service/hid/hid.cpp b/src/core/hle/service/hid/hid.cpp
index 5559587e3..c84cb1483 100644
--- a/src/core/hle/service/hid/hid.cpp
+++ b/src/core/hle/service/hid/hid.cpp
@@ -157,7 +157,7 @@ Hid::Hid(Core::System& system) : ServiceFramework("hid"), system(system) {
157 {11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"}, 157 {11, &Hid::ActivateTouchScreen, "ActivateTouchScreen"},
158 {21, &Hid::ActivateMouse, "ActivateMouse"}, 158 {21, &Hid::ActivateMouse, "ActivateMouse"},
159 {31, &Hid::ActivateKeyboard, "ActivateKeyboard"}, 159 {31, &Hid::ActivateKeyboard, "ActivateKeyboard"},
160 {32, nullptr, "SendKeyboardLockKeyEvent"}, 160 {32, &Hid::SendKeyboardLockKeyEvent, "SendKeyboardLockKeyEvent"},
161 {40, nullptr, "AcquireXpadIdEventHandle"}, 161 {40, nullptr, "AcquireXpadIdEventHandle"},
162 {41, nullptr, "ReleaseXpadIdEventHandle"}, 162 {41, nullptr, "ReleaseXpadIdEventHandle"},
163 {51, &Hid::ActivateXpad, "ActivateXpad"}, 163 {51, &Hid::ActivateXpad, "ActivateXpad"},
@@ -871,6 +871,15 @@ void Hid::InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx) {
871 rb.Push(RESULT_SUCCESS); 871 rb.Push(RESULT_SUCCESS);
872} 872}
873 873
874void Hid::SendKeyboardLockKeyEvent(Kernel::HLERequestContext& ctx) {
875 IPC::RequestParser rp{ctx};
876 const auto flags{rp.Pop<u32>()};
877 LOG_WARNING(Service_HID, "(STUBBED) called. flags={}", flags);
878
879 IPC::ResponseBuilder rb{ctx, 2};
880 rb.Push(RESULT_SUCCESS);
881}
882
874class HidDbg final : public ServiceFramework<HidDbg> { 883class HidDbg final : public ServiceFramework<HidDbg> {
875public: 884public:
876 explicit HidDbg() : ServiceFramework{"hid:dbg"} { 885 explicit HidDbg() : ServiceFramework{"hid:dbg"} {
diff --git a/src/core/hle/service/hid/hid.h b/src/core/hle/service/hid/hid.h
index 23552efb1..c8ed4ad8b 100644
--- a/src/core/hle/service/hid/hid.h
+++ b/src/core/hle/service/hid/hid.h
@@ -130,6 +130,7 @@ private:
130 void SetPalmaBoostMode(Kernel::HLERequestContext& ctx); 130 void SetPalmaBoostMode(Kernel::HLERequestContext& ctx);
131 void StopSevenSixAxisSensor(Kernel::HLERequestContext& ctx); 131 void StopSevenSixAxisSensor(Kernel::HLERequestContext& ctx);
132 void InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx); 132 void InitializeSevenSixAxisSensor(Kernel::HLERequestContext& ctx);
133 void SendKeyboardLockKeyEvent(Kernel::HLERequestContext& ctx);
133 134
134 std::shared_ptr<IAppletResource> applet_resource; 135 std::shared_ptr<IAppletResource> applet_resource;
135 Core::System& system; 136 Core::System& system;
diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp
index 558cbe6d7..76cfa5a17 100644
--- a/src/core/reporter.cpp
+++ b/src/core/reporter.cpp
@@ -4,11 +4,12 @@
4 4
5#include <ctime> 5#include <ctime>
6#include <fstream> 6#include <fstream>
7#include <iomanip>
7 8
8#include <fmt/chrono.h> 9#include <fmt/chrono.h>
9#include <fmt/format.h> 10#include <fmt/format.h>
10#include <fmt/ostream.h> 11#include <fmt/ostream.h>
11#include <json.hpp> 12#include <nlohmann/json.hpp>
12 13
13#include "common/file_util.h" 14#include "common/file_util.h"
14#include "common/hex_util.h" 15#include "common/hex_util.h"
diff --git a/src/core/settings.cpp b/src/core/settings.cpp
index cd6c257f5..2b0bdc4d3 100644
--- a/src/core/settings.cpp
+++ b/src/core/settings.cpp
@@ -96,6 +96,7 @@ void LogSettings() {
96 LogSetting("Renderer_UseAsynchronousGpuEmulation", 96 LogSetting("Renderer_UseAsynchronousGpuEmulation",
97 Settings::values.use_asynchronous_gpu_emulation); 97 Settings::values.use_asynchronous_gpu_emulation);
98 LogSetting("Renderer_UseVsync", Settings::values.use_vsync); 98 LogSetting("Renderer_UseVsync", Settings::values.use_vsync);
99 LogSetting("Renderer_AnisotropicFilteringLevel", Settings::values.max_anisotropy);
99 LogSetting("Audio_OutputEngine", Settings::values.sink_id); 100 LogSetting("Audio_OutputEngine", Settings::values.sink_id);
100 LogSetting("Audio_EnableAudioStretching", Settings::values.enable_audio_stretching); 101 LogSetting("Audio_EnableAudioStretching", Settings::values.enable_audio_stretching);
101 LogSetting("Audio_OutputDevice", Settings::values.audio_device_id); 102 LogSetting("Audio_OutputDevice", Settings::values.audio_device_id);