Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: handler/win/registration_server.cc

Issue 1126783004: Introduce RegistrationServer. (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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.
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698