summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/mutex.cpp
diff options
context:
space:
mode:
authorGravatar Yuri Kunde Schlesner2014-10-23 01:20:01 -0200
committerGravatar Yuri Kunde Schlesner2014-11-24 17:08:36 -0200
commitc2588403c0b8cf198f13f903f626851c7e94266c (patch)
tree09d26cdae187a47338caf94943291c60b4a40a4c /src/core/hle/kernel/mutex.cpp
parentChange some SkyEye defines to const ints (diff)
downloadyuzu-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/mutex.cpp')
-rw-r--r--src/core/hle/kernel/mutex.cpp25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp
index 31129fd86..e4ff1ef40 100644
--- a/src/core/hle/kernel/mutex.cpp
+++ b/src/core/hle/kernel/mutex.cpp
@@ -32,10 +32,10 @@ public:
32 * @param wait Boolean wait set if current thread should wait as a result of sync operation 32 * @param wait Boolean wait set if current thread should wait as a result of sync operation
33 * @return Result of operation, 0 on success, otherwise error code 33 * @return Result of operation, 0 on success, otherwise error code
34 */ 34 */
35 Result SyncRequest(bool* wait) override { 35 ResultVal<bool> SyncRequest() override {
36 // TODO(bunnei): ImplementMe 36 // TODO(bunnei): ImplementMe
37 locked = true; 37 locked = true;
38 return 0; 38 return MakeResult<bool>(false);
39 } 39 }
40 40
41 /** 41 /**
@@ -43,15 +43,14 @@ public:
43 * @param wait Boolean wait set if current thread should wait as a result of sync operation 43 * @param wait Boolean wait set if current thread should wait as a result of sync operation
44 * @return Result of operation, 0 on success, otherwise error code 44 * @return Result of operation, 0 on success, otherwise error code
45 */ 45 */
46 Result WaitSynchronization(bool* wait) override { 46 ResultVal<bool> WaitSynchronization() override {
47 // TODO(bunnei): ImplementMe 47 // TODO(bunnei): ImplementMe
48 *wait = locked; 48 bool wait = locked;
49
50 if (locked) { 49 if (locked) {
51 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle()); 50 Kernel::WaitCurrentThread(WAITTYPE_MUTEX, GetHandle());
52 } 51 }
53 52
54 return 0; 53 return MakeResult<bool>(wait);
55 } 54 }
56}; 55};
57 56
@@ -119,15 +118,17 @@ bool ReleaseMutex(Mutex* mutex) {
119 * Releases a mutex 118 * Releases a mutex
120 * @param handle Handle to mutex to release 119 * @param handle Handle to mutex to release
121 */ 120 */
122Result ReleaseMutex(Handle handle) { 121ResultCode ReleaseMutex(Handle handle) {
123 Mutex* mutex = Kernel::g_object_pool.GetFast<Mutex>(handle); 122 Mutex* mutex = Kernel::g_object_pool.Get<Mutex>(handle);
124 123 if (mutex == nullptr) return InvalidHandle(ErrorModule::Kernel);
125 _assert_msg_(KERNEL, (mutex != nullptr), "ReleaseMutex tried to release a nullptr mutex!");
126 124
127 if (!ReleaseMutex(mutex)) { 125 if (!ReleaseMutex(mutex)) {
128 return -1; 126 // TODO(yuriks): Verify error code, this one was pulled out of thin air. I'm not even sure
127 // what error condition this is supposed to be signaling.
128 return ResultCode(ErrorDescription::AlreadyDone, ErrorModule::Kernel,
129 ErrorSummary::NothingHappened, ErrorLevel::Temporary);
129 } 130 }
130 return 0; 131 return RESULT_SUCCESS;
131} 132}
132 133
133/** 134/**