| OLD | NEW |
| (Empty) |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef COMPONENTS_CRASH_CONTENT_APP_FALLBACK_CRASH_HANDLER_LAUNCHER_WIN_H_ | |
| 6 #define COMPONENTS_CRASH_CONTENT_APP_FALLBACK_CRASH_HANDLER_LAUNCHER_WIN_H_ | |
| 7 | |
| 8 #include "base/command_line.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/macros.h" | |
| 11 #include "base/win/scoped_handle.h" | |
| 12 #include "base/win/startup_information.h" | |
| 13 | |
| 14 #include <windows.h> | |
| 15 | |
| 16 namespace crash_reporter { | |
| 17 | |
| 18 // This class is a last-ditch crash handler for the Crashpad handler process. | |
| 19 // It prepares and stores a command line, ready for dispatching when | |
| 20 // an exception occurs. Everything needed to call CreateProcess is pre-allocated | |
| 21 // to minimize the odds of re-faulting due to e.g. tripping over the same issue | |
| 22 // that caused the initial crash. | |
| 23 // This is still very much best-effort, as doing anything at all inside a | |
| 24 // process that's crashed is always going to be iffy^2. | |
| 25 class FallbackCrashHandlerLauncher { | |
| 26 public: | |
| 27 FallbackCrashHandlerLauncher(); | |
| 28 ~FallbackCrashHandlerLauncher(); | |
| 29 | |
| 30 // Initializes everything that's needed in LaunchAndWaitForHandler. | |
| 31 bool Initialize(const base::CommandLine& program, | |
| 32 const base::FilePath& crashpad_database); | |
| 33 | |
| 34 // Launch the pre-computed command line for the fallback error handler. | |
| 35 // The expectation is that this function will never return, as the fallback | |
| 36 // error handler should terminate it with the exception code as the process | |
| 37 // exit code. The return value from this function is therefore academic in | |
| 38 // the normal case. | |
| 39 // However, for completeness, this function returns one of: | |
| 40 // - The error from CreateProcess if it fails to launch the fallback handler. | |
| 41 // - The error from waiting on the fallback crash handler process if it | |
| 42 // fails to wait for that process to exit. | |
| 43 // - The exit code from the fallback crash handler process. | |
| 44 // - The error encountered in retrieving the crash handler process' exit code. | |
| 45 // Note that the return value is used in testing. | |
| 46 DWORD LaunchAndWaitForHandler(EXCEPTION_POINTERS* pointers); | |
| 47 | |
| 48 private: | |
| 49 // A copy of the actual exception pointers made at time of exception. | |
| 50 EXCEPTION_POINTERS exception_pointers_; | |
| 51 | |
| 52 // The precomputed startup info and command line for launching the fallback | |
| 53 // handler. | |
| 54 base::win::StartupInformation startup_info_; | |
| 55 // Stores the pre-cooked command line, with an allotment of zeros at the back | |
| 56 // sufficient for writing in the thread id, just before launch. | |
| 57 std::vector<wchar_t> cmd_line_; | |
| 58 | |
| 59 // An inheritable handle to our own process, the raw handle is necessary | |
| 60 // for pre-computing the startup info. | |
| 61 base::win::ScopedHandle self_process_handle_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(FallbackCrashHandlerLauncher); | |
| 64 }; | |
| 65 | |
| 66 } // namespace crash_reporter | |
| 67 | |
| 68 #endif // COMPONENTS_CRASH_CONTENT_APP_FALLBACK_CRASH_HANDLER_LAUNCHER_WIN_H_ | |
| OLD | NEW |