1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_ResultFailureHandler.cpp
4 
5   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 18248 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/Result.h>
17 #include <nn/dbg.h>
18 #include <nn/svc.h>
19 
20 using namespace nn::dbg;
21 
22 namespace {
nnosGetProcessId(bit32 * pOut)23     void nnosGetProcessId(bit32* pOut)
24     {
25 #if     defined(NN_PROCESSOR_ARM11MPCORE)
26         nn::svc::GetProcessId(pOut, nn::PSEUDO_HANDLE_CURRENT_PROCESS);
27 #elif   defined(NN_PROCESSOR_ARM946ES)
28         *pOut = 0;
29 #endif
30     }
31 
32 #ifndef NN_SWITCH_DISABLE_DEBUG_PRINT
nnResultFailureHandlerImpl(nn::Result result,const char * filename,int lineno,const char * fmt,va_list vlist)33     void nnResultFailureHandlerImpl(nn::Result result, const char* filename, int lineno, const char* fmt, va_list vlist)
34     {
35         bit32 processId;
36         nnosGetProcessId(&processId);
37         nn::dbg::detail::Printf("RESULT FAILURE [%x]: ", result.GetPrintableBits());
38         nn::dbg::detail::VPrintf(fmt, vlist);
39         nn::dbg::detail::Printf(" (process_id:%d) (%s:%d)\n", processId, filename, lineno);
40         PrintResult(result);
41 
42         Break(BREAK_REASON_ASSERT);
43     }
nnResultTFailureHandlerImpl(nn::Result result,const char * filename,int lineno,const char * fmt,va_list vlist)44     void nnResultTFailureHandlerImpl(nn::Result result, const char* filename, int lineno, const char* fmt, va_list vlist)
45     {
46         bit32 processId;
47         nnosGetProcessId(&processId);
48         nn::dbg::detail::TPrintf("RESULT FAILURE [%x]: ", result.GetPrintableBits());
49         nn::dbg::detail::TVPrintf(fmt, vlist);
50         nn::dbg::detail::TPrintf(" (process_id:%d) (%s:%d)\n", processId, filename, lineno);
51         TPrintResult(result);
52 
53         Break(BREAK_REASON_ASSERT);
54     }
55 #else
nnResultFailureHandlerImpl(nn::Result,const char *,int,const char *,va_list)56     void nnResultFailureHandlerImpl(nn::Result, const char*, int, const char*, va_list)
57     {
58         Break(BREAK_REASON_ASSERT);
59     }
nnResultTFailureHandlerImpl(nn::Result,const char *,int,const char *,va_list)60     void nnResultTFailureHandlerImpl(nn::Result, const char*, int, const char*, va_list)
61     {
62         Break(BREAK_REASON_ASSERT);
63     }
64 #endif
65 
nnResultPanicHandlerImpl(nn::Result result,const char * filename,int lineno,const char * fmt,va_list vlist)66     void nnResultPanicHandlerImpl(nn::Result result, const char* filename, int lineno, const char* fmt, va_list vlist)
67     {
68 #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT
69         NN_UNUSED_VAR(filename);
70         NN_UNUSED_VAR(lineno);
71 #endif //NN_SWITCH_DISABLE_DEBUG_PRINT
72 
73         bit32 processId;
74         nnosGetProcessId(&processId);
75         NN_LOG("RESULT [%x]:", result.GetPrintableBits());
76         //nn::dbg::detail::VPrintf(fmt, vlist);
77         NN_UNUSED_VAR(fmt);
78         NN_UNUSED_VAR(vlist);
79         NN_LOG(" (process_id:%d) (%s:%d)\n", processId, filename, lineno);
80         PrintResult(result);
81 
82         //Break(BREAK_REASON_PANIC);
83     }
nnResultTPanicHandlerImpl(nn::Result result,const char * filename,int lineno,const char * fmt,va_list vlist)84     void nnResultTPanicHandlerImpl(nn::Result result, const char* filename, int lineno, const char* fmt, va_list vlist)
85     {
86 #ifdef NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
87         NN_UNUSED_VAR(filename);
88         NN_UNUSED_VAR(lineno);
89 #endif //NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK
90 
91         bit32 processId;
92         nnosGetProcessId(&processId);
93         NN_TLOG_("RESULT [%x]:", result.GetPrintableBits());
94         //nn::dbg::detail::TVPrintf(fmt, vlist);
95         NN_UNUSED_VAR(fmt);
96         NN_UNUSED_VAR(vlist);
97         NN_TLOG_(" (process_id:%d) (%s:%d)\n", processId, filename, lineno);
98         TPrintResult(result);
99 
100         //Break(BREAK_REASON_PANIC);
101     }
102 }
103 
104 extern "C" {
105 
106 // nnResultFailureHandler のデフォルト実装
nnResultFailureHandler(nnResult result,const char * filename,int lineno,const char * fmt,...)107 NN_WEAK_SYMBOL int nnResultFailureHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...)
108 {
109     va_list vlist;
110     va_start(vlist, fmt);
111     nnResultFailureHandlerImpl(result, filename, lineno, fmt, vlist);
112     va_end(vlist);
113     return 0;
114 }
115 // nnResultTFailureHandler のデフォルト実装
nnResultTFailureHandler(nnResult result,const char * filename,int lineno,const char * fmt,...)116 NN_WEAK_SYMBOL int nnResultTFailureHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...)
117 {
118     va_list vlist;
119     va_start(vlist, fmt);
120     nnResultTFailureHandlerImpl(result, filename, lineno, fmt, vlist);
121     va_end(vlist);
122     return 0;
123 }
124 
125 // nnResultPanicHandler のデフォルト実装
nnResultPanicHandler(nnResult result,const char * filename,int lineno,const char * fmt,...)126 NN_WEAK_SYMBOL int nnResultPanicHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...)
127 {
128     va_list vlist;
129     va_start(vlist, fmt);
130     nnResultPanicHandlerImpl(result, filename, lineno, fmt, vlist);
131     va_end(vlist);
132     return 0;
133 }
134 // nnResultTPanicHandler のデフォルト実装
nnResultTPanicHandler(nnResult result,const char * filename,int lineno,const char * fmt,...)135 NN_WEAK_SYMBOL int nnResultTPanicHandler(nnResult result, const char* filename, int lineno, const char* fmt, ...)
136 {
137     va_list vlist;
138     va_start(vlist, fmt);
139     nnResultTPanicHandlerImpl(result, filename, lineno, fmt, vlist);
140     va_end(vlist);
141     return 0;
142 }
143 
nnMakeInvalidResult()144 nnResult nnMakeInvalidResult()
145 {
146     nn::Result result = nn::MakePermanentResult(
147                             nn::Result::SUMMARY_INVALID_RESULT_VALUE,
148                             nn::Result::MODULE_INVALID_RESULT_VALUE,
149                             nn::Result::DESCRIPTION_INVALID_RESULT_VALUE);
150     return static_cast<nnResult>(result);
151 }
152 
153 }
154