summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
authorGravatar bunnei2015-01-09 12:59:35 -0500
committerGravatar bunnei2015-01-09 12:59:35 -0500
commit6ae12424df58f0ea171fc75ca4b700ab1fffc192 (patch)
tree93d87f3cb19d08541c6b8f8a9e0ceb730a2b13d9 /src/core/hle/svc.cpp
parentMerge pull request #436 from kevinhartman/system-core (diff)
parentThread: Fix nullptr access in a logging function (diff)
downloadyuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.gz
yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.xz
yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.zip
Merge pull request #444 from yuriks/handle-reform2
Kernel Lifetime Reform Pt. 2
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp52
1 files changed, 32 insertions, 20 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 051f2d2c6..8ac1c7350 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -7,6 +7,7 @@
7#include "common/string_util.h" 7#include "common/string_util.h"
8#include "common/symbols.h" 8#include "common/symbols.h"
9 9
10#include "core/arm/arm_interface.h"
10#include "core/mem_map.h" 11#include "core/mem_map.h"
11 12
12#include "core/hle/kernel/address_arbiter.h" 13#include "core/hle/kernel/address_arbiter.h"
@@ -230,14 +231,17 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
230 name = Common::StringFromFormat("unknown-%08x", entry_point); 231 name = Common::StringFromFormat("unknown-%08x", entry_point);
231 } 232 }
232 233
233 Handle thread = Kernel::CreateThread(name.c_str(), entry_point, priority, arg, processor_id, 234 ResultVal<Kernel::Thread*> thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg,
234 stack_top); 235 processor_id, stack_top);
236 if (thread_res.Failed())
237 return thread_res.Code().raw;
238 Kernel::Thread* thread = *thread_res;
235 239
236 Core::g_app_core->SetReg(1, thread); 240 Core::g_app_core->SetReg(1, thread->GetHandle());
237 241
238 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " 242 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
239 "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, 243 "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point,
240 name.c_str(), arg, stack_top, priority, processor_id, thread); 244 name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle());
241 245
242 if (THREADPROCESSORID_1 == processor_id) { 246 if (THREADPROCESSORID_1 == processor_id) {
243 LOG_WARNING(Kernel_SVC, 247 LOG_WARNING(Kernel_SVC,
@@ -248,28 +252,31 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
248} 252}
249 253
250/// Called when a thread exits 254/// Called when a thread exits
251static u32 ExitThread() { 255static void ExitThread() {
252 Handle thread = Kernel::GetCurrentThreadHandle(); 256 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC());
253 257
254 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C 258 Kernel::GetCurrentThread()->Stop(__func__);
255
256 Kernel::StopThread(thread, __func__);
257 HLE::Reschedule(__func__); 259 HLE::Reschedule(__func__);
258 return 0;
259} 260}
260 261
261/// Gets the priority for the specified thread 262/// Gets the priority for the specified thread
262static Result GetThreadPriority(s32* priority, Handle handle) { 263static Result GetThreadPriority(s32* priority, Handle handle) {
263 ResultVal<u32> priority_result = Kernel::GetThreadPriority(handle); 264 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
264 if (priority_result.Succeeded()) { 265 if (thread == nullptr)
265 *priority = *priority_result; 266 return InvalidHandle(ErrorModule::Kernel).raw;
266 } 267
267 return priority_result.Code().raw; 268 *priority = thread->GetPriority();
269 return RESULT_SUCCESS.raw;
268} 270}
269 271
270/// Sets the priority for the specified thread 272/// Sets the priority for the specified thread
271static Result SetThreadPriority(Handle handle, s32 priority) { 273static Result SetThreadPriority(Handle handle, s32 priority) {
272 return Kernel::SetThreadPriority(handle, priority).raw; 274 Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
275 if (thread == nullptr)
276 return InvalidHandle(ErrorModule::Kernel).raw;
277
278 thread->SetPriority(priority);
279 return RESULT_SUCCESS.raw;
273} 280}
274 281
275/// Create a mutex 282/// Create a mutex
@@ -290,8 +297,13 @@ static Result ReleaseMutex(Handle handle) {
290/// Get the ID for the specified thread. 297/// Get the ID for the specified thread.
291static Result GetThreadId(u32* thread_id, Handle handle) { 298static Result GetThreadId(u32* thread_id, Handle handle) {
292 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 299 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
293 ResultCode result = Kernel::GetThreadId(thread_id, handle); 300
294 return result.raw; 301 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
302 if (thread == nullptr)
303 return InvalidHandle(ErrorModule::Kernel).raw;
304
305 *thread_id = thread->GetThreadId();
306 return RESULT_SUCCESS.raw;
295} 307}
296 308
297/// Creates a semaphore 309/// Creates a semaphore
@@ -379,7 +391,7 @@ static void SleepThread(s64 nanoseconds) {
379 Kernel::WaitCurrentThread(WAITTYPE_SLEEP); 391 Kernel::WaitCurrentThread(WAITTYPE_SLEEP);
380 392
381 // Create an event to wake the thread up after the specified nanosecond delay has passed 393 // Create an event to wake the thread up after the specified nanosecond delay has passed
382 Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThreadHandle(), nanoseconds); 394 Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds);
383 395
384 HLE::Reschedule(__func__); 396 HLE::Reschedule(__func__);
385} 397}
@@ -411,7 +423,7 @@ const HLE::FunctionDef SVC_Table[] = {
411 {0x06, nullptr, "GetProcessIdealProcessor"}, 423 {0x06, nullptr, "GetProcessIdealProcessor"},
412 {0x07, nullptr, "SetProcessIdealProcessor"}, 424 {0x07, nullptr, "SetProcessIdealProcessor"},
413 {0x08, HLE::Wrap<CreateThread>, "CreateThread"}, 425 {0x08, HLE::Wrap<CreateThread>, "CreateThread"},
414 {0x09, HLE::Wrap<ExitThread>, "ExitThread"}, 426 {0x09, ExitThread, "ExitThread"},
415 {0x0A, HLE::Wrap<SleepThread>, "SleepThread"}, 427 {0x0A, HLE::Wrap<SleepThread>, "SleepThread"},
416 {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"}, 428 {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"},
417 {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"}, 429 {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"},