diff options
| author | 2014-10-23 01:20:01 -0200 | |
|---|---|---|
| committer | 2014-11-24 17:08:36 -0200 | |
| commit | c2588403c0b8cf198f13f903f626851c7e94266c (patch) | |
| tree | 09d26cdae187a47338caf94943291c60b4a40a4c /src/core/hle/kernel/kernel.h | |
| parent | Change some SkyEye defines to const ints (diff) | |
| download | yuzu-c2588403c0b8cf198f13f903f626851c7e94266c.tar.gz yuzu-c2588403c0b8cf198f13f903f626851c7e94266c.tar.xz yuzu-c2588403c0b8cf198f13f903f626851c7e94266c.zip | |
HLE: Revamp error handling throrough the HLE code
All service calls in the CTR OS return result codes indicating the
success or failure of the call. Previous to this commit, Citra's HLE
emulation of services and the kernel universally either ignored errors
or returned dummy -1 error codes.
This commit makes an initial effort to provide an infrastructure for
error reporting and propagation which can be use going forward to make
HLE calls accurately return errors as the original system. A few parts
of the code have been updated to use the new system where applicable.
One part of this effort is the definition of the `ResultCode` type,
which provides facilities for constructing and parsing error codes in
the structured format used by the CTR.
The `ResultVal` type builds on `ResultCode` by providing a container for
values returned by function that can report errors. It enforces that
correct error checking will be done on function returns by preventing
the use of the return value if the function returned an error code.
Currently this change is mostly internal since errors are still
suppressed on the ARM<->HLE border, as a temporary compatibility hack.
As functionality is implemented and tested this hack can be eventually
removed.
Diffstat (limited to 'src/core/hle/kernel/kernel.h')
| -rw-r--r-- | src/core/hle/kernel/kernel.h | 44 |
1 files changed, 17 insertions, 27 deletions
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h index e0c94f186..8d3937ce8 100644 --- a/src/core/hle/kernel/kernel.h +++ b/src/core/hle/kernel/kernel.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <string> | 8 | #include <string> |
| 9 | #include "common/common.h" | 9 | #include "common/common.h" |
| 10 | #include "core/hle/result.h" | ||
| 10 | 11 | ||
| 11 | typedef u32 Handle; | 12 | typedef u32 Handle; |
| 12 | typedef s32 Result; | 13 | typedef s32 Result; |
| @@ -52,21 +53,19 @@ public: | |||
| 52 | virtual Kernel::HandleType GetHandleType() const = 0; | 53 | virtual Kernel::HandleType GetHandleType() const = 0; |
| 53 | 54 | ||
| 54 | /** | 55 | /** |
| 55 | * Synchronize kernel object | 56 | * Synchronize kernel object. |
| 56 | * @param wait Boolean wait set if current thread should wait as a result of sync operation | 57 | * @return True if the current thread should wait as a result of the sync |
| 57 | * @return Result of operation, 0 on success, otherwise error code | ||
| 58 | */ | 58 | */ |
| 59 | virtual Result SyncRequest(bool* wait) { | 59 | virtual ResultVal<bool> SyncRequest() { |
| 60 | ERROR_LOG(KERNEL, "(UNIMPLEMENTED)"); | 60 | ERROR_LOG(KERNEL, "(UNIMPLEMENTED)"); |
| 61 | return -1; | 61 | return UnimplementedFunction(ErrorModule::Kernel); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | /** | 64 | /** |
| 65 | * Wait for kernel object to synchronize | 65 | * Wait for kernel object to synchronize. |
| 66 | * @param wait Boolean wait set if current thread should wait as a result of sync operation | 66 | * @return True if the current thread should wait as a result of the wait |
| 67 | * @return Result of operation, 0 on success, otherwise error code | ||
| 68 | */ | 67 | */ |
| 69 | virtual Result WaitSynchronization(bool* wait) = 0; | 68 | virtual ResultVal<bool> WaitSynchronization() = 0; |
| 70 | }; | 69 | }; |
| 71 | 70 | ||
| 72 | class ObjectPool : NonCopyable { | 71 | class ObjectPool : NonCopyable { |
| @@ -80,38 +79,29 @@ public: | |||
| 80 | static Object* CreateByIDType(int type); | 79 | static Object* CreateByIDType(int type); |
| 81 | 80 | ||
| 82 | template <class T> | 81 | template <class T> |
| 83 | u32 Destroy(Handle handle) { | 82 | void Destroy(Handle handle) { |
| 84 | u32 error; | 83 | if (Get<T>(handle)) { |
| 85 | if (Get<T>(handle, error)) { | ||
| 86 | occupied[handle - HANDLE_OFFSET] = false; | 84 | occupied[handle - HANDLE_OFFSET] = false; |
| 87 | delete pool[handle - HANDLE_OFFSET]; | 85 | delete pool[handle - HANDLE_OFFSET]; |
| 88 | } | 86 | } |
| 89 | return error; | ||
| 90 | } | 87 | } |
| 91 | 88 | ||
| 92 | bool IsValid(Handle handle); | 89 | bool IsValid(Handle handle); |
| 93 | 90 | ||
| 94 | template <class T> | 91 | template <class T> |
| 95 | T* Get(Handle handle, u32& outError) { | 92 | T* Get(Handle handle) { |
| 96 | if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) { | 93 | if (handle < HANDLE_OFFSET || handle >= HANDLE_OFFSET + MAX_COUNT || !occupied[handle - HANDLE_OFFSET]) { |
| 97 | // Tekken 6 spams 0x80020001 gets wrong with no ill effects, also on the real PSP | 94 | if (handle != 0) { |
| 98 | if (handle != 0 && (u32)handle != 0x80020001) { | ||
| 99 | WARN_LOG(KERNEL, "Kernel: Bad object handle %i (%08x)", handle, handle); | 95 | WARN_LOG(KERNEL, "Kernel: Bad object handle %i (%08x)", handle, handle); |
| 100 | } | 96 | } |
| 101 | outError = 0;//T::GetMissingErrorCode(); | 97 | return nullptr; |
| 102 | return 0; | ||
| 103 | } else { | 98 | } else { |
| 104 | // Previously we had a dynamic_cast here, but since RTTI was disabled traditionally, | 99 | Object* t = pool[handle - HANDLE_OFFSET]; |
| 105 | // it just acted as a static case and everything worked. This means that we will never | 100 | if (t->GetHandleType() != T::GetStaticHandleType()) { |
| 106 | // see the Wrong type object error below, but we'll just have to live with that danger. | ||
| 107 | T* t = static_cast<T*>(pool[handle - HANDLE_OFFSET]); | ||
| 108 | if (t == 0 || t->GetHandleType() != T::GetStaticHandleType()) { | ||
| 109 | WARN_LOG(KERNEL, "Kernel: Wrong object type for %i (%08x)", handle, handle); | 101 | WARN_LOG(KERNEL, "Kernel: Wrong object type for %i (%08x)", handle, handle); |
| 110 | outError = 0;//T::GetMissingErrorCode(); | 102 | return nullptr; |
| 111 | return 0; | ||
| 112 | } | 103 | } |
| 113 | outError = 0;//SCE_KERNEL_ERROR_OK; | 104 | return static_cast<T*>(t); |
| 114 | return t; | ||
| 115 | } | 105 | } |
| 116 | } | 106 | } |
| 117 | 107 | ||