From 4bb33dfc30768c536d3f0ffb980464b1ab2d25d9 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sun, 11 Jan 2015 03:43:29 -0200 Subject: Kernel: Convert SharedMemory to not use Handles --- src/core/hle/svc.cpp | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 3d743f125..165da0402 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -63,21 +63,28 @@ static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, /// Maps a memory block to specified address static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { + using Kernel::SharedMemory; + using Kernel::MemoryPermission; + LOG_TRACE(Kernel_SVC, "called memblock=0x%08X, addr=0x%08X, mypermissions=0x%08X, otherpermission=%d", handle, addr, permissions, other_permissions); - Kernel::MemoryPermission permissions_type = static_cast(permissions); + SharedPtr shared_memory = Kernel::g_handle_table.Get(handle); + if (shared_memory == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + MemoryPermission permissions_type = static_cast(permissions); switch (permissions_type) { - case Kernel::MemoryPermission::Read: - case Kernel::MemoryPermission::Write: - case Kernel::MemoryPermission::ReadWrite: - case Kernel::MemoryPermission::Execute: - case Kernel::MemoryPermission::ReadExecute: - case Kernel::MemoryPermission::WriteExecute: - case Kernel::MemoryPermission::ReadWriteExecute: - case Kernel::MemoryPermission::DontCare: - Kernel::MapSharedMemory(handle, addr, permissions_type, - static_cast(other_permissions)); + case MemoryPermission::Read: + case MemoryPermission::Write: + case MemoryPermission::ReadWrite: + case MemoryPermission::Execute: + case MemoryPermission::ReadExecute: + case MemoryPermission::WriteExecute: + case MemoryPermission::ReadWriteExecute: + case MemoryPermission::DontCare: + shared_memory->Map(addr, permissions_type, + static_cast(other_permissions)); break; default: LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); @@ -463,12 +470,19 @@ static s64 GetSystemTick() { /// Creates a memory block at the specified address with the specified permissions and size static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, - u32 other_permission) { - + u32 other_permission) { + using Kernel::SharedMemory; // TODO(Subv): Implement this function - Handle shared_memory = Kernel::CreateSharedMemory(); - *memblock = shared_memory; + ResultVal> shared_memory_res = SharedMemory::Create(); + if (shared_memory_res.Failed()) + return shared_memory_res.Code().raw; + + ResultVal handle_res = Kernel::g_handle_table.Create(*shared_memory_res); + if (handle_res.Failed()) + return handle_res.Code().raw; + + *memblock = *handle_res; LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); return 0; } -- cgit v1.2.3 From d9b19be1d9c1baa5e8b92c1960c14e435e6b532f Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sun, 11 Jan 2015 13:53:11 -0200 Subject: Kernel: Convert Semaphore to not use Handles --- src/core/hle/svc.cpp | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 165da0402..6cbe38bc3 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -374,17 +374,38 @@ static Result GetThreadId(u32* thread_id, Handle handle) { /// Creates a semaphore static Result CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { - ResultCode res = Kernel::CreateSemaphore(semaphore, initial_count, max_count); + using Kernel::Semaphore; + + ResultVal> semaphore_res = Semaphore::Create(initial_count, max_count); + if (semaphore_res.Failed()) + return semaphore_res.Code().raw; + + ResultVal handle_res = Kernel::g_handle_table.Create(*semaphore_res); + if (handle_res.Failed()) + return handle_res.Code().raw; + + *semaphore = *handle_res; LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", initial_count, max_count, *semaphore); - return res.raw; + return RESULT_SUCCESS.raw; } /// Releases a certain number of slots in a semaphore -static Result ReleaseSemaphore(s32* count, Handle semaphore, s32 release_count) { - LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, semaphore); - ResultCode res = Kernel::ReleaseSemaphore(count, semaphore, release_count); - return res.raw; +static Result ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { + using Kernel::Semaphore; + + LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); + + SharedPtr semaphore = Kernel::g_handle_table.Get(handle); + if (semaphore == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + ResultVal release_res = semaphore->Release(release_count); + if (release_res.Failed()) + return release_res.Code().raw; + + *count = *release_res; + return RESULT_SUCCESS.raw; } /// Query memory -- cgit v1.2.3 From 38e7122f23424d40e0555fa40daeff55e23e4da4 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sun, 11 Jan 2015 14:46:49 -0200 Subject: Kernel: Convert AddressArbiter to not use Handles --- src/core/hle/svc.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 6cbe38bc3..b093d0368 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -247,16 +247,34 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, /// Create an address arbiter (to allocate access to shared resources) static Result CreateAddressArbiter(u32* arbiter) { - Handle handle = Kernel::CreateAddressArbiter(); - *arbiter = handle; - return 0; + using Kernel::AddressArbiter; + + ResultVal> arbiter_res = AddressArbiter::Create(); + if (arbiter_res.Failed()) + return arbiter_res.Code().raw; + + ResultVal handle_res = Kernel::g_handle_table.Create(*arbiter_res); + if (handle_res.Failed()) + return handle_res.Code().raw; + + LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res); + + *arbiter = *handle_res; + return RESULT_SUCCESS.raw; } /// Arbitrate address -static Result ArbitrateAddress(Handle arbiter, u32 address, u32 type, u32 value, s64 nanoseconds) { - LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", arbiter, +static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { + using Kernel::AddressArbiter; + + LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle, address, type, value); - return Kernel::ArbitrateAddress(arbiter, static_cast(type), + + SharedPtr arbiter = Kernel::g_handle_table.Get(handle); + if (arbiter == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + return arbiter->ArbitrateAddress(static_cast(type), address, value, nanoseconds).raw; } -- cgit v1.2.3 From 882b6fed75b7bf34809493482496e98c498a14e0 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Thu, 22 Jan 2015 23:12:19 -0200 Subject: Kernel: Convert Mutex to not use Handles --- src/core/hle/svc.cpp | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index b093d0368..76ce59b29 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -364,18 +364,32 @@ static Result SetThreadPriority(Handle handle, s32 priority) { } /// Create a mutex -static Result CreateMutex(Handle* mutex, u32 initial_locked) { - *mutex = Kernel::CreateMutex((initial_locked != 0)); +static Result CreateMutex(Handle* handle, u32 initial_locked) { + using Kernel::Mutex; + + auto mutex_res = Mutex::Create(initial_locked != 0); + if (mutex_res.Failed()) + return mutex_res.Code().raw; + SharedPtr mutex = mutex_res.MoveFrom(); + + *handle = Kernel::g_handle_table.Create(mutex).MoveFrom(); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", - initial_locked ? "true" : "false", *mutex); + initial_locked ? "true" : "false", *handle); return 0; } /// Release a mutex static Result ReleaseMutex(Handle handle) { + using Kernel::Mutex; + LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); - ResultCode res = Kernel::ReleaseMutex(handle); - return res.raw; + + SharedPtr mutex = Kernel::g_handle_table.Get(handle); + if (mutex == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + mutex->Release(); + return RESULT_SUCCESS.raw; } /// Get the ID for the specified thread. -- cgit v1.2.3 From ad80ff1e322430634e04ffcb39ffef268411ea6b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 23 Jan 2015 02:19:33 -0200 Subject: Kernel: Convert Timer to (mostly) not use Handles --- src/core/hle/svc.cpp | 47 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 7 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 76ce59b29..95403644b 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -479,28 +479,61 @@ static Result ClearEvent(Handle evt) { /// Creates a timer static Result CreateTimer(Handle* handle, u32 reset_type) { - ResultCode res = Kernel::CreateTimer(handle, static_cast(reset_type)); - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", - reset_type, *handle); - return res.raw; + using Kernel::Timer; + + auto timer_res = Timer::Create(static_cast(reset_type)); + if (timer_res.Failed()) + return timer_res.Code().raw; + + auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom()); + if (handle_res.Failed()) + return handle_res.Code().raw; + *handle = handle_res.MoveFrom(); + + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); + return RESULT_SUCCESS.raw; } /// Clears a timer static Result ClearTimer(Handle handle) { + using Kernel::Timer; + LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); - return Kernel::ClearTimer(handle).raw; + + SharedPtr timer = Kernel::g_handle_table.Get(handle); + if (timer == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + timer->Clear(); + return RESULT_SUCCESS.raw; } /// Starts a timer static Result SetTimer(Handle handle, s64 initial, s64 interval) { + using Kernel::Timer; + LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); - return Kernel::SetTimer(handle, initial, interval).raw; + + SharedPtr timer = Kernel::g_handle_table.Get(handle); + if (timer == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + timer->Set(initial, interval); + return RESULT_SUCCESS.raw; } /// Cancels a timer static Result CancelTimer(Handle handle) { + using Kernel::Timer; + LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); - return Kernel::CancelTimer(handle).raw; + + SharedPtr timer = Kernel::g_handle_table.Get(handle); + if (timer == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + timer->Cancel(); + return RESULT_SUCCESS.raw; } /// Sleep the current thread -- cgit v1.2.3 From d52d85993683a6948285801ab54d51c79c98afba Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 23 Jan 2015 03:11:25 -0200 Subject: Kernel: Convert Event to not use Handles --- src/core/hle/svc.cpp | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 95403644b..0c50f0d5b 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -447,11 +447,17 @@ static Result QueryMemory(void* info, void* out, u32 addr) { } /// Create an event -static Result CreateEvent(Handle* evt, u32 reset_type) { - *evt = Kernel::CreateEvent((ResetType)reset_type); - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", - reset_type, *evt); - return 0; +static Result CreateEvent(Handle* handle, u32 reset_type) { + auto evt_res = Kernel::Event::Create(static_cast(reset_type)); + if (evt_res.Failed()) + return evt_res.Code().raw; + auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom()); + if (handle_res.Failed()) + return handle_res.Code().raw; + *handle = handle_res.MoveFrom(); + + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); + return RESULT_SUCCESS.raw; } /// Duplicates a kernel handle @@ -465,16 +471,28 @@ static Result DuplicateHandle(Handle* out, Handle handle) { } /// Signals an event -static Result SignalEvent(Handle evt) { - LOG_TRACE(Kernel_SVC, "called event=0x%08X", evt); +static Result SignalEvent(Handle handle) { + LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); + + auto evt = Kernel::g_handle_table.Get(handle); + if (evt == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + evt->Signal(); HLE::Reschedule(__func__); - return Kernel::SignalEvent(evt).raw; + return RESULT_SUCCESS.raw; } /// Clears an event -static Result ClearEvent(Handle evt) { - LOG_TRACE(Kernel_SVC, "called event=0x%08X", evt); - return Kernel::ClearEvent(evt).raw; +static Result ClearEvent(Handle handle) { + LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); + + auto evt = Kernel::g_handle_table.Get(handle); + if (evt == nullptr) + return InvalidHandle(ErrorModule::Kernel).raw; + + evt->Clear(); + return RESULT_SUCCESS.raw; } /// Creates a timer -- cgit v1.2.3 From 44f90340dcf8dc0686bf63ad2244567c55e08e70 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 23 Jan 2015 03:36:58 -0200 Subject: SVC: Change return type of handlers to ResultCode --- src/core/hle/svc.cpp | 180 +++++++++++++++++++++++++-------------------------- 1 file changed, 90 insertions(+), 90 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index 0c50f0d5b..bec9837a4 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -38,7 +38,7 @@ enum ControlMemoryOperation { }; /// Map application or GSP heap memory -static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { +static ResultCode ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, u32 size, u32 permissions) { LOG_TRACE(Kernel_SVC,"called operation=0x%08X, addr0=0x%08X, addr1=0x%08X, size=%08X, permissions=0x%08X", operation, addr0, addr1, size, permissions); @@ -58,11 +58,11 @@ static Result ControlMemory(u32* out_addr, u32 operation, u32 addr0, u32 addr1, default: LOG_ERROR(Kernel_SVC, "unknown operation=0x%08X", operation); } - return 0; + return RESULT_SUCCESS; } /// Maps a memory block to specified address -static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { +static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other_permissions) { using Kernel::SharedMemory; using Kernel::MemoryPermission; @@ -71,7 +71,7 @@ static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other SharedPtr shared_memory = Kernel::g_handle_table.Get(handle); if (shared_memory == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); MemoryPermission permissions_type = static_cast(permissions); switch (permissions_type) { @@ -89,11 +89,11 @@ static Result MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 other default: LOG_ERROR(Kernel_SVC, "unknown permissions=0x%08X", permissions); } - return 0; + return RESULT_SUCCESS; } /// Connect to an OS service given the port name, returns the handle to the port to out -static Result ConnectToPort(Handle* out, const char* port_name) { +static ResultCode ConnectToPort(Handle* out, const char* port_name) { Service::Interface* service = Service::g_manager->FetchFromPortName(port_name); LOG_TRACE(Kernel_SVC, "called port_name=%s", port_name); @@ -101,33 +101,33 @@ static Result ConnectToPort(Handle* out, const char* port_name) { *out = service->GetHandle(); - return 0; + return RESULT_SUCCESS; } /// Synchronize to an OS service -static Result SendSyncRequest(Handle handle) { +static ResultCode SendSyncRequest(Handle handle) { SharedPtr session = Kernel::g_handle_table.Get(handle); if (session == nullptr) { - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); } LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); - return session->SyncRequest().Code().raw; + return session->SyncRequest().Code(); } /// Close a handle -static Result CloseHandle(Handle handle) { +static ResultCode CloseHandle(Handle handle) { // ImplementMe LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called handle=0x%08X", handle); - return 0; + return RESULT_SUCCESS; } /// Wait for a handle to synchronize, timeout after the specified nanoseconds -static Result WaitSynchronization1(Handle handle, s64 nano_seconds) { +static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { auto object = Kernel::g_handle_table.GetWaitObject(handle); if (object == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); @@ -144,22 +144,22 @@ static Result WaitSynchronization1(Handle handle, s64 nano_seconds) { HLE::Reschedule(__func__); // NOTE: output of this SVC will be set later depending on how the thread resumes - return RESULT_INVALID.raw; + return RESULT_INVALID; } object->Acquire(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Wait for the given handles to synchronize, timeout after the specified nanoseconds -static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) { +static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, bool wait_all, s64 nano_seconds) { bool wait_thread = !wait_all; int handle_index = 0; // Check if 'handles' is invalid if (handles == nullptr) - return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent).raw; + return ResultCode(ErrorDescription::InvalidPointer, ErrorModule::Kernel, ErrorSummary::InvalidArgument, ErrorLevel::Permanent); // NOTE: on real hardware, there is no nullptr check for 'out' (tested with firmware 4.4). If // this happens, the running application will crash. @@ -167,7 +167,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, // Check if 'handle_count' is invalid if (handle_count < 0) - return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage).raw; + return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, ErrorSummary::InvalidArgument, ErrorLevel::Usage); // If 'handle_count' is non-zero, iterate through each handle and wait the current thread if // necessary @@ -176,7 +176,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, for (int i = 0; i < handle_count; ++i) { auto object = Kernel::g_handle_table.GetWaitObject(handles[i]); if (object == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); // Check if the current thread should wait on this object... if (object->ShouldWait()) { @@ -220,7 +220,7 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, HLE::Reschedule(__func__); // NOTE: output of this SVC will be set later depending on how the thread resumes - return RESULT_INVALID.raw; + return RESULT_INVALID; } // Acquire objects if we did not wait... @@ -242,29 +242,29 @@ static Result WaitSynchronizationN(s32* out, Handle* handles, s32 handle_count, // not seem to set it to any meaningful value. *out = wait_all ? 0 : handle_index; - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Create an address arbiter (to allocate access to shared resources) -static Result CreateAddressArbiter(u32* arbiter) { +static ResultCode CreateAddressArbiter(u32* arbiter) { using Kernel::AddressArbiter; ResultVal> arbiter_res = AddressArbiter::Create(); if (arbiter_res.Failed()) - return arbiter_res.Code().raw; + return arbiter_res.Code(); ResultVal handle_res = Kernel::g_handle_table.Create(*arbiter_res); if (handle_res.Failed()) - return handle_res.Code().raw; + return handle_res.Code(); LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res); *arbiter = *handle_res; - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Arbitrate address -static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { +static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, s64 nanoseconds) { using Kernel::AddressArbiter; LOG_TRACE(Kernel_SVC, "called handle=0x%08X, address=0x%08X, type=0x%08X, value=0x%08X", handle, @@ -272,10 +272,10 @@ static Result ArbitrateAddress(Handle handle, u32 address, u32 type, u32 value, SharedPtr arbiter = Kernel::g_handle_table.Get(handle); if (arbiter == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); return arbiter->ArbitrateAddress(static_cast(type), - address, value, nanoseconds).raw; + address, value, nanoseconds); } /// Used to output a message on a debug hardware unit - does nothing on a retail unit @@ -284,26 +284,26 @@ static void OutputDebugString(const char* string) { } /// Get resource limit -static Result GetResourceLimit(Handle* resource_limit, Handle process) { +static ResultCode GetResourceLimit(Handle* resource_limit, Handle process) { // With regards to proceess values: // 0xFFFF8001 is a handle alias for the current KProcess, and 0xFFFF8000 is a handle alias for // the current KThread. *resource_limit = 0xDEADBEEF; LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called process=0x%08X", process); - return 0; + return RESULT_SUCCESS; } /// Get resource limit current values -static Result GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names, +static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_limit, void* names, s32 name_count) { LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called resource_limit=%08X, names=%s, name_count=%d", resource_limit, names, name_count); Memory::Write32(Core::g_app_core->GetReg(0), 0); // Normmatt: Set used memory to 0 for now - return 0; + return RESULT_SUCCESS; } /// Creates a new thread -static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { +static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { using Kernel::Thread; std::string name; @@ -317,7 +317,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top ResultVal> thread_res = Kernel::Thread::Create( name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE); if (thread_res.Failed()) - return thread_res.Code().raw; + return thread_res.Code(); SharedPtr thread = std::move(*thread_res); // TODO(yuriks): Create new handle instead of using built-in @@ -332,7 +332,7 @@ static Result CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); } - return 0; + return RESULT_SUCCESS; } /// Called when a thread exits @@ -344,214 +344,214 @@ static void ExitThread() { } /// Gets the priority for the specified thread -static Result GetThreadPriority(s32* priority, Handle handle) { +static ResultCode GetThreadPriority(s32* priority, Handle handle) { const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); *priority = thread->GetPriority(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Sets the priority for the specified thread -static Result SetThreadPriority(Handle handle, s32 priority) { +static ResultCode SetThreadPriority(Handle handle, s32 priority) { SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); thread->SetPriority(priority); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Create a mutex -static Result CreateMutex(Handle* handle, u32 initial_locked) { +static ResultCode CreateMutex(Handle* handle, u32 initial_locked) { using Kernel::Mutex; auto mutex_res = Mutex::Create(initial_locked != 0); if (mutex_res.Failed()) - return mutex_res.Code().raw; + return mutex_res.Code(); SharedPtr mutex = mutex_res.MoveFrom(); *handle = Kernel::g_handle_table.Create(mutex).MoveFrom(); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", initial_locked ? "true" : "false", *handle); - return 0; + return RESULT_SUCCESS; } /// Release a mutex -static Result ReleaseMutex(Handle handle) { +static ResultCode ReleaseMutex(Handle handle) { using Kernel::Mutex; LOG_TRACE(Kernel_SVC, "called handle=0x%08X", handle); SharedPtr mutex = Kernel::g_handle_table.Get(handle); if (mutex == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); mutex->Release(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Get the ID for the specified thread. -static Result GetThreadId(u32* thread_id, Handle handle) { +static ResultCode GetThreadId(u32* thread_id, Handle handle) { LOG_TRACE(Kernel_SVC, "called thread=0x%08X", handle); const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); *thread_id = thread->GetThreadId(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Creates a semaphore -static Result CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { +static ResultCode CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { using Kernel::Semaphore; ResultVal> semaphore_res = Semaphore::Create(initial_count, max_count); if (semaphore_res.Failed()) - return semaphore_res.Code().raw; + return semaphore_res.Code(); ResultVal handle_res = Kernel::g_handle_table.Create(*semaphore_res); if (handle_res.Failed()) - return handle_res.Code().raw; + return handle_res.Code(); *semaphore = *handle_res; LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", initial_count, max_count, *semaphore); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Releases a certain number of slots in a semaphore -static Result ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { +static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) { using Kernel::Semaphore; LOG_TRACE(Kernel_SVC, "called release_count=%d, handle=0x%08X", release_count, handle); SharedPtr semaphore = Kernel::g_handle_table.Get(handle); if (semaphore == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); ResultVal release_res = semaphore->Release(release_count); if (release_res.Failed()) - return release_res.Code().raw; + return release_res.Code(); *count = *release_res; - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Query memory -static Result QueryMemory(void* info, void* out, u32 addr) { +static ResultCode QueryMemory(void* info, void* out, u32 addr) { LOG_ERROR(Kernel_SVC, "(UNIMPLEMENTED) called addr=0x%08X", addr); - return 0; + return RESULT_SUCCESS; } /// Create an event -static Result CreateEvent(Handle* handle, u32 reset_type) { +static ResultCode CreateEvent(Handle* handle, u32 reset_type) { auto evt_res = Kernel::Event::Create(static_cast(reset_type)); if (evt_res.Failed()) - return evt_res.Code().raw; + return evt_res.Code(); auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom()); if (handle_res.Failed()) - return handle_res.Code().raw; + return handle_res.Code(); *handle = handle_res.MoveFrom(); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Duplicates a kernel handle -static Result DuplicateHandle(Handle* out, Handle handle) { +static ResultCode DuplicateHandle(Handle* out, Handle handle) { ResultVal out_h = Kernel::g_handle_table.Duplicate(handle); if (out_h.Succeeded()) { *out = *out_h; LOG_TRACE(Kernel_SVC, "duplicated 0x%08X to 0x%08X", handle, *out); } - return out_h.Code().raw; + return out_h.Code(); } /// Signals an event -static Result SignalEvent(Handle handle) { +static ResultCode SignalEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); auto evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); evt->Signal(); HLE::Reschedule(__func__); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Clears an event -static Result ClearEvent(Handle handle) { +static ResultCode ClearEvent(Handle handle) { LOG_TRACE(Kernel_SVC, "called event=0x%08X", handle); auto evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); evt->Clear(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Creates a timer -static Result CreateTimer(Handle* handle, u32 reset_type) { +static ResultCode CreateTimer(Handle* handle, u32 reset_type) { using Kernel::Timer; auto timer_res = Timer::Create(static_cast(reset_type)); if (timer_res.Failed()) - return timer_res.Code().raw; + return timer_res.Code(); auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom()); if (handle_res.Failed()) - return handle_res.Code().raw; + return handle_res.Code(); *handle = handle_res.MoveFrom(); LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Clears a timer -static Result ClearTimer(Handle handle) { +static ResultCode ClearTimer(Handle handle) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); timer->Clear(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Starts a timer -static Result SetTimer(Handle handle, s64 initial, s64 interval) { +static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); timer->Set(initial, interval); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Cancels a timer -static Result CancelTimer(Handle handle) { +static ResultCode CancelTimer(Handle handle) { using Kernel::Timer; LOG_TRACE(Kernel_SVC, "called timer=0x%08X", handle); SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel).raw; + return InvalidHandle(ErrorModule::Kernel); timer->Cancel(); - return RESULT_SUCCESS.raw; + return RESULT_SUCCESS; } /// Sleep the current thread @@ -573,22 +573,22 @@ static s64 GetSystemTick() { } /// Creates a memory block at the specified address with the specified permissions and size -static Result CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, +static ResultCode CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, u32 other_permission) { using Kernel::SharedMemory; // TODO(Subv): Implement this function ResultVal> shared_memory_res = SharedMemory::Create(); if (shared_memory_res.Failed()) - return shared_memory_res.Code().raw; + return shared_memory_res.Code(); ResultVal handle_res = Kernel::g_handle_table.Create(*shared_memory_res); if (handle_res.Failed()) - return handle_res.Code().raw; + return handle_res.Code(); *memblock = *handle_res; LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); - return 0; + return RESULT_SUCCESS; } const HLE::FunctionDef SVC_Table[] = { -- cgit v1.2.3 From 09ae6e1fa38bbf75dcb2796e96575fdba32ec69c Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 23 Jan 2015 03:44:52 -0200 Subject: Remove result.h InvalidHandle It was only being used in two places, where it was replaced by a local constant. --- src/core/hle/svc.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) (limited to 'src/core/hle/svc.cpp') diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index bec9837a4..46fca51c7 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp @@ -26,6 +26,7 @@ // Namespace SVC using Kernel::SharedPtr; +using Kernel::ERR_INVALID_HANDLE; namespace SVC { @@ -71,7 +72,7 @@ static ResultCode MapMemoryBlock(Handle handle, u32 addr, u32 permissions, u32 o SharedPtr shared_memory = Kernel::g_handle_table.Get(handle); if (shared_memory == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; MemoryPermission permissions_type = static_cast(permissions); switch (permissions_type) { @@ -108,7 +109,7 @@ static ResultCode ConnectToPort(Handle* out, const char* port_name) { static ResultCode SendSyncRequest(Handle handle) { SharedPtr session = Kernel::g_handle_table.Get(handle); if (session == nullptr) { - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; } LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s)", handle, session->GetName().c_str()); @@ -127,7 +128,7 @@ static ResultCode CloseHandle(Handle handle) { static ResultCode WaitSynchronization1(Handle handle, s64 nano_seconds) { auto object = Kernel::g_handle_table.GetWaitObject(handle); if (object == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; LOG_TRACE(Kernel_SVC, "called handle=0x%08X(%s:%s), nanoseconds=%lld", handle, object->GetTypeName().c_str(), object->GetName().c_str(), nano_seconds); @@ -176,7 +177,7 @@ static ResultCode WaitSynchronizationN(s32* out, Handle* handles, s32 handle_cou for (int i = 0; i < handle_count; ++i) { auto object = Kernel::g_handle_table.GetWaitObject(handles[i]); if (object == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; // Check if the current thread should wait on this object... if (object->ShouldWait()) { @@ -272,7 +273,7 @@ static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 val SharedPtr arbiter = Kernel::g_handle_table.Get(handle); if (arbiter == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; return arbiter->ArbitrateAddress(static_cast(type), address, value, nanoseconds); @@ -347,7 +348,7 @@ static void ExitThread() { static ResultCode GetThreadPriority(s32* priority, Handle handle) { const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; *priority = thread->GetPriority(); return RESULT_SUCCESS; @@ -357,7 +358,7 @@ static ResultCode GetThreadPriority(s32* priority, Handle handle) { static ResultCode SetThreadPriority(Handle handle, s32 priority) { SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; thread->SetPriority(priority); return RESULT_SUCCESS; @@ -386,7 +387,7 @@ static ResultCode ReleaseMutex(Handle handle) { SharedPtr mutex = Kernel::g_handle_table.Get(handle); if (mutex == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; mutex->Release(); return RESULT_SUCCESS; @@ -398,7 +399,7 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) { const SharedPtr thread = Kernel::g_handle_table.Get(handle); if (thread == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; *thread_id = thread->GetThreadId(); return RESULT_SUCCESS; @@ -430,7 +431,7 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) SharedPtr semaphore = Kernel::g_handle_table.Get(handle); if (semaphore == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; ResultVal release_res = semaphore->Release(release_count); if (release_res.Failed()) @@ -476,7 +477,7 @@ static ResultCode SignalEvent(Handle handle) { auto evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; evt->Signal(); HLE::Reschedule(__func__); @@ -489,7 +490,7 @@ static ResultCode ClearEvent(Handle handle) { auto evt = Kernel::g_handle_table.Get(handle); if (evt == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; evt->Clear(); return RESULT_SUCCESS; @@ -520,7 +521,7 @@ static ResultCode ClearTimer(Handle handle) { SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; timer->Clear(); return RESULT_SUCCESS; @@ -534,7 +535,7 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; timer->Set(initial, interval); return RESULT_SUCCESS; @@ -548,7 +549,7 @@ static ResultCode CancelTimer(Handle handle) { SharedPtr timer = Kernel::g_handle_table.Get(handle); if (timer == nullptr) - return InvalidHandle(ErrorModule::Kernel); + return ERR_INVALID_HANDLE; timer->Cancel(); return RESULT_SUCCESS; -- cgit v1.2.3 From 58b544db9958078098a8daf6316cbb58faa729dc Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 23 Jan 2015 04:00:39 -0200 Subject: SVC: Use CASCADE_RESULT in SVC handlers --- src/core/hle/svc.cpp | 105 ++++++++++++++++----------------------------------- 1 file changed, 32 insertions(+), 73 deletions(-) (limited to 'src/core/hle/svc.cpp') 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 } /// Create an address arbiter (to allocate access to shared resources) -static ResultCode CreateAddressArbiter(u32* arbiter) { +static ResultCode CreateAddressArbiter(Handle* out_handle) { using Kernel::AddressArbiter; - ResultVal> arbiter_res = AddressArbiter::Create(); - if (arbiter_res.Failed()) - return arbiter_res.Code(); - - ResultVal handle_res = Kernel::g_handle_table.Create(*arbiter_res); - if (handle_res.Failed()) - return handle_res.Code(); - - LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *handle_res); - - *arbiter = *handle_res; + CASCADE_RESULT(SharedPtr arbiter, AddressArbiter::Create()); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(arbiter))); + LOG_TRACE(Kernel_SVC, "returned handle=0x%08X", *out_handle); return RESULT_SUCCESS; } @@ -304,7 +296,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim } /// Creates a new thread -static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { +static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { using Kernel::Thread; std::string name; @@ -315,18 +307,13 @@ static ResultCode CreateThread(u32 priority, u32 entry_point, u32 arg, u32 stack name = Common::StringFromFormat("unknown-%08x", entry_point); } - ResultVal> thread_res = Kernel::Thread::Create( - name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE); - if (thread_res.Failed()) - return thread_res.Code(); - SharedPtr thread = std::move(*thread_res); - - // TODO(yuriks): Create new handle instead of using built-in - Core::g_app_core->SetReg(1, thread->GetHandle()); + CASCADE_RESULT(SharedPtr thread, Kernel::Thread::Create( + name, entry_point, priority, arg, processor_id, stack_top, Kernel::DEFAULT_STACK_SIZE)); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); 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->GetHandle()); + name.c_str(), arg, stack_top, priority, processor_id, *out_handle); if (THREADPROCESSORID_1 == processor_id) { LOG_WARNING(Kernel_SVC, @@ -365,17 +352,14 @@ static ResultCode SetThreadPriority(Handle handle, s32 priority) { } /// Create a mutex -static ResultCode CreateMutex(Handle* handle, u32 initial_locked) { +static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { using Kernel::Mutex; - auto mutex_res = Mutex::Create(initial_locked != 0); - if (mutex_res.Failed()) - return mutex_res.Code(); - SharedPtr mutex = mutex_res.MoveFrom(); + CASCADE_RESULT(SharedPtr mutex, Mutex::Create(initial_locked != 0)); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); - *handle = Kernel::g_handle_table.Create(mutex).MoveFrom(); LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", - initial_locked ? "true" : "false", *handle); + initial_locked ? "true" : "false", *out_handle); return RESULT_SUCCESS; } @@ -406,20 +390,14 @@ static ResultCode GetThreadId(u32* thread_id, Handle handle) { } /// Creates a semaphore -static ResultCode CreateSemaphore(Handle* semaphore, s32 initial_count, s32 max_count) { +static ResultCode CreateSemaphore(Handle* out_handle, s32 initial_count, s32 max_count) { using Kernel::Semaphore; - ResultVal> semaphore_res = Semaphore::Create(initial_count, max_count); - if (semaphore_res.Failed()) - return semaphore_res.Code(); - - ResultVal handle_res = Kernel::g_handle_table.Create(*semaphore_res); - if (handle_res.Failed()) - return handle_res.Code(); + CASCADE_RESULT(SharedPtr semaphore, Semaphore::Create(initial_count, max_count)); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(semaphore))); - *semaphore = *handle_res; LOG_TRACE(Kernel_SVC, "called initial_count=%d, max_count=%d, created handle=0x%08X", - initial_count, max_count, *semaphore); + initial_count, max_count, *out_handle); return RESULT_SUCCESS; } @@ -433,11 +411,7 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) if (semaphore == nullptr) return ERR_INVALID_HANDLE; - ResultVal release_res = semaphore->Release(release_count); - if (release_res.Failed()) - return release_res.Code(); - - *count = *release_res; + CASCADE_RESULT(*count, semaphore->Release(release_count)); return RESULT_SUCCESS; } @@ -448,16 +422,12 @@ static ResultCode QueryMemory(void* info, void* out, u32 addr) { } /// Create an event -static ResultCode CreateEvent(Handle* handle, u32 reset_type) { - auto evt_res = Kernel::Event::Create(static_cast(reset_type)); - if (evt_res.Failed()) - return evt_res.Code(); - auto handle_res = Kernel::g_handle_table.Create(evt_res.MoveFrom()); - if (handle_res.Failed()) - return handle_res.Code(); - *handle = handle_res.MoveFrom(); - - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); +static ResultCode CreateEvent(Handle* out_handle, u32 reset_type) { + CASCADE_RESULT(auto evt, Kernel::Event::Create(static_cast(reset_type))); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(evt))); + + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", + reset_type, *out_handle); return RESULT_SUCCESS; } @@ -497,19 +467,14 @@ static ResultCode ClearEvent(Handle handle) { } /// Creates a timer -static ResultCode CreateTimer(Handle* handle, u32 reset_type) { +static ResultCode CreateTimer(Handle* out_handle, u32 reset_type) { using Kernel::Timer; - auto timer_res = Timer::Create(static_cast(reset_type)); - if (timer_res.Failed()) - return timer_res.Code(); + CASCADE_RESULT(auto timer, Timer::Create(static_cast(reset_type))); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(timer))); - auto handle_res = Kernel::g_handle_table.Create(timer_res.MoveFrom()); - if (handle_res.Failed()) - return handle_res.Code(); - *handle = handle_res.MoveFrom(); - - LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", reset_type, *handle); + LOG_TRACE(Kernel_SVC, "called reset_type=0x%08X : created handle=0x%08X", + reset_type, *out_handle); return RESULT_SUCCESS; } @@ -574,20 +539,14 @@ static s64 GetSystemTick() { } /// Creates a memory block at the specified address with the specified permissions and size -static ResultCode CreateMemoryBlock(Handle* memblock, u32 addr, u32 size, u32 my_permission, +static ResultCode CreateMemoryBlock(Handle* out_handle, u32 addr, u32 size, u32 my_permission, u32 other_permission) { using Kernel::SharedMemory; // TODO(Subv): Implement this function - ResultVal> shared_memory_res = SharedMemory::Create(); - if (shared_memory_res.Failed()) - return shared_memory_res.Code(); - - ResultVal handle_res = Kernel::g_handle_table.Create(*shared_memory_res); - if (handle_res.Failed()) - return handle_res.Code(); + CASCADE_RESULT(auto shared_memory, SharedMemory::Create()); + CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(shared_memory))); - *memblock = *handle_res; LOG_WARNING(Kernel_SVC, "(STUBBED) called addr=0x%08X", addr); return RESULT_SUCCESS; } -- cgit v1.2.3