Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (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 | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #include "handler/win/registration_server.h" | |
| 16 | |
| 17 #include <windows.h> | |
| 18 #include "client/registration_request_win.h" | |
|
Mark Mentovai
2015/05/05 20:20:33
Blank line before this.
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| 19 #include "client/registration_response_win.h" | |
| 20 | |
| 21 namespace crashpad { | |
| 22 | |
| 23 namespace { | |
| 24 const int kNumThreads = 3; | |
|
Mark Mentovai
2015/05/05 20:20:33
This is only used in the constructor, it doesn’t n
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| 25 } // namespace | |
| 26 | |
| 27 RegistrationServer::RegistrationServer(const base::string16& pipe_name, | |
| 28 scoped_ptr<Delegate> delegate) | |
| 29 : delegate_(delegate.Pass()) { | |
|
Mark Mentovai
2015/05/05 20:20:33
Explicitly initialize everything even if it’s the
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| 30 for (int i = 0; i < kNumThreads; ++i) { | |
| 31 DWORD open_mode = PIPE_ACCESS_DUPLEX; | |
| 32 if (i == 0) | |
| 33 open_mode |= FILE_FLAG_FIRST_PIPE_INSTANCE; | |
| 34 ScopedKernelHANDLE pipe( | |
| 35 ::CreateNamedPipe(pipe_name.c_str(), open_mode, | |
|
Mark Mentovai
2015/05/05 20:20:33
No :: in crashpad except where it’s needed to disa
erikwright (departed)
2015/05/20 17:10:16
Done.
| |
| 36 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, | |
| 37 kNumThreads, 512, 512, 20, NULL)); | |
|
Mark Mentovai
2015/05/05 20:20:33
What is the significance of 20?
Mark Mentovai
2015/05/05 20:20:33
In Crashpad, use nullptr, not NULL. Generally we d
erikwright (departed)
2015/05/20 17:10:16
Done.
erikwright (departed)
2015/05/20 17:10:16
Done.
| |
| 38 if (pipe.is_valid()) { | |
| 39 listener_threads_.push_back( | |
| 40 new ListenerThread(pipe.Pass(), delegate_.get())); | |
| 41 listener_threads_.back()->Start(); | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 RegistrationServer::~RegistrationServer() { | |
| 47 for (auto& thread : listener_threads_) { | |
| 48 thread->Stop(); | |
| 49 } | |
| 50 for (auto& thread : listener_threads_) { | |
| 51 thread->Join(); | |
| 52 delete thread; | |
|
Mark Mentovai
2015/05/05 20:20:33
Use a PointerVector<>.
erikwright (departed)
2015/05/20 17:10:16
Done.
| |
| 53 } | |
| 54 } | |
| 55 | |
| 56 RegistrationServer::ListenerThread::ListenerThread( | |
| 57 ScopedKernelHANDLE pipe, | |
|
Mark Mentovai
2015/05/05 20:20:33
This would fit on the preceding line.
erikwright (departed)
2015/05/20 17:10:16
Done.
| |
| 58 Delegate* delegate) | |
| 59 : pipe_(pipe.Pass()), | |
| 60 delegate_(delegate) { | |
| 61 } | |
| 62 | |
| 63 void RegistrationServer::ListenerThread::ThreadMain() { | |
| 64 while (true) { | |
| 65 if (!::ConnectNamedPipe(pipe_.get(), NULL)) { | |
| 66 if (::GetLastError() != ERROR_PIPE_CONNECTED) | |
| 67 break; | |
|
Mark Mentovai
2015/05/05 20:20:33
PLOG(ERROR)
erikwright (departed)
2015/05/20 17:10:16
Done.
| |
| 68 } | |
| 69 | |
| 70 DWORD bytes_read = 0; | |
| 71 RegistrationRequest request; | |
| 72 if (::ReadFile(pipe_.get(), &request, sizeof(request), &bytes_read, NULL)) { | |
| 73 if (bytes_read == sizeof(request)) { | |
| 74 ScopedKernelHANDLE client_process(::OpenProcess( | |
| 75 PROCESS_ALL_ACCESS, FALSE, request.client_process_id)); | |
| 76 if (!client_process.is_valid()) { | |
| 77 if (::ImpersonateNamedPipeClient(pipe_.get())) { | |
| 78 client_process.reset(::OpenProcess( | |
| 79 PROCESS_ALL_ACCESS, FALSE, request.client_process_id)); | |
| 80 ::RevertToSelf(); | |
| 81 } | |
|
Mark Mentovai
2015/05/05 20:20:33
…otherwise? Is this something that should be logge
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| 82 } | |
| 83 | |
| 84 // TODO(erikwright): Verify that the client process ID is not forged. | |
| 85 | |
| 86 if (client_process.is_valid()) { | |
| 87 RegistrationResponse response = {0}; | |
| 88 if (delegate_->RegisterClient(client_process.Pass(), | |
| 89 request.crashpad_info_address, | |
| 90 &response.request_report_event, | |
| 91 &response.report_complete_event)) { | |
| 92 DWORD bytes_written = 0; | |
| 93 ::WriteFile( | |
|
Mark Mentovai
2015/05/05 20:20:33
Check everything.
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| 94 pipe_.get(), &response, sizeof(response), &bytes_written, NULL); | |
| 95 } | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 | |
| 100 ::DisconnectNamedPipe(pipe_.get()); | |
| 101 } | |
| 102 } | |
| 103 | |
| 104 void RegistrationServer::ListenerThread::Stop() { pipe_.reset(); } | |
| 105 | |
| 106 } // namespace crashpad | |
| 107 | |
|
Mark Mentovai
2015/05/05 20:20:33
Get rid of the blank line here.
erikwright (departed)
2015/05/20 17:10:15
Done.
| |
| OLD | NEW |