| OLD | NEW |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | 1 // Copyright 2015 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include <malloc.h> | 15 #include <malloc.h> |
| 16 #include <stdlib.h> | 16 #include <stdlib.h> |
| 17 #include <windows.h> | 17 #include <windows.h> |
| 18 #include <winternl.h> | 18 #include <winternl.h> |
| 19 | 19 |
| 20 #include "base/logging.h" | 20 #include "base/logging.h" |
| 21 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 22 #include "client/crashpad_client.h" | 22 #include "client/crashpad_client.h" |
| 23 #include "snapshot/win/process_reader_win.h" | 23 #include "snapshot/win/process_reader_win.h" |
| 24 #include "tools/tool_support.h" | |
| 25 | 24 |
| 26 namespace crashpad { | 25 namespace crashpad { |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 // We VirtualFree a region in ourselves (the stack) to confirm that the | 28 // We VirtualFree a region in ourselves (the stack) to confirm that the |
| 30 // exception reporter captures as much as possible in the minidump and doesn't | 29 // exception reporter captures as much as possible in the minidump and doesn't |
| 31 // abort. __debugbreak() immediately after doing so because the process is | 30 // abort. __debugbreak() immediately after doing so because the process is |
| 32 // clearly in a very broken state at this point. | 31 // clearly in a very broken state at this point. |
| 33 bool FreeOwnStackAndBreak() { | 32 bool FreeOwnStackAndBreak() { |
| 34 ProcessReaderWin process_reader; | 33 ProcessReaderWin process_reader; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 58 return false; | 57 return false; |
| 59 } | 58 } |
| 60 | 59 |
| 61 // If the VirtualFree() succeeds, we may have already crashed. __debugbreak() | 60 // If the VirtualFree() succeeds, we may have already crashed. __debugbreak() |
| 62 // just to be sure. | 61 // just to be sure. |
| 63 __debugbreak(); | 62 __debugbreak(); |
| 64 | 63 |
| 65 return true; | 64 return true; |
| 66 } | 65 } |
| 67 | 66 |
| 68 int SelfDestroyingMain(int argc, char* argv[]) { | 67 int SelfDestroyingMain(int argc, wchar_t* argv[]) { |
| 69 if (argc != 2) { | 68 if (argc != 2) { |
| 70 fprintf(stderr, "Usage: %s <server_pipe_name>\n", argv[0]); | 69 fprintf(stderr, "Usage: %ls <server_pipe_name>\n", argv[0]); |
| 71 return EXIT_FAILURE; | 70 return EXIT_FAILURE; |
| 72 } | 71 } |
| 73 | 72 |
| 74 CrashpadClient client; | 73 CrashpadClient client; |
| 75 if (!client.SetHandler(argv[1])) { | 74 if (!client.SetHandlerIPCPipe(argv[1])) { |
| 76 LOG(ERROR) << "SetHandler"; | 75 LOG(ERROR) << "SetHandler"; |
| 77 return EXIT_FAILURE; | 76 return EXIT_FAILURE; |
| 78 } | 77 } |
| 79 if (!client.UseHandler()) { | 78 if (!client.UseHandler()) { |
| 80 LOG(ERROR) << "UseHandler"; | 79 LOG(ERROR) << "UseHandler"; |
| 81 return EXIT_FAILURE; | 80 return EXIT_FAILURE; |
| 82 } | 81 } |
| 83 | 82 |
| 84 if (!FreeOwnStackAndBreak()) | 83 if (!FreeOwnStackAndBreak()) |
| 85 return EXIT_FAILURE; | 84 return EXIT_FAILURE; |
| 86 | 85 |
| 87 // This will never be reached. On success, we'll have crashed above, or | 86 // This will never be reached. On success, we'll have crashed above, or |
| 88 // otherwise returned before here. | 87 // otherwise returned before here. |
| 89 return EXIT_SUCCESS; | 88 return EXIT_SUCCESS; |
| 90 } | 89 } |
| 91 | 90 |
| 92 } // namespace | 91 } // namespace |
| 93 } // namespace crashpad | 92 } // namespace crashpad |
| 94 | 93 |
| 95 int wmain(int argc, wchar_t* argv[]) { | 94 int wmain(int argc, wchar_t* argv[]) { |
| 96 return crashpad::ToolSupport::Wmain(argc, argv, crashpad::SelfDestroyingMain); | 95 return crashpad::SelfDestroyingMain(argc, argv); |
| 97 } | 96 } |
| OLD | NEW |