| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 WinVMAddress exception_information_address_; | 177 WinVMAddress exception_information_address_; |
| 178 | 178 |
| 179 DISALLOW_COPY_AND_ASSIGN(ClientData); | 179 DISALLOW_COPY_AND_ASSIGN(ClientData); |
| 180 }; | 180 }; |
| 181 | 181 |
| 182 } // namespace internal | 182 } // namespace internal |
| 183 | 183 |
| 184 ExceptionHandlerServer::Delegate::~Delegate() { | 184 ExceptionHandlerServer::Delegate::~Delegate() { |
| 185 } | 185 } |
| 186 | 186 |
| 187 ExceptionHandlerServer::ExceptionHandlerServer(Delegate* delegate) | 187 ExceptionHandlerServer::ExceptionHandlerServer() |
| 188 : delegate_(delegate), | 188 : port_(CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 1)), |
| 189 port_(CreateIoCompletionPort(INVALID_HANDLE_VALUE, nullptr, 0, 1)), | |
| 190 clients_lock_(), | 189 clients_lock_(), |
| 191 clients_() { | 190 clients_() { |
| 192 } | 191 } |
| 193 | 192 |
| 194 ExceptionHandlerServer::~ExceptionHandlerServer() { | 193 ExceptionHandlerServer::~ExceptionHandlerServer() { |
| 195 } | 194 } |
| 196 | 195 |
| 197 void ExceptionHandlerServer::Run(const std::string& pipe_name) { | 196 void ExceptionHandlerServer::Run(Delegate* delegate, |
| 197 const std::string& pipe_name) { |
| 198 uint64_t shutdown_token = base::RandUint64(); | 198 uint64_t shutdown_token = base::RandUint64(); |
| 199 // We create two pipe instances, so that there's one listening while the | 199 // We create two pipe instances, so that there's one listening while the |
| 200 // PipeServiceProc is processing a registration. | 200 // PipeServiceProc is processing a registration. |
| 201 ScopedKernelHANDLE thread_handles[2]; | 201 ScopedKernelHANDLE thread_handles[2]; |
| 202 base::string16 pipe_name_16(base::UTF8ToUTF16(pipe_name)); | 202 base::string16 pipe_name_16(base::UTF8ToUTF16(pipe_name)); |
| 203 for (int i = 0; i < arraysize(thread_handles); ++i) { | 203 for (int i = 0; i < arraysize(thread_handles); ++i) { |
| 204 HANDLE pipe = | 204 HANDLE pipe = |
| 205 CreateNamedPipe(pipe_name_16.c_str(), | 205 CreateNamedPipe(pipe_name_16.c_str(), |
| 206 PIPE_ACCESS_DUPLEX, | 206 PIPE_ACCESS_DUPLEX, |
| 207 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, | 207 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, |
| 208 arraysize(thread_handles), | 208 arraysize(thread_handles), |
| 209 512, | 209 512, |
| 210 512, | 210 512, |
| 211 0, | 211 0, |
| 212 nullptr); | 212 nullptr); |
| 213 | 213 |
| 214 // Ownership of this object (and the pipe instance) is given to the new | 214 // Ownership of this object (and the pipe instance) is given to the new |
| 215 // thread. We close the thread handles at the end of the scope. They clean | 215 // thread. We close the thread handles at the end of the scope. They clean |
| 216 // up the context object and the pipe instance on termination. | 216 // up the context object and the pipe instance on termination. |
| 217 internal::PipeServiceContext* context = | 217 internal::PipeServiceContext* context = |
| 218 new internal::PipeServiceContext(port_.get(), | 218 new internal::PipeServiceContext(port_.get(), |
| 219 pipe, | 219 pipe, |
| 220 delegate_, | 220 delegate, |
| 221 &clients_lock_, | 221 &clients_lock_, |
| 222 &clients_, | 222 &clients_, |
| 223 shutdown_token); | 223 shutdown_token); |
| 224 thread_handles[i].reset( | 224 thread_handles[i].reset( |
| 225 CreateThread(nullptr, 0, &PipeServiceProc, context, 0, nullptr)); | 225 CreateThread(nullptr, 0, &PipeServiceProc, context, 0, nullptr)); |
| 226 } | 226 } |
| 227 | 227 |
| 228 delegate_->ExceptionHandlerServerStarted(); | 228 delegate->ExceptionHandlerServerStarted(); |
| 229 | 229 |
| 230 // This is the main loop of the server. Most work is done on the threadpool, | 230 // This is the main loop of the server. Most work is done on the threadpool, |
| 231 // other than process end handling which is posted back to this main thread, | 231 // other than process end handling which is posted back to this main thread, |
| 232 // as we must unregister the threadpool waits here. | 232 // as we must unregister the threadpool waits here. |
| 233 for (;;) { | 233 for (;;) { |
| 234 OVERLAPPED* ov = nullptr; | 234 OVERLAPPED* ov = nullptr; |
| 235 ULONG_PTR key = 0; | 235 ULONG_PTR key = 0; |
| 236 DWORD bytes = 0; | 236 DWORD bytes = 0; |
| 237 GetQueuedCompletionStatus(port_.get(), &bytes, &key, &ov, INFINITE); | 237 GetQueuedCompletionStatus(port_.get(), &bytes, &key, &ov, INFINITE); |
| 238 if (!key) { | 238 if (!key) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { | 413 void __stdcall ExceptionHandlerServer::OnProcessEnd(void* ctx, BOOLEAN) { |
| 414 // This function is executed on the thread pool. | 414 // This function is executed on the thread pool. |
| 415 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); | 415 internal::ClientData* client = reinterpret_cast<internal::ClientData*>(ctx); |
| 416 base::AutoLock lock(*client->lock()); | 416 base::AutoLock lock(*client->lock()); |
| 417 | 417 |
| 418 // Post back to the main thread to have it delete this client record. | 418 // Post back to the main thread to have it delete this client record. |
| 419 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); | 419 PostQueuedCompletionStatus(client->port(), 0, ULONG_PTR(client), nullptr); |
| 420 } | 420 } |
| 421 | 421 |
| 422 } // namespace crashpad | 422 } // namespace crashpad |
| OLD | NEW |