From 505042bc7330afa45f239898d816aae1b7bfa827 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 28 Mar 2019 17:17:10 -0400 Subject: [PATCH] Added ErrorCode and the funcs for it, funcs which use low/desc now use this instead. Updated docs. --- nx/include/switch/applets/error.h | 123 +++++++++++++++++++----------- nx/source/applets/error.c | 40 ++++++++-- 2 files changed, 111 insertions(+), 52 deletions(-) diff --git a/nx/include/switch/applets/error.h b/nx/include/switch/applets/error.h index a4f510b4..babc1a19 100644 --- a/nx/include/switch/applets/error.h +++ b/nx/include/switch/applets/error.h @@ -9,104 +9,140 @@ #include "../services/applet.h" #include "../services/set.h" +/// Stores error-codes which are displayed as XXXX-XXXX, low for the former and desc for the latter. typedef struct { - char str[0x1f4]; - u8 unk_x1f4[0xc]; + u32 low; ///< The module portion of the error, normally this should be set to module + 2000. + u32 desc; ///< The error description. +} ErrorCode; + +/// Error context. +typedef struct { + char str[0x1f4]; ///< String + u8 unk_x1f4[0xc]; ///< Unknown } PACKED ErrorContext; /// Common header for the start of the arg storage. typedef struct { - u8 type; + u8 type; ///< Type u8 jumpFlag; ///< When clear, this indicates WithoutJump. - u8 unk_x2[3]; - u8 contextFlag; - u8 resultFlag; ///< \ref ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res. + u8 unk_x2[3]; ///< Unknown + u8 contextFlag; ///< When set with type=0, indicates that an additional storage is pushed for \ref ErrorResultBacktrace. [4.0.0+] Otherwise, when set indicates that an additional storage is pushed for \ref ErrorContext. + u8 resultFlag; ///< ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res. u8 contextFlag2; ///< Similar to contextFlag except for ErrorCommonArg, indicating \ref ErrorContext is used. } ErrorCommonHeader; -/// Error arg data for non-{System/Application}. +/// Common error arg data. typedef struct { - ErrorCommonHeader hdr; - u64 errorCode; - Result res; + ErrorCommonHeader hdr; ///< Common header. + ErrorCode errorCode; ///< \ref ErrorCode + Result res; ///< Result } ErrorCommonArg; /// Error arg data for certain errors with module PCTL. typedef struct { - ErrorCommonHeader hdr; - Result res; + ErrorCommonHeader hdr; ///< Common header. + Result res; ///< Result } ErrorPctlArg; /// ResultBacktrace typedef struct { - s32 count; - Result backtrace[0x20]; + s32 count; ///< Total entries in the backtrace array. + Result backtrace[0x20]; ///< Result backtrace. } ErrorResultBacktrace; +/// Error arg data for EULA. typedef struct { - ErrorCommonHeader hdr; - SetRegion regionCode; + ErrorCommonHeader hdr; ///< Common header. + SetRegion regionCode; ///< \ref SetRegion } ErrorEulaArg; +/// Additional input storage data for \ref errorSystemUpdateEulaShow. typedef struct { - u8 data[0x20000]; + u8 data[0x20000]; ///< data } ErrorEulaData; +/// Error arg data for Record. typedef struct { - ErrorCommonHeader hdr; - u64 errorCode; - u64 timestamp; ///< POSIX timestamp. + ErrorCommonHeader hdr; ///< Common header. + ErrorCode errorCode; ///< \ref ErrorCode + u64 timestamp; ///< POSIX timestamp. } ErrorRecordArg; /// SystemErrorArg typedef struct { - ErrorCommonHeader hdr; - u64 errorCode; - u64 languageCode; + ErrorCommonHeader hdr; ///< Common header. + ErrorCode errorCode; ///< \ref ErrorCode + u64 languageCode; ///< See set.h. char dialogMessage[0x800]; ///< UTF-8 Dialog message. char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details"). } ErrorSystemArg; +/// Error system config. typedef struct { - ErrorSystemArg arg; - ErrorContext ctx; + ErrorSystemArg arg; ///< Arg data. + ErrorContext ctx; ///< Optional error context. } ErrorSystemConfig; /// ApplicationErrorArg typedef struct { - ErrorCommonHeader hdr; - u32 errorNumber; - u64 languageCode; + ErrorCommonHeader hdr; ///< Common header. + u32 errorNumber; ///< Raw decimal error number which is displayed in the dialog. + u64 languageCode; ///< See set.h. char dialogMessage[0x800]; ///< UTF-8 Dialog message. char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details"). } PACKED ErrorApplicationArg; +/// Error application config. typedef struct { - ErrorApplicationArg arg; - ErrorContext ctx; + ErrorApplicationArg arg; ///< Arg data. } ErrorApplicationConfig; +/** + * @brief Creates an \ref ErrorCode. + * @param low The module portion of the error, normally this should be set to module + 2000. + * @param desc The error description. + */ +ErrorCode errorCodeCreate(u32 low, u32 desc); + +/** + * @brief Creates an \ref ErrorCode with the input Result. Wrapper for \ref errorCodeCreate. + * @param res Input Result. + */ +ErrorCode errorCodeCreateResult(Result res); + +/** + * @brief Creates an invalid \ref ErrorCode. + */ +ErrorCode errorCodeCreateInvalid(void); + +/** + * @brief Checks whether the input ErrorCode is valid. + * @param errorCode \ref ErrorCode + */ +bool errorCodeIsValid(ErrorCode errorCode); + /** * @brief Launches the applet for displaying the specified Result. * @param res Result * @param jumpFlag Jump flag, normally this is true. * @param ctx \ref ErrorContext, unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+]. * @note Sets the following fields: jumpFlag and contextFlag2. Uses type=0 normally. - * @note For module=PCTL errors with desc 100-119 this sets \ref ErrorCommonHeader type=4, in which case the applet will display the following dialog (without the report logging mentioned below): "This software is restricted by Parental Controls". - * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! + * @note For module=PCTL errors with desc 100-119 this sets \ref ErrorCommonHeader type=4, in which case the applet will display the following special dialog: "This software is restricted by Parental Controls". + * @note If the input Result is 0xC8A2, the applet will display a special dialog regarding the current application requiring a software update, with buttons "Later" and "Restart". + * @note [3.0.0+] If the input Result is 0xCAA2, the applet will display a special dialog related to DLC version. + * @warning This applet creates an error report that is logged in the system, when not handling the above special dialogs. Proceed at your own risk! */ Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx); /** * @brief Launches the applet for displaying the specified ErrorCode. - * @param low The module portion of the error, normally this should be set to module + 2000. - * @param desc The error description. + * @param errorCode \ref ErrorCode * @param jumpFlag Jump flag, normally this is true. * @param ctx \ref ErrorContext, unused when jumpFlag=false. Ignored on pre-4.0.0, since it's only available for [4.0.0+]. * @note Sets the following fields: jumpFlag and contextFlag2. type=0 and resultFlag=1. * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! */ -Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx); +Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx); /** * @brief Creates an ErrorResultBacktrace struct. @@ -126,6 +162,7 @@ void errorResultBacktraceClose(ErrorResultBacktrace* backtrace); * @brief Launches the applet for \ref ErrorResultBacktrace. * @param backtrace ErrorResultBacktrace struct. * @param res Result + * @note Sets the following fields: type=0, jumpFlag=1, and contextFlag=1. * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! */ Result errorResultBacktraceShow(Result res, ErrorResultBacktrace* backtrace); @@ -147,18 +184,17 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula); * @brief Launches the applet for displaying an error full-screen, using the specified Result and timestamp. * @param res Result * @param timestamp POSIX timestamp. - * @note Wrapper for \ref errorCodeRecordShow. - * @note The applet does not log an error report for this. + * @note Wrapper for \ref errorCodeRecordShow, see \ref errorCodeRecordShow notes. */ Result errorResultRecordShow(Result res, u64 timestamp); /** * @brief Launches the applet for displaying an error full-screen, using the specified ErrorCode and timestamp. - * @param low The module portion of the error, normally this should be set to module + 2000. - * @param desc The error description. - * @note The applet does not log an error report for this. + * @param errorCode \ref ErrorCode + * @param timestamp POSIX timestamp. + * @note The applet does not log an error report for this. error*RecordShow is used by qlaunch for displaying previously logged error reports. */ -Result errorCodeRecordShow(u32 low, u32 desc, u64 timestamp); +Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp); /** * @brief Creates an ErrorSystemConfig struct. @@ -186,10 +222,9 @@ Result errorSystemShow(ErrorSystemConfig* c); /** * @brief Sets the error code. * @param c ErrorSystemConfig struct. - * @param low The module portion of the error, normally this should be set to module + 2000. - * @param desc The error description. + * @param errorCode \ref ErrorCode */ -void errorSystemSetCode(ErrorSystemConfig* c, u32 low, u32 desc); +void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode); /** * @brief Sets the error code, using the input Result. Wrapper for \ref errorSystemSetCode. diff --git a/nx/source/applets/error.c b/nx/source/applets/error.c index 4ed0c468..38b1f2d3 100644 --- a/nx/source/applets/error.c +++ b/nx/source/applets/error.c @@ -76,6 +76,30 @@ static Result _errorShowContext(const void* indata, size_t insize, ErrorContext* return _errorShow(indata, insize, ctx_ptr, ctx_size); } +// Code + +ErrorCode errorCodeCreate(u32 low, u32 desc) { + ErrorCode c; + + c.low = low; + c.desc = desc; + + return c; +} + +ErrorCode errorCodeCreateResult(Result res) { + return errorCodeCreate(2000 + R_MODULE(res), R_DESCRIPTION(res)); +} + +ErrorCode errorCodeCreateInvalid(void) { + ErrorCode c={0}; + return c; +} + +bool errorCodeIsValid(ErrorCode errorCode) { + return errorCode.low!=0; +} + // {Result/Code}Show Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { @@ -108,7 +132,7 @@ Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { } } -Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx) { +Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx) { if (!jumpFlag) ctx = NULL; bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL; ErrorCommonArg arg; @@ -118,7 +142,7 @@ Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx) { arg.hdr.jumpFlag = jumpFlag!=0; if (flag) arg.hdr.contextFlag2 = 1; arg.hdr.resultFlag = 1; - arg.errorCode = (u64)low | ((u64)desc<<32); + arg.errorCode = errorCode; return _errorShowContext(&arg, sizeof(arg), ctx); } @@ -194,16 +218,16 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) { // Record Result errorResultRecordShow(Result res, u64 timestamp) { - return errorCodeRecordShow(2000 + R_MODULE(res), R_DESCRIPTION(res), timestamp); + return errorCodeRecordShow(errorCodeCreateResult(res), timestamp); } -Result errorCodeRecordShow(u32 low, u32 desc, u64 timestamp) { +Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp) { ErrorRecordArg arg; memset(&arg, 0, sizeof(arg)); arg.hdr.type = 5; arg.hdr.jumpFlag = 1; - arg.errorCode = (u64)low | ((u64)desc<<32); + arg.errorCode = errorCode; arg.timestamp = timestamp; return _errorShow(&arg, sizeof(arg), NULL, 0); @@ -237,12 +261,12 @@ Result errorSystemShow(ErrorSystemConfig* c) { return _errorShowContext(&c->arg, sizeof(c->arg), c->arg.hdr.contextFlag!=0 ? &c->ctx : NULL); } -void errorSystemSetCode(ErrorSystemConfig* c, u32 low, u32 desc) { - c->arg.errorCode = (u64)low | ((u64)desc<<32); +void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode) { + c->arg.errorCode = errorCode; } void errorSystemSetResult(ErrorSystemConfig* c, Result res) { - errorSystemSetCode(c, 2000 + R_MODULE(res), R_DESCRIPTION(res)); + errorSystemSetCode(c, errorCodeCreateResult(res)); } void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode) {