diff --git a/nx/include/switch/applets/error.h b/nx/include/switch/applets/error.h index b98533cb..3c0cfdaf 100644 --- a/nx/include/switch/applets/error.h +++ b/nx/include/switch/applets/error.h @@ -30,7 +30,7 @@ typedef struct { typedef struct { char str[0x1f4]; ///< String u8 unk_x1f4[0xc]; ///< Unknown -} PACKED ErrorContext; +} ErrorContext; /// Common header for the start of the arg storage. typedef struct { @@ -114,8 +114,7 @@ typedef struct { * @param desc The error description. */ static inline ErrorCode errorCodeCreate(u32 low, u32 desc) { - ErrorCode c = {.low = low, .desc = desc}; - return c; + return (ErrorCode){low, desc}; } /** @@ -130,8 +129,7 @@ static inline ErrorCode errorCodeCreateResult(Result res) { * @brief Creates an invalid \ref ErrorCode. */ static inline ErrorCode errorCodeCreateInvalid(void) { - ErrorCode c={0}; - return c; + return (ErrorCode){0}; } /** @@ -153,7 +151,7 @@ static inline bool errorCodeIsValid(ErrorCode errorCode) { * @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, const ErrorContext* ctx); /** * @brief Launches the applet for displaying the specified ErrorCode. @@ -163,7 +161,7 @@ Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx); * @note Sets the following fields: jumpFlag and contextFlag2. resultFlag=1. Uses ::ErrorType_Normal. * @warning This applet creates an error report that is logged in the system. Proceed at your own risk! */ -Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx); +Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, const ErrorContext* ctx); /** * @brief Creates an ErrorResultBacktrace struct. @@ -171,13 +169,7 @@ Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx); * @param count Total number of entries. * @param entries Input array of Result. */ -Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, Result* entries); - -/** - * @brief Closes an ErrorResultBacktrace struct. - * @param backtrace \ref ErrorResultBacktrace struct. - */ -void errorResultBacktraceClose(ErrorResultBacktrace* backtrace); +Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, const Result* entries); /** * @brief Launches the applet for \ref ErrorResultBacktrace. @@ -186,7 +178,7 @@ void errorResultBacktraceClose(ErrorResultBacktrace* backtrace); * @note Sets the following fields: jumpFlag=1, contextFlag=1, and uses ::ErrorType_Normal. * @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, const ErrorResultBacktrace* backtrace); /** * @brief Launches the applet for displaying the EULA. @@ -201,15 +193,7 @@ Result errorEulaShow(SetRegion RegionCode); * @param eula EULA data. Address must be 0x1000-byte aligned. * @note Sets the following fields: jumpFlag=1, regionCode, and uses ::ErrorType_SystemUpdateEula. */ -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, see \ref errorCodeRecordShow notes. - */ -Result errorResultRecordShow(Result res, u64 timestamp); +Result errorSystemUpdateEulaShow(SetRegion RegionCode, const ErrorEulaData* eula); /** * @brief Launches the applet for displaying an error full-screen, using the specified ErrorCode and timestamp. @@ -220,6 +204,16 @@ Result errorResultRecordShow(Result res, u64 timestamp); */ Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp); +/** + * @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, see \ref errorCodeRecordShow notes. + */ +static inline Result errorResultRecordShow(Result res, u64 timestamp) { + return errorCodeRecordShow(errorCodeCreateResult(res), timestamp); +} + /** * @brief Creates an ErrorSystemConfig struct. * @param c ErrorSystemConfig struct. @@ -231,12 +225,6 @@ Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp); */ Result errorSystemCreate(ErrorSystemConfig* c, const char* dialog_message, const char* fullscreen_message); -/** - * @brief Closes an ErrorSystemConfig struct. - * @param c ErrorSystemConfig struct. - */ -void errorSystemClose(ErrorSystemConfig* c); - /** * @brief Launches the applet with the specified config. * @param c ErrorSystemConfig struct. @@ -248,21 +236,27 @@ Result errorSystemShow(ErrorSystemConfig* c); * @param c ErrorSystemConfig struct. * @param errorCode \ref ErrorCode */ -void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode); +static inline void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode) { + c->arg.errorCode = errorCode; +} /** * @brief Sets the error code, using the input Result. Wrapper for \ref errorSystemSetCode. * @param c ErrorSystemConfig struct. * @param res The Result to set. */ -void errorSystemSetResult(ErrorSystemConfig* c, Result res); +static inline void errorSystemSetResult(ErrorSystemConfig* c, Result res) { + errorSystemSetCode(c, errorCodeCreateResult(res)); +} /** * @brief Sets the LanguageCode. * @param c ErrorSystemConfig struct. * @param LanguageCode LanguageCode, see set.h. */ -void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode); +static inline void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode) { + c->arg.languageCode = LanguageCode; +} /** * @brief Sets the ErrorContext. @@ -270,7 +264,7 @@ void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode); * @param c ErrorSystemConfig struct. * @param ctx ErrorContext, NULL to clear it. */ -void errorSystemSetContext(ErrorSystemConfig* c, ErrorContext* ctx); +void errorSystemSetContext(ErrorSystemConfig* c, const ErrorContext* ctx); /** * @brief Creates an ErrorApplicationConfig struct. @@ -283,12 +277,6 @@ void errorSystemSetContext(ErrorSystemConfig* c, ErrorContext* ctx); */ Result errorApplicationCreate(ErrorApplicationConfig* c, const char* dialog_message, const char* fullscreen_message); -/** - * @brief Closes an ErrorApplicationConfig struct. - * @param c ErrorApplicationConfig struct. - */ -void errorApplicationClose(ErrorApplicationConfig* c); - /** * @brief Launches the applet with the specified config. * @param c ErrorApplicationConfig struct. @@ -307,5 +295,7 @@ void errorApplicationSetNumber(ErrorApplicationConfig* c, u32 errorNumber); * @param c ErrorApplicationConfig struct. * @param LanguageCode LanguageCode, see set.h. */ -void errorApplicationSetLanguageCode(ErrorApplicationConfig* c, u64 LanguageCode); +static inline void errorApplicationSetLanguageCode(ErrorApplicationConfig* c, u64 LanguageCode) { + c->arg.languageCode = LanguageCode; +} diff --git a/nx/source/applets/error.c b/nx/source/applets/error.c index dc27e32a..c92f8166 100644 --- a/nx/source/applets/error.c +++ b/nx/source/applets/error.c @@ -65,8 +65,8 @@ static Result _errorShow(const void* indata, size_t insize, const void* indata2, return rc; } -static Result _errorShowContext(const void* indata, size_t insize, ErrorContext* ctx) { - void* ctx_ptr = NULL; +static Result _errorShowContext(const void* indata, size_t insize, const ErrorContext* ctx) { + const void* ctx_ptr = NULL; size_t ctx_size = 0; if (hosversionAtLeast(4,0,0)) { ctx_ptr = ctx; @@ -78,7 +78,7 @@ static Result _errorShowContext(const void* indata, size_t insize, ErrorContext* // {Result/Code}Show -Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { +Result errorResultShow(Result res, bool jumpFlag, const ErrorContext* ctx) { if (!jumpFlag) ctx = NULL; ErrorCommonArg arg_common; ErrorPctlArg arg_pctl; @@ -108,7 +108,7 @@ Result errorResultShow(Result res, bool jumpFlag, ErrorContext* ctx) { } } -Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx) { +Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, const ErrorContext* ctx) { if (!jumpFlag) ctx = NULL; bool flag = hosversionAtLeast(4,0,0) && ctx!=NULL; ErrorCommonArg arg; @@ -125,7 +125,7 @@ Result errorCodeShow(ErrorCode errorCode, bool jumpFlag, ErrorContext* ctx) { // Backtrace -Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, Result* entries) { +Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, const Result* entries) { if (backtrace==NULL || count < 0 || count > sizeof(backtrace->backtrace)/sizeof(Result)) return MAKERESULT(Module_Libnx, LibnxError_BadInput); @@ -136,11 +136,7 @@ Result errorResultBacktraceCreate(ErrorResultBacktrace* backtrace, s32 count, Re return 0; } -void errorResultBacktraceClose(ErrorResultBacktrace* backtrace) { - memset(backtrace, 0, sizeof(*backtrace)); -} - -Result errorResultBacktraceShow(Result res, ErrorResultBacktrace* backtrace) { +Result errorResultBacktraceShow(Result res, const ErrorResultBacktrace* backtrace) { ErrorCommonArg arg; memset(&arg, 0, sizeof(arg)); @@ -165,7 +161,7 @@ Result errorEulaShow(SetRegion RegionCode) { return _errorShow(&arg, sizeof(arg), NULL, 0); } -Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) { +Result errorSystemUpdateEulaShow(SetRegion RegionCode, const ErrorEulaData* eula) { Result rc=0; AppletHolder holder; AppletStorage storage={0}; @@ -179,7 +175,7 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) { rc = _errorAppletCreate(&holder, &arg, sizeof(arg), NULL, 0); if (R_SUCCEEDED(rc)) { - if (R_SUCCEEDED(rc)) rc = appletCreateTransferMemoryStorage(&storage, eula, sizeof(*eula), false); + if (R_SUCCEEDED(rc)) rc = appletCreateTransferMemoryStorage(&storage, (void*)eula, sizeof(*eula), false); if (R_SUCCEEDED(rc)) rc = appletHolderPushInData(&holder, &storage); } @@ -193,10 +189,6 @@ Result errorSystemUpdateEulaShow(SetRegion RegionCode, ErrorEulaData* eula) { // Record -Result errorResultRecordShow(Result res, u64 timestamp) { - return errorCodeRecordShow(errorCodeCreateResult(res), timestamp); -} - Result errorCodeRecordShow(ErrorCode errorCode, u64 timestamp) { ErrorRecordArg arg; @@ -229,27 +221,11 @@ Result errorSystemCreate(ErrorSystemConfig* c, const char* dialog_message, const return rc; } -void errorSystemClose(ErrorSystemConfig* c) { - memset(c, 0, sizeof(*c)); -} - Result errorSystemShow(ErrorSystemConfig* c) { return _errorShowContext(&c->arg, sizeof(c->arg), c->arg.hdr.contextFlag!=0 ? &c->ctx : NULL); } -void errorSystemSetCode(ErrorSystemConfig* c, ErrorCode errorCode) { - c->arg.errorCode = errorCode; -} - -void errorSystemSetResult(ErrorSystemConfig* c, Result res) { - errorSystemSetCode(c, errorCodeCreateResult(res)); -} - -void errorSystemSetLanguageCode(ErrorSystemConfig* c, u64 LanguageCode) { - c->arg.languageCode = LanguageCode; -} - -void errorSystemSetContext(ErrorSystemConfig* c, ErrorContext* ctx) { +void errorSystemSetContext(ErrorSystemConfig* c, const ErrorContext* ctx) { if (hosversionBefore(4,0,0)) return; c->arg.hdr.contextFlag = ctx!=0; @@ -278,10 +254,6 @@ Result errorApplicationCreate(ErrorApplicationConfig* c, const char* dialog_mess return rc; } -void errorApplicationClose(ErrorApplicationConfig* c) { - memset(c, 0, sizeof(*c)); -} - Result errorApplicationShow(ErrorApplicationConfig* c) { return _errorShow(&c->arg, sizeof(c->arg), NULL, 0); } @@ -290,7 +262,3 @@ void errorApplicationSetNumber(ErrorApplicationConfig* c, u32 errorNumber) { c->arg.errorNumber = errorNumber; } -void errorApplicationSetLanguageCode(ErrorApplicationConfig* c, u64 LanguageCode) { - c->arg.languageCode = LanguageCode; -} -