bool RuntimeProtector::TryProtectedFunc() { // allow cascading by storing prev and current impl m_pImpl->m_pPrevImpl = Impl::m_pCurrImpl; Impl::m_pCurrImpl = m_pImpl; struct sigaction oldAction[3]; // we need to store old actions, could remove for optimization m_bHashadException = false; if( setjmp(m_pImpl->m_env) ) { m_bHashadException = true; } else { struct sigaction newAction; memset( &newAction, 0, sizeof( newAction )); newAction.sa_sigaction = signalHandler; newAction.sa_flags = SA_SIGINFO; //use complex signal hander function sa_sigaction not sa_handler sigaction(SIGILL, &newAction, &oldAction[0] ); sigaction(SIGBUS, &newAction, &oldAction[1] ); sigaction(SIGSEGV, &newAction, &oldAction[2] ); ProtectedFunc(); } //reset sigaction(SIGILL, &oldAction[0], NULL ); sigaction(SIGBUS, &oldAction[1], NULL ); sigaction(SIGSEGV, &oldAction[2], NULL ); return !m_bHashadException; };
// クラス内から基底クラスのメンバへアクセス void Do() { _publicData = 0; // OK ; publicにはアクセス可。 PublicFunc(); // OK _protectedData = 0; // OK ; 同上。 ProtectedFunc(); // OK _privateData = 0; // NG ; 当然の如くprivateにはアクセス不可。 PrivateFunc(); // NG }