diff options
author | bunnei <bunneidev@gmail.com> | 2015-01-09 18:59:35 +0100 |
---|---|---|
committer | bunnei <bunneidev@gmail.com> | 2015-01-09 18:59:35 +0100 |
commit | 6ae12424df58f0ea171fc75ca4b700ab1fffc192 (patch) | |
tree | 93d87f3cb19d08541c6b8f8a9e0ceb730a2b13d9 /src/core/hle/svc.cpp | |
parent | Merge pull request #436 from kevinhartman/system-core (diff) | |
parent | Thread: Fix nullptr access in a logging function (diff) | |
download | yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.gz yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.bz2 yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.lz yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.xz yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.tar.zst yuzu-6ae12424df58f0ea171fc75ca4b700ab1fffc192.zip |
Diffstat (limited to '')
-rw-r--r-- | src/core/hle/svc.cpp | 52 |
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 @@ #include "common/string_util.h" #include "common/symbols.h" +#include "core/arm/arm_interface.h" #include "core/mem_map.h" #include "core/hle/kernel/address_arbiter.h" @@ -230,14 +231,17 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top name = Common::StringFromFormat("unknown-%08x", entry_point); } - Handle thread = Kernel::CreateThread(name.c_str(), entry_point, priority, arg, processor_id, - stack_top); + ResultVal<Kernel::Thread*> thread_res = Kernel::Thread::Create(name.c_str(), entry_point, priority, arg, + processor_id, stack_top); + if (thread_res.Failed()) + return thread_res.Code().raw; + Kernel::Thread* thread = *thread_res; - Core::g_app_core->SetReg(1, thread); + Core::g_app_core->SetReg(1, thread->GetHandle()); LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, - name.c_str(), arg, stack_top, priority, processor_id, thread); + name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle()); if (THREADPROCESSORID_1 == processor_id) { LOG_WARNING(Kernel_SVC, @@ -248,28 +252,31 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top } /// Called when a thread exits -static u32 ExitThread() { - Handle thread = Kernel::GetCurrentThreadHandle(); +static void ExitThread() { + LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); - LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C - - Kernel::StopThread(thread, __func__); + Kernel::GetCurrentThread()->Stop(__func__); HLE::Reschedule(__func__); - return 0; } /// Gets the priority for the specified thread static Result GetThreadPriority(s32* priority, Handle handle) { - ResultVal<u32> priority_result = Kernel::GetThreadPriority(handle); - if (priority_result.Succeeded()) { - *priority = *priority_result; - } - return priority_result.Code().raw; + const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *priority = thread->GetPriority(); + return RESULT_SUCCESS.raw; } /// Sets the priority for the specified thread static Result SetThreadPriority(Handle handle, s32 priority) { - return Kernel::SetThreadPriority(handle, priority).raw; + Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + thread->SetPriority(priority); + return RESULT_SUCCESS.raw; } /// Create a mutex @@ -290,8 +297,13 @@ static Result ReleaseMutex(Handle handle) { /// Get the ID for the specified thread. static Result GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); - ResultCode result = Kernel::GetThreadId(thread_id, handle); - return result.raw; + + const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle); + if (thread == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + *thread_id = thread->GetThreadId(); + return RESULT_SUCCESS.raw; } /// Creates a semaphore @@ -379,7 +391,7 @@ static void SleepThread(s64 nanoseconds) { Kernel::WaitCurrentThread(WAITTYPE_SLEEP); // Create an event to wake the thread up after the specified nanosecond delay has passed - Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThreadHandle(), nanoseconds); + Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds); HLE::Reschedule(__func__); } @@ -411,7 +423,7 @@ const HLE::FunctionDef SVC_Table[] = { {0x06, nullptr, "GetProcessIdealProcessor"}, {0x07, nullptr, "SetProcessIdealProcessor"}, {0x08, HLE::Wrap<CreateThread>, "CreateThread"}, - {0x09, HLE::Wrap<ExitThread>, "ExitThread"}, + {0x09, ExitThread, "ExitThread"}, {0x0A, HLE::Wrap<SleepThread>, "SleepThread"}, {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"}, {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"}, |