From 4d35ffa80ebafdcdec5b580323a1005b182d2ec9 Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Thu, 18 Sep 2014 13:53:43 -0400 Subject: [PATCH] Use more-specific typedefs for send rights to task, thread, and exception handler ports. task_t, thread_t, and exception_handler_t are typedefs for mach_port_t. They are more descriptive than mach_port_t, and are already in use in exc_server_variants. TEST=util_test R=rsesek@chromium.org Review URL: https://codereview.chromium.org/577293002 --- tools/exception_port_tool.cc | 4 ++-- util/mac/process_reader.cc | 4 ++-- util/mac/process_reader.h | 6 +++--- util/mac/process_reader_test.cc | 8 ++++---- util/mach/exc_server_variants_test.cc | 4 ++-- util/mach/mach_extensions.cc | 4 ++-- util/mach/mach_extensions.h | 2 +- util/mach/mach_message_server.cc | 6 ++---- util/mach/task_memory.cc | 2 +- util/mach/task_memory.h | 4 ++-- util/test/mac/mach_multiprocess.cc | 2 +- util/test/mac/mach_multiprocess.h | 2 +- 12 files changed, 23 insertions(+), 25 deletions(-) diff --git a/tools/exception_port_tool.cc b/tools/exception_port_tool.cc index 728cf3e8..52ef223b 100644 --- a/tools/exception_port_tool.cc +++ b/tools/exception_port_tool.cc @@ -280,7 +280,7 @@ void ShowExceptionPorts(const ExceptionPorts& exception_ports, bool SetExceptionPort(const ExceptionHandlerDescription* description, mach_port_t target_port) { base::mac::ScopedMachSendRight service_port_owner; - mach_port_t service_port = MACH_PORT_NULL; + exception_handler_t service_port = MACH_PORT_NULL; kern_return_t kr; if (description->handler.compare( 0, strlen(kHandlerBootstrapColon), kHandlerBootstrapColon) == 0) { @@ -394,7 +394,7 @@ int main(int argc, char* argv[]) { std::vector show_bootstrap; std::vector set_handler; pid_t pid; - mach_port_t alternate_task; + task_t alternate_task; bool show_host; bool show_task; bool show_thread; diff --git a/util/mac/process_reader.cc b/util/mac/process_reader.cc index de48eba6..5d990c4e 100644 --- a/util/mac/process_reader.cc +++ b/util/mac/process_reader.cc @@ -35,7 +35,7 @@ void MachTimeValueToTimeval(const time_value& mach, timeval* tv) { tv->tv_usec = mach.microseconds; } -kern_return_t MachVMRegionRecurseDeepest(mach_port_t task, +kern_return_t MachVMRegionRecurseDeepest(task_t task, mach_vm_address_t* address, mach_vm_size_t* size, natural_t* depth, @@ -107,7 +107,7 @@ ProcessReader::~ProcessReader() { } } -bool ProcessReader::Initialize(mach_port_t task) { +bool ProcessReader::Initialize(task_t task) { INITIALIZATION_STATE_SET_INITIALIZING(initialized_); pid_t pid; diff --git a/util/mac/process_reader.h b/util/mac/process_reader.h index 0e5a30ef..fd5f209e 100644 --- a/util/mac/process_reader.h +++ b/util/mac/process_reader.h @@ -64,7 +64,7 @@ class ProcessReader { mach_vm_address_t stack_region_address; mach_vm_size_t stack_region_size; mach_vm_address_t thread_specific_data_address; - mach_port_t port; + task_t port; int suspend_count; int priority; }; @@ -101,7 +101,7 @@ class ProcessReader { //! \return `true` on success, indicating that this object will respond //! validly to further method calls. `false` on failure. On failure, no //! further method calls should be made. - bool Initialize(mach_port_t task); + bool Initialize(task_t task); //! \return `true` if the target task is a 64-bit process. bool Is64Bit() const { return is_64_bit_; } @@ -205,7 +205,7 @@ class ProcessReader { std::vector threads_; // owns send rights std::vector modules_; scoped_ptr task_memory_; - mach_port_t task_; // weak + task_t task_; // weak InitializationStateDcheck initialized_; // This shadows a bit in kern_proc_info_, but it’s accessed so frequently that diff --git a/util/mac/process_reader_test.cc b/util/mac/process_reader_test.cc index f60d3f87..d6726738 100644 --- a/util/mac/process_reader_test.cc +++ b/util/mac/process_reader_test.cc @@ -154,7 +154,7 @@ TEST(ProcessReader, SelfOneThread) { EXPECT_EQ(PthreadToThreadID(pthread_self()), threads[0].id); - mach_port_t thread_self = MachThreadSelf(); + thread_t thread_self = MachThreadSelf(); EXPECT_EQ(thread_self, threads[0].port); EXPECT_EQ(0, threads[0].suspend_count); @@ -174,7 +174,7 @@ class TestThreadPool { // to exit, and joins each thread, blocking until they have all exited. ~TestThreadPool() { for (ThreadInfo* thread_info : thread_infos_) { - mach_port_t thread_port = pthread_mach_thread_np(thread_info->pthread); + thread_t thread_port = pthread_mach_thread_np(thread_info->pthread); while (thread_info->suspend_count > 0) { kern_return_t kr = thread_resume(thread_port); EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); @@ -220,7 +220,7 @@ class TestThreadPool { for (size_t thread_index = 1; thread_index < thread_infos_.size() && thread_index < 4; ++thread_index) { - mach_port_t thread_port = + thread_t thread_port = pthread_mach_thread_np(thread_infos_[thread_index]->pthread); for (size_t suspend_count = 0; suspend_count < thread_index; @@ -419,7 +419,7 @@ TEST(ProcessReader, SelfSeveralThreads) { // When testing in-process, verify that when this thread shows up in the // vector, it has the expected thread port, and that this thread port only // shows up once. - mach_port_t thread_self = MachThreadSelf(); + thread_t thread_self = MachThreadSelf(); bool found_thread_self = false; for (const ProcessReader::Thread& thread : threads) { if (thread.port == thread_self) { diff --git a/util/mach/exc_server_variants_test.cc b/util/mach/exc_server_variants_test.cc index 35c6d660..9f4963a3 100644 --- a/util/mach/exc_server_variants_test.cc +++ b/util/mach/exc_server_variants_test.cc @@ -38,8 +38,8 @@ using namespace testing; // places. const mach_port_t kClientRemotePort = 0x01010101; const mach_port_t kServerLocalPort = 0x02020202; -const mach_port_t kExceptionThreadPort = 0x03030303; -const mach_port_t kExceptionTaskPort = 0x04040404; +const thread_t kExceptionThreadPort = 0x03030303; +const task_t kExceptionTaskPort = 0x04040404; // Other fake exception values. const exception_type_t kExceptionType = EXC_BAD_ACCESS; diff --git a/util/mach/mach_extensions.cc b/util/mach/mach_extensions.cc index d012538e..86ca7bf2 100644 --- a/util/mach/mach_extensions.cc +++ b/util/mach/mach_extensions.cc @@ -21,8 +21,8 @@ namespace crashpad { -mach_port_t MachThreadSelf() { - // The pthreads library keeps its own copy of the mach_port_t. Using it does +thread_t MachThreadSelf() { + // The pthreads library keeps its own copy of the thread port. Using it does // not increment its reference count. return pthread_mach_thread_np(pthread_self()); } diff --git a/util/mach/mach_extensions.h b/util/mach/mach_extensions.h index f9d04b71..14a2862f 100644 --- a/util/mach/mach_extensions.h +++ b/util/mach/mach_extensions.h @@ -65,7 +65,7 @@ const exception_type_t kMachExceptionSimulated = 'CPsx'; //! count. The returned port must not be deallocated by //! `mach_port_deallocate()`. The returned value is valid as long as the //! thread continues to exist as a `pthread_t`. -mach_port_t MachThreadSelf(); +thread_t MachThreadSelf(); //! \brief The value for `EXC_MASK_ALL` appropriate for the operating system at //! run time. diff --git a/util/mach/mach_message_server.cc b/util/mach/mach_message_server.cc index 98e41041..e79acfe4 100644 --- a/util/mach/mach_message_server.cc +++ b/util/mach/mach_message_server.cc @@ -133,8 +133,6 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface, (options & MACH_SEND_TRAILER) ? (max_reply_size + MAX_TRAILER_SIZE) : max_reply_size); - mach_port_t self = mach_task_self(); - kern_return_t kr; do { @@ -146,7 +144,7 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface, while (!request_scoper.address()) { vm_address_t request_addr; - kr = vm_allocate(self, + kr = vm_allocate(mach_task_self(), &request_addr, this_request_alloc, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG)); @@ -189,7 +187,7 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface, } vm_address_t reply_addr; - kr = vm_allocate(self, + kr = vm_allocate(mach_task_self(), &reply_addr, reply_alloc, VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG)); diff --git a/util/mach/task_memory.cc b/util/mach/task_memory.cc index d3d2ea6f..b87d02ea 100644 --- a/util/mach/task_memory.cc +++ b/util/mach/task_memory.cc @@ -64,7 +64,7 @@ TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address, DCHECK_LE(user_end, vm_end); } -TaskMemory::TaskMemory(mach_port_t task) : task_(task) { +TaskMemory::TaskMemory(task_t task) : task_(task) { } bool TaskMemory::Read(mach_vm_address_t address, size_t size, void* buffer) { diff --git a/util/mach/task_memory.h b/util/mach/task_memory.h index 374f3304..cd1adf96 100644 --- a/util/mach/task_memory.h +++ b/util/mach/task_memory.h @@ -88,7 +88,7 @@ class TaskMemory { //! \param[in] task A send right to the target task’s task port. This object //! does not take ownership of the send right. - explicit TaskMemory(mach_port_t task); + explicit TaskMemory(task_t task); ~TaskMemory() {} @@ -167,7 +167,7 @@ class TaskMemory { mach_vm_size_t size, std::string* string); - mach_port_t task_; // weak + task_t task_; // weak DISALLOW_COPY_AND_ASSIGN(TaskMemory); }; diff --git a/util/test/mac/mach_multiprocess.cc b/util/test/mac/mach_multiprocess.cc index f41024e5..10fe15de 100644 --- a/util/test/mac/mach_multiprocess.cc +++ b/util/test/mac/mach_multiprocess.cc @@ -115,7 +115,7 @@ mach_port_t MachMultiprocess::RemotePort() const { return info_->remote_port; } -mach_port_t MachMultiprocess::ChildTask() const { +task_t MachMultiprocess::ChildTask() const { EXPECT_NE(kMachPortNull, info_->child_task); return info_->child_task; } diff --git a/util/test/mac/mach_multiprocess.h b/util/test/mac/mach_multiprocess.h index b949e652..e709533a 100644 --- a/util/test/mac/mach_multiprocess.h +++ b/util/test/mac/mach_multiprocess.h @@ -68,7 +68,7 @@ class MachMultiprocess : public Multiprocess { //! \brief Returns a send right for the child’s task port. //! //! This method may only be called by the parent process. - mach_port_t ChildTask() const; + task_t ChildTask() const; private: // Multiprocess: