summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel/event.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/event.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/event.cpp')
-rw-r--r--src/core/hle/kernel/event.cpp38
1 files changed, 19 insertions, 19 deletions
diff --git a/src/core/hle/kernel/event.cpp b/src/core/hle/kernel/event.cpp
index e0117c0bc..8a2925a3c 100644
--- a/src/core/hle/kernel/event.cpp
+++ b/src/core/hle/kernel/event.cpp
@@ -35,8 +35,8 @@ public:
35 * @param wait Boolean wait set if current thread should wait as a result of sync operation 35 * @param wait Boolean wait set if current thread should wait as a result of sync operation
36 * @return Result of operation, 0 on success, otherwise error code 36 * @return Result of operation, 0 on success, otherwise error code
37 */ 37 */
38 Result WaitSynchronization(bool* wait) override { 38 ResultVal<bool> WaitSynchronization() override {
39 *wait = locked; 39 bool wait = locked;
40 if (locked) { 40 if (locked) {
41 Handle thread = GetCurrentThreadHandle(); 41 Handle thread = GetCurrentThreadHandle();
42 if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) { 42 if (std::find(waiting_threads.begin(), waiting_threads.end(), thread) == waiting_threads.end()) {
@@ -47,7 +47,7 @@ public:
47 if (reset_type != RESETTYPE_STICKY && !permanent_locked) { 47 if (reset_type != RESETTYPE_STICKY && !permanent_locked) {
48 locked = true; 48 locked = true;
49 } 49 }
50 return 0; 50 return MakeResult<bool>(wait);
51 } 51 }
52}; 52};
53 53
@@ -57,12 +57,12 @@ public:
57 * @param permanent_locked Boolean permanent locked value to set event 57 * @param permanent_locked Boolean permanent locked value to set event
58 * @return Result of operation, 0 on success, otherwise error code 58 * @return Result of operation, 0 on success, otherwise error code
59 */ 59 */
60Result SetPermanentLock(Handle handle, const bool permanent_locked) { 60ResultCode SetPermanentLock(Handle handle, const bool permanent_locked) {
61 Event* evt = g_object_pool.GetFast<Event>(handle); 61 Event* evt = g_object_pool.Get<Event>(handle);
62 _assert_msg_(KERNEL, (evt != nullptr), "called, but event is nullptr!"); 62 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
63 63
64 evt->permanent_locked = permanent_locked; 64 evt->permanent_locked = permanent_locked;
65 return 0; 65 return RESULT_SUCCESS;
66} 66}
67 67
68/** 68/**
@@ -71,14 +71,14 @@ Result SetPermanentLock(Handle handle, const bool permanent_locked) {
71 * @param locked Boolean locked value to set event 71 * @param locked Boolean locked value to set event
72 * @return Result of operation, 0 on success, otherwise error code 72 * @return Result of operation, 0 on success, otherwise error code
73 */ 73 */
74Result SetEventLocked(const Handle handle, const bool locked) { 74ResultCode SetEventLocked(const Handle handle, const bool locked) {
75 Event* evt = g_object_pool.GetFast<Event>(handle); 75 Event* evt = g_object_pool.Get<Event>(handle);
76 _assert_msg_(KERNEL, (evt != nullptr), "called, but event is nullptr!"); 76 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
77 77
78 if (!evt->permanent_locked) { 78 if (!evt->permanent_locked) {
79 evt->locked = locked; 79 evt->locked = locked;
80 } 80 }
81 return 0; 81 return RESULT_SUCCESS;
82} 82}
83 83
84/** 84/**
@@ -86,9 +86,9 @@ Result SetEventLocked(const Handle handle, const bool locked) {
86 * @param handle Handle to event to signal 86 * @param handle Handle to event to signal
87 * @return Result of operation, 0 on success, otherwise error code 87 * @return Result of operation, 0 on success, otherwise error code
88 */ 88 */
89Result SignalEvent(const Handle handle) { 89ResultCode SignalEvent(const Handle handle) {
90 Event* evt = g_object_pool.GetFast<Event>(handle); 90 Event* evt = g_object_pool.Get<Event>(handle);
91 _assert_msg_(KERNEL, (evt != nullptr), "called, but event is nullptr!"); 91 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
92 92
93 // Resume threads waiting for event to signal 93 // Resume threads waiting for event to signal
94 bool event_caught = false; 94 bool event_caught = false;
@@ -106,7 +106,7 @@ Result SignalEvent(const Handle handle) {
106 if (!evt->permanent_locked) { 106 if (!evt->permanent_locked) {
107 evt->locked = event_caught; 107 evt->locked = event_caught;
108 } 108 }
109 return 0; 109 return RESULT_SUCCESS;
110} 110}
111 111
112/** 112/**
@@ -114,14 +114,14 @@ Result SignalEvent(const Handle handle) {
114 * @param handle Handle to event to clear 114 * @param handle Handle to event to clear
115 * @return Result of operation, 0 on success, otherwise error code 115 * @return Result of operation, 0 on success, otherwise error code
116 */ 116 */
117Result ClearEvent(Handle handle) { 117ResultCode ClearEvent(Handle handle) {
118 Event* evt = g_object_pool.GetFast<Event>(handle); 118 Event* evt = g_object_pool.Get<Event>(handle);
119 _assert_msg_(KERNEL, (evt != nullptr), "called, but event is nullptr!"); 119 if (evt == nullptr) return InvalidHandle(ErrorModule::Kernel);
120 120
121 if (!evt->permanent_locked) { 121 if (!evt->permanent_locked) {
122 evt->locked = true; 122 evt->locked = true;
123 } 123 }
124 return 0; 124 return RESULT_SUCCESS;
125} 125}
126 126
127/** 127/**