summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2015-01-23 04:00:39 -0200
committerGravatar Yuri Kunde Schlesner2015-01-30 11:49:46 -0200
commit58b544db9958078098a8daf6316cbb58faa729dc (patch)
tree7fdf94ad70c9f3afa4e83ca33bb4c0db51bafe17 /src
parentRemove result.h InvalidHandle (diff)
downloadyuzu-58b544db9958078098a8daf6316cbb58faa729dc.tar.gz
yuzu-58b544db9958078098a8daf6316cbb58faa729dc.tar.xz
yuzu-58b544db9958078098a8daf6316cbb58faa729dc.zip
SVC: Use CASCADE_RESULT in SVC handlers
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/function_wrappers.h4
-rw-r--r--src/core/hle/svc.cpp105
2 files changed, 32 insertions, 77 deletions
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h
index ebb6ba1af..0b6b6f518 100644
--- a/src/core/hle/function_wrappers.h
+++ b/src/core/hle/function_wrappers.h
@@ -39,10 +39,6 @@ template<ResultCode func(u32, u32, u32, u32)> void Wrap() {
39 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)).raw); 39 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3)).raw);
40} 40}
41 41
42template<ResultCode func(u32, u32, u32, u32, u32)> void Wrap() {
43 FuncReturn(func(PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw);
44}
45
46template<ResultCode func(u32*, u32, u32, u32, u32, u32)> void Wrap(){ 42template<ResultCode func(u32*, u32, u32, u32, u32, u32)> void Wrap(){
47 u32 param_1 = 0; 43 u32 param_1 = 0;
48 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; 44 u32 retval = func(&param_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw;
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp
index 46fca51c7..88813c2ce 100644
--- a/src/core/hle/svc.cpp
+++ b/src/core/hle/svc.cpp
@@ -247,20 +247,12 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou
247} 247}
248 248
249/// Create an address arbiter (to allocate access to shared resources) 249/// Create an address arbiter (to allocate access to shared resources)
250static ResultCode CreateAddressArbiter(u32* arbiter) { 250static ResultCode CreateAddressArbiter(Handle* out_handle) {
251 using Kernel::AddressArbiter; 251 using Kernel::AddressArbiter;
252 252
253 ResultVal<SharedPtr<AddressArbiter>> arbiter_res = AddressArbiter::Create(); 253 CASCADE_RESULT(SharedPtr<AddressArbiter> arbiter, AddressArbiter::Create());
254 if (arbiter_res.Failed()) 254 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(arbiter)));
255 return arbiter_res.Code(); 255 LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *out_handle);
256
257 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*arbiter_res);
258 if (handle_res.Failed())
259 return handle_res.Code();
260
261 LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res);
262
263 *arbiter = *handle_res;
264 return RESULT_SUCCESS; 256 return RESULT_SUCCESS;
265} 257}
266 258
@@ -304,7 +296,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim
304} 296}
305 297
306/// Creates a new thread 298/// Creates a new thread
307static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { 299static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) {
308 using Kernel::Thread; 300 using Kernel::Thread;
309 301
310 std::string name; 302 std::string name;
@@ -315,18 +307,13 @@ static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack
315 name = Common::StringFromFormat("unknown-%08x", entry_point); 307 name = Common::StringFromFormat("unknown-%08x", entry_point);
316 } 308 }
317 309
318 ResultVal<SharedPtr<Thread>> thread_res = Kernel::Thread::Create( 310 CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create(
319 name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE); 311 name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE));
320 if (thread_res.Failed()) 312 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread)));
321 return thread_res.Code();
322 SharedPtr<Thread> thread = std::move(*thread_res);
323
324 // TODO(yuriks): Create new handle instead of using built-in
325 Core::g_app_core->SetReg(1, thread->GetHandle());
326 313
327 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, " 314 LOG_TRACE(Kernel_SVC, "called entrypoint=0x%08X (%s), arg=0x%08X, stacktop=0x%08X, "
328 "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, 315 "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point,
329 name.c_str(), arg, stack_top, priority, processor_id, thread->GetHandle()); 316 name.c_str(), arg, stack_top, priority, processor_id, *out_handle);
330 317
331 if (THREADPROCESSORID_1 == processor_id) { 318 if (THREADPROCESSORID_1 == processor_id) {
332 LOG_WARNING(Kernel_SVC, 319 LOG_WARNING(Kernel_SVC,
@@ -365,17 +352,14 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) {
365} 352}
366 353
367/// Create a mutex 354/// Create a mutex
368static ResultCode CreateMutex(Handle* handle, u32 initial_locked) { 355static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) {
369 using Kernel::Mutex; 356 using Kernel::Mutex;
370 357
371 auto mutex_res = Mutex::Create(initial_locked != 0); 358 CASCADE_RESULT(SharedPtr<Mutex> mutex, Mutex::Create(initial_locked != 0));
372 if (mutex_res.Failed()) 359 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex)));
373 return mutex_res.Code();
374 SharedPtr<Mutex> mutex = mutex_res.MoveFrom();
375 360
376 *handle = Kernel::g_handle_table.Create(mutex).MoveFrom();
377 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", 361 LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X",
378 initial_locked ? "true" : "false", *handle); 362 initial_locked ? "true" : "false", *out_handle);
379 return RESULT_SUCCESS; 363 return RESULT_SUCCESS;
380} 364}
381 365
@@ -406,20 +390,14 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) {
406} 390}
407 391
408/// Creates a semaphore 392/// Creates a semaphore
409static ResultCode CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { 393static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) {
410 using Kernel::Semaphore; 394 using Kernel::Semaphore;
411 395
412 ResultVal<SharedPtr<Semaphore>> semaphore_res = Semaphore::Create(initial_count, max_count); 396 CASCADE_RESULT(SharedPtr<Semaphore> semaphore, Semaphore::Create(initial_count, max_count));
413 if (semaphore_res.Failed()) 397 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore)));
414 return semaphore_res.Code();
415
416 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*semaphore_res);
417 if (handle_res.Failed())
418 return handle_res.Code();
419 398
420 *semaphore = *handle_res;
421 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", 399 LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X",
422 initial_count, max_count, *semaphore); 400 initial_count, max_count, *out_handle);
423 return RESULT_SUCCESS; 401 return RESULT_SUCCESS;
424} 402}
425 403
@@ -433,11 +411,7 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count)
433 if (semaphore == nullptr) 411 if (semaphore == nullptr)
434 return ERR_INVALID_HANDLE; 412 return ERR_INVALID_HANDLE;
435 413
436 ResultVal<s32> release_res = semaphore->Release(release_count); 414 CASCADE_RESULT(*count, semaphore->Release(release_count));
437 if (release_res.Failed())
438 return release_res.Code();
439
440 *count = *release_res;
441 return RESULT_SUCCESS; 415 return RESULT_SUCCESS;
442} 416}
443 417
@@ -448,16 +422,12 @@ static ResultCode QueryMemory(void* info, void* out, u32 addr) {
448} 422}
449 423
450/// Create an event 424/// Create an event
451static ResultCode CreateEvent(Handle* handle, u32 reset_type) { 425static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) {
452 auto evt_res = Kernel::Event::Create(static_cast<ResetType>(reset_type)); 426 CASCADE_RESULT(auto evt, Kernel::Event::Create(static_cast<ResetType>(reset_type)));
453 if (evt_res.Failed()) 427 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt)));
454 return evt_res.Code(); 428
455 auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom()); 429 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
456 if (handle_res.Failed()) 430 reset_type, *out_handle);
457 return handle_res.Code();
458 *handle = handle_res.MoveFrom();
459
460 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle);
461 return RESULT_SUCCESS; 431 return RESULT_SUCCESS;
462} 432}
463 433
@@ -497,19 +467,14 @@ static ResultCode ClearEvent(Handle handle) {
497} 467}
498 468
499/// Creates a timer 469/// Creates a timer
500static ResultCode CreateTimer(Handle* handle, u32 reset_type) { 470static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) {
501 using Kernel::Timer; 471 using Kernel::Timer;
502 472
503 auto timer_res = Timer::Create(static_cast<ResetType>(reset_type)); 473 CASCADE_RESULT(auto timer, Timer::Create(static_cast<ResetType>(reset_type)));
504 if (timer_res.Failed()) 474 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer)));
505 return timer_res.Code();
506 475
507 auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom()); 476 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X",
508 if (handle_res.Failed()) 477 reset_type, *out_handle);
509 return handle_res.Code();
510 *handle = handle_res.MoveFrom();
511
512 LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle);
513 return RESULT_SUCCESS; 478 return RESULT_SUCCESS;
514} 479}
515 480
@@ -574,20 +539,14 @@ static s64 GetSystemTick() {
574} 539}
575 540
576/// Creates a memory block at the specified address with the specified permissions and size 541/// Creates a memory block at the specified address with the specified permissions and size
577static ResultCode CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, 542static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission,
578 u32 other_permission) { 543 u32 other_permission) {
579 using Kernel::SharedMemory; 544 using Kernel::SharedMemory;
580 // TODO(Subv): Implement this function 545 // TODO(Subv): Implement this function
581 546
582 ResultVal<SharedPtr<SharedMemory>> shared_memory_res = SharedMemory::Create(); 547 CASCADE_RESULT(auto shared_memory, SharedMemory::Create());
583 if (shared_memory_res.Failed()) 548 CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory)));
584 return shared_memory_res.Code();
585
586 ResultVal<Handle> handle_res = Kernel::g_handle_table.Create(*shared_memory_res);
587 if (handle_res.Failed())
588 return handle_res.Code();
589 549
590 *memblock = *handle_res;
591 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); 550 LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr);
592 return RESULT_SUCCESS; 551 return RESULT_SUCCESS;
593} 552}