summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/address_arbiter.cpp25
-rw-r--r--src/core/hle/kernel/errors.h5
-rw-r--r--src/core/hle/kernel/handle_table.cpp2
-rw-r--r--src/core/hle/kernel/handle_table.h2
-rw-r--r--src/core/hle/kernel/hle_ipc.cpp27
-rw-r--r--src/core/hle/kernel/hle_ipc.h20
-rw-r--r--src/core/hle/kernel/mutex.cpp4
-rw-r--r--src/core/hle/kernel/process.cpp6
-rw-r--r--src/core/hle/kernel/process.h4
-rw-r--r--src/core/hle/kernel/shared_memory.h2
-rw-r--r--src/core/hle/kernel/svc.cpp128
-rw-r--r--src/core/hle/kernel/svc_wrap.h73
-rw-r--r--src/core/hle/kernel/thread.cpp6
-rw-r--r--src/core/hle/kernel/thread.h2
-rw-r--r--src/core/hle/kernel/vm_manager.cpp2
-rw-r--r--src/core/hle/kernel/vm_manager.h4
-rw-r--r--src/core/hle/kernel/wait_object.cpp2
17 files changed, 190 insertions, 124 deletions
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp
index 6657accd5..93577591f 100644
--- a/src/core/hle/kernel/address_arbiter.cpp
+++ b/src/core/hle/kernel/address_arbiter.cpp
@@ -35,16 +35,17 @@ static ResultCode WaitForAddress(VAddr address, s64 timeout) {
35 35
36// Gets the threads waiting on an address. 36// Gets the threads waiting on an address.
37static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) { 37static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address) {
38 const auto RetrieveWaitingThreads = 38 const auto RetrieveWaitingThreads = [](std::size_t core_index,
39 [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr arb_addr) { 39 std::vector<SharedPtr<Thread>>& waiting_threads,
40 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); 40 VAddr arb_addr) {
41 auto& thread_list = scheduler->GetThreadList(); 41 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index);
42 42 auto& thread_list = scheduler->GetThreadList();
43 for (auto& thread : thread_list) { 43
44 if (thread->arb_wait_address == arb_addr) 44 for (auto& thread : thread_list) {
45 waiting_threads.push_back(thread); 45 if (thread->arb_wait_address == arb_addr)
46 } 46 waiting_threads.push_back(thread);
47 }; 47 }
48 };
48 49
49 // Retrieve all threads that are waiting for this address. 50 // Retrieve all threads that are waiting for this address.
50 std::vector<SharedPtr<Thread>> threads; 51 std::vector<SharedPtr<Thread>> threads;
@@ -66,12 +67,12 @@ static std::vector<SharedPtr<Thread>> GetThreadsWaitingOnAddress(VAddr address)
66static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_to_wake) { 67static void WakeThreads(std::vector<SharedPtr<Thread>>& waiting_threads, s32 num_to_wake) {
67 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process 68 // Only process up to 'target' threads, unless 'target' is <= 0, in which case process
68 // them all. 69 // them all.
69 size_t last = waiting_threads.size(); 70 std::size_t last = waiting_threads.size();
70 if (num_to_wake > 0) 71 if (num_to_wake > 0)
71 last = num_to_wake; 72 last = num_to_wake;
72 73
73 // Signal the waiting threads. 74 // Signal the waiting threads.
74 for (size_t i = 0; i < last; i++) { 75 for (std::size_t i = 0; i < last; i++) {
75 ASSERT(waiting_threads[i]->status == ThreadStatus::WaitArb); 76 ASSERT(waiting_threads[i]->status == ThreadStatus::WaitArb);
76 waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS); 77 waiting_threads[i]->SetWaitSynchronizationResult(RESULT_SUCCESS);
77 waiting_threads[i]->arb_wait_address = 0; 78 waiting_threads[i]->arb_wait_address = 0;
diff --git a/src/core/hle/kernel/errors.h b/src/core/hle/kernel/errors.h
index ad39c8271..8c2be2681 100644
--- a/src/core/hle/kernel/errors.h
+++ b/src/core/hle/kernel/errors.h
@@ -17,6 +17,7 @@ enum {
17 17
18 // Confirmed Switch OS error codes 18 // Confirmed Switch OS error codes
19 MaxConnectionsReached = 7, 19 MaxConnectionsReached = 7,
20 InvalidSize = 101,
20 InvalidAddress = 102, 21 InvalidAddress = 102,
21 HandleTableFull = 105, 22 HandleTableFull = 105,
22 InvalidMemoryState = 106, 23 InvalidMemoryState = 106,
@@ -29,6 +30,7 @@ enum {
29 SynchronizationCanceled = 118, 30 SynchronizationCanceled = 118,
30 TooLarge = 119, 31 TooLarge = 119,
31 InvalidEnumValue = 120, 32 InvalidEnumValue = 120,
33 NoSuchEntry = 121,
32 InvalidState = 125, 34 InvalidState = 125,
33 ResourceLimitExceeded = 132, 35 ResourceLimitExceeded = 132,
34}; 36};
@@ -55,6 +57,7 @@ constexpr ResultCode ERR_INVALID_MEMORY_PERMISSIONS(ErrorModule::Kernel,
55 ErrCodes::InvalidMemoryPermissions); 57 ErrCodes::InvalidMemoryPermissions);
56constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle); 58constexpr ResultCode ERR_INVALID_HANDLE(ErrorModule::Kernel, ErrCodes::InvalidHandle);
57constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId); 59constexpr ResultCode ERR_INVALID_PROCESSOR_ID(ErrorModule::Kernel, ErrCodes::InvalidProcessorId);
60constexpr ResultCode ERR_INVALID_SIZE(ErrorModule::Kernel, ErrCodes::InvalidSize);
58constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState); 61constexpr ResultCode ERR_INVALID_STATE(ErrorModule::Kernel, ErrCodes::InvalidState);
59constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel, 62constexpr ResultCode ERR_INVALID_THREAD_PRIORITY(ErrorModule::Kernel,
60 ErrCodes::InvalidThreadPriority); 63 ErrCodes::InvalidThreadPriority);
@@ -63,7 +66,7 @@ constexpr ResultCode ERR_INVALID_OBJECT_ADDR(-1);
63constexpr ResultCode ERR_NOT_AUTHORIZED(-1); 66constexpr ResultCode ERR_NOT_AUTHORIZED(-1);
64/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths. 67/// Alternate code returned instead of ERR_INVALID_HANDLE in some code paths.
65constexpr ResultCode ERR_INVALID_HANDLE_OS(-1); 68constexpr ResultCode ERR_INVALID_HANDLE_OS(-1);
66constexpr ResultCode ERR_NOT_FOUND(-1); 69constexpr ResultCode ERR_NOT_FOUND(ErrorModule::Kernel, ErrCodes::NoSuchEntry);
67constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout); 70constexpr ResultCode RESULT_TIMEOUT(ErrorModule::Kernel, ErrCodes::Timeout);
68/// Returned when Accept() is called on a port with no sessions to be accepted. 71/// Returned when Accept() is called on a port with no sessions to be accepted.
69constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1); 72constexpr ResultCode ERR_NO_PENDING_SESSIONS(-1);
diff --git a/src/core/hle/kernel/handle_table.cpp b/src/core/hle/kernel/handle_table.cpp
index 3a079b9a9..5ee5c05e3 100644
--- a/src/core/hle/kernel/handle_table.cpp
+++ b/src/core/hle/kernel/handle_table.cpp
@@ -65,7 +65,7 @@ ResultCode HandleTable::Close(Handle handle) {
65} 65}
66 66
67bool HandleTable::IsValid(Handle handle) const { 67bool HandleTable::IsValid(Handle handle) const {
68 size_t slot = GetSlot(handle); 68 std::size_t slot = GetSlot(handle);
69 u16 generation = GetGeneration(handle); 69 u16 generation = GetGeneration(handle);
70 70
71 return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation; 71 return slot < MAX_COUNT && objects[slot] != nullptr && generations[slot] == generation;
diff --git a/src/core/hle/kernel/handle_table.h b/src/core/hle/kernel/handle_table.h
index cac928adb..9e2f33e8a 100644
--- a/src/core/hle/kernel/handle_table.h
+++ b/src/core/hle/kernel/handle_table.h
@@ -93,7 +93,7 @@ private:
93 * This is the maximum limit of handles allowed per process in CTR-OS. It can be further 93 * This is the maximum limit of handles allowed per process in CTR-OS. It can be further
94 * reduced by ExHeader values, but this is not emulated here. 94 * reduced by ExHeader values, but this is not emulated here.
95 */ 95 */
96 static const size_t MAX_COUNT = 4096; 96 static const std::size_t MAX_COUNT = 4096;
97 97
98 static u16 GetSlot(Handle handle) { 98 static u16 GetSlot(Handle handle) {
99 return handle >> 15; 99 return handle >> 15;
diff --git a/src/core/hle/kernel/hle_ipc.cpp b/src/core/hle/kernel/hle_ipc.cpp
index 7264be906..72fb9d250 100644
--- a/src/core/hle/kernel/hle_ipc.cpp
+++ b/src/core/hle/kernel/hle_ipc.cpp
@@ -42,9 +42,9 @@ SharedPtr<Event> HLERequestContext::SleepClientThread(SharedPtr<Thread> thread,
42 Kernel::SharedPtr<Kernel::Event> event) { 42 Kernel::SharedPtr<Kernel::Event> event) {
43 43
44 // Put the client thread to sleep until the wait event is signaled or the timeout expires. 44 // Put the client thread to sleep until the wait event is signaled or the timeout expires.
45 thread->wakeup_callback = 45 thread->wakeup_callback = [context = *this, callback](
46 [context = *this, callback](ThreadWakeupReason reason, SharedPtr<Thread> thread, 46 ThreadWakeupReason reason, SharedPtr<Thread> thread,
47 SharedPtr<WaitObject> object, size_t index) mutable -> bool { 47 SharedPtr<WaitObject> object, std::size_t index) mutable -> bool {
48 ASSERT(thread->status == ThreadStatus::WaitHLEEvent); 48 ASSERT(thread->status == ThreadStatus::WaitHLEEvent);
49 callback(thread, context, reason); 49 callback(thread, context, reason);
50 context.WriteToOutgoingCommandBuffer(*thread); 50 context.WriteToOutgoingCommandBuffer(*thread);
@@ -199,8 +199,8 @@ ResultCode HLERequestContext::PopulateFromIncomingCommandBuffer(u32_le* src_cmdb
199 } 199 }
200 200
201 // The data_size already includes the payload header, the padding and the domain header. 201 // The data_size already includes the payload header, the padding and the domain header.
202 size_t size = data_payload_offset + command_header->data_size - 202 std::size_t size = data_payload_offset + command_header->data_size -
203 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; 203 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
204 if (domain_message_header) 204 if (domain_message_header)
205 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); 205 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
206 std::copy_n(src_cmdbuf, size, cmd_buf.begin()); 206 std::copy_n(src_cmdbuf, size, cmd_buf.begin());
@@ -217,8 +217,8 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
217 ParseCommandBuffer(cmd_buf.data(), false); 217 ParseCommandBuffer(cmd_buf.data(), false);
218 218
219 // The data_size already includes the payload header, the padding and the domain header. 219 // The data_size already includes the payload header, the padding and the domain header.
220 size_t size = data_payload_offset + command_header->data_size - 220 std::size_t size = data_payload_offset + command_header->data_size -
221 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4; 221 sizeof(IPC::DataPayloadHeader) / sizeof(u32) - 4;
222 if (domain_message_header) 222 if (domain_message_header)
223 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32); 223 size -= sizeof(IPC::DomainMessageHeader) / sizeof(u32);
224 224
@@ -229,7 +229,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
229 "Handle descriptor bit set but no handles to translate"); 229 "Handle descriptor bit set but no handles to translate");
230 // We write the translated handles at a specific offset in the command buffer, this space 230 // We write the translated handles at a specific offset in the command buffer, this space
231 // was already reserved when writing the header. 231 // was already reserved when writing the header.
232 size_t current_offset = 232 std::size_t current_offset =
233 (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32); 233 (sizeof(IPC::CommandHeader) + sizeof(IPC::HandleDescriptorHeader)) / sizeof(u32);
234 ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented"); 234 ASSERT_MSG(!handle_descriptor_header->send_current_pid, "Sending PID is not implemented");
235 235
@@ -258,7 +258,7 @@ ResultCode HLERequestContext::WriteToOutgoingCommandBuffer(const Thread& thread)
258 ASSERT(domain_message_header->num_objects == domain_objects.size()); 258 ASSERT(domain_message_header->num_objects == domain_objects.size());
259 // Write the domain objects to the command buffer, these go after the raw untranslated data. 259 // Write the domain objects to the command buffer, these go after the raw untranslated data.
260 // TODO(Subv): This completely ignores C buffers. 260 // TODO(Subv): This completely ignores C buffers.
261 size_t domain_offset = size - domain_message_header->num_objects; 261 std::size_t domain_offset = size - domain_message_header->num_objects;
262 auto& request_handlers = server_session->domain_request_handlers; 262 auto& request_handlers = server_session->domain_request_handlers;
263 263
264 for (auto& object : domain_objects) { 264 for (auto& object : domain_objects) {
@@ -291,14 +291,15 @@ std::vector<u8> HLERequestContext::ReadBuffer(int buffer_index) const {
291 return buffer; 291 return buffer;
292} 292}
293 293
294size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffer_index) const { 294std::size_t HLERequestContext::WriteBuffer(const void* buffer, std::size_t size,
295 int buffer_index) const {
295 if (size == 0) { 296 if (size == 0) {
296 LOG_WARNING(Core, "skip empty buffer write"); 297 LOG_WARNING(Core, "skip empty buffer write");
297 return 0; 298 return 0;
298 } 299 }
299 300
300 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; 301 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()};
301 const size_t buffer_size{GetWriteBufferSize(buffer_index)}; 302 const std::size_t buffer_size{GetWriteBufferSize(buffer_index)};
302 if (size > buffer_size) { 303 if (size > buffer_size) {
303 LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size, 304 LOG_CRITICAL(Core, "size ({:016X}) is greater than buffer_size ({:016X})", size,
304 buffer_size); 305 buffer_size);
@@ -314,13 +315,13 @@ size_t HLERequestContext::WriteBuffer(const void* buffer, size_t size, int buffe
314 return size; 315 return size;
315} 316}
316 317
317size_t HLERequestContext::GetReadBufferSize(int buffer_index) const { 318std::size_t HLERequestContext::GetReadBufferSize(int buffer_index) const {
318 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()}; 319 const bool is_buffer_a{BufferDescriptorA().size() && BufferDescriptorA()[buffer_index].Size()};
319 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size() 320 return is_buffer_a ? BufferDescriptorA()[buffer_index].Size()
320 : BufferDescriptorX()[buffer_index].Size(); 321 : BufferDescriptorX()[buffer_index].Size();
321} 322}
322 323
323size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const { 324std::size_t HLERequestContext::GetWriteBufferSize(int buffer_index) const {
324 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()}; 325 const bool is_buffer_b{BufferDescriptorB().size() && BufferDescriptorB()[buffer_index].Size()};
325 return is_buffer_b ? BufferDescriptorB()[buffer_index].Size() 326 return is_buffer_b ? BufferDescriptorB()[buffer_index].Size()
326 : BufferDescriptorC()[buffer_index].Size(); 327 : BufferDescriptorC()[buffer_index].Size();
diff --git a/src/core/hle/kernel/hle_ipc.h b/src/core/hle/kernel/hle_ipc.h
index f0d07f1b6..894479ee0 100644
--- a/src/core/hle/kernel/hle_ipc.h
+++ b/src/core/hle/kernel/hle_ipc.h
@@ -170,7 +170,7 @@ public:
170 std::vector<u8> ReadBuffer(int buffer_index = 0) const; 170 std::vector<u8> ReadBuffer(int buffer_index = 0) const;
171 171
172 /// Helper function to write a buffer using the appropriate buffer descriptor 172 /// Helper function to write a buffer using the appropriate buffer descriptor
173 size_t WriteBuffer(const void* buffer, size_t size, int buffer_index = 0) const; 173 std::size_t WriteBuffer(const void* buffer, std::size_t size, int buffer_index = 0) const;
174 174
175 /* Helper function to write a buffer using the appropriate buffer descriptor 175 /* Helper function to write a buffer using the appropriate buffer descriptor
176 * 176 *
@@ -182,7 +182,7 @@ public:
182 */ 182 */
183 template <typename ContiguousContainer, 183 template <typename ContiguousContainer,
184 typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>> 184 typename = std::enable_if_t<!std::is_pointer_v<ContiguousContainer>>>
185 size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const { 185 std::size_t WriteBuffer(const ContiguousContainer& container, int buffer_index = 0) const {
186 using ContiguousType = typename ContiguousContainer::value_type; 186 using ContiguousType = typename ContiguousContainer::value_type;
187 187
188 static_assert(std::is_trivially_copyable_v<ContiguousType>, 188 static_assert(std::is_trivially_copyable_v<ContiguousType>,
@@ -193,19 +193,19 @@ public:
193 } 193 }
194 194
195 /// Helper function to get the size of the input buffer 195 /// Helper function to get the size of the input buffer
196 size_t GetReadBufferSize(int buffer_index = 0) const; 196 std::size_t GetReadBufferSize(int buffer_index = 0) const;
197 197
198 /// Helper function to get the size of the output buffer 198 /// Helper function to get the size of the output buffer
199 size_t GetWriteBufferSize(int buffer_index = 0) const; 199 std::size_t GetWriteBufferSize(int buffer_index = 0) const;
200 200
201 template <typename T> 201 template <typename T>
202 SharedPtr<T> GetCopyObject(size_t index) { 202 SharedPtr<T> GetCopyObject(std::size_t index) {
203 ASSERT(index < copy_objects.size()); 203 ASSERT(index < copy_objects.size());
204 return DynamicObjectCast<T>(copy_objects[index]); 204 return DynamicObjectCast<T>(copy_objects[index]);
205 } 205 }
206 206
207 template <typename T> 207 template <typename T>
208 SharedPtr<T> GetMoveObject(size_t index) { 208 SharedPtr<T> GetMoveObject(std::size_t index) {
209 ASSERT(index < move_objects.size()); 209 ASSERT(index < move_objects.size());
210 return DynamicObjectCast<T>(move_objects[index]); 210 return DynamicObjectCast<T>(move_objects[index]);
211 } 211 }
@@ -223,7 +223,7 @@ public:
223 } 223 }
224 224
225 template <typename T> 225 template <typename T>
226 std::shared_ptr<T> GetDomainRequestHandler(size_t index) const { 226 std::shared_ptr<T> GetDomainRequestHandler(std::size_t index) const {
227 return std::static_pointer_cast<T>(domain_request_handlers[index]); 227 return std::static_pointer_cast<T>(domain_request_handlers[index]);
228 } 228 }
229 229
@@ -240,15 +240,15 @@ public:
240 domain_objects.clear(); 240 domain_objects.clear();
241 } 241 }
242 242
243 size_t NumMoveObjects() const { 243 std::size_t NumMoveObjects() const {
244 return move_objects.size(); 244 return move_objects.size();
245 } 245 }
246 246
247 size_t NumCopyObjects() const { 247 std::size_t NumCopyObjects() const {
248 return copy_objects.size(); 248 return copy_objects.size();
249 } 249 }
250 250
251 size_t NumDomainObjects() const { 251 std::size_t NumDomainObjects() const {
252 return domain_objects.size(); 252 return domain_objects.size();
253 } 253 }
254 254
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 36bf0b677..51f4544be 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -62,7 +62,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
62 Handle requesting_thread_handle) { 62 Handle requesting_thread_handle) {
63 // The mutex address must be 4-byte aligned 63 // The mutex address must be 4-byte aligned
64 if ((address % sizeof(u32)) != 0) { 64 if ((address % sizeof(u32)) != 0) {
65 return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress); 65 return ERR_INVALID_ADDRESS;
66 } 66 }
67 67
68 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle); 68 SharedPtr<Thread> holding_thread = handle_table.Get<Thread>(holding_thread_handle);
@@ -100,7 +100,7 @@ ResultCode Mutex::TryAcquire(HandleTable& handle_table, VAddr address, Handle ho
100ResultCode Mutex::Release(VAddr address) { 100ResultCode Mutex::Release(VAddr address) {
101 // The mutex address must be 4-byte aligned 101 // The mutex address must be 4-byte aligned
102 if ((address % sizeof(u32)) != 0) { 102 if ((address % sizeof(u32)) != 0) {
103 return ResultCode(ErrorModule::Kernel, ErrCodes::InvalidAddress); 103 return ERR_INVALID_ADDRESS;
104 } 104 }
105 105
106 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address); 106 auto [thread, num_waiters] = GetHighestPriorityMutexWaitingThread(GetCurrentThread(), address);
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp
index b025e323f..7a272d031 100644
--- a/src/core/hle/kernel/process.cpp
+++ b/src/core/hle/kernel/process.cpp
@@ -40,8 +40,8 @@ SharedPtr<Process> Process::Create(KernelCore& kernel, std::string&& name) {
40 return process; 40 return process;
41} 41}
42 42
43void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) { 43void Process::ParseKernelCaps(const u32* kernel_caps, std::size_t len) {
44 for (size_t i = 0; i < len; ++i) { 44 for (std::size_t i = 0; i < len; ++i) {
45 u32 descriptor = kernel_caps[i]; 45 u32 descriptor = kernel_caps[i];
46 u32 type = descriptor >> 20; 46 u32 type = descriptor >> 20;
47 47
@@ -211,7 +211,7 @@ ResultCode Process::MirrorMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
211 "Shared memory exceeds bounds of mapped block"); 211 "Shared memory exceeds bounds of mapped block");
212 212
213 const std::shared_ptr<std::vector<u8>>& backing_block = vma->second.backing_block; 213 const std::shared_ptr<std::vector<u8>>& backing_block = vma->second.backing_block;
214 size_t backing_block_offset = vma->second.offset + vma_offset; 214 std::size_t backing_block_offset = vma->second.offset + vma_offset;
215 215
216 CASCADE_RESULT(auto new_vma, 216 CASCADE_RESULT(auto new_vma,
217 vm_manager.MapMemoryBlock(dst_addr, backing_block, backing_block_offset, size, 217 vm_manager.MapMemoryBlock(dst_addr, backing_block, backing_block_offset, size,
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h
index 1587d40c1..81538f70c 100644
--- a/src/core/hle/kernel/process.h
+++ b/src/core/hle/kernel/process.h
@@ -59,7 +59,7 @@ class ResourceLimit;
59 59
60struct CodeSet final : public Object { 60struct CodeSet final : public Object {
61 struct Segment { 61 struct Segment {
62 size_t offset = 0; 62 std::size_t offset = 0;
63 VAddr addr = 0; 63 VAddr addr = 0;
64 u32 size = 0; 64 u32 size = 0;
65 }; 65 };
@@ -164,7 +164,7 @@ public:
164 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them 164 * Parses a list of kernel capability descriptors (as found in the ExHeader) and applies them
165 * to this process. 165 * to this process.
166 */ 166 */
167 void ParseKernelCaps(const u32* kernel_caps, size_t len); 167 void ParseKernelCaps(const u32* kernel_caps, std::size_t len);
168 168
169 /** 169 /**
170 * Applies address space changes and launches the process main thread. 170 * Applies address space changes and launches the process main thread.
diff --git a/src/core/hle/kernel/shared_memory.h b/src/core/hle/kernel/shared_memory.h
index 2c729afe3..2c06bb7ce 100644
--- a/src/core/hle/kernel/shared_memory.h
+++ b/src/core/hle/kernel/shared_memory.h
@@ -119,7 +119,7 @@ public:
119 /// Backing memory for this shared memory block. 119 /// Backing memory for this shared memory block.
120 std::shared_ptr<std::vector<u8>> backing_block; 120 std::shared_ptr<std::vector<u8>> backing_block;
121 /// Offset into the backing block for this shared memory. 121 /// Offset into the backing block for this shared memory.
122 size_t backing_block_offset; 122 std::size_t backing_block_offset;
123 /// Size of the memory block. Page-aligned. 123 /// Size of the memory block. Page-aligned.
124 u64 size; 124 u64 size;
125 /// Permission restrictions applied to the process which created the block. 125 /// Permission restrictions applied to the process which created the block.
diff --git a/src/core/hle/kernel/svc.cpp b/src/core/hle/kernel/svc.cpp
index f500fd2e7..371fc439e 100644
--- a/src/core/hle/kernel/svc.cpp
+++ b/src/core/hle/kernel/svc.cpp
@@ -35,10 +35,21 @@
35#include "core/hle/service/service.h" 35#include "core/hle/service/service.h"
36 36
37namespace Kernel { 37namespace Kernel {
38namespace {
39constexpr bool Is4KBAligned(VAddr address) {
40 return (address & 0xFFF) == 0;
41}
42} // Anonymous namespace
38 43
39/// Set the process heap to a given Size. It can both extend and shrink the heap. 44/// Set the process heap to a given Size. It can both extend and shrink the heap.
40static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) { 45static ResultCode SetHeapSize(VAddr* heap_addr, u64 heap_size) {
41 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", heap_size); 46 LOG_TRACE(Kernel_SVC, "called, heap_size=0x{:X}", heap_size);
47
48 // Size must be a multiple of 0x200000 (2MB) and be equal to or less than 4GB.
49 if ((heap_size & 0xFFFFFFFE001FFFFF) != 0) {
50 return ERR_INVALID_SIZE;
51 }
52
42 auto& process = *Core::CurrentProcess(); 53 auto& process = *Core::CurrentProcess();
43 CASCADE_RESULT(*heap_addr, 54 CASCADE_RESULT(*heap_addr,
44 process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite)); 55 process.HeapAllocate(Memory::HEAP_VADDR, heap_size, VMAPermission::ReadWrite));
@@ -56,6 +67,15 @@ static ResultCode SetMemoryAttribute(VAddr addr, u64 size, u32 state0, u32 state
56static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 67static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
57 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 68 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
58 src_addr, size); 69 src_addr, size);
70
71 if (!Is4KBAligned(dst_addr) || !Is4KBAligned(src_addr)) {
72 return ERR_INVALID_ADDRESS;
73 }
74
75 if (size == 0 || !Is4KBAligned(size)) {
76 return ERR_INVALID_SIZE;
77 }
78
59 return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size); 79 return Core::CurrentProcess()->MirrorMemory(dst_addr, src_addr, size);
60} 80}
61 81
@@ -63,6 +83,15 @@ static ResultCode MapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
63static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) { 83static ResultCode UnmapMemory(VAddr dst_addr, VAddr src_addr, u64 size) {
64 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr, 84 LOG_TRACE(Kernel_SVC, "called, dst_addr=0x{:X}, src_addr=0x{:X}, size=0x{:X}", dst_addr,
65 src_addr, size); 85 src_addr, size);
86
87 if (!Is4KBAligned(dst_addr) || !Is4KBAligned(src_addr)) {
88 return ERR_INVALID_ADDRESS;
89 }
90
91 if (size == 0 || !Is4KBAligned(size)) {
92 return ERR_INVALID_SIZE;
93 }
94
66 return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size); 95 return Core::CurrentProcess()->UnmapMemory(dst_addr, src_addr, size);
67} 96}
68 97
@@ -146,7 +175,7 @@ static ResultCode GetProcessId(u32* process_id, Handle process_handle) {
146 175
147/// Default thread wakeup callback for WaitSynchronization 176/// Default thread wakeup callback for WaitSynchronization
148static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread, 177static bool DefaultThreadWakeupCallback(ThreadWakeupReason reason, SharedPtr<Thread> thread,
149 SharedPtr<WaitObject> object, size_t index) { 178 SharedPtr<WaitObject> object, std::size_t index) {
150 ASSERT(thread->status == ThreadStatus::WaitSynchAny); 179 ASSERT(thread->status == ThreadStatus::WaitSynchAny);
151 180
152 if (reason == ThreadWakeupReason::Timeout) { 181 if (reason == ThreadWakeupReason::Timeout) {
@@ -251,6 +280,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
251 "requesting_current_thread_handle=0x{:08X}", 280 "requesting_current_thread_handle=0x{:08X}",
252 holding_thread_handle, mutex_addr, requesting_thread_handle); 281 holding_thread_handle, mutex_addr, requesting_thread_handle);
253 282
283 if (Memory::IsKernelVirtualAddress(mutex_addr)) {
284 return ERR_INVALID_ADDRESS_STATE;
285 }
286
254 auto& handle_table = Core::System::GetInstance().Kernel().HandleTable(); 287 auto& handle_table = Core::System::GetInstance().Kernel().HandleTable();
255 return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle, 288 return Mutex::TryAcquire(handle_table, mutex_addr, holding_thread_handle,
256 requesting_thread_handle); 289 requesting_thread_handle);
@@ -260,6 +293,10 @@ static ResultCode ArbitrateLock(Handle holding_thread_handle, VAddr mutex_addr,
260static ResultCode ArbitrateUnlock(VAddr mutex_addr) { 293static ResultCode ArbitrateUnlock(VAddr mutex_addr) {
261 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr); 294 LOG_TRACE(Kernel_SVC, "called mutex_addr=0x{:X}", mutex_addr);
262 295
296 if (Memory::IsKernelVirtualAddress(mutex_addr)) {
297 return ERR_INVALID_ADDRESS_STATE;
298 }
299
263 return Mutex::Release(mutex_addr); 300 return Mutex::Release(mutex_addr);
264} 301}
265 302
@@ -415,35 +452,43 @@ static ResultCode MapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 s
415 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}", 452 "called, shared_memory_handle=0x{:X}, addr=0x{:X}, size=0x{:X}, permissions=0x{:08X}",
416 shared_memory_handle, addr, size, permissions); 453 shared_memory_handle, addr, size, permissions);
417 454
455 if (!Is4KBAligned(addr)) {
456 return ERR_INVALID_ADDRESS;
457 }
458
459 if (size == 0 || !Is4KBAligned(size)) {
460 return ERR_INVALID_SIZE;
461 }
462
463 const auto permissions_type = static_cast<MemoryPermission>(permissions);
464 if (permissions_type != MemoryPermission::Read &&
465 permissions_type != MemoryPermission::ReadWrite) {
466 LOG_ERROR(Kernel_SVC, "Invalid permissions=0x{:08X}", permissions);
467 return ERR_INVALID_MEMORY_PERMISSIONS;
468 }
469
418 auto& kernel = Core::System::GetInstance().Kernel(); 470 auto& kernel = Core::System::GetInstance().Kernel();
419 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); 471 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
420 if (!shared_memory) { 472 if (!shared_memory) {
421 return ERR_INVALID_HANDLE; 473 return ERR_INVALID_HANDLE;
422 } 474 }
423 475
424 MemoryPermission permissions_type = static_cast<MemoryPermission>(permissions); 476 return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type,
425 switch (permissions_type) { 477 MemoryPermission::DontCare);
426 case MemoryPermission::Read:
427 case MemoryPermission::Write:
428 case MemoryPermission::ReadWrite:
429 case MemoryPermission::Execute:
430 case MemoryPermission::ReadExecute:
431 case MemoryPermission::WriteExecute:
432 case MemoryPermission::ReadWriteExecute:
433 case MemoryPermission::DontCare:
434 return shared_memory->Map(Core::CurrentProcess().get(), addr, permissions_type,
435 MemoryPermission::DontCare);
436 default:
437 LOG_ERROR(Kernel_SVC, "unknown permissions=0x{:08X}", permissions);
438 }
439
440 return RESULT_SUCCESS;
441} 478}
442 479
443static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) { 480static ResultCode UnmapSharedMemory(Handle shared_memory_handle, VAddr addr, u64 size) {
444 LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}", 481 LOG_WARNING(Kernel_SVC, "called, shared_memory_handle=0x{:08X}, addr=0x{:X}, size=0x{:X}",
445 shared_memory_handle, addr, size); 482 shared_memory_handle, addr, size);
446 483
484 if (!Is4KBAligned(addr)) {
485 return ERR_INVALID_ADDRESS;
486 }
487
488 if (size == 0 || !Is4KBAligned(size)) {
489 return ERR_INVALID_SIZE;
490 }
491
447 auto& kernel = Core::System::GetInstance().Kernel(); 492 auto& kernel = Core::System::GetInstance().Kernel();
448 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle); 493 auto shared_memory = kernel.HandleTable().Get<SharedMemory>(shared_memory_handle);
449 494
@@ -524,7 +569,7 @@ static void ExitProcess() {
524/// Creates a new thread 569/// Creates a new thread
525static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top, 570static ResultCode CreateThread(Handle* out_handle, VAddr entry_point, u64 arg, VAddr stack_top,
526 u32 priority, s32 processor_id) { 571 u32 priority, s32 processor_id) {
527 std::string name = fmt::format("unknown-{:X}", entry_point); 572 std::string name = fmt::format("thread-{:X}", entry_point);
528 573
529 if (priority > THREADPRIO_LOWEST) { 574 if (priority > THREADPRIO_LOWEST) {
530 return ERR_INVALID_THREAD_PRIORITY; 575 return ERR_INVALID_THREAD_PRIORITY;
@@ -647,16 +692,17 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
647 LOG_TRACE(Kernel_SVC, "called, condition_variable_addr=0x{:X}, target=0x{:08X}", 692 LOG_TRACE(Kernel_SVC, "called, condition_variable_addr=0x{:X}, target=0x{:08X}",
648 condition_variable_addr, target); 693 condition_variable_addr, target);
649 694
650 auto RetrieveWaitingThreads = 695 auto RetrieveWaitingThreads = [](std::size_t core_index,
651 [](size_t core_index, std::vector<SharedPtr<Thread>>& waiting_threads, VAddr condvar_addr) { 696 std::vector<SharedPtr<Thread>>& waiting_threads,
652 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index); 697 VAddr condvar_addr) {
653 auto& thread_list = scheduler->GetThreadList(); 698 const auto& scheduler = Core::System::GetInstance().Scheduler(core_index);
699 auto& thread_list = scheduler->GetThreadList();
654 700
655 for (auto& thread : thread_list) { 701 for (auto& thread : thread_list) {
656 if (thread->condvar_wait_address == condvar_addr) 702 if (thread->condvar_wait_address == condvar_addr)
657 waiting_threads.push_back(thread); 703 waiting_threads.push_back(thread);
658 } 704 }
659 }; 705 };
660 706
661 // Retrieve a list of all threads that are waiting for this condition variable. 707 // Retrieve a list of all threads that are waiting for this condition variable.
662 std::vector<SharedPtr<Thread>> waiting_threads; 708 std::vector<SharedPtr<Thread>> waiting_threads;
@@ -672,7 +718,7 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
672 718
673 // Only process up to 'target' threads, unless 'target' is -1, in which case process 719 // Only process up to 'target' threads, unless 'target' is -1, in which case process
674 // them all. 720 // them all.
675 size_t last = waiting_threads.size(); 721 std::size_t last = waiting_threads.size();
676 if (target != -1) 722 if (target != -1)
677 last = target; 723 last = target;
678 724
@@ -680,12 +726,12 @@ static ResultCode SignalProcessWideKey(VAddr condition_variable_addr, s32 target
680 if (last > waiting_threads.size()) 726 if (last > waiting_threads.size())
681 return RESULT_SUCCESS; 727 return RESULT_SUCCESS;
682 728
683 for (size_t index = 0; index < last; ++index) { 729 for (std::size_t index = 0; index < last; ++index) {
684 auto& thread = waiting_threads[index]; 730 auto& thread = waiting_threads[index];
685 731
686 ASSERT(thread->condvar_wait_address == condition_variable_addr); 732 ASSERT(thread->condvar_wait_address == condition_variable_addr);
687 733
688 size_t current_core = Core::System::GetInstance().CurrentCoreIndex(); 734 std::size_t current_core = Core::System::GetInstance().CurrentCoreIndex();
689 735
690 auto& monitor = Core::System::GetInstance().Monitor(); 736 auto& monitor = Core::System::GetInstance().Monitor();
691 737
@@ -898,12 +944,28 @@ static ResultCode CreateSharedMemory(Handle* handle, u64 size, u32 local_permiss
898 LOG_TRACE(Kernel_SVC, "called, size=0x{:X}, localPerms=0x{:08X}, remotePerms=0x{:08X}", size, 944 LOG_TRACE(Kernel_SVC, "called, size=0x{:X}, localPerms=0x{:08X}, remotePerms=0x{:08X}", size,
899 local_permissions, remote_permissions); 945 local_permissions, remote_permissions);
900 946
947 // Size must be a multiple of 4KB and be less than or equal to
948 // approx. 8 GB (actually (1GB - 512B) * 8)
949 if (size == 0 || (size & 0xFFFFFFFE00000FFF) != 0) {
950 return ERR_INVALID_SIZE;
951 }
952
953 const auto local_perms = static_cast<MemoryPermission>(local_permissions);
954 if (local_perms != MemoryPermission::Read && local_perms != MemoryPermission::ReadWrite) {
955 return ERR_INVALID_MEMORY_PERMISSIONS;
956 }
957
958 const auto remote_perms = static_cast<MemoryPermission>(remote_permissions);
959 if (remote_perms != MemoryPermission::Read && remote_perms != MemoryPermission::ReadWrite &&
960 remote_perms != MemoryPermission::DontCare) {
961 return ERR_INVALID_MEMORY_PERMISSIONS;
962 }
963
901 auto& kernel = Core::System::GetInstance().Kernel(); 964 auto& kernel = Core::System::GetInstance().Kernel();
902 auto& handle_table = kernel.HandleTable(); 965 auto& handle_table = kernel.HandleTable();
903 auto shared_mem_handle = 966 auto shared_mem_handle =
904 SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size, 967 SharedMemory::Create(kernel, handle_table.Get<Process>(KernelHandle::CurrentProcess), size,
905 static_cast<MemoryPermission>(local_permissions), 968 local_perms, remote_perms);
906 static_cast<MemoryPermission>(remote_permissions));
907 969
908 CASCADE_RESULT(*handle, handle_table.Create(shared_mem_handle)); 970 CASCADE_RESULT(*handle, handle_table.Create(shared_mem_handle));
909 return RESULT_SUCCESS; 971 return RESULT_SUCCESS;
diff --git a/src/core/hle/kernel/svc_wrap.h b/src/core/hle/kernel/svc_wrap.h
index 1eda5f879..fea9ba5ea 100644
--- a/src/core/hle/kernel/svc_wrap.h
+++ b/src/core/hle/kernel/svc_wrap.h
@@ -13,7 +13,9 @@
13 13
14namespace Kernel { 14namespace Kernel {
15 15
16#define PARAM(n) Core::CurrentArmInterface().GetReg(n) 16static inline u64 Param(int n) {
17 return Core::CurrentArmInterface().GetReg(n);
18}
17 19
18/** 20/**
19 * HLE a function return from the current ARM userland process 21 * HLE a function return from the current ARM userland process
@@ -28,23 +30,23 @@ static inline void FuncReturn(u64 res) {
28 30
29template <ResultCode func(u64)> 31template <ResultCode func(u64)>
30void SvcWrap() { 32void SvcWrap() {
31 FuncReturn(func(PARAM(0)).raw); 33 FuncReturn(func(Param(0)).raw);
32} 34}
33 35
34template <ResultCode func(u32)> 36template <ResultCode func(u32)>
35void SvcWrap() { 37void SvcWrap() {
36 FuncReturn(func((u32)PARAM(0)).raw); 38 FuncReturn(func((u32)Param(0)).raw);
37} 39}
38 40
39template <ResultCode func(u32, u32)> 41template <ResultCode func(u32, u32)>
40void SvcWrap() { 42void SvcWrap() {
41 FuncReturn(func((u32)PARAM(0), (u32)PARAM(1)).raw); 43 FuncReturn(func((u32)Param(0), (u32)Param(1)).raw);
42} 44}
43 45
44template <ResultCode func(u32*, u32)> 46template <ResultCode func(u32*, u32)>
45void SvcWrap() { 47void SvcWrap() {
46 u32 param_1 = 0; 48 u32 param_1 = 0;
47 u32 retval = func(&param_1, (u32)PARAM(1)).raw; 49 u32 retval = func(&param_1, (u32)Param(1)).raw;
48 Core::CurrentArmInterface().SetReg(1, param_1); 50 Core::CurrentArmInterface().SetReg(1, param_1);
49 FuncReturn(retval); 51 FuncReturn(retval);
50} 52}
@@ -52,39 +54,39 @@ void SvcWrap() {
52template <ResultCode func(u32*, u64)> 54template <ResultCode func(u32*, u64)>
53void SvcWrap() { 55void SvcWrap() {
54 u32 param_1 = 0; 56 u32 param_1 = 0;
55 u32 retval = func(&param_1, PARAM(1)).raw; 57 u32 retval = func(&param_1, Param(1)).raw;
56 Core::CurrentArmInterface().SetReg(1, param_1); 58 Core::CurrentArmInterface().SetReg(1, param_1);
57 FuncReturn(retval); 59 FuncReturn(retval);
58} 60}
59 61
60template <ResultCode func(u64, s32)> 62template <ResultCode func(u64, s32)>
61void SvcWrap() { 63void SvcWrap() {
62 FuncReturn(func(PARAM(0), (s32)PARAM(1)).raw); 64 FuncReturn(func(Param(0), (s32)Param(1)).raw);
63} 65}
64 66
65template <ResultCode func(u64*, u64)> 67template <ResultCode func(u64*, u64)>
66void SvcWrap() { 68void SvcWrap() {
67 u64 param_1 = 0; 69 u64 param_1 = 0;
68 u32 retval = func(&param_1, PARAM(1)).raw; 70 u32 retval = func(&param_1, Param(1)).raw;
69 Core::CurrentArmInterface().SetReg(1, param_1); 71 Core::CurrentArmInterface().SetReg(1, param_1);
70 FuncReturn(retval); 72 FuncReturn(retval);
71} 73}
72 74
73template <ResultCode func(u32, u64)> 75template <ResultCode func(u32, u64)>
74void SvcWrap() { 76void SvcWrap() {
75 FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), PARAM(1)).raw); 77 FuncReturn(func((u32)(Param(0) & 0xFFFFFFFF), Param(1)).raw);
76} 78}
77 79
78template <ResultCode func(u32, u32, u64)> 80template <ResultCode func(u32, u32, u64)>
79void SvcWrap() { 81void SvcWrap() {
80 FuncReturn(func((u32)(PARAM(0) & 0xFFFFFFFF), (u32)(PARAM(1) & 0xFFFFFFFF), PARAM(2)).raw); 82 FuncReturn(func((u32)(Param(0) & 0xFFFFFFFF), (u32)(Param(1) & 0xFFFFFFFF), Param(2)).raw);
81} 83}
82 84
83template <ResultCode func(u32, u32*, u64*)> 85template <ResultCode func(u32, u32*, u64*)>
84void SvcWrap() { 86void SvcWrap() {
85 u32 param_1 = 0; 87 u32 param_1 = 0;
86 u64 param_2 = 0; 88 u64 param_2 = 0;
87 ResultCode retval = func((u32)(PARAM(2) & 0xFFFFFFFF), &param_1, &param_2); 89 ResultCode retval = func((u32)(Param(2) & 0xFFFFFFFF), &param_1, &param_2);
88 Core::CurrentArmInterface().SetReg(1, param_1); 90 Core::CurrentArmInterface().SetReg(1, param_1);
89 Core::CurrentArmInterface().SetReg(2, param_2); 91 Core::CurrentArmInterface().SetReg(2, param_2);
90 FuncReturn(retval.raw); 92 FuncReturn(retval.raw);
@@ -93,46 +95,46 @@ void SvcWrap() {
93template <ResultCode func(u64, u64, u32, u32)> 95template <ResultCode func(u64, u64, u32, u32)>
94void SvcWrap() { 96void SvcWrap() {
95 FuncReturn( 97 FuncReturn(
96 func(PARAM(0), PARAM(1), (u32)(PARAM(3) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw); 98 func(Param(0), Param(1), (u32)(Param(3) & 0xFFFFFFFF), (u32)(Param(3) & 0xFFFFFFFF)).raw);
97} 99}
98 100
99template <ResultCode func(u32, u64, u32)> 101template <ResultCode func(u32, u64, u32)>
100void SvcWrap() { 102void SvcWrap() {
101 FuncReturn(func((u32)PARAM(0), PARAM(1), (u32)PARAM(2)).raw); 103 FuncReturn(func((u32)Param(0), Param(1), (u32)Param(2)).raw);
102} 104}
103 105
104template <ResultCode func(u64, u64, u64)> 106template <ResultCode func(u64, u64, u64)>
105void SvcWrap() { 107void SvcWrap() {
106 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2)).raw); 108 FuncReturn(func(Param(0), Param(1), Param(2)).raw);
107} 109}
108 110
109template <ResultCode func(u32, u64, u64, u32)> 111template <ResultCode func(u32, u64, u64, u32)>
110void SvcWrap() { 112void SvcWrap() {
111 FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2), (u32)PARAM(3)).raw); 113 FuncReturn(func((u32)Param(0), Param(1), Param(2), (u32)Param(3)).raw);
112} 114}
113 115
114template <ResultCode func(u32, u64, u64)> 116template <ResultCode func(u32, u64, u64)>
115void SvcWrap() { 117void SvcWrap() {
116 FuncReturn(func((u32)PARAM(0), PARAM(1), PARAM(2)).raw); 118 FuncReturn(func((u32)Param(0), Param(1), Param(2)).raw);
117} 119}
118 120
119template <ResultCode func(u32*, u64, u64, s64)> 121template <ResultCode func(u32*, u64, u64, s64)>
120void SvcWrap() { 122void SvcWrap() {
121 u32 param_1 = 0; 123 u32 param_1 = 0;
122 ResultCode retval = func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3)); 124 ResultCode retval = func(&param_1, Param(1), (u32)(Param(2) & 0xFFFFFFFF), (s64)Param(3));
123 Core::CurrentArmInterface().SetReg(1, param_1); 125 Core::CurrentArmInterface().SetReg(1, param_1);
124 FuncReturn(retval.raw); 126 FuncReturn(retval.raw);
125} 127}
126 128
127template <ResultCode func(u64, u64, u32, s64)> 129template <ResultCode func(u64, u64, u32, s64)>
128void SvcWrap() { 130void SvcWrap() {
129 FuncReturn(func(PARAM(0), PARAM(1), (u32)PARAM(2), (s64)PARAM(3)).raw); 131 FuncReturn(func(Param(0), Param(1), (u32)Param(2), (s64)Param(3)).raw);
130} 132}
131 133
132template <ResultCode func(u64*, u64, u64, u64)> 134template <ResultCode func(u64*, u64, u64, u64)>
133void SvcWrap() { 135void SvcWrap() {
134 u64 param_1 = 0; 136 u64 param_1 = 0;
135 u32 retval = func(&param_1, PARAM(1), PARAM(2), PARAM(3)).raw; 137 u32 retval = func(&param_1, Param(1), Param(2), Param(3)).raw;
136 Core::CurrentArmInterface().SetReg(1, param_1); 138 Core::CurrentArmInterface().SetReg(1, param_1);
137 FuncReturn(retval); 139 FuncReturn(retval);
138} 140}
@@ -141,7 +143,7 @@ template <ResultCode func(u32*, u64, u64, u64, u32, s32)>
141void SvcWrap() { 143void SvcWrap() {
142 u32 param_1 = 0; 144 u32 param_1 = 0;
143 u32 retval = 145 u32 retval =
144 func(&param_1, PARAM(1), PARAM(2), PARAM(3), (u32)PARAM(4), (s32)(PARAM(5) & 0xFFFFFFFF)) 146 func(&param_1, Param(1), Param(2), Param(3), (u32)Param(4), (s32)(Param(5) & 0xFFFFFFFF))
145 .raw; 147 .raw;
146 Core::CurrentArmInterface().SetReg(1, param_1); 148 Core::CurrentArmInterface().SetReg(1, param_1);
147 FuncReturn(retval); 149 FuncReturn(retval);
@@ -151,13 +153,13 @@ template <ResultCode func(MemoryInfo*, PageInfo*, u64)>
151void SvcWrap() { 153void SvcWrap() {
152 MemoryInfo memory_info = {}; 154 MemoryInfo memory_info = {};
153 PageInfo page_info = {}; 155 PageInfo page_info = {};
154 u32 retval = func(&memory_info, &page_info, PARAM(2)).raw; 156 u32 retval = func(&memory_info, &page_info, Param(2)).raw;
155 157
156 Memory::Write64(PARAM(0), memory_info.base_address); 158 Memory::Write64(Param(0), memory_info.base_address);
157 Memory::Write64(PARAM(0) + 8, memory_info.size); 159 Memory::Write64(Param(0) + 8, memory_info.size);
158 Memory::Write32(PARAM(0) + 16, memory_info.type); 160 Memory::Write32(Param(0) + 16, memory_info.type);
159 Memory::Write32(PARAM(0) + 20, memory_info.attributes); 161 Memory::Write32(Param(0) + 20, memory_info.attributes);
160 Memory::Write32(PARAM(0) + 24, memory_info.permission); 162 Memory::Write32(Param(0) + 24, memory_info.permission);
161 163
162 FuncReturn(retval); 164 FuncReturn(retval);
163} 165}
@@ -165,7 +167,7 @@ void SvcWrap() {
165template <ResultCode func(u32*, u64, u64, u32)> 167template <ResultCode func(u32*, u64, u64, u32)>
166void SvcWrap() { 168void SvcWrap() {
167 u32 param_1 = 0; 169 u32 param_1 = 0;
168 u32 retval = func(&param_1, PARAM(1), PARAM(2), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; 170 u32 retval = func(&param_1, Param(1), Param(2), (u32)(Param(3) & 0xFFFFFFFF)).raw;
169 Core::CurrentArmInterface().SetReg(1, param_1); 171 Core::CurrentArmInterface().SetReg(1, param_1);
170 FuncReturn(retval); 172 FuncReturn(retval);
171} 173}
@@ -174,7 +176,7 @@ template <ResultCode func(Handle*, u64, u32, u32)>
174void SvcWrap() { 176void SvcWrap() {
175 u32 param_1 = 0; 177 u32 param_1 = 0;
176 u32 retval = 178 u32 retval =
177 func(&param_1, PARAM(1), (u32)(PARAM(2) & 0xFFFFFFFF), (u32)(PARAM(3) & 0xFFFFFFFF)).raw; 179 func(&param_1, Param(1), (u32)(Param(2) & 0xFFFFFFFF), (u32)(Param(3) & 0xFFFFFFFF)).raw;
178 Core::CurrentArmInterface().SetReg(1, param_1); 180 Core::CurrentArmInterface().SetReg(1, param_1);
179 FuncReturn(retval); 181 FuncReturn(retval);
180} 182}
@@ -182,14 +184,14 @@ void SvcWrap() {
182template <ResultCode func(u64, u32, s32, s64)> 184template <ResultCode func(u64, u32, s32, s64)>
183void SvcWrap() { 185void SvcWrap() {
184 FuncReturn( 186 FuncReturn(
185 func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF), (s64)PARAM(3)) 187 func(Param(0), (u32)(Param(1) & 0xFFFFFFFF), (s32)(Param(2) & 0xFFFFFFFF), (s64)Param(3))
186 .raw); 188 .raw);
187} 189}
188 190
189template <ResultCode func(u64, u32, s32, s32)> 191template <ResultCode func(u64, u32, s32, s32)>
190void SvcWrap() { 192void SvcWrap() {
191 FuncReturn(func(PARAM(0), (u32)(PARAM(1) & 0xFFFFFFFF), (s32)(PARAM(2) & 0xFFFFFFFF), 193 FuncReturn(func(Param(0), (u32)(Param(1) & 0xFFFFFFFF), (s32)(Param(2) & 0xFFFFFFFF),
192 (s32)(PARAM(3) & 0xFFFFFFFF)) 194 (s32)(Param(3) & 0xFFFFFFFF))
193 .raw); 195 .raw);
194} 196}
195 197
@@ -219,20 +221,17 @@ void SvcWrap() {
219 221
220template <void func(s64)> 222template <void func(s64)>
221void SvcWrap() { 223void SvcWrap() {
222 func((s64)PARAM(0)); 224 func((s64)Param(0));
223} 225}
224 226
225template <void func(u64, u64 len)> 227template <void func(u64, u64 len)>
226void SvcWrap() { 228void SvcWrap() {
227 func(PARAM(0), PARAM(1)); 229 func(Param(0), Param(1));
228} 230}
229 231
230template <void func(u64, u64, u64)> 232template <void func(u64, u64, u64)>
231void SvcWrap() { 233void SvcWrap() {
232 func(PARAM(0), PARAM(1), PARAM(2)); 234 func(Param(0), Param(1), Param(2));
233} 235}
234 236
235#undef PARAM
236#undef FuncReturn
237
238} // namespace Kernel 237} // namespace Kernel
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp
index 3f12a84dc..d4183d6e3 100644
--- a/src/core/hle/kernel/thread.cpp
+++ b/src/core/hle/kernel/thread.cpp
@@ -217,8 +217,8 @@ static void ResetThreadContext(Core::ARM_Interface::ThreadContext& context, VAdd
217 context.cpu_registers[0] = arg; 217 context.cpu_registers[0] = arg;
218 context.pc = entry_point; 218 context.pc = entry_point;
219 context.sp = stack_top; 219 context.sp = stack_top;
220 context.cpsr = 0; 220 context.pstate = 0;
221 context.fpscr = 0; 221 context.fpcr = 0;
222} 222}
223 223
224ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name, VAddr entry_point, 224ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name, VAddr entry_point,
@@ -275,7 +275,7 @@ ResultVal<SharedPtr<Thread>> Thread::Create(KernelCore& kernel, std::string name
275 available_slot = 0; // Use the first slot in the new page 275 available_slot = 0; // Use the first slot in the new page
276 276
277 // Allocate some memory from the end of the linear heap for this region. 277 // Allocate some memory from the end of the linear heap for this region.
278 const size_t offset = thread->tls_memory->size(); 278 const std::size_t offset = thread->tls_memory->size();
279 thread->tls_memory->insert(thread->tls_memory->end(), Memory::PAGE_SIZE, 0); 279 thread->tls_memory->insert(thread->tls_memory->end(), Memory::PAGE_SIZE, 0);
280 280
281 auto& vm_manager = owner_process->vm_manager; 281 auto& vm_manager = owner_process->vm_manager;
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h
index cb57ee78a..df4748942 100644
--- a/src/core/hle/kernel/thread.h
+++ b/src/core/hle/kernel/thread.h
@@ -254,7 +254,7 @@ public:
254 Handle callback_handle; 254 Handle callback_handle;
255 255
256 using WakeupCallback = bool(ThreadWakeupReason reason, SharedPtr<Thread> thread, 256 using WakeupCallback = bool(ThreadWakeupReason reason, SharedPtr<Thread> thread,
257 SharedPtr<WaitObject> object, size_t index); 257 SharedPtr<WaitObject> object, std::size_t index);
258 // Callback that will be invoked when the thread is resumed from a waiting state. If the thread 258 // Callback that will be invoked when the thread is resumed from a waiting state. If the thread
259 // was waiting via WaitSynchronizationN then the object will be the last object that became 259 // was waiting via WaitSynchronizationN then the object will be the last object that became
260 // available. In case of a timeout, the object will be nullptr. 260 // available. In case of a timeout, the object will be nullptr.
diff --git a/src/core/hle/kernel/vm_manager.cpp b/src/core/hle/kernel/vm_manager.cpp
index 479cacb62..608cbd57b 100644
--- a/src/core/hle/kernel/vm_manager.cpp
+++ b/src/core/hle/kernel/vm_manager.cpp
@@ -86,7 +86,7 @@ VMManager::VMAHandle VMManager::FindVMA(VAddr target) const {
86 86
87ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target, 87ResultVal<VMManager::VMAHandle> VMManager::MapMemoryBlock(VAddr target,
88 std::shared_ptr<std::vector<u8>> block, 88 std::shared_ptr<std::vector<u8>> block,
89 size_t offset, u64 size, 89 std::size_t offset, u64 size,
90 MemoryState state) { 90 MemoryState state) {
91 ASSERT(block != nullptr); 91 ASSERT(block != nullptr);
92 ASSERT(offset + size <= block->size()); 92 ASSERT(offset + size <= block->size());
diff --git a/src/core/hle/kernel/vm_manager.h b/src/core/hle/kernel/vm_manager.h
index 98bd04bea..de75036c0 100644
--- a/src/core/hle/kernel/vm_manager.h
+++ b/src/core/hle/kernel/vm_manager.h
@@ -81,7 +81,7 @@ struct VirtualMemoryArea {
81 /// Memory block backing this VMA. 81 /// Memory block backing this VMA.
82 std::shared_ptr<std::vector<u8>> backing_block = nullptr; 82 std::shared_ptr<std::vector<u8>> backing_block = nullptr;
83 /// Offset into the backing_memory the mapping starts from. 83 /// Offset into the backing_memory the mapping starts from.
84 size_t offset = 0; 84 std::size_t offset = 0;
85 85
86 // Settings for type = BackingMemory 86 // Settings for type = BackingMemory
87 /// Pointer backing this VMA. It will not be destroyed or freed when the VMA is removed. 87 /// Pointer backing this VMA. It will not be destroyed or freed when the VMA is removed.
@@ -147,7 +147,7 @@ public:
147 * @param state MemoryState tag to attach to the VMA. 147 * @param state MemoryState tag to attach to the VMA.
148 */ 148 */
149 ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block, 149 ResultVal<VMAHandle> MapMemoryBlock(VAddr target, std::shared_ptr<std::vector<u8>> block,
150 size_t offset, u64 size, MemoryState state); 150 std::size_t offset, u64 size, MemoryState state);
151 151
152 /** 152 /**
153 * Maps an unmanaged host memory pointer at a given address. 153 * Maps an unmanaged host memory pointer at a given address.
diff --git a/src/core/hle/kernel/wait_object.cpp b/src/core/hle/kernel/wait_object.cpp
index eef00b729..b190ceb98 100644
--- a/src/core/hle/kernel/wait_object.cpp
+++ b/src/core/hle/kernel/wait_object.cpp
@@ -81,7 +81,7 @@ void WaitObject::WakeupWaitingThread(SharedPtr<Thread> thread) {
81 } 81 }
82 } 82 }
83 83
84 size_t index = thread->GetWaitObjectIndex(this); 84 std::size_t index = thread->GetWaitObjectIndex(this);
85 85
86 for (auto& object : thread->wait_objects) 86 for (auto& object : thread->wait_objects)
87 object->RemoveWaitingThread(thread.get()); 87 object->RemoveWaitingThread(thread.get());