1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     os_ErrorHandler.cpp
4 
5   Copyright (C)2009-2011 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: 38267 $
14  *---------------------------------------------------------------------------*/
15 
16 #include <nn/os/os_ErrorHandlerSelect.h>
17 #include <nn/os/os_Private.h>
18 #include <nn/util.h>
19 #include <nn/err.h>
20 #include <nn/err/CTR/err_ApiPrivate.h>
21 
22 namespace nn { namespace os { namespace CTR { namespace detail {
23 
24 #if ( defined(NN_PROCESSOR_ARM11MPCORE) && !defined(NN_HARDWARE_CTR_LEGACY) )
25     namespace
26     {
27         bool s_PreferFatal = true;
28     }
29 #endif
30 
31 // Internal error handler for the os library (with source debug information)
InternalErrorHandler(Result result,const char * filename,int lineno)32 void InternalErrorHandler( Result result, const char* filename, int lineno )
33 {
34 #if ( defined(NN_PROCESSOR_ARM11MPCORE) && !defined(NN_HARDWARE_CTR_LEGACY) )
35     Result::Level level = result.GetLevel();
36     if ( nn::os::IsRunOnDevelopmentHardware() && !s_PreferFatal )
37     {
38         if ( level == Result::LEVEL_FATAL )
39         {
40             nn::err::ThrowFatalErr(result, NN_ERR_FATAL_TYPE_SYSTEM_COMMON, __return_address());
41         }
42         nnResultTFailureHandler(result, filename, lineno, "Unexpected Result Failure.");
43     }
44     else
45     {
46         switch ( level )
47         {
48         case Result::LEVEL_STATUS:
49         case Result::LEVEL_INFO:
50             break;
51         default:
52             nn::err::ThrowFatalErr(result, NN_ERR_FATAL_TYPE_SYSTEM_COMMON, __return_address());
53         }
54     }
55 #else
56     nnResultTFailureHandler(result, filename, lineno, "Unexpected Result Failure.");
57 #endif
58 }
59 
60 // Internal error handler for the os library (without source debug information)
InternalErrorHandler(Result result)61 void InternalErrorHandler( Result result )
62 {
63 #if ( defined(NN_PROCESSOR_ARM11MPCORE) && !defined(NN_HARDWARE_CTR_LEGACY) )
64     Result::Level level = result.GetLevel();
65     if ( nn::os::IsRunOnDevelopmentHardware() && !s_PreferFatal )
66     {
67         if ( level == Result::LEVEL_FATAL )
68         {
69             nn::err::ThrowFatalErr(result, NN_ERR_FATAL_TYPE_SYSTEM_COMMON, __return_address());
70         }
71         nnResultTFailureHandler(result, "", 0, "");
72     }
73     else
74     {
75         switch ( level )
76         {
77         case Result::LEVEL_STATUS:
78         case Result::LEVEL_INFO:
79             break;
80         default:
81             nn::err::ThrowFatalErr(result, NN_ERR_FATAL_TYPE_SYSTEM_COMMON, __return_address());
82         }
83     }
84 #else
85     nnResultTFailureHandler(result, "", 0, "");
86 #endif
87 }
88 
89 // Change mode of the internal error handler for os library
SetInternalErrorHandlerMode(bool preferFatal)90 void SetInternalErrorHandlerMode( bool preferFatal )
91 {
92 #if ( defined(NN_PROCESSOR_ARM11MPCORE) && !defined(NN_HARDWARE_CTR_LEGACY) )
93     s_PreferFatal = preferFatal;
94 #else
95     NN_UNUSED_VAR(preferFatal);
96 #endif
97 }
98 
99 }}}} // nn::os::CTR::detail
100 
101