mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
UniversalMachExcServer: eliminate multiple implementation inheritance.
UniversalMachExcServer provided both an interface and an implementation, contrary to the other classes in the exc_server_variants family. This was mostly done for reasons of economy in an already-large class family. Unfortunately, this decision meant that it was impossible for other code to use UniversalMachExcServer, which required that CatchMachException() be implemented, and also extend another class without violating the style guide’s prohibition of multiple implementation inheritance. This became a problem in a lot of test code, which extended MachMultiprocess and UniversalMachExcServer. UniversalMachExcServer is now given its own nested Interface class, which is a pure interface. All users of UniversalMachExcServer are changed from “is-a” UniversalMachExcServer to “has-a” UniversalMachExcServer and “is-a” UniversalMachExcServer::Interface. TEST=client_test, snapshot_test, util_test R=rsesek@chromium.org Review URL: https://codereview.chromium.org/775943005
This commit is contained in:
parent
86588c5526
commit
821ed8fe0f
@ -35,7 +35,7 @@ namespace test {
|
||||
namespace {
|
||||
|
||||
class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
public UniversalMachExcServer {
|
||||
public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
// Defines which targets the child should set an EXC_CRASH exception handler
|
||||
// for.
|
||||
@ -68,7 +68,9 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
TestSimulateCrashMac(ExceptionPortsTarget target,
|
||||
exception_behavior_t behavior,
|
||||
thread_state_flavor_t flavor)
|
||||
: target_(target),
|
||||
: MachMultiprocess(),
|
||||
UniversalMachExcServer::Interface(),
|
||||
target_(target),
|
||||
behavior_(behavior),
|
||||
flavor_(flavor),
|
||||
succeed_(true) {
|
||||
@ -76,7 +78,7 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
|
||||
~TestSimulateCrashMac() {}
|
||||
|
||||
// UniversalMachExcServer:
|
||||
// UniversalMachExcServer::Interface:
|
||||
kern_return_t CatchMachException(exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
thread_t thread,
|
||||
@ -236,6 +238,8 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
return;
|
||||
}
|
||||
|
||||
UniversalMachExcServer universal_mach_exc_server(this);
|
||||
|
||||
mach_msg_return_t mr;
|
||||
if (target_ == kExceptionPortsTargetBoth) {
|
||||
// The client has registered EXC_CRASH handlers for both its thread and
|
||||
@ -243,7 +247,7 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
// exception message is sent to the thread target, which will cause the
|
||||
// client to fall back to the task target and send another message.
|
||||
succeed_ = false;
|
||||
mr = MachMessageServer::Run(this,
|
||||
mr = MachMessageServer::Run(&universal_mach_exc_server,
|
||||
LocalPort(),
|
||||
MACH_MSG_OPTION_NONE,
|
||||
MachMessageServer::kOneShot,
|
||||
@ -255,7 +259,7 @@ class TestSimulateCrashMac final : public MachMultiprocess,
|
||||
}
|
||||
|
||||
succeed_ = true;
|
||||
mr = MachMessageServer::Run(this,
|
||||
mr = MachMessageServer::Run(&universal_mach_exc_server,
|
||||
LocalPort(),
|
||||
MACH_MSG_OPTION_NONE,
|
||||
MachMessageServer::kOneShot,
|
||||
|
@ -43,8 +43,9 @@ namespace crashpad {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
class TestMachOImageAnnotationsReader final : public MachMultiprocess,
|
||||
public UniversalMachExcServer {
|
||||
class TestMachOImageAnnotationsReader final
|
||||
: public MachMultiprocess,
|
||||
public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
enum TestType {
|
||||
// Don’t crash, just test the CrashpadInfo interface.
|
||||
@ -62,13 +63,13 @@ class TestMachOImageAnnotationsReader final : public MachMultiprocess,
|
||||
|
||||
explicit TestMachOImageAnnotationsReader(TestType test_type)
|
||||
: MachMultiprocess(),
|
||||
UniversalMachExcServer(),
|
||||
UniversalMachExcServer::Interface(),
|
||||
test_type_(test_type) {
|
||||
}
|
||||
|
||||
~TestMachOImageAnnotationsReader() {}
|
||||
|
||||
// UniversalMachExcServer:
|
||||
// UniversalMachExcServer::Interface:
|
||||
kern_return_t CatchMachException(exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
thread_t thread,
|
||||
@ -219,8 +220,10 @@ class TestMachOImageAnnotationsReader final : public MachMultiprocess,
|
||||
if (test_type_ != kDontCrash) {
|
||||
// Handle the child’s crash. Further validation will be done in
|
||||
// CatchMachException().
|
||||
UniversalMachExcServer universal_mach_exc_server(this);
|
||||
|
||||
mach_msg_return_t mr =
|
||||
MachMessageServer::Run(this,
|
||||
MachMessageServer::Run(&universal_mach_exc_server,
|
||||
LocalPort(),
|
||||
MACH_MSG_OPTION_NONE,
|
||||
MachMessageServer::kOneShot,
|
||||
|
@ -47,16 +47,17 @@ struct Options {
|
||||
MachMessageServer::Persistent persistent;
|
||||
};
|
||||
|
||||
class ExceptionServer : public UniversalMachExcServer {
|
||||
class ExceptionServer : public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
ExceptionServer(const Options& options,
|
||||
const std::string& me,
|
||||
int* exceptions_handled)
|
||||
: UniversalMachExcServer(),
|
||||
: UniversalMachExcServer::Interface(),
|
||||
options_(options),
|
||||
me_(me),
|
||||
exceptions_handled_(exceptions_handled) {}
|
||||
|
||||
// UniversalMachExcServer::Interface:
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
@ -275,6 +276,7 @@ int CatchExceptionToolMain(int argc, char* argv[]) {
|
||||
|
||||
int exceptions_handled = 0;
|
||||
ExceptionServer exception_server(options, me, &exceptions_handled);
|
||||
UniversalMachExcServer universal_mach_exc_server(&exception_server);
|
||||
|
||||
// Assume that if persistent mode has been requested, it’s desirable to ignore
|
||||
// large messages and keep running.
|
||||
@ -287,7 +289,7 @@ int CatchExceptionToolMain(int argc, char* argv[]) {
|
||||
? options.timeout_secs * 1000
|
||||
: MACH_MSG_TIMEOUT_NONE;
|
||||
|
||||
mach_msg_return_t mr = MachMessageServer::Run(&exception_server,
|
||||
mach_msg_return_t mr = MachMessageServer::Run(&universal_mach_exc_server,
|
||||
service_port,
|
||||
MACH_MSG_OPTION_NONE,
|
||||
options.persistent,
|
||||
|
@ -31,12 +31,12 @@ namespace crashpad {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
class TestExcClientVariants : public UniversalMachExcServer,
|
||||
public MachMultiprocess {
|
||||
class TestExcClientVariants : public MachMultiprocess,
|
||||
public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
TestExcClientVariants(exception_behavior_t behavior, bool all_fields)
|
||||
: UniversalMachExcServer(),
|
||||
MachMultiprocess(),
|
||||
: MachMultiprocess(),
|
||||
UniversalMachExcServer::Interface(),
|
||||
behavior_(behavior),
|
||||
all_fields_(all_fields),
|
||||
handled_(false) {
|
||||
@ -45,7 +45,7 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
++exception_subcode_;
|
||||
}
|
||||
|
||||
// UniversalMachExcServer:
|
||||
// UniversalMachExcServer::Interface:
|
||||
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
@ -134,8 +134,10 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
// MachMultiprocess:
|
||||
|
||||
void MachMultiprocessParent() override {
|
||||
UniversalMachExcServer universal_mach_exc_server(this);
|
||||
|
||||
kern_return_t kr =
|
||||
MachMessageServer::Run(this,
|
||||
MachMessageServer::Run(&universal_mach_exc_server,
|
||||
LocalPort(),
|
||||
MACH_MSG_OPTION_NONE,
|
||||
MachMessageServer::kOneShot,
|
||||
|
@ -490,7 +490,7 @@ kern_return_t SimplifiedExcServer::CatchExceptionRaise(
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
&flavor,
|
||||
nullptr,
|
||||
@ -518,12 +518,12 @@ kern_return_t SimplifiedExcServer::CatchExceptionRaiseState(
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
&destroy_complex_request);
|
||||
@ -548,12 +548,12 @@ kern_return_t SimplifiedExcServer::CatchExceptionRaiseStateIdentity(
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
destroy_request);
|
||||
@ -583,7 +583,7 @@ kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaise(
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
&flavor,
|
||||
nullptr,
|
||||
@ -611,12 +611,12 @@ kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseState(
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
&destroy_complex_request);
|
||||
@ -642,12 +642,12 @@ kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseStateIdentity(
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
destroy_request);
|
||||
@ -655,12 +655,14 @@ kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseStateIdentity(
|
||||
|
||||
} // namespace internal
|
||||
|
||||
UniversalMachExcServer::UniversalMachExcServer()
|
||||
UniversalMachExcServer::UniversalMachExcServer(
|
||||
UniversalMachExcServer::Interface* interface)
|
||||
: MachMessageServer::Interface(),
|
||||
internal::SimplifiedExcServer::Interface(),
|
||||
internal::SimplifiedMachExcServer::Interface(),
|
||||
exc_server_(this),
|
||||
mach_exc_server_(this) {
|
||||
mach_exc_server_(this),
|
||||
interface_(interface) {
|
||||
}
|
||||
|
||||
bool UniversalMachExcServer::MachMessageServerFunction(
|
||||
@ -718,20 +720,51 @@ kern_return_t UniversalMachExcServer::CatchException(
|
||||
mach_codes.push_back(code[index]);
|
||||
}
|
||||
|
||||
return CatchMachException(behavior,
|
||||
exception_port,
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code_count ? &mach_codes[0] : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state,
|
||||
old_state_count,
|
||||
new_state,
|
||||
new_state_count,
|
||||
trailer,
|
||||
destroy_complex_request);
|
||||
return interface_->CatchMachException(behavior,
|
||||
exception_port,
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code_count ? &mach_codes[0] : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
destroy_complex_request);
|
||||
}
|
||||
|
||||
kern_return_t UniversalMachExcServer::CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
thread_t thread,
|
||||
task_t task,
|
||||
exception_type_t exception,
|
||||
const mach_exception_data_type_t* code,
|
||||
mach_msg_type_number_t code_count,
|
||||
thread_state_flavor_t* flavor,
|
||||
const natural_t* old_state,
|
||||
mach_msg_type_number_t old_state_count,
|
||||
thread_state_t new_state,
|
||||
mach_msg_type_number_t* new_state_count,
|
||||
const mach_msg_trailer_t* trailer,
|
||||
bool* destroy_complex_request) {
|
||||
return interface_->CatchMachException(behavior,
|
||||
exception_port,
|
||||
thread,
|
||||
task,
|
||||
exception,
|
||||
code_count ? code : nullptr,
|
||||
code_count,
|
||||
flavor,
|
||||
old_state_count ? old_state : nullptr,
|
||||
old_state_count,
|
||||
new_state_count ? new_state : nullptr,
|
||||
new_state_count,
|
||||
trailer,
|
||||
destroy_complex_request);
|
||||
}
|
||||
|
||||
exception_type_t ExcCrashRecoverOriginalException(
|
||||
|
@ -329,10 +329,6 @@ class SimplifiedMachExcServer : public MachExcServer,
|
||||
//! `mach_exception_raise_state()`, and
|
||||
//! `mach_exception_raise_state_identity()`.
|
||||
//!
|
||||
//! When used with UniversalMachExcServer, this also handles exceptions
|
||||
//! raised by `exception_raise()`, `exception_raise_state()`, and
|
||||
//! `exception_raise_state_identity()`.
|
||||
//!
|
||||
//! For convenience in implementation, these different “behaviors” of
|
||||
//! exception messages are all mapped to a single interface method. The
|
||||
//! exception’s original “behavior” is specified in the \a behavior
|
||||
@ -346,9 +342,7 @@ class SimplifiedMachExcServer : public MachExcServer,
|
||||
//! `MACH_EXCEPTION_CODES | EXCEPTION_STATE`, or
|
||||
//! `MACH_EXCEPTION_CODES | EXCEPTION_STATE_IDENTITY`, identifying which
|
||||
//! exception request message was processed and thus which other
|
||||
//! parameters are valid. When used with UniversalMachExcServer, \a
|
||||
//! behavior can also be `EXCEPTION_DEFAULT`, `EXCEPTION_STATE`, or
|
||||
//! `EXCEPTION_STATE_IDENTITY`.
|
||||
//! parameters are valid.
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
@ -436,8 +430,52 @@ class UniversalMachExcServer
|
||||
public internal::SimplifiedExcServer::Interface,
|
||||
public internal::SimplifiedMachExcServer::Interface {
|
||||
public:
|
||||
//! \brief An interface that the different request messages that are a part of
|
||||
//! the `exc` and `mach_exc` Mach subsystems can be dispatched to.
|
||||
class Interface {
|
||||
public:
|
||||
//! \brief Handles exceptions raised by `exception_raise()`,
|
||||
//! `exception_raise_state()`, `exception_raise_state_identity()`,
|
||||
//! `mach_exception_raise()`, `mach_exception_raise_state()`, and
|
||||
//! `mach_exception_raise_state_identity()`.
|
||||
//!
|
||||
//! For convenience in implementation, these different “behaviors” of
|
||||
//! exception messages are all mapped to a single interface method. The
|
||||
//! exception’s original “behavior” is specified in the \a behavior
|
||||
//! parameter. Only parameters that were supplied in the request message
|
||||
//! are populated, other parameters are set to reasonable default values.
|
||||
//!
|
||||
//! The meanings of most parameters are identical to that of
|
||||
//! MachExcServer::Interface::CatchMachExceptionRaiseStateIdentity().
|
||||
//!
|
||||
//! \param[in] behavior `EXCEPTION_DEFAULT`, `EXCEPTION_STATE`,
|
||||
//! or `EXCEPTION_STATE_IDENTITY`, possibly with `MACH_EXCEPTION_CODES`
|
||||
//! ORed in. This identifies which exception request message was
|
||||
//! processed and thus which other parameters are valid.
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
thread_t thread,
|
||||
task_t task,
|
||||
exception_type_t exception,
|
||||
const mach_exception_data_type_t* code,
|
||||
mach_msg_type_number_t code_count,
|
||||
thread_state_flavor_t* flavor,
|
||||
const natural_t* old_state,
|
||||
mach_msg_type_number_t old_state_count,
|
||||
thread_state_t new_state,
|
||||
mach_msg_type_number_t* new_state_count,
|
||||
const mach_msg_trailer_t* trailer,
|
||||
bool* destroy_complex_request) = 0;
|
||||
|
||||
protected:
|
||||
~Interface() {}
|
||||
};
|
||||
|
||||
//! \brief Constructs an object of this class.
|
||||
UniversalMachExcServer();
|
||||
//!
|
||||
//! \param[in] interface The interface to dispatch requests to. Weak.
|
||||
explicit UniversalMachExcServer(Interface* interface);
|
||||
|
||||
// MachMessageServer::Interface:
|
||||
|
||||
@ -465,9 +503,27 @@ class UniversalMachExcServer
|
||||
const mach_msg_trailer_t* trailer,
|
||||
bool* destroy_complex_request) override;
|
||||
|
||||
// internal::SimplifiedMachExcServer::Interface:
|
||||
|
||||
kern_return_t CatchMachException(exception_behavior_t behavior,
|
||||
exception_handler_t exception_port,
|
||||
thread_t thread,
|
||||
task_t task,
|
||||
exception_type_t exception,
|
||||
const mach_exception_data_type_t* code,
|
||||
mach_msg_type_number_t code_count,
|
||||
thread_state_flavor_t* flavor,
|
||||
const natural_t* old_state,
|
||||
mach_msg_type_number_t old_state_count,
|
||||
thread_state_t new_state,
|
||||
mach_msg_type_number_t* new_state_count,
|
||||
const mach_msg_trailer_t* trailer,
|
||||
bool* destroy_complex_request) override;
|
||||
|
||||
private:
|
||||
internal::SimplifiedExcServer exc_server_;
|
||||
internal::SimplifiedMachExcServer mach_exc_server_;
|
||||
Interface* interface_; // weak
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(UniversalMachExcServer);
|
||||
};
|
||||
|
@ -449,7 +449,7 @@ struct BadIDErrorReply : public mig_reply_error_t {
|
||||
}
|
||||
};
|
||||
|
||||
class MockUniversalMachExcServer : public UniversalMachExcServer {
|
||||
class MockUniversalMachExcServer : public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
struct ConstExceptionCodes {
|
||||
const mach_exception_data_type_t* code;
|
||||
@ -464,6 +464,8 @@ class MockUniversalMachExcServer : public UniversalMachExcServer {
|
||||
mach_msg_type_number_t* state_count;
|
||||
};
|
||||
|
||||
// UniversalMachExcServer::Interface:
|
||||
|
||||
// CatchMachException is the method to mock, but it has 13 parameters, and
|
||||
// gmock can only mock methods with up to 10 parameters. Coalesce some related
|
||||
// parameters together into structs, and call a mocked method.
|
||||
@ -580,12 +582,15 @@ TEST(ExcServerVariants, MockExceptionRaise) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
ExceptionRaiseRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
ExceptionRaiseReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior = EXCEPTION_DEFAULT;
|
||||
|
||||
@ -605,7 +610,7 @@ TEST(ExcServerVariants, MockExceptionRaise) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -618,12 +623,15 @@ TEST(ExcServerVariants, MockExceptionRaiseState) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
ExceptionRaiseStateRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
ExceptionRaiseStateReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE;
|
||||
|
||||
@ -644,7 +652,7 @@ TEST(ExcServerVariants, MockExceptionRaiseState) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -660,12 +668,15 @@ TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
ExceptionRaiseStateIdentityRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
ExceptionRaiseStateIdentityReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior = EXCEPTION_STATE_IDENTITY;
|
||||
|
||||
@ -686,7 +697,7 @@ TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -699,12 +710,15 @@ TEST(ExcServerVariants, MockMachExceptionRaise) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
MachExceptionRaiseRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
MachExceptionRaiseReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior =
|
||||
EXCEPTION_DEFAULT | MACH_EXCEPTION_CODES;
|
||||
@ -726,7 +740,7 @@ TEST(ExcServerVariants, MockMachExceptionRaise) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -739,12 +753,15 @@ TEST(ExcServerVariants, MockMachExceptionRaiseState) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
MachExceptionRaiseStateRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
MachExceptionRaiseStateReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior =
|
||||
EXCEPTION_STATE | MACH_EXCEPTION_CODES;
|
||||
@ -766,7 +783,7 @@ TEST(ExcServerVariants, MockMachExceptionRaiseState) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -782,12 +799,15 @@ TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
MachExceptionRaiseStateIdentityRequest request;
|
||||
EXPECT_LE(request.Head.msgh_size, server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(request.Head.msgh_size,
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
MachExceptionRaiseStateIdentityReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
const exception_behavior_t kExceptionBehavior =
|
||||
EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES;
|
||||
@ -809,7 +829,7 @@ TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) {
|
||||
.RetiresOnSaturation();
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_TRUE(server.MachMessageServerFunction(
|
||||
EXPECT_TRUE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -822,6 +842,7 @@ TEST(ExcServerVariants, MockUnknownID) {
|
||||
ScopedDefaultValue<kern_return_t> default_kern_return_t(KERN_FAILURE);
|
||||
|
||||
MockUniversalMachExcServer server;
|
||||
UniversalMachExcServer universal_mach_exc_server(&server);
|
||||
|
||||
// Make sure that a message with an unknown ID is handled appropriately.
|
||||
// UniversalMachExcServer should not dispatch the message to
|
||||
@ -862,13 +883,15 @@ TEST(ExcServerVariants, MockUnknownID) {
|
||||
SCOPED_TRACE(base::StringPrintf("unknown id %d", id));
|
||||
|
||||
InvalidRequest request(id);
|
||||
EXPECT_LE(sizeof(request), server.MachMessageServerRequestSize());
|
||||
EXPECT_LE(sizeof(request),
|
||||
universal_mach_exc_server.MachMessageServerRequestSize());
|
||||
|
||||
BadIDErrorReply reply;
|
||||
EXPECT_LE(sizeof(reply), server.MachMessageServerReplySize());
|
||||
EXPECT_LE(sizeof(reply),
|
||||
universal_mach_exc_server.MachMessageServerReplySize());
|
||||
|
||||
bool destroy_complex_request = false;
|
||||
EXPECT_FALSE(server.MachMessageServerFunction(
|
||||
EXPECT_FALSE(universal_mach_exc_server.MachMessageServerFunction(
|
||||
reinterpret_cast<mach_msg_header_t*>(&request),
|
||||
reinterpret_cast<mach_msg_header_t*>(&reply),
|
||||
&destroy_complex_request));
|
||||
@ -883,20 +906,20 @@ TEST(ExcServerVariants, MockUnknownID) {
|
||||
}
|
||||
}
|
||||
|
||||
class TestExcServerVariants : public UniversalMachExcServer,
|
||||
public MachMultiprocess {
|
||||
class TestExcServerVariants : public MachMultiprocess,
|
||||
public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
TestExcServerVariants(exception_behavior_t behavior,
|
||||
thread_state_flavor_t flavor,
|
||||
mach_msg_type_number_t state_count)
|
||||
: UniversalMachExcServer(),
|
||||
MachMultiprocess(),
|
||||
: MachMultiprocess(),
|
||||
UniversalMachExcServer::Interface(),
|
||||
behavior_(behavior),
|
||||
flavor_(flavor),
|
||||
state_count_(state_count),
|
||||
handled_(false) {}
|
||||
|
||||
// UniversalMachExcServer:
|
||||
// UniversalMachExcServer::Interface:
|
||||
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
@ -970,8 +993,10 @@ class TestExcServerVariants : public UniversalMachExcServer,
|
||||
// MachMultiprocess:
|
||||
|
||||
void MachMultiprocessParent() override {
|
||||
UniversalMachExcServer universal_mach_exc_server(this);
|
||||
|
||||
kern_return_t kr =
|
||||
MachMessageServer::Run(this,
|
||||
MachMessageServer::Run(&universal_mach_exc_server,
|
||||
LocalPort(),
|
||||
kMachMessageOptions,
|
||||
MachMessageServer::kOneShot,
|
||||
|
@ -102,8 +102,8 @@ void TestGetExceptionPorts(const ExceptionPorts& exception_ports,
|
||||
}
|
||||
}
|
||||
|
||||
class TestExceptionPorts : public UniversalMachExcServer,
|
||||
public MachMultiprocess {
|
||||
class TestExceptionPorts : public MachMultiprocess,
|
||||
public UniversalMachExcServer::Interface {
|
||||
public:
|
||||
// Where to call ExceptionPorts::SetExceptionPort() from.
|
||||
enum SetType {
|
||||
@ -128,8 +128,8 @@ class TestExceptionPorts : public UniversalMachExcServer,
|
||||
};
|
||||
|
||||
TestExceptionPorts(SetType set_type, SetOn set_on, WhoCrashes who_crashes)
|
||||
: UniversalMachExcServer(),
|
||||
MachMultiprocess(),
|
||||
: MachMultiprocess(),
|
||||
UniversalMachExcServer::Interface(),
|
||||
set_type_(set_type),
|
||||
set_on_(set_on),
|
||||
who_crashes_(who_crashes),
|
||||
@ -139,7 +139,7 @@ class TestExceptionPorts : public UniversalMachExcServer,
|
||||
SetOn set_on() const { return set_on_; }
|
||||
WhoCrashes who_crashes() const { return who_crashes_; }
|
||||
|
||||
// UniversalMachExcServer:
|
||||
// UniversalMachExcServer::Interface:
|
||||
|
||||
virtual kern_return_t CatchMachException(
|
||||
exception_behavior_t behavior,
|
||||
@ -443,8 +443,10 @@ class TestExceptionPorts : public UniversalMachExcServer,
|
||||
CheckedWriteFD(WritePipeFD(), &c, 1);
|
||||
|
||||
if (who_crashes_ != kNobodyCrashes) {
|
||||
UniversalMachExcServer universal_mach_exc_server(this);
|
||||
|
||||
kern_return_t kr =
|
||||
MachMessageServer::Run(this,
|
||||
MachMessageServer::Run(&universal_mach_exc_server,
|
||||
local_port,
|
||||
MACH_MSG_OPTION_NONE,
|
||||
MachMessageServer::kOneShot,
|
||||
|
Loading…
x
Reference in New Issue
Block a user