summaryrefslogtreecommitdiff
path: root/src/core/hle/svc.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/hle/svc.cpp')
-rw-r--r--src/core/hle/svc.cpp51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 92de442e8..6380d214c 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -231,41 +231,47 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top
231 name = Common::StringFromFormat("unknown-%08x", entry_point); 231 name = Common::StringFromFormat("unknown-%08x", entry_point);
232 } 232 }
233 233
234 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,
235 stack_top); 235 processor_id, stack_top);
236 if (thread_res.Failed())
237 return thread_res.Code().raw;
238 Kernel::Thread* thread = *thread_res;
236 239
237 Core::g_app_core->SetReg(1, thread); 240 Core::g_app_core->SetReg(1, thread->GetHandle());
238 241
239 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, "
240 "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,
241 name.c_str(), arg, stack_top, priority, processor_id, thread); 244 name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle());
242 245
243 return 0; 246 return 0;
244} 247}
245 248
246/// Called when a thread exits 249/// Called when a thread exits
247static u32 ExitThread() { 250static void ExitThread() {
248 Handle thread = Kernel::GetCurrentThreadHandle(); 251 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC());
249 252
250 LOG_TRACE(Kernel_SVC, "called, pc=0x%08X", Core::g_app_core->GetPC()); // PC = 0x0010545C 253 Kernel::GetCurrentThread()->Stop(__func__);
251
252 Kernel::StopThread(thread, __func__);
253 HLE::Reschedule(__func__); 254 HLE::Reschedule(__func__);
254 return 0;
255} 255}
256 256
257/// Gets the priority for the specified thread 257/// Gets the priority for the specified thread
258static Result GetThreadPriority(s32* priority, Handle handle) { 258static Result GetThreadPriority(s32* priority, Handle handle) {
259 ResultVal<u32> priority_result = Kernel::GetThreadPriority(handle); 259 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
260 if (priority_result.Succeeded()) { 260 if (thread == nullptr)
261 *priority = *priority_result; 261 return InvalidHandle(ErrorModule::Kernel).raw;
262 } 262
263 return priority_result.Code().raw; 263 *priority = thread->GetPriority();
264 return RESULT_SUCCESS.raw;
264} 265}
265 266
266/// Sets the priority for the specified thread 267/// Sets the priority for the specified thread
267static Result SetThreadPriority(Handle handle, s32 priority) { 268static Result SetThreadPriority(Handle handle, s32 priority) {
268 return Kernel::SetThreadPriority(handle, priority).raw; 269 Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
270 if (thread == nullptr)
271 return InvalidHandle(ErrorModule::Kernel).raw;
272
273 thread->SetPriority(priority);
274 return RESULT_SUCCESS.raw;
269} 275}
270 276
271/// Create a mutex 277/// Create a mutex
@@ -286,8 +292,13 @@ static Result ReleaseMutex(Handle handle) {
286/// Get the ID for the specified thread. 292/// Get the ID for the specified thread.
287static Result GetThreadId(u32* thread_id, Handle handle) { 293static Result GetThreadId(u32* thread_id, Handle handle) {
288 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); 294 LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle);
289 ResultCode result = Kernel::GetThreadId(thread_id, handle); 295
290 return result.raw; 296 const Kernel::Thread* thread = Kernel::g_handle_table.Get<Kernel::Thread>(handle);
297 if (thread == nullptr)
298 return InvalidHandle(ErrorModule::Kernel).raw;
299
300 *thread_id = thread->GetThreadId();
301 return RESULT_SUCCESS.raw;
291} 302}
292 303
293/// Creates a semaphore 304/// Creates a semaphore
@@ -375,7 +386,7 @@ static void SleepThread(s64 nanoseconds) {
375 Kernel::WaitCurrentThread(WAITTYPE_SLEEP); 386 Kernel::WaitCurrentThread(WAITTYPE_SLEEP);
376 387
377 // Create an event to wake the thread up after the specified nanosecond delay has passed 388 // Create an event to wake the thread up after the specified nanosecond delay has passed
378 Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThreadHandle(), nanoseconds); 389 Kernel::WakeThreadAfterDelay(Kernel::GetCurrentThread(), nanoseconds);
379 390
380 HLE::Reschedule(__func__); 391 HLE::Reschedule(__func__);
381} 392}
@@ -407,7 +418,7 @@ const HLE::FunctionDef SVC_Table[] = {
407 {0x06, nullptr, "GetProcessIdealProcessor"}, 418 {0x06, nullptr, "GetProcessIdealProcessor"},
408 {0x07, nullptr, "SetProcessIdealProcessor"}, 419 {0x07, nullptr, "SetProcessIdealProcessor"},
409 {0x08, HLE::Wrap<CreateThread>, "CreateThread"}, 420 {0x08, HLE::Wrap<CreateThread>, "CreateThread"},
410 {0x09, HLE::Wrap<ExitThread>, "ExitThread"}, 421 {0x09, ExitThread, "ExitThread"},
411 {0x0A, HLE::Wrap<SleepThread>, "SleepThread"}, 422 {0x0A, HLE::Wrap<SleepThread>, "SleepThread"},
412 {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"}, 423 {0x0B, HLE::Wrap<GetThreadPriority>, "GetThreadPriority"},
413 {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"}, 424 {0x0C, HLE::Wrap<SetThreadPriority>, "SetThreadPriority"},