Annotation of truecrypt/main/fatalerrorhandler.cpp, revision 1.1

1.1     ! root        1: /*
        !             2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
        !             3: 
        !             4:  Governed by the TrueCrypt License 2.4 the full text of which is contained
        !             5:  in the file License.txt included in TrueCrypt binary and source code
        !             6:  distribution packages.
        !             7: */
        !             8: 
        !             9: #include "System.h"
        !            10: #include <wx/stackwalk.h>
        !            11: 
        !            12: #include "Main.h"
        !            13: #include "UserInterface.h"
        !            14: #include "GraphicUserInterface.h"
        !            15: 
        !            16: #ifdef TC_UNIX
        !            17: #include <signal.h>
        !            18: #endif
        !            19: 
        !            20: #ifdef TC_MACOSX
        !            21: #      ifdef __ppc__
        !            22: #              include <ppc/ucontext.h>
        !            23: #      else
        !            24: #              include <i386/ucontext.h>
        !            25: #      endif
        !            26: #endif
        !            27: 
        !            28: #include "FatalErrorHandler.h"
        !            29: 
        !            30: namespace TrueCrypt
        !            31: {
        !            32:        static terminate_handler DefaultTerminateHandler;
        !            33: 
        !            34:        struct FatalErrorReport
        !            35:        {
        !            36:                bool UnhandledException;
        !            37:        };
        !            38: 
        !            39: #ifdef TC_UNIX
        !            40:        static void OnFatalProgramErrorSignal (int, siginfo_t *signalInfo, void *contextArg)
        !            41:        {
        !            42:                ucontext_t *context = (ucontext_t *) contextArg;
        !            43:                uint64 faultingInstructionAddress = 0;
        !            44: 
        !            45: #ifdef TC_LINUX
        !            46: #      ifdef REG_EIP
        !            47:                faultingInstructionAddress = context->uc_mcontext.gregs[REG_EIP];
        !            48: #      elif defined (REG_RIP)
        !            49:                faultingInstructionAddress = context->uc_mcontext.gregs[REG_RIP];
        !            50: #      endif
        !            51: 
        !            52: #elif defined (TC_MACOSX)
        !            53: #      ifdef __ppc__
        !            54:                faultingInstructionAddress = context->uc_mcontext->ss.srr0;
        !            55: #      elif defined (__x86_64__)
        !            56:                faultingInstructionAddress = context->uc_mcontext->ss.rip;
        !            57: #      else
        !            58:                faultingInstructionAddress = context->uc_mcontext->ss.eip;
        !            59: #      endif
        !            60: 
        !            61: #endif
        !            62: 
        !            63:                wstringstream vars;
        !            64:                vars << L"err=" << signalInfo->si_signo;
        !            65:                vars << L"&addr=" << hex << faultingInstructionAddress << dec;
        !            66:                
        !            67: #if wxUSE_STACKWALKER == 1
        !            68: 
        !            69:                class StackWalker : public wxStackWalker
        !            70:                {
        !            71:                public:
        !            72:                        StackWalker () : FrameCount (0) { }
        !            73: 
        !            74:                        void OnStackFrame (const wxStackFrame &frame)
        !            75:                        {
        !            76:                                if (FrameCount > 8)
        !            77:                                        return;
        !            78: 
        !            79:                                StackVars << L"&st" << FrameCount++ << L"=" << hex << frame.GetAddress();
        !            80:                        }
        !            81: 
        !            82:                        int FrameCount;
        !            83:                        wstringstream StackVars;
        !            84:                };
        !            85: 
        !            86:                StackWalker stackWalker;
        !            87:                stackWalker.Walk (1);
        !            88:                if (!stackWalker.StackVars.str().empty())
        !            89:                        vars << stackWalker.StackVars.str();
        !            90: 
        !            91: #endif // wxUSE_STACKWALKER
        !            92: 
        !            93:                wxString url = Gui->GetHomepageLinkURL (L"err-report", vars.str());
        !            94:                url.Replace (L"0x", L"");
        !            95: 
        !            96:                wxString msg = L"A critical error has occured and TrueCrypt must be terminated. If this is caused by a bug in TrueCrypt, we would like to fix it. To help us, you can send us an automatically generated error report containing the following items:\n\n- Program version\n- Operating system version\n- Hardware architecture\n- Error category\n- Error address\n";
        !            97: #if wxUSE_STACKWALKER == 1
        !            98:                msg += L"- TrueCrypt call stack\n";
        !            99: #endif
        !           100:                msg += L"\nIf you select 'Yes', the following URL (which contains the entire error report) will be opened in your default Internet browser.\n\n";
        !           101: #ifdef __WXGTK__
        !           102:                wxString fUrl = url;
        !           103:                fUrl.Replace (L"&st", L" &st");
        !           104:                msg += fUrl;
        !           105: #else
        !           106:                msg += url;
        !           107: #endif
        !           108:                msg += L"\n\nDo you want to send us the error report?";
        !           109: 
        !           110:                if (Gui->AskYesNo (msg, true))
        !           111:                        wxLaunchDefaultBrowser (url, wxBROWSER_NEW_WINDOW);
        !           112: 
        !           113:                _exit (1);
        !           114:        }
        !           115: #endif // TC_UNIX
        !           116: 
        !           117:        void FatalErrorHandler::Deregister()
        !           118:        {
        !           119: #ifdef TC_UNIX
        !           120:                signal (SIGILL, SIG_DFL);
        !           121:                signal (SIGFPE, SIG_DFL);
        !           122:                signal (SIGSEGV, SIG_DFL);
        !           123:                signal (SIGBUS, SIG_DFL);
        !           124:                signal (SIGSYS, SIG_DFL);
        !           125: #endif
        !           126: 
        !           127: #ifndef TC_WINDOWS
        !           128:                std::set_terminate (DefaultTerminateHandler);
        !           129: #endif
        !           130:        }
        !           131: 
        !           132:        void FatalErrorHandler::OnTerminate ()
        !           133:        {
        !           134:                try
        !           135:                {
        !           136:                        throw;
        !           137:                }
        !           138:                catch (UserAbort&)
        !           139:                {
        !           140:                }
        !           141:                catch (Exception &e)
        !           142:                {
        !           143:                        wxString vars;
        !           144: 
        !           145:                        wxString exName = StringConverter::ToWide (StringConverter::GetTypeName (typeid (e)));
        !           146:                        if (exName.find (L"TrueCrypt::") != string::npos)
        !           147:                                exName = exName.Mid (11);
        !           148: 
        !           149:                        wxString exPos = StringConverter::ToWide (e.what());
        !           150:                        if (exPos.find (L"TrueCrypt::") != string::npos)
        !           151:                                exPos = exPos.Mid (11);
        !           152: 
        !           153:                        vars << L"&exception=" << exName;
        !           154:                        vars << L"&exlocation=" << exPos;
        !           155:                        vars.Replace (L"::", L".");
        !           156:                        vars.Replace (L":", L".");
        !           157: 
        !           158:                        wxString url = Gui->GetHomepageLinkURL (L"err-report", vars);
        !           159: 
        !           160:                        wxString msg = L"An unhandled exception has occured and TrueCrypt must be terminated. If this is caused by a bug in TrueCrypt, we would like to fix it. To help us, you can send us an automatically generated error report containing the following items:\n\n- Program version\n- Operating system version\n- Hardware architecture\n- Error description\n- Error location\n";
        !           161:                        msg += L"\nIf you select 'Yes', the following URL (which contains the entire error report) will be opened in your default Internet browser.\n\n";
        !           162:                        msg += url;
        !           163:                        msg += L"\n\nDo you want to send us the error report?";
        !           164: 
        !           165:                        if (Gui->AskYesNo (msg, true))
        !           166:                                wxLaunchDefaultBrowser (url, wxBROWSER_NEW_WINDOW);
        !           167: 
        !           168:                }
        !           169:                catch (exception &e)
        !           170:                {
        !           171:                        Gui->ShowError (e);
        !           172:                }
        !           173:                catch (...)
        !           174:                {
        !           175:                        Gui->ShowError (_("Unknown exception occurred."));
        !           176:                }
        !           177: 
        !           178:                _exit (1);
        !           179:        }
        !           180: 
        !           181:        void FatalErrorHandler::Register ()
        !           182:        {
        !           183: #ifndef TC_WINDOWS
        !           184:                 // OnUnhandledException() seems to be called only on Windows
        !           185:                DefaultTerminateHandler = std::set_terminate (OnTerminate);
        !           186: #endif
        !           187: 
        !           188: #ifdef TC_UNIX
        !           189:                struct sigaction action;
        !           190:                Memory::Zero (&action, sizeof (action));
        !           191:                action.sa_flags = SA_SIGINFO;
        !           192:                action.sa_sigaction = OnFatalProgramErrorSignal;
        !           193: 
        !           194:                throw_sys_if (sigaction (SIGILL, &action, nullptr) == -1);
        !           195:                throw_sys_if (sigaction (SIGFPE, &action, nullptr) == -1);
        !           196:                throw_sys_if (sigaction (SIGSEGV, &action, nullptr) == -1);
        !           197:                throw_sys_if (sigaction (SIGBUS, &action, nullptr) == -1);
        !           198:                throw_sys_if (sigaction (SIGSYS, &action, nullptr) == -1);
        !           199: #endif
        !           200:        }
        !           201: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.