/*---------------------------------------------------------------------------* Project: Horizon File: os_CppException.cpp Copyright (C)2011 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: 35648 $ *---------------------------------------------------------------------------*/ #include #include #include #include namespace nn { namespace os { namespace CTR { namespace { extern "C" NN_WEAK_SYMBOL void __ARM_exceptions_buffer_required(void); extern "C" void* __ARM_exceptions_buffer_init(void); typedef void (*handler)(void); struct __cxa_eh_globals { uint32_t uncaughtExceptions; // counter std::unexpected_handler unexpectedHandler; // per-thread handler std::terminate_handler terminateHandler; // per-thread handler bool implementation_ever_called_terminate; // true if it ever did NN_PADDING3; handler call_hook; // transient field to tell terminate/unexpected which hook to call void* caughtExceptions; // chain of "caught" exceptions void* propagatingExceptions; // chain of "propagating" (in cleanup) exceptions void* emergency_buffer; // emergency buffer for when rest of heap full }; bool IsArmExceptionsBufferNotRequired() { return &__ARM_exceptions_buffer_required == NULL; } void DefaultTerminateHandler() { std::abort(); } void DefaultUnexpectedHandler() { std::terminate(); } } void SetupThreadCppExceptionEnvironment() { CTR::ThreadLocalRegion* pTlr = os::CTR::GetThreadLocalRegion(); NN_STATIC_ASSERT( sizeof(pTlr->ehGlobals) == sizeof(__cxa_eh_globals) ); pTlr->ehGlobalsAddr = pTlr->ehGlobals; __cxa_eh_globals& ceg = *reinterpret_cast<__cxa_eh_globals*>(pTlr->ehGlobals); ceg.uncaughtExceptions = 0; ceg.unexpectedHandler = DefaultUnexpectedHandler; ceg.terminateHandler = DefaultTerminateHandler; ceg.implementation_ever_called_terminate = false; ceg.call_hook = NULL; ceg.caughtExceptions = NULL; ceg.propagatingExceptions = NULL; ceg.emergency_buffer = IsArmExceptionsBufferNotRequired() ? NULL: __ARM_exceptions_buffer_init(); } }}}