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

Side by Side Diff: client/simulate_crash_mac_test.cc

Issue 775943005: UniversalMachExcServer: eliminate multiple implementation inheritance (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years 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 | snapshot/mac/mach_o_image_annotations_reader_test.cc » ('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,
(...skipping 17 matching lines...) Expand all
28 #include "util/mach/mach_message_server.h" 28 #include "util/mach/mach_message_server.h"
29 #include "util/mach/symbolic_constants_mach.h" 29 #include "util/mach/symbolic_constants_mach.h"
30 #include "util/test/mac/mach_errors.h" 30 #include "util/test/mac/mach_errors.h"
31 #include "util/test/mac/mach_multiprocess.h" 31 #include "util/test/mac/mach_multiprocess.h"
32 32
33 namespace crashpad { 33 namespace crashpad {
34 namespace test { 34 namespace test {
35 namespace { 35 namespace {
36 36
37 class TestSimulateCrashMac final : public MachMultiprocess, 37 class TestSimulateCrashMac final : public MachMultiprocess,
38 public UniversalMachExcServer { 38 public UniversalMachExcServer::Interface {
39 public: 39 public:
40 // Defines which targets the child should set an EXC_CRASH exception handler 40 // Defines which targets the child should set an EXC_CRASH exception handler
41 // for. 41 // for.
42 enum ExceptionPortsTarget { 42 enum ExceptionPortsTarget {
43 // The child should clear its EXC_CRASH handler for both its task and thread 43 // The child should clear its EXC_CRASH handler for both its task and thread
44 // targets. SimulateCrash() will attempt to deliver the exception to the 44 // targets. SimulateCrash() will attempt to deliver the exception to the
45 // host target, which will fail if not running as root. In any case, the 45 // host target, which will fail if not running as root. In any case, the
46 // parent should not expect to receive any exception message from the child. 46 // parent should not expect to receive any exception message from the child.
47 kExceptionPortsTargetNone = 0, 47 kExceptionPortsTargetNone = 0,
48 48
(...skipping 12 matching lines...) Expand all
61 // delivered to the thread target, but returns an error code. The child will 61 // delivered to the thread target, but returns an error code. The child will
62 // then fall back to trying the server registered for the task target, 62 // then fall back to trying the server registered for the task target,
63 // sending a second message to the parent. The server in the parent will 63 // sending a second message to the parent. The server in the parent will
64 // handle this one successfully. 64 // handle this one successfully.
65 kExceptionPortsTargetBoth, 65 kExceptionPortsTargetBoth,
66 }; 66 };
67 67
68 TestSimulateCrashMac(ExceptionPortsTarget target, 68 TestSimulateCrashMac(ExceptionPortsTarget target,
69 exception_behavior_t behavior, 69 exception_behavior_t behavior,
70 thread_state_flavor_t flavor) 70 thread_state_flavor_t flavor)
71 : target_(target), 71 : MachMultiprocess(),
72 UniversalMachExcServer::Interface(),
73 target_(target),
72 behavior_(behavior), 74 behavior_(behavior),
73 flavor_(flavor), 75 flavor_(flavor),
74 succeed_(true) { 76 succeed_(true) {
75 } 77 }
76 78
77 ~TestSimulateCrashMac() {} 79 ~TestSimulateCrashMac() {}
78 80
79 // UniversalMachExcServer: 81 // UniversalMachExcServer::Interface:
80 kern_return_t CatchMachException(exception_behavior_t behavior, 82 kern_return_t CatchMachException(exception_behavior_t behavior,
81 exception_handler_t exception_port, 83 exception_handler_t exception_port,
82 thread_t thread, 84 thread_t thread,
83 task_t task, 85 task_t task,
84 exception_type_t exception, 86 exception_type_t exception,
85 const mach_exception_data_type_t* code, 87 const mach_exception_data_type_t* code,
86 mach_msg_type_number_t code_count, 88 mach_msg_type_number_t code_count,
87 thread_state_flavor_t* flavor, 89 thread_state_flavor_t* flavor,
88 const natural_t* old_state, 90 const natural_t* old_state,
89 mach_msg_type_number_t old_state_count, 91 mach_msg_type_number_t old_state_count,
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 // MachMultiprocess: 231 // MachMultiprocess:
230 232
231 void MachMultiprocessParent() override { 233 void MachMultiprocessParent() override {
232 if (target_ == kExceptionPortsTargetNone) { 234 if (target_ == kExceptionPortsTargetNone) {
233 // The child does not have any EXC_CRASH handlers registered for its 235 // The child does not have any EXC_CRASH handlers registered for its
234 // thread or task targets, so no exception message is expected to be 236 // thread or task targets, so no exception message is expected to be
235 // generated. Don’t run the server at all. 237 // generated. Don’t run the server at all.
236 return; 238 return;
237 } 239 }
238 240
241 UniversalMachExcServer universal_mach_exc_server(this);
242
239 mach_msg_return_t mr; 243 mach_msg_return_t mr;
240 if (target_ == kExceptionPortsTargetBoth) { 244 if (target_ == kExceptionPortsTargetBoth) {
241 // The client has registered EXC_CRASH handlers for both its thread and 245 // The client has registered EXC_CRASH handlers for both its thread and
242 // task targets. Run a server that will return a failure code when the 246 // task targets. Run a server that will return a failure code when the
243 // exception message is sent to the thread target, which will cause the 247 // exception message is sent to the thread target, which will cause the
244 // client to fall back to the task target and send another message. 248 // client to fall back to the task target and send another message.
245 succeed_ = false; 249 succeed_ = false;
246 mr = MachMessageServer::Run(this, 250 mr = MachMessageServer::Run(&universal_mach_exc_server,
247 LocalPort(), 251 LocalPort(),
248 MACH_MSG_OPTION_NONE, 252 MACH_MSG_OPTION_NONE,
249 MachMessageServer::kOneShot, 253 MachMessageServer::kOneShot,
250 MachMessageServer::kBlocking, 254 MachMessageServer::kBlocking,
251 MachMessageServer::kReceiveLargeError, 255 MachMessageServer::kReceiveLargeError,
252 MACH_MSG_TIMEOUT_NONE); 256 MACH_MSG_TIMEOUT_NONE);
253 EXPECT_EQ(MACH_MSG_SUCCESS, mr) 257 EXPECT_EQ(MACH_MSG_SUCCESS, mr)
254 << MachErrorMessage(mr, "MachMessageServer::Run"); 258 << MachErrorMessage(mr, "MachMessageServer::Run");
255 } 259 }
256 260
257 succeed_ = true; 261 succeed_ = true;
258 mr = MachMessageServer::Run(this, 262 mr = MachMessageServer::Run(&universal_mach_exc_server,
259 LocalPort(), 263 LocalPort(),
260 MACH_MSG_OPTION_NONE, 264 MACH_MSG_OPTION_NONE,
261 MachMessageServer::kOneShot, 265 MachMessageServer::kOneShot,
262 MachMessageServer::kBlocking, 266 MachMessageServer::kBlocking,
263 MachMessageServer::kReceiveLargeError, 267 MachMessageServer::kReceiveLargeError,
264 MACH_MSG_TIMEOUT_NONE); 268 MACH_MSG_TIMEOUT_NONE);
265 EXPECT_EQ(MACH_MSG_SUCCESS, mr) 269 EXPECT_EQ(MACH_MSG_SUCCESS, mr)
266 << MachErrorMessage(mr, "MachMessageServer::Run"); 270 << MachErrorMessage(mr, "MachMessageServer::Run");
267 } 271 }
268 272
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 test_simulate_crash_mac.Run(); 375 test_simulate_crash_mac.Run();
372 } 376 }
373 } 377 }
374 } 378 }
375 } 379 }
376 } 380 }
377 381
378 } // namespace 382 } // namespace
379 } // namespace test 383 } // namespace test
380 } // namespace crashpad 384 } // namespace crashpad
OLDNEW
« no previous file with comments | « no previous file | snapshot/mac/mach_o_image_annotations_reader_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698