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

Side by Side Diff: handler/mac/exception_handler_server.cc

Issue 1414413006: mac: Add NotifyServer::DefaultInterface, a default no-op implementation (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 5 years, 1 month 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
« no previous file with comments | « no previous file | util/mach/notify_server.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 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 "handler/mac/exception_handler_server.h" 15 #include "handler/mac/exception_handler_server.h"
16 16
17 #include "base/logging.h" 17 #include "base/logging.h"
18 #include "base/mac/mach_logging.h" 18 #include "base/mac/mach_logging.h"
19 #include "util/mach/composite_mach_message_server.h" 19 #include "util/mach/composite_mach_message_server.h"
20 #include "util/mach/mach_extensions.h" 20 #include "util/mach/mach_extensions.h"
21 #include "util/mach/mach_message.h" 21 #include "util/mach/mach_message.h"
22 #include "util/mach/mach_message_server.h" 22 #include "util/mach/mach_message_server.h"
23 #include "util/mach/notify_server.h" 23 #include "util/mach/notify_server.h"
24 24
25 namespace crashpad { 25 namespace crashpad {
26 26
27 namespace { 27 namespace {
28 28
29 class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, 29 class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface,
30 public NotifyServer::Interface { 30 public NotifyServer::DefaultInterface {
31 public: 31 public:
32 ExceptionHandlerServerRun( 32 ExceptionHandlerServerRun(
33 mach_port_t exception_port, 33 mach_port_t exception_port,
34 UniversalMachExcServer::Interface* exception_interface) 34 UniversalMachExcServer::Interface* exception_interface)
35 : UniversalMachExcServer::Interface(), 35 : UniversalMachExcServer::Interface(),
36 NotifyServer::Interface(), 36 NotifyServer::DefaultInterface(),
37 mach_exc_server_(this), 37 mach_exc_server_(this),
38 notify_server_(this), 38 notify_server_(this),
39 composite_mach_message_server_(), 39 composite_mach_message_server_(),
40 exception_interface_(exception_interface), 40 exception_interface_(exception_interface),
41 exception_port_(exception_port), 41 exception_port_(exception_port),
42 notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)), 42 notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)),
43 running_(true) { 43 running_(true) {
44 CHECK(notify_port_.is_valid()); 44 CHECK(notify_port_.is_valid());
45 45
46 composite_mach_message_server_.AddHandler(&mach_exc_server_); 46 composite_mach_message_server_.AddHandler(&mach_exc_server_);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 code_count, 137 code_count,
138 flavor, 138 flavor,
139 old_state, 139 old_state,
140 old_state_count, 140 old_state_count,
141 new_state, 141 new_state,
142 new_state_count, 142 new_state_count,
143 trailer, 143 trailer,
144 destroy_complex_request); 144 destroy_complex_request);
145 } 145 }
146 146
147 // NotifyServer::Interface: 147 // NotifyServer::DefaultInterface:
148
149 kern_return_t DoMachNotifyPortDeleted(
150 notify_port_t notify,
151 mach_port_name_t name,
152 const mach_msg_trailer_t* trailer) override {
153 return UnimplementedNotifyRoutine(notify);
154 }
155
156 kern_return_t DoMachNotifyPortDestroyed(notify_port_t notify,
157 mach_port_t rights,
158 const mach_msg_trailer_t* trailer,
159 bool* destroy_request) override {
160 *destroy_request = true;
161 return UnimplementedNotifyRoutine(notify);
162 }
163 148
164 kern_return_t DoMachNotifyNoSenders( 149 kern_return_t DoMachNotifyNoSenders(
165 notify_port_t notify, 150 notify_port_t notify,
166 mach_port_mscount_t mscount, 151 mach_port_mscount_t mscount,
167 const mach_msg_trailer_t* trailer) override { 152 const mach_msg_trailer_t* trailer) override {
168 if (notify != notify_port_) { 153 if (notify != notify_port_) {
169 // The message was received as part of a port set. This check ensures that 154 // The message was received as part of a port set. This check ensures that
170 // only the authorized sender of the no-senders notification is able to 155 // only the authorized sender of the no-senders notification is able to
171 // stop the exception server. Otherwise, a malicious client would be able 156 // stop the exception server. Otherwise, a malicious client would be able
172 // to craft and send a no-senders notification via its exception port, and 157 // to craft and send a no-senders notification via its exception port, and
173 // cause the handler to stop processing exceptions and exit. 158 // cause the handler to stop processing exceptions and exit.
174 LOG(WARNING) << "notify port mismatch"; 159 LOG(WARNING) << "notify port mismatch";
175 return KERN_FAILURE; 160 return KERN_FAILURE;
176 } 161 }
177 162
178 running_ = false; 163 running_ = false;
179 164
180 return KERN_SUCCESS; 165 return KERN_SUCCESS;
181 } 166 }
182 167
183 kern_return_t DoMachNotifySendOnce(
184 notify_port_t notify,
185 const mach_msg_trailer_t* trailer) override {
186 return UnimplementedNotifyRoutine(notify);
187 }
188
189 kern_return_t DoMachNotifyDeadName(
190 notify_port_t notify,
191 mach_port_name_t name,
192 const mach_msg_trailer_t* trailer) override {
193 return UnimplementedNotifyRoutine(notify);
194 }
195
196 private: 168 private:
197 kern_return_t UnimplementedNotifyRoutine(notify_port_t notify) {
198 // Most of the routines in the notify subsystem are not expected to be
199 // called.
200 if (notify != notify_port_) {
201 LOG(WARNING) << "notify port mismatch";
202 return KERN_FAILURE;
203 }
204
205 NOTREACHED();
206 return MIG_BAD_ID;
207 }
208
209 UniversalMachExcServer mach_exc_server_; 169 UniversalMachExcServer mach_exc_server_;
210 NotifyServer notify_server_; 170 NotifyServer notify_server_;
211 CompositeMachMessageServer composite_mach_message_server_; 171 CompositeMachMessageServer composite_mach_message_server_;
212 UniversalMachExcServer::Interface* exception_interface_; // weak 172 UniversalMachExcServer::Interface* exception_interface_; // weak
213 mach_port_t exception_port_; // weak 173 mach_port_t exception_port_; // weak
214 base::mac::ScopedMachReceiveRight notify_port_; 174 base::mac::ScopedMachReceiveRight notify_port_;
215 bool running_; 175 bool running_;
216 176
217 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun); 177 DISALLOW_COPY_AND_ASSIGN(ExceptionHandlerServerRun);
218 }; 178 };
219 179
220 } // namespace 180 } // namespace
221 181
222 ExceptionHandlerServer::ExceptionHandlerServer( 182 ExceptionHandlerServer::ExceptionHandlerServer(
223 base::mac::ScopedMachReceiveRight receive_port) 183 base::mac::ScopedMachReceiveRight receive_port)
224 : receive_port_(receive_port.Pass()) { 184 : receive_port_(receive_port.Pass()) {
225 CHECK(receive_port_.is_valid()); 185 CHECK(receive_port_.is_valid());
226 } 186 }
227 187
228 ExceptionHandlerServer::~ExceptionHandlerServer() { 188 ExceptionHandlerServer::~ExceptionHandlerServer() {
229 } 189 }
230 190
231 void ExceptionHandlerServer::Run( 191 void ExceptionHandlerServer::Run(
232 UniversalMachExcServer::Interface* exception_interface) { 192 UniversalMachExcServer::Interface* exception_interface) {
233 ExceptionHandlerServerRun run(receive_port_.get(), exception_interface); 193 ExceptionHandlerServerRun run(receive_port_.get(), exception_interface);
234 run.Run(); 194 run.Run();
235 } 195 }
236 196
237 } // namespace crashpad 197 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | util/mach/notify_server.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698