/*---------------------------------------------------------------------------* Project: Horizon File: os_ResultFailureHandler.cpp Copyright (C)2009 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 29262 $ *---------------------------------------------------------------------------*/ #include #include #include using namespace nn::dbg; namespace { void nnosGetProcessId(bit32* pOut) { #if defined(NN_PROCESSOR_ARM11MPCORE) nn::svc::GetProcessId(pOut, nn::PSEUDO_HANDLE_CURRENT_PROCESS); #elif defined(NN_PROCESSOR_ARM946ES) *pOut = 0; #endif } #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT void nnosResultFailureHandlerImplDefault(nnResult result, const char* filename, int lineno, const char* fmt, va_list vlist) { bit32 processId; nnosGetProcessId(&processId); nn::dbg::detail::Printf("RESULT FAILURE [%x]: ", nn::Result(result).GetPrintableBits()); nn::dbg::detail::VPrintf(fmt, vlist); nn::dbg::detail::Printf(" (process_id:%d) (%s:%d)\n", processId, filename, lineno); PrintResult(result); Break(BREAK_REASON_ASSERT); } void nnosResultTFailureHandlerImplDefault(nnResult result, const char* filename, int lineno, const char* fmt, va_list vlist) { bit32 processId; nnosGetProcessId(&processId); nn::dbg::detail::TPrintf("RESULT FAILURE [%x]: ", nn::Result(result).GetPrintableBits()); nn::dbg::detail::TVPrintf(fmt, vlist); nn::dbg::detail::TPrintf(" (process_id:%d) (%s:%d)\n", processId, filename, lineno); TPrintResult(result); Break(BREAK_REASON_ASSERT); } #else void nnosResultFailureHandlerImplDefault(nnResult, const char*, int, const char*, va_list) { Break(BREAK_REASON_ASSERT); } void nnosResultTFailureHandlerImplDefault(nnResult, const char*, int, const char*, va_list) { Break(BREAK_REASON_ASSERT); } #endif void nnosResultPanicHandlerImplDefault(nnResult result, const char* filename, int lineno, const char* fmt, va_list vlist) { #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT NN_UNUSED_VAR(filename); NN_UNUSED_VAR(lineno); #endif //NN_SWITCH_DISABLE_DEBUG_PRINT bit32 processId; nnosGetProcessId(&processId); NN_LOG("RESULT [%x]:", nn::Result(result).GetPrintableBits()); //nn::dbg::detail::VPrintf(fmt, vlist); NN_UNUSED_VAR(fmt); NN_UNUSED_VAR(vlist); NN_LOG(" (process_id:%d) (%s:%d)\n", processId, filename, lineno); PrintResult(result); //Break(BREAK_REASON_PANIC); } void nnosResultTPanicHandlerImplDefault(nnResult result, const char* filename, int lineno, const char* fmt, va_list vlist) { #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK NN_UNUSED_VAR(filename); NN_UNUSED_VAR(lineno); #endif //NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK bit32 processId; nnosGetProcessId(&processId); NN_TLOG_("RESULT [%x]:", nn::Result(result).GetPrintableBits()); //nn::dbg::detail::TVPrintf(fmt, vlist); NN_UNUSED_VAR(fmt); NN_UNUSED_VAR(vlist); NN_TLOG_(" (process_id:%d) (%s:%d)\n", processId, filename, lineno); TPrintResult(result); //Break(BREAK_REASON_PANIC); } } extern "C" { // アプリは弱シンボルを上書き、ライブラリは関数ポインタを上書き nnResultHandlerImpl nnResultFailureHandlerImpl = nnosResultFailureHandlerImplDefault; nnResultHandlerImpl nnResultTFailureHandlerImpl = nnosResultTFailureHandlerImplDefault; nnResultHandlerImpl nnResultPanicHandlerImpl = nnosResultPanicHandlerImplDefault; nnResultHandlerImpl nnResultTPanicHandlerImpl = nnosResultTPanicHandlerImplDefault; // nnResultFailureHandler のデフォルト実装 NN_WEAK_SYMBOL int nnResultFailureHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...) { va_list vlist; va_start(vlist, fmt); nnResultFailureHandlerImpl(result, filename, lineno, fmt, vlist); va_end(vlist); return 0; } // nnResultTFailureHandler のデフォルト実装 NN_WEAK_SYMBOL int nnResultTFailureHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...) { va_list vlist; va_start(vlist, fmt); nnResultTFailureHandlerImpl(result, filename, lineno, fmt, vlist); va_end(vlist); return 0; } // nnResultPanicHandler のデフォルト実装 NN_WEAK_SYMBOL int nnResultPanicHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...) { va_list vlist; va_start(vlist, fmt); nnResultPanicHandlerImpl(result, filename, lineno, fmt, vlist); va_end(vlist); return 0; } // nnResultTPanicHandler のデフォルト実装 NN_WEAK_SYMBOL int nnResultTPanicHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...) { va_list vlist; va_start(vlist, fmt); nnResultTPanicHandlerImpl(result, filename, lineno, fmt, vlist); va_end(vlist); return 0; } nnResult nnMakeInvalidResult() { nn::Result result = nn::MakePermanentResult( nn::Result::SUMMARY_INVALID_RESULT_VALUE, nn::Result::MODULE_INVALID_RESULT_VALUE, nn::Result::DESCRIPTION_INVALID_RESULT_VALUE); return static_cast(result); } }