Added ErrorCode and the funcs for it, funcs which use low/desc now use this instead. Updated docs.

This commit is contained in:
yellows8 2019-03-28 17:17:10 -04:00
parent 71a711e5d7
commit 505042bc73
2 changed files with 111 additions and 52 deletions

View File

@ -9,104 +9,140 @@
#include "../services/applet.h" #include "../services/applet.h"
#include "../services/set.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 { typedef struct {
char str[0x1f4]; u32 low; ///< The module portion of the error, normally this should be set to module + 2000.
u8 unk_x1f4[0xc]; u32 desc; ///< The error description.
} ErrorCode;
/// Error context.
typedef struct {
char str[0x1f4]; ///< String
u8 unk_x1f4[0xc]; ///< Unknown
} PACKED ErrorContext; } PACKED ErrorContext;
/// Common header for the start of the arg storage. /// Common header for the start of the arg storage.
typedef struct { typedef struct {
u8 type; u8 type; ///< Type
u8 jumpFlag; ///< When clear, this indicates WithoutJump. u8 jumpFlag; ///< When clear, this indicates WithoutJump.
u8 unk_x2[3]; u8 unk_x2[3]; ///< Unknown
u8 contextFlag; 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; ///< \ref ErrorCommonArg: When clear, errorCode is used, otherwise the applet generates the error-code from res. 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. u8 contextFlag2; ///< Similar to contextFlag except for ErrorCommonArg, indicating \ref ErrorContext is used.
} ErrorCommonHeader; } ErrorCommonHeader;
/// Error arg data for non-{System/Application}. /// Common error arg data.
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
u64 errorCode; ErrorCode errorCode; ///< \ref ErrorCode
Result res; Result res; ///< Result
} ErrorCommonArg; } ErrorCommonArg;
/// Error arg data for certain errors with module PCTL. /// Error arg data for certain errors with module PCTL.
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
Result res; Result res; ///< Result
} ErrorPctlArg; } ErrorPctlArg;
/// ResultBacktrace /// ResultBacktrace
typedef struct { typedef struct {
s32 count; s32 count; ///< Total entries in the backtrace array.
Result backtrace[0x20]; Result backtrace[0x20]; ///< Result backtrace.
} ErrorResultBacktrace; } ErrorResultBacktrace;
/// Error arg data for EULA.
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
SetRegion regionCode; SetRegion regionCode; ///< \ref SetRegion
} ErrorEulaArg; } ErrorEulaArg;
/// Additional input storage data for \ref errorSystemUpdateEulaShow.
typedef struct { typedef struct {
u8 data[0x20000]; u8 data[0x20000]; ///< data
} ErrorEulaData; } ErrorEulaData;
/// Error arg data for Record.
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
u64 errorCode; ErrorCode errorCode; ///< \ref ErrorCode
u64 timestamp; ///< POSIX timestamp. u64 timestamp; ///< POSIX timestamp.
} ErrorRecordArg; } ErrorRecordArg;
/// SystemErrorArg /// SystemErrorArg
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
u64 errorCode; ErrorCode errorCode; ///< \ref ErrorCode
u64 languageCode; u64 languageCode; ///< See set.h.
char dialogMessage[0x800]; ///< UTF-8 Dialog message. char dialogMessage[0x800]; ///< UTF-8 Dialog message.
char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details"). char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details").
} ErrorSystemArg; } ErrorSystemArg;
/// Error system config.
typedef struct { typedef struct {
ErrorSystemArg arg; ErrorSystemArg arg; ///< Arg data.
ErrorContext ctx; ErrorContext ctx; ///< Optional error context.
} ErrorSystemConfig; } ErrorSystemConfig;
/// ApplicationErrorArg /// ApplicationErrorArg
typedef struct { typedef struct {
ErrorCommonHeader hdr; ErrorCommonHeader hdr; ///< Common header.
u32 errorNumber; u32 errorNumber; ///< Raw decimal error number which is displayed in the dialog.
u64 languageCode; u64 languageCode; ///< See set.h.
char dialogMessage[0x800]; ///< UTF-8 Dialog message. char dialogMessage[0x800]; ///< UTF-8 Dialog message.
char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details"). char fullscreenMessage[0x800]; ///< UTF-8 Fullscreen message (displayed when the user clicks on "Details").
} PACKED ErrorApplicationArg; } PACKED ErrorApplicationArg;
/// Error application config.
typedef struct { typedef struct {
ErrorApplicationArg arg; ErrorApplicationArg arg; ///< Arg data.
ErrorContext ctx;
} ErrorApplicationConfig; } 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. * @brief Launches the applet for displaying the specified Result.
* @param res Result * @param res Result
* @param jumpFlag Jump flag, normally this is true. * @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+]. * @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 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". * @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".
* @warning This applet creates an error report that is logged in the system. Proceed at your own risk! * @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); Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx);
/** /**
* @brief Launches the applet for displaying the specified ErrorCode. * @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 errorCode \ref ErrorCode
* @param desc The error description.
* @param jumpFlag Jump flag, normally this is true. * @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+]. * @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. * @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! * @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. * @brief Creates an ErrorResultBacktrace struct.
@ -126,6 +162,7 @@ void errorResultBacktraceClose(ErrorResultBacktrace* backtrace);
* @brief Launches the applet for \ref ErrorResultBacktrace. * @brief Launches the applet for \ref ErrorResultBacktrace.
* @param backtrace ErrorResultBacktrace struct. * @param backtrace ErrorResultBacktrace struct.
* @param res Result * @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! * @warning This applet creates an error report that is logged in the system. Proceed at your own risk!
*/ */
Result errorResultBacktraceShow(Result res, ErrorResultBacktrace* backtrace); 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. * @brief Launches the applet for displaying an error full-screen, using the specified Result and timestamp.
* @param res Result * @param res Result
* @param timestamp POSIX timestamp. * @param timestamp POSIX timestamp.
* @note Wrapper for \ref errorCodeRecordShow. * @note Wrapper for \ref errorCodeRecordShow, see \ref errorCodeRecordShow notes.
* @note The applet does not log an error report for this.
*/ */
Result errorResultRecordShow(Result res, u64 timestamp); Result errorResultRecordShow(Result res, u64 timestamp);
/** /**
* @brief Launches the applet for displaying an error full-screen, using the specified ErrorCode and 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 errorCode \ref ErrorCode
* @param desc The error description. * @param timestamp POSIX timestamp.
* @note The applet does not log an error report for this. * @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. * @brief Creates an ErrorSystemConfig struct.
@ -186,10 +222,9 @@ Result errorSystemShow(ErrorSystemConfig* c);
/** /**
* @brief Sets the error code. * @brief Sets the error code.
* @param c ErrorSystemConfig struct. * @param c ErrorSystemConfig struct.
* @param low The module portion of the error, normally this should be set to module + 2000. * @param errorCode \ref ErrorCode
* @param desc The error description.
*/ */
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. * @brief Sets the error code, using the input Result. Wrapper for \ref errorSystemSetCode.

View File

@ -76,6 +76,30 @@ static Result _errorShowContext(const void* indata, size_t insize, ErrorContext*
return _errorShow(indata, insize, ctx_ptr, ctx_size); 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/Code}Show
Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { 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; if (!jumpFlag) ctx = NULL;
bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL; bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL;
ErrorCommonArg arg; ErrorCommonArg arg;
@ -118,7 +142,7 @@ Result errorCodeShow(u32 low, u32 desc, bool jumpFlag, ErrorContext* ctx) {
arg.hdr.jumpFlag = jumpFlag!=0; arg.hdr.jumpFlag = jumpFlag!=0;
if (flag) arg.hdr.contextFlag2 = 1; if (flag) arg.hdr.contextFlag2 = 1;
arg.hdr.resultFlag = 1; arg.hdr.resultFlag = 1;
arg.errorCode = (u64)low | ((u64)desc<<32); arg.errorCode = errorCode;
return _errorShowContext(&arg, sizeof(arg), ctx); return _errorShowContext(&arg, sizeof(arg), ctx);
} }
@ -194,16 +218,16 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) {
// Record // Record
Result errorResultRecordShow(Result res, u64 timestamp) { 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; ErrorRecordArg arg;
memset(&arg, 0, sizeof(arg)); memset(&arg, 0, sizeof(arg));
arg.hdr.type = 5; arg.hdr.type = 5;
arg.hdr.jumpFlag = 1; arg.hdr.jumpFlag = 1;
arg.errorCode = (u64)low | ((u64)desc<<32); arg.errorCode = errorCode;
arg.timestamp = timestamp; arg.timestamp = timestamp;
return _errorShow(&arg, sizeof(arg), NULL, 0); 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); return _errorShowContext(&c->arg, sizeof(c->arg), c->arg.hdr.contextFlag!=0 ? &c->ctx : NULL);
} }
void errorSystemSetCode(ErrorSystemConfig* c, u32 low, u32 desc) { void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode) {
c->arg.errorCode = (u64)low | ((u64)desc<<32); c->arg.errorCode = errorCode;
} }
void errorSystemSetResult(ErrorSystemConfig* c, Result res) { 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) { void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode) {