From 40b1d7cb1d9e22bdc588dd8d2fe76e5688e41616 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Thu, 2 Apr 2015 15:28:28 -0400 Subject: [PATCH] Add ConstThreadState to mach_extensions.h and use it everywhere. TEST=everything R=rsesek@chromium.org Review URL: https://codereview.chromium.org/1058523002 --- client/simulate_crash_mac.cc | 3 -- client/simulate_crash_mac_test.cc | 2 +- handler/mac/crash_report_exception_handler.cc | 2 +- handler/mac/crash_report_exception_handler.h | 2 +- handler/mac/exception_handler_server.cc | 2 +- snapshot/mac/cpu_context_mac.cc | 20 +++---- snapshot/mac/cpu_context_mac.h | 5 +- snapshot/mac/exception_snapshot_mac.cc | 2 +- snapshot/mac/exception_snapshot_mac.h | 3 +- .../mach_o_image_annotations_reader_test.cc | 3 +- snapshot/mac/process_snapshot_mac.cc | 2 +- snapshot/mac/process_snapshot_mac.h | 3 +- tools/mac/catch_exception_tool.cc | 2 +- util/mach/exc_client_variants.cc | 3 +- util/mach/exc_client_variants.h | 4 +- util/mach/exc_client_variants_test.cc | 2 +- util/mach/exc_server_variants.cc | 16 +++--- util/mach/exc_server_variants.h | 5 +- util/mach/exc_server_variants_test.cc | 54 +++++++++---------- util/mach/exception_ports_test.cc | 2 +- util/mach/mach_extensions.h | 7 +++ 21 files changed, 77 insertions(+), 67 deletions(-) diff --git a/client/simulate_crash_mac.cc b/client/simulate_crash_mac.cc index 053b50a2..cdcf662d 100644 --- a/client/simulate_crash_mac.cc +++ b/client/simulate_crash_mac.cc @@ -70,9 +70,6 @@ bool DeliverException(thread_t thread, set_state = false; } - // A const version of thread_state_t. - using ConstThreadState = const natural_t*; - // old_state is only used if the context already captured doesn’t match (or // can’t be converted to) what’s registered for the handler. thread_state_data_t old_state; diff --git a/client/simulate_crash_mac_test.cc b/client/simulate_crash_mac_test.cc index 5ab975fd..e585838a 100644 --- a/client/simulate_crash_mac_test.cc +++ b/client/simulate_crash_mac_test.cc @@ -88,7 +88,7 @@ class TestSimulateCrashMac final : public MachMultiprocess, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/handler/mac/crash_report_exception_handler.cc b/handler/mac/crash_report_exception_handler.cc index 1eaec68c..ba7e97e7 100644 --- a/handler/mac/crash_report_exception_handler.cc +++ b/handler/mac/crash_report_exception_handler.cc @@ -88,7 +88,7 @@ kern_return_t CrashReportExceptionHandler::CatchMachException( const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/handler/mac/crash_report_exception_handler.h b/handler/mac/crash_report_exception_handler.h index 01b95509..67a523a9 100644 --- a/handler/mac/crash_report_exception_handler.h +++ b/handler/mac/crash_report_exception_handler.h @@ -66,7 +66,7 @@ class CrashReportExceptionHandler : public UniversalMachExcServer::Interface { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/handler/mac/exception_handler_server.cc b/handler/mac/exception_handler_server.cc index faf8b6e0..39348ec4 100644 --- a/handler/mac/exception_handler_server.cc +++ b/handler/mac/exception_handler_server.cc @@ -117,7 +117,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/snapshot/mac/cpu_context_mac.cc b/snapshot/mac/cpu_context_mac.cc index a6270869..8dca246c 100644 --- a/snapshot/mac/cpu_context_mac.cc +++ b/snapshot/mac/cpu_context_mac.cc @@ -83,7 +83,7 @@ void InitializeCPUContextX86Debug( thread_state_flavor_t InitializeCPUContextX86Flavor( CPUContextX86* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count) { mach_msg_type_number_t expected_state_count; switch (flavor) { @@ -131,7 +131,7 @@ thread_state_flavor_t InitializeCPUContextX86Flavor( return InitializeCPUContextX86Flavor( context, x86_thread_state->tsh.flavor, - reinterpret_cast(&x86_thread_state->uts.ts32), + reinterpret_cast(&x86_thread_state->uts.ts32), x86_thread_state->tsh.count); } @@ -146,7 +146,7 @@ thread_state_flavor_t InitializeCPUContextX86Flavor( return InitializeCPUContextX86Flavor( context, x86_float_state->fsh.flavor, - reinterpret_cast(&x86_float_state->ufs.fs32), + reinterpret_cast(&x86_float_state->ufs.fs32), x86_float_state->fsh.count); } @@ -161,7 +161,7 @@ thread_state_flavor_t InitializeCPUContextX86Flavor( return InitializeCPUContextX86Flavor( context, x86_debug_state->dsh.flavor, - reinterpret_cast(&x86_debug_state->uds.ds32), + reinterpret_cast(&x86_debug_state->uds.ds32), x86_debug_state->dsh.count); } @@ -264,7 +264,7 @@ void InitializeCPUContextX86_64Debug( thread_state_flavor_t InitializeCPUContextX86_64Flavor( CPUContextX86_64* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count) { mach_msg_type_number_t expected_state_count; switch (flavor) { @@ -312,7 +312,7 @@ thread_state_flavor_t InitializeCPUContextX86_64Flavor( return InitializeCPUContextX86_64Flavor( context, x86_thread_state->tsh.flavor, - reinterpret_cast(&x86_thread_state->uts.ts64), + reinterpret_cast(&x86_thread_state->uts.ts64), x86_thread_state->tsh.count); } @@ -327,7 +327,7 @@ thread_state_flavor_t InitializeCPUContextX86_64Flavor( return InitializeCPUContextX86_64Flavor( context, x86_float_state->fsh.flavor, - reinterpret_cast(&x86_float_state->ufs.fs64), + reinterpret_cast(&x86_float_state->ufs.fs64), x86_float_state->fsh.count); } @@ -342,7 +342,7 @@ thread_state_flavor_t InitializeCPUContextX86_64Flavor( return InitializeCPUContextX86_64Flavor( context, x86_debug_state->dsh.flavor, - reinterpret_cast(&x86_debug_state->uds.ds64), + reinterpret_cast(&x86_debug_state->uds.ds64), x86_debug_state->dsh.count); } @@ -387,7 +387,7 @@ namespace internal { void InitializeCPUContextX86(CPUContextX86* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count, const x86_thread_state32_t* x86_thread_state32, const x86_float_state32_t* x86_float_state32, @@ -411,7 +411,7 @@ void InitializeCPUContextX86(CPUContextX86* context, void InitializeCPUContextX86_64(CPUContextX86_64* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count, const x86_thread_state64_t* x86_thread_state64, const x86_float_state64_t* x86_float_state64, diff --git a/snapshot/mac/cpu_context_mac.h b/snapshot/mac/cpu_context_mac.h index d8086378..1d016cf5 100644 --- a/snapshot/mac/cpu_context_mac.h +++ b/snapshot/mac/cpu_context_mac.h @@ -19,6 +19,7 @@ #include "build/build_config.h" #include "snapshot/cpu_context.h" +#include "util/mach/mach_extensions.h" namespace crashpad { namespace internal { @@ -60,7 +61,7 @@ namespace internal { //! \param[in] x86_debug_state32 The state of the thread’s debug registers. void InitializeCPUContextX86(CPUContextX86* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count, const x86_thread_state32_t* x86_thread_state32, const x86_float_state32_t* x86_float_state32, @@ -101,7 +102,7 @@ void InitializeCPUContextX86(CPUContextX86* context, //! \param[in] x86_debug_state64 The state of the thread’s debug registers. void InitializeCPUContextX86_64(CPUContextX86_64* context, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count, const x86_thread_state64_t* x86_thread_state64, const x86_float_state64_t* x86_float_state64, diff --git a/snapshot/mac/exception_snapshot_mac.cc b/snapshot/mac/exception_snapshot_mac.cc index 95d8c620..69ac6b52 100644 --- a/snapshot/mac/exception_snapshot_mac.cc +++ b/snapshot/mac/exception_snapshot_mac.cc @@ -45,7 +45,7 @@ bool ExceptionSnapshotMac::Initialize(ProcessReader* process_reader, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count) { INITIALIZATION_STATE_SET_INITIALIZING(initialized_); diff --git a/snapshot/mac/exception_snapshot_mac.h b/snapshot/mac/exception_snapshot_mac.h index fd0eab01..e6255b1b 100644 --- a/snapshot/mac/exception_snapshot_mac.h +++ b/snapshot/mac/exception_snapshot_mac.h @@ -24,6 +24,7 @@ #include "build/build_config.h" #include "snapshot/cpu_context.h" #include "snapshot/exception_snapshot.h" +#include "util/mach/mach_extensions.h" #include "util/misc/initialization_state_dcheck.h" namespace crashpad { @@ -55,7 +56,7 @@ class ExceptionSnapshotMac final : public ExceptionSnapshot { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count); // ExceptionSnapshot: diff --git a/snapshot/mac/mach_o_image_annotations_reader_test.cc b/snapshot/mac/mach_o_image_annotations_reader_test.cc index 50ba56f9..b9a782ca 100644 --- a/snapshot/mac/mach_o_image_annotations_reader_test.cc +++ b/snapshot/mac/mach_o_image_annotations_reader_test.cc @@ -37,6 +37,7 @@ #include "util/mac/mac_util.h" #include "util/mach/exc_server_variants.h" #include "util/mach/exception_ports.h" +#include "util/mach/mach_extensions.h" #include "util/mach/mach_message.h" #include "util/mach/mach_message_server.h" @@ -79,7 +80,7 @@ class TestMachOImageAnnotationsReader final const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/snapshot/mac/process_snapshot_mac.cc b/snapshot/mac/process_snapshot_mac.cc index 76cd3186..71d45c3c 100644 --- a/snapshot/mac/process_snapshot_mac.cc +++ b/snapshot/mac/process_snapshot_mac.cc @@ -62,7 +62,7 @@ bool ProcessSnapshotMac::InitializeException( const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count) { INITIALIZATION_STATE_DCHECK_VALID(initialized_); DCHECK(!exception_); diff --git a/snapshot/mac/process_snapshot_mac.h b/snapshot/mac/process_snapshot_mac.h index 7221d2cf..d9d34804 100644 --- a/snapshot/mac/process_snapshot_mac.h +++ b/snapshot/mac/process_snapshot_mac.h @@ -37,6 +37,7 @@ #include "snapshot/process_snapshot.h" #include "snapshot/system_snapshot.h" #include "snapshot/thread_snapshot.h" +#include "util/mach/mach_extensions.h" #include "util/misc/initialization_state_dcheck.h" #include "util/misc/uuid.h" #include "util/stdlib/pointer_container.h" @@ -74,7 +75,7 @@ class ProcessSnapshotMac final : public ProcessSnapshot { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t flavor, - const natural_t* state, + ConstThreadState state, mach_msg_type_number_t state_count); //! \brief Sets the value to be returned by ReportID(). diff --git a/tools/mac/catch_exception_tool.cc b/tools/mac/catch_exception_tool.cc index eb97befb..08a916bf 100644 --- a/tools/mac/catch_exception_tool.cc +++ b/tools/mac/catch_exception_tool.cc @@ -68,7 +68,7 @@ class ExceptionServer : public UniversalMachExcServer::Interface { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/util/mach/exc_client_variants.cc b/util/mach/exc_client_variants.cc index 0c51bc34..71e39691 100644 --- a/util/mach/exc_client_variants.cc +++ b/util/mach/exc_client_variants.cc @@ -19,7 +19,6 @@ #include "base/logging.h" #include "util/mach/exc.h" #include "util/mach/mach_exc.h" -#include "util/mach/mach_extensions.h" namespace crashpad { @@ -31,7 +30,7 @@ kern_return_t UniversalExceptionRaise(exception_behavior_t behavior, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count) { diff --git a/util/mach/exc_client_variants.h b/util/mach/exc_client_variants.h index f797f448..d96e689e 100644 --- a/util/mach/exc_client_variants.h +++ b/util/mach/exc_client_variants.h @@ -17,6 +17,8 @@ #include +#include "util/mach/mach_extensions.h" + namespace crashpad { //! \brief Calls the appropriate `*exception_raise*()` function for the @@ -73,7 +75,7 @@ kern_return_t UniversalExceptionRaise(exception_behavior_t behavior, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count); diff --git a/util/mach/exc_client_variants_test.cc b/util/mach/exc_client_variants_test.cc index a2ceafd5..b3d34ed0 100644 --- a/util/mach/exc_client_variants_test.cc +++ b/util/mach/exc_client_variants_test.cc @@ -58,7 +58,7 @@ class TestExcClientVariants : public MachMultiprocess, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/util/mach/exc_server_variants.cc b/util/mach/exc_server_variants.cc index b6e046a4..e204ca5d 100644 --- a/util/mach/exc_server_variants.cc +++ b/util/mach/exc_server_variants.cc @@ -276,7 +276,7 @@ class ExcServer : public MachMessageServer::Interface { const typename Traits::ExceptionCode* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -302,7 +302,7 @@ class ExcServer : public MachMessageServer::Interface { const typename Traits::ExceptionCode* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -523,7 +523,7 @@ class SimplifiedExcServer final : public ExcServer, const typename Traits::ExceptionCode* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -577,7 +577,7 @@ class SimplifiedExcServer final : public ExcServer, const typename Traits::ExceptionCode* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -608,7 +608,7 @@ class SimplifiedExcServer final : public ExcServer, const typename Traits::ExceptionCode* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -669,7 +669,7 @@ class UniversalMachExcServerImpl final const exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -706,7 +706,7 @@ class UniversalMachExcServerImpl final const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -804,7 +804,7 @@ kern_return_t ExcServerSuccessfulReturnValue(exception_behavior_t behavior, } void ExcServerCopyState(exception_behavior_t behavior, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count) { diff --git a/util/mach/exc_server_variants.h b/util/mach/exc_server_variants.h index 3109ca0d..5b791688 100644 --- a/util/mach/exc_server_variants.h +++ b/util/mach/exc_server_variants.h @@ -21,6 +21,7 @@ #include "base/basictypes.h" #include "base/memory/scoped_ptr.h" +#include "util/mach/mach_extensions.h" #include "util/mach/mach_message_server.h" namespace crashpad { @@ -83,7 +84,7 @@ class UniversalMachExcServer final : public MachMessageServer::Interface { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -231,7 +232,7 @@ kern_return_t ExcServerSuccessfulReturnValue(exception_behavior_t behavior, //! \a behavior is state-carrying, this parameter should be at least as //! large as \a old_state_count. void ExcServerCopyState(exception_behavior_t behavior, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count); diff --git a/util/mach/exc_server_variants_test.cc b/util/mach/exc_server_variants_test.cc index b0309bee..b24f7b6a 100644 --- a/util/mach/exc_server_variants_test.cc +++ b/util/mach/exc_server_variants_test.cc @@ -24,7 +24,6 @@ #include "test/mac/mach_errors.h" #include "test/mac/mach_multiprocess.h" #include "util/mach/exception_behaviors.h" -#include "util/mach/mach_extensions.h" #include "util/mach/mach_message.h" namespace crashpad { @@ -455,12 +454,12 @@ class MockUniversalMachExcServer : public UniversalMachExcServer::Interface { const mach_exception_data_type_t* code; mach_msg_type_number_t code_count; }; - struct ThreadState { + struct ThreadStateAndCount { thread_state_t state; mach_msg_type_number_t* state_count; }; - struct ConstThreadState { - const natural_t* state; + struct ConstThreadStateAndCount { + ConstThreadState state; mach_msg_type_number_t* state_count; }; @@ -478,7 +477,7 @@ class MockUniversalMachExcServer : public UniversalMachExcServer::Interface { const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, @@ -486,8 +485,9 @@ class MockUniversalMachExcServer : public UniversalMachExcServer::Interface { bool* destroy_complex_request) override { *destroy_complex_request = true; const ConstExceptionCodes exception_codes = {code, code_count}; - const ConstThreadState old_thread_state = {old_state, &old_state_count}; - ThreadState new_thread_state = {new_state, new_state_count}; + const ConstThreadStateAndCount old_thread_state = {old_state, + &old_state_count}; + ThreadStateAndCount new_thread_state = {new_state, new_state_count}; return MockCatchMachException(behavior, exception_port, thread, @@ -508,8 +508,8 @@ class MockUniversalMachExcServer : public UniversalMachExcServer::Interface { exception_type_t exception, const ConstExceptionCodes* exception_codes, thread_state_flavor_t* flavor, - const ConstThreadState* old_thread_state, - ThreadState* new_thread_state, + const ConstThreadStateAndCount* old_thread_state, + ThreadStateAndCount* new_thread_state, const mach_msg_trailer_t* trailer)); }; @@ -537,11 +537,11 @@ MATCHER_P2(AreExceptionCodes, code_0, code_1, "") { return false; } -// Matcher for ThreadState and ConstThreadState, testing that *state_count is -// present and matches the specified value. If 0 is specified for the count, -// |state| must be nullptr (not present), otherwise |state| must not be nullptr -// (present). -MATCHER_P(IsThreadStateCount, state_count, "") { +// Matcher for ThreadStateAndCount and ConstThreadStateAndCount, testing that +// *state_count is present and matches the specified value. If 0 is specified +// for the count, |state| must be nullptr (not present), otherwise |state| must +// not be nullptr (present). +MATCHER_P(IsThreadStateAndCount, state_count, "") { if (!arg) { return false; } @@ -607,8 +607,8 @@ TEST(ExcServerVariants, MockExceptionRaise) { AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), Pointee(Eq(THREAD_STATE_NONE)), - IsThreadStateCount(0u), - IsThreadStateCount(0u), + IsThreadStateAndCount(0u), + IsThreadStateAndCount(0u), Eq(&request.trailer))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -653,8 +653,8 @@ TEST(ExcServerVariants, MockExceptionRaiseState) { kExceptionType, AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), Pointee(Eq(kThreadStateFlavor)), - IsThreadStateCount(kThreadStateFlavorCount), - IsThreadStateCount(arraysize(reply.new_state)), + IsThreadStateAndCount(kThreadStateFlavorCount), + IsThreadStateAndCount(arraysize(reply.new_state)), Eq(request.Trailer()))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -702,8 +702,8 @@ TEST(ExcServerVariants, MockExceptionRaiseStateIdentity) { kExceptionType, AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]), Pointee(Eq(kThreadStateFlavor)), - IsThreadStateCount(kThreadStateFlavorCount), - IsThreadStateCount(arraysize(reply.new_state)), + IsThreadStateAndCount(kThreadStateFlavorCount), + IsThreadStateAndCount(arraysize(reply.new_state)), Eq(request.Trailer()))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -749,8 +749,8 @@ TEST(ExcServerVariants, MockMachExceptionRaise) { AreExceptionCodes(kTestMachExceptionCodes[0], kTestMachExceptionCodes[1]), Pointee(Eq(THREAD_STATE_NONE)), - IsThreadStateCount(0u), - IsThreadStateCount(0u), + IsThreadStateAndCount(0u), + IsThreadStateAndCount(0u), Eq(&request.trailer))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -796,8 +796,8 @@ TEST(ExcServerVariants, MockMachExceptionRaiseState) { AreExceptionCodes(kTestMachExceptionCodes[0], kTestMachExceptionCodes[1]), Pointee(Eq(kThreadStateFlavor)), - IsThreadStateCount(kThreadStateFlavorCount), - IsThreadStateCount(arraysize(reply.new_state)), + IsThreadStateAndCount(kThreadStateFlavorCount), + IsThreadStateAndCount(arraysize(reply.new_state)), Eq(request.Trailer()))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -846,8 +846,8 @@ TEST(ExcServerVariants, MockMachExceptionRaiseStateIdentity) { AreExceptionCodes(kTestMachExceptionCodes[0], kTestMachExceptionCodes[1]), Pointee(Eq(kThreadStateFlavor)), - IsThreadStateCount(kThreadStateFlavorCount), - IsThreadStateCount(arraysize(reply.new_state)), + IsThreadStateAndCount(kThreadStateFlavorCount), + IsThreadStateAndCount(arraysize(reply.new_state)), Eq(request.Trailer()))) .WillOnce(Return(KERN_SUCCESS)) .RetiresOnSaturation(); @@ -976,7 +976,7 @@ class TestExcServerVariants : public MachMultiprocess, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/util/mach/exception_ports_test.cc b/util/mach/exception_ports_test.cc index 37e44dd3..9b81eb2d 100644 --- a/util/mach/exception_ports_test.cc +++ b/util/mach/exception_ports_test.cc @@ -152,7 +152,7 @@ class TestExceptionPorts : public MachMultiprocess, const mach_exception_data_type_t* code, mach_msg_type_number_t code_count, thread_state_flavor_t* flavor, - const natural_t* old_state, + ConstThreadState old_state, mach_msg_type_number_t old_state_count, thread_state_t new_state, mach_msg_type_number_t* new_state_count, diff --git a/util/mach/mach_extensions.h b/util/mach/mach_extensions.h index 6c378ca6..d1e392ad 100644 --- a/util/mach/mach_extensions.h +++ b/util/mach/mach_extensions.h @@ -47,6 +47,13 @@ const exception_behavior_t kMachExceptionCodes = MACH_EXCEPTION_CODES; //! \brief An exception type to use for simulated exceptions. const exception_type_t kMachExceptionSimulated = 'CPsx'; +//! \brief A const version of `thread_state_t`. +//! +//! This is useful as the \a old_state parameter to exception handler functions. +//! Normally, these parameters are of type `thread_state_t`, but this allows +//! modification of the state, which is conceptually `const`. +using ConstThreadState = const natural_t*; + //! \brief Like `mach_thread_self()`, but without the obligation to release the //! send right. //!