| 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, |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 DISALLOW_COPY_AND_ASSIGN(Delegate); | 106 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 107 }; | 107 }; |
| 108 | 108 |
| 109 private: | 109 private: |
| 110 ScopedKernelHANDLE exception_happened_; | 110 ScopedKernelHANDLE exception_happened_; |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 // Runs the ExceptionHandlerServer on a background thread. | 113 // Runs the ExceptionHandlerServer on a background thread. |
| 114 class RunServerThread : public Thread { | 114 class RunServerThread : public Thread { |
| 115 public: | 115 public: |
| 116 // Instantiates a thread which will invoke server->Run(pipe_name); | 116 // Instantiates a thread which will invoke server->Run(delegate, pipe_name); |
| 117 explicit RunServerThread(ExceptionHandlerServer* server, | 117 RunServerThread(ExceptionHandlerServer* server, |
| 118 const std::string& pipe_name) | 118 ExceptionHandlerServer::Delegate* delegate, |
| 119 : server_(server), pipe_name_(pipe_name) {} | 119 const std::string& pipe_name) |
| 120 : server_(server), delegate_(delegate), pipe_name_(pipe_name) {} |
| 120 ~RunServerThread() override {} | 121 ~RunServerThread() override {} |
| 121 | 122 |
| 122 private: | 123 private: |
| 123 // Thread: | 124 // Thread: |
| 124 void ThreadMain() override { server_->Run(pipe_name_); } | 125 void ThreadMain() override { server_->Run(delegate_, pipe_name_); } |
| 125 | 126 |
| 126 ExceptionHandlerServer* server_; | 127 ExceptionHandlerServer* server_; |
| 128 ExceptionHandlerServer::Delegate* delegate_; |
| 127 std::string pipe_name_; | 129 std::string pipe_name_; |
| 128 | 130 |
| 129 DISALLOW_COPY_AND_ASSIGN(RunServerThread); | 131 DISALLOW_COPY_AND_ASSIGN(RunServerThread); |
| 130 }; | 132 }; |
| 131 | 133 |
| 132 // During destruction, ensures that the server is stopped and the background | 134 // During destruction, ensures that the server is stopped and the background |
| 133 // thread joined. | 135 // thread joined. |
| 134 class ScopedStopServerAndJoinThread { | 136 class ScopedStopServerAndJoinThread { |
| 135 public: | 137 public: |
| 136 explicit ScopedStopServerAndJoinThread(ExceptionHandlerServer* server, | 138 ScopedStopServerAndJoinThread(ExceptionHandlerServer* server, Thread* thread) |
| 137 Thread* thread) | |
| 138 : server_(server), thread_(thread) {} | 139 : server_(server), thread_(thread) {} |
| 139 ~ScopedStopServerAndJoinThread() { | 140 ~ScopedStopServerAndJoinThread() { |
| 140 server_->Stop(); | 141 server_->Stop(); |
| 141 thread_->Join(); | 142 thread_->Join(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 private: | 145 private: |
| 145 ExceptionHandlerServer* server_; | 146 ExceptionHandlerServer* server_; |
| 146 Thread* thread_; | 147 Thread* thread_; |
| 147 DISALLOW_COPY_AND_ASSIGN(ScopedStopServerAndJoinThread); | 148 DISALLOW_COPY_AND_ASSIGN(ScopedStopServerAndJoinThread); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 WinChildProcess::EntryPoint<CrashingChildProcess>(); | 193 WinChildProcess::EntryPoint<CrashingChildProcess>(); |
| 193 scoped_ptr<WinChildProcess::Handles> handle = WinChildProcess::Launch(); | 194 scoped_ptr<WinChildProcess::Handles> handle = WinChildProcess::Launch(); |
| 194 | 195 |
| 195 // Set up the registration server on a background thread. | 196 // Set up the registration server on a background thread. |
| 196 std::string pipe_name = "\\\\.\\pipe\\handler_test_pipe_" + | 197 std::string pipe_name = "\\\\.\\pipe\\handler_test_pipe_" + |
| 197 base::StringPrintf("%08x", GetCurrentProcessId()); | 198 base::StringPrintf("%08x", GetCurrentProcessId()); |
| 198 ScopedKernelHANDLE server_ready(CreateEvent(nullptr, false, false, nullptr)); | 199 ScopedKernelHANDLE server_ready(CreateEvent(nullptr, false, false, nullptr)); |
| 199 ScopedKernelHANDLE completed(CreateEvent(nullptr, false, false, nullptr)); | 200 ScopedKernelHANDLE completed(CreateEvent(nullptr, false, false, nullptr)); |
| 200 Delegate delegate(server_ready.get(), completed.get()); | 201 Delegate delegate(server_ready.get(), completed.get()); |
| 201 | 202 |
| 202 ExceptionHandlerServer exception_handler_server(&delegate); | 203 ExceptionHandlerServer exception_handler_server; |
| 203 RunServerThread server_thread(&exception_handler_server, pipe_name); | 204 RunServerThread server_thread( |
| 205 &exception_handler_server, &delegate, pipe_name); |
| 204 server_thread.Start(); | 206 server_thread.Start(); |
| 205 ScopedStopServerAndJoinThread scoped_stop_server_and_join_thread( | 207 ScopedStopServerAndJoinThread scoped_stop_server_and_join_thread( |
| 206 &exception_handler_server, &server_thread); | 208 &exception_handler_server, &server_thread); |
| 207 | 209 |
| 208 WaitForSingleObject(server_ready.get(), INFINITE); | 210 WaitForSingleObject(server_ready.get(), INFINITE); |
| 209 // Allow the child to continue and tell it where to connect to. | 211 // Allow the child to continue and tell it where to connect to. |
| 210 WriteString(handle->write.get(), pipe_name); | 212 WriteString(handle->write.get(), pipe_name); |
| 211 | 213 |
| 212 // The child tells us (approximately) where it will crash. | 214 // The child tells us (approximately) where it will crash. |
| 213 void* break_near_address; | 215 void* break_near_address; |
| 214 LoggingReadFile( | 216 LoggingReadFile( |
| 215 handle->read.get(), &break_near_address, sizeof(break_near_address)); | 217 handle->read.get(), &break_near_address, sizeof(break_near_address)); |
| 216 delegate.set_break_near(break_near_address); | 218 delegate.set_break_near(break_near_address); |
| 217 | 219 |
| 218 // Wait for the child to crash and the exception information to be validated. | 220 // Wait for the child to crash and the exception information to be validated. |
| 219 WaitForSingleObject(completed.get(), INFINITE); | 221 WaitForSingleObject(completed.get(), INFINITE); |
| 220 } | 222 } |
| 221 | 223 |
| 222 } // namespace | 224 } // namespace |
| 223 } // namespace test | 225 } // namespace test |
| 224 } // namespace crashpad | 226 } // namespace crashpad |
| OLD | NEW |