summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar FearlessTobi2024-01-18 22:39:15 +0100
committerGravatar Liam2024-01-25 16:42:06 -0500
commit54372fdff5fd982b4ac08315abcd42d81683b00d (patch)
tree3c9ad14c965a00a0fb12bfe850c2b5373e4099a0
parentfs/errors: Unify naming of result codes (diff)
downloadyuzu-54372fdff5fd982b4ac08315abcd42d81683b00d.tar.gz
yuzu-54372fdff5fd982b4ac08315abcd42d81683b00d.tar.xz
yuzu-54372fdff5fd982b4ac08315abcd42d81683b00d.zip
result: Make fully constexpr, add ON_RESULT_INCLUDED
-rw-r--r--src/core/frontend/applets/error.cpp6
-rw-r--r--src/core/hle/result.h38
-rw-r--r--src/core/hle/service/am/applets/applet_error.cpp4
-rw-r--r--src/core/hle/service/audio/audren_u.cpp3
-rw-r--r--src/core/hle/service/caps/caps_a.cpp13
-rw-r--r--src/core/hle/service/fatal/fatal.cpp4
-rw-r--r--src/core/hle/service/nfc/nfc_interface.cpp2
-rw-r--r--src/core/reporter.cpp4
-rw-r--r--src/yuzu/applets/qt_error.cpp12
9 files changed, 57 insertions, 29 deletions
diff --git a/src/core/frontend/applets/error.cpp b/src/core/frontend/applets/error.cpp
index 2e6f7a3d9..53d4be2e5 100644
--- a/src/core/frontend/applets/error.cpp
+++ b/src/core/frontend/applets/error.cpp
@@ -12,7 +12,7 @@ void DefaultErrorApplet::Close() const {}
12 12
13void DefaultErrorApplet::ShowError(Result error, FinishedCallback finished) const { 13void DefaultErrorApplet::ShowError(Result error, FinishedCallback finished) const {
14 LOG_CRITICAL(Service_Fatal, "Application requested error display: {:04}-{:04} (raw={:08X})", 14 LOG_CRITICAL(Service_Fatal, "Application requested error display: {:04}-{:04} (raw={:08X})",
15 error.module.Value(), error.description.Value(), error.raw); 15 error.GetModule(), error.GetDescription(), error.raw);
16} 16}
17 17
18void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::seconds time, 18void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::seconds time,
@@ -20,7 +20,7 @@ void DefaultErrorApplet::ShowErrorWithTimestamp(Result error, std::chrono::secon
20 LOG_CRITICAL( 20 LOG_CRITICAL(
21 Service_Fatal, 21 Service_Fatal,
22 "Application requested error display: {:04X}-{:04X} (raw={:08X}) with timestamp={:016X}", 22 "Application requested error display: {:04X}-{:04X} (raw={:08X}) with timestamp={:016X}",
23 error.module.Value(), error.description.Value(), error.raw, time.count()); 23 error.GetModule(), error.GetDescription(), error.raw, time.count());
24} 24}
25 25
26void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text, 26void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text,
@@ -28,7 +28,7 @@ void DefaultErrorApplet::ShowCustomErrorText(Result error, std::string main_text
28 FinishedCallback finished) const { 28 FinishedCallback finished) const {
29 LOG_CRITICAL(Service_Fatal, 29 LOG_CRITICAL(Service_Fatal,
30 "Application requested custom error with error_code={:04X}-{:04X} (raw={:08X})", 30 "Application requested custom error with error_code={:04X}-{:04X} (raw={:08X})",
31 error.module.Value(), error.description.Value(), error.raw); 31 error.GetModule(), error.GetDescription(), error.raw);
32 LOG_CRITICAL(Service_Fatal, " Main Text: {}", main_text); 32 LOG_CRITICAL(Service_Fatal, " Main Text: {}", main_text);
33 LOG_CRITICAL(Service_Fatal, " Detail Text: {}", detail_text); 33 LOG_CRITICAL(Service_Fatal, " Detail Text: {}", detail_text);
34} 34}
diff --git a/src/core/hle/result.h b/src/core/hle/result.h
index 749f51f69..316370266 100644
--- a/src/core/hle/result.h
+++ b/src/core/hle/result.h
@@ -189,14 +189,14 @@ enum class ErrorModule : u32 {
189union Result { 189union Result {
190 u32 raw; 190 u32 raw;
191 191
192 BitField<0, 9, ErrorModule> module; 192 using Module = BitField<0, 9, ErrorModule>;
193 BitField<9, 13, u32> description; 193 using Description = BitField<9, 13, u32>;
194 194
195 Result() = default; 195 Result() = default;
196 constexpr explicit Result(u32 raw_) : raw(raw_) {} 196 constexpr explicit Result(u32 raw_) : raw(raw_) {}
197 197
198 constexpr Result(ErrorModule module_, u32 description_) 198 constexpr Result(ErrorModule module_, u32 description_)
199 : raw(module.FormatValue(module_) | description.FormatValue(description_)) {} 199 : raw(Module::FormatValue(module_) | Description::FormatValue(description_)) {}
200 200
201 [[nodiscard]] constexpr bool IsSuccess() const { 201 [[nodiscard]] constexpr bool IsSuccess() const {
202 return raw == 0; 202 return raw == 0;
@@ -211,7 +211,15 @@ union Result {
211 } 211 }
212 212
213 [[nodiscard]] constexpr u32 GetInnerValue() const { 213 [[nodiscard]] constexpr u32 GetInnerValue() const {
214 return static_cast<u32>(module.Value()) | (description << module.bits); 214 return raw;
215 }
216
217 [[nodiscard]] constexpr ErrorModule GetModule() const {
218 return Module::ExtractValue(raw);
219 }
220
221 [[nodiscard]] constexpr u32 GetDescription() const {
222 return Description::ExtractValue(raw);
215 } 223 }
216 224
217 [[nodiscard]] constexpr bool Includes(Result result) const { 225 [[nodiscard]] constexpr bool Includes(Result result) const {
@@ -274,8 +282,9 @@ public:
274 } 282 }
275 283
276 [[nodiscard]] constexpr bool Includes(Result other) const { 284 [[nodiscard]] constexpr bool Includes(Result other) const {
277 return code.module == other.module && code.description <= other.description && 285 return code.GetModule() == other.GetModule() &&
278 other.description <= description_end; 286 code.GetDescription() <= other.GetDescription() &&
287 other.GetDescription() <= description_end;
279 } 288 }
280 289
281private: 290private:
@@ -330,6 +339,16 @@ constexpr bool EvaluateResultFailure(const Result& r) {
330 return R_FAILED(r); 339 return R_FAILED(r);
331} 340}
332 341
342template <auto... R>
343constexpr bool EvaluateAnyResultIncludes(const Result& r) {
344 return ((r == R) || ...);
345}
346
347template <auto... R>
348constexpr bool EvaluateResultNotIncluded(const Result& r) {
349 return !EvaluateAnyResultIncludes<R...>(r);
350}
351
333template <typename T> 352template <typename T>
334constexpr void UpdateCurrentResultReference(T result_reference, Result result) = delete; 353constexpr void UpdateCurrentResultReference(T result_reference, Result result) = delete;
335// Intentionally not defined 354// Intentionally not defined
@@ -371,6 +390,13 @@ constexpr void UpdateCurrentResultReference<const Result>(Result result_referenc
371 DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \ 390 DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \
372 ON_RESULT_SUCCESS_2 391 ON_RESULT_SUCCESS_2
373 392
393#define ON_RESULT_INCLUDED_2(...) \
394 ON_RESULT_RETURN_IMPL(ResultImpl::EvaluateAnyResultIncludes<__VA_ARGS__>)
395
396#define ON_RESULT_INCLUDED(...) \
397 DECLARE_CURRENT_RESULT_REFERENCE_AND_STORAGE(__COUNTER__); \
398 ON_RESULT_INCLUDED_2(__VA_ARGS__)
399
374constexpr inline Result __TmpCurrentResultReference = ResultSuccess; 400constexpr inline Result __TmpCurrentResultReference = ResultSuccess;
375 401
376/// Returns a result. 402/// Returns a result.
diff --git a/src/core/hle/service/am/applets/applet_error.cpp b/src/core/hle/service/am/applets/applet_error.cpp
index 5d17c353f..084bc138c 100644
--- a/src/core/hle/service/am/applets/applet_error.cpp
+++ b/src/core/hle/service/am/applets/applet_error.cpp
@@ -27,8 +27,8 @@ struct ErrorCode {
27 27
28 static constexpr ErrorCode FromResult(Result result) { 28 static constexpr ErrorCode FromResult(Result result) {
29 return { 29 return {
30 .error_category{2000 + static_cast<u32>(result.module.Value())}, 30 .error_category{2000 + static_cast<u32>(result.GetModule())},
31 .error_number{result.description.Value()}, 31 .error_number{result.GetDescription()},
32 }; 32 };
33 } 33 }
34 34
diff --git a/src/core/hle/service/audio/audren_u.cpp b/src/core/hle/service/audio/audren_u.cpp
index bd4ca753b..05581e6e0 100644
--- a/src/core/hle/service/audio/audren_u.cpp
+++ b/src/core/hle/service/audio/audren_u.cpp
@@ -139,7 +139,8 @@ private:
139 ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1); 139 ctx.WriteBufferC(performance_buffer.data(), performance_buffer.size(), 1);
140 } 140 }
141 } else { 141 } else {
142 LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!", result.description); 142 LOG_ERROR(Service_Audio, "RequestUpdate failed error 0x{:02X}!",
143 result.GetDescription());
143 } 144 }
144 145
145 IPC::ResponseBuilder rb{ctx, 2}; 146 IPC::ResponseBuilder rb{ctx, 2};
diff --git a/src/core/hle/service/caps/caps_a.cpp b/src/core/hle/service/caps/caps_a.cpp
index 9925720a3..69acb3a8b 100644
--- a/src/core/hle/service/caps/caps_a.cpp
+++ b/src/core/hle/service/caps/caps_a.cpp
@@ -202,14 +202,14 @@ Result IAlbumAccessorService::TranslateResult(Result in_result) {
202 } 202 }
203 203
204 if ((in_result.raw & 0x3801ff) == ResultUnknown1024.raw) { 204 if ((in_result.raw & 0x3801ff) == ResultUnknown1024.raw) {
205 if (in_result.description - 0x514 < 100) { 205 if (in_result.GetDescription() - 0x514 < 100) {
206 return ResultInvalidFileData; 206 return ResultInvalidFileData;
207 } 207 }
208 if (in_result.description - 0x5dc < 100) { 208 if (in_result.GetDescription() - 0x5dc < 100) {
209 return ResultInvalidFileData; 209 return ResultInvalidFileData;
210 } 210 }
211 211
212 if (in_result.description - 0x578 < 100) { 212 if (in_result.GetDescription() - 0x578 < 100) {
213 if (in_result == ResultFileCountLimit) { 213 if (in_result == ResultFileCountLimit) {
214 return ResultUnknown22; 214 return ResultUnknown22;
215 } 215 }
@@ -244,9 +244,10 @@ Result IAlbumAccessorService::TranslateResult(Result in_result) {
244 return ResultUnknown1024; 244 return ResultUnknown1024;
245 } 245 }
246 246
247 if (in_result.module == ErrorModule::FS) { 247 if (in_result.GetModule() == ErrorModule::FS) {
248 if ((in_result.description >> 0xc < 0x7d) || (in_result.description - 1000 < 2000) || 248 if ((in_result.GetDescription() >> 0xc < 0x7d) ||
249 (((in_result.description - 3000) >> 3) < 0x271)) { 249 (in_result.GetDescription() - 1000 < 2000) ||
250 (((in_result.GetDescription() - 3000) >> 3) < 0x271)) {
250 // TODO: Translate FS error 251 // TODO: Translate FS error
251 return in_result; 252 return in_result;
252 } 253 }
diff --git a/src/core/hle/service/fatal/fatal.cpp b/src/core/hle/service/fatal/fatal.cpp
index 31da86074..dfcac1ffd 100644
--- a/src/core/hle/service/fatal/fatal.cpp
+++ b/src/core/hle/service/fatal/fatal.cpp
@@ -73,8 +73,8 @@ static void GenerateErrorReport(Core::System& system, Result error_code, const F
73 "Program entry point: 0x{:16X}\n" 73 "Program entry point: 0x{:16X}\n"
74 "\n", 74 "\n",
75 Common::g_scm_branch, Common::g_scm_desc, title_id, error_code.raw, 75 Common::g_scm_branch, Common::g_scm_desc, title_id, error_code.raw,
76 2000 + static_cast<u32>(error_code.module.Value()), 76 2000 + static_cast<u32>(error_code.GetModule()),
77 static_cast<u32>(error_code.description.Value()), info.set_flags, info.program_entry_point); 77 static_cast<u32>(error_code.GetDescription()), info.set_flags, info.program_entry_point);
78 if (info.backtrace_size != 0x0) { 78 if (info.backtrace_size != 0x0) {
79 crash_report += "Registers:\n"; 79 crash_report += "Registers:\n";
80 for (size_t i = 0; i < info.registers.size(); i++) { 80 for (size_t i = 0; i < info.registers.size(); i++) {
diff --git a/src/core/hle/service/nfc/nfc_interface.cpp b/src/core/hle/service/nfc/nfc_interface.cpp
index 207ac4efe..3e2c7deab 100644
--- a/src/core/hle/service/nfc/nfc_interface.cpp
+++ b/src/core/hle/service/nfc/nfc_interface.cpp
@@ -301,7 +301,7 @@ Result NfcInterface::TranslateResultToServiceError(Result result) const {
301 return result; 301 return result;
302 } 302 }
303 303
304 if (result.module != ErrorModule::NFC) { 304 if (result.GetModule() != ErrorModule::NFC) {
305 return result; 305 return result;
306 } 306 }
307 307
diff --git a/src/core/reporter.cpp b/src/core/reporter.cpp
index dc3883528..1a0138697 100644
--- a/src/core/reporter.cpp
+++ b/src/core/reporter.cpp
@@ -68,8 +68,8 @@ json GetReportCommonData(u64 title_id, Result result, const std::string& timesta
68 auto out = json{ 68 auto out = json{
69 {"title_id", fmt::format("{:016X}", title_id)}, 69 {"title_id", fmt::format("{:016X}", title_id)},
70 {"result_raw", fmt::format("{:08X}", result.raw)}, 70 {"result_raw", fmt::format("{:08X}", result.raw)},
71 {"result_module", fmt::format("{:08X}", static_cast<u32>(result.module.Value()))}, 71 {"result_module", fmt::format("{:08X}", static_cast<u32>(result.GetModule()))},
72 {"result_description", fmt::format("{:08X}", result.description.Value())}, 72 {"result_description", fmt::format("{:08X}", result.GetDescription())},
73 {"timestamp", timestamp}, 73 {"timestamp", timestamp},
74 }; 74 };
75 75
diff --git a/src/yuzu/applets/qt_error.cpp b/src/yuzu/applets/qt_error.cpp
index 1dc4f0383..ad35f4126 100644
--- a/src/yuzu/applets/qt_error.cpp
+++ b/src/yuzu/applets/qt_error.cpp
@@ -25,8 +25,8 @@ void QtErrorDisplay::ShowError(Result error, FinishedCallback finished) const {
25 callback = std::move(finished); 25 callback = std::move(finished);
26 emit MainWindowDisplayError( 26 emit MainWindowDisplayError(
27 tr("Error Code: %1-%2 (0x%3)") 27 tr("Error Code: %1-%2 (0x%3)")
28 .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) 28 .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
29 .arg(error.description, 4, 10, QChar::fromLatin1('0')) 29 .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
30 .arg(error.raw, 8, 16, QChar::fromLatin1('0')), 30 .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
31 tr("An error has occurred.\nPlease try again or contact the developer of the software.")); 31 tr("An error has occurred.\nPlease try again or contact the developer of the software."));
32} 32}
@@ -38,8 +38,8 @@ void QtErrorDisplay::ShowErrorWithTimestamp(Result error, std::chrono::seconds t
38 const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count()); 38 const QDateTime date_time = QDateTime::fromSecsSinceEpoch(time.count());
39 emit MainWindowDisplayError( 39 emit MainWindowDisplayError(
40 tr("Error Code: %1-%2 (0x%3)") 40 tr("Error Code: %1-%2 (0x%3)")
41 .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) 41 .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
42 .arg(error.description, 4, 10, QChar::fromLatin1('0')) 42 .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
43 .arg(error.raw, 8, 16, QChar::fromLatin1('0')), 43 .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
44 tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the " 44 tr("An error occurred on %1 at %2.\nPlease try again or contact the developer of the "
45 "software.") 45 "software.")
@@ -53,8 +53,8 @@ void QtErrorDisplay::ShowCustomErrorText(Result error, std::string dialog_text,
53 callback = std::move(finished); 53 callback = std::move(finished);
54 emit MainWindowDisplayError( 54 emit MainWindowDisplayError(
55 tr("Error Code: %1-%2 (0x%3)") 55 tr("Error Code: %1-%2 (0x%3)")
56 .arg(static_cast<u32>(error.module.Value()) + 2000, 4, 10, QChar::fromLatin1('0')) 56 .arg(static_cast<u32>(error.GetModule()) + 2000, 4, 10, QChar::fromLatin1('0'))
57 .arg(error.description, 4, 10, QChar::fromLatin1('0')) 57 .arg(error.GetDescription(), 4, 10, QChar::fromLatin1('0'))
58 .arg(error.raw, 8, 16, QChar::fromLatin1('0')), 58 .arg(error.raw, 8, 16, QChar::fromLatin1('0')),
59 tr("An error has occurred.\n\n%1\n\n%2") 59 tr("An error has occurred.\n\n%1\n\n%2")
60 .arg(QString::fromStdString(dialog_text)) 60 .arg(QString::fromStdString(dialog_text))