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
This commit is contained in:
Mark Mentovai 2014-09-18 13:53:43 -04:00
parent 1b61c90e7c
commit 4d35ffa80e
12 changed files with 23 additions and 25 deletions

View File

@ -280,7 +280,7 @@ void ShowExceptionPorts(const ExceptionPorts& exception_ports,
bool SetExceptionPort(const ExceptionHandlerDescription* description, bool SetExceptionPort(const ExceptionHandlerDescription* description,
mach_port_t target_port) { mach_port_t target_port) {
base::mac::ScopedMachSendRight service_port_owner; 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; kern_return_t kr;
if (description->handler.compare( if (description->handler.compare(
0, strlen(kHandlerBootstrapColon), kHandlerBootstrapColon) == 0) { 0, strlen(kHandlerBootstrapColon), kHandlerBootstrapColon) == 0) {
@ -394,7 +394,7 @@ int main(int argc, char* argv[]) {
std::vector<const char*> show_bootstrap; std::vector<const char*> show_bootstrap;
std::vector<ExceptionHandlerDescription> set_handler; std::vector<ExceptionHandlerDescription> set_handler;
pid_t pid; pid_t pid;
mach_port_t alternate_task; task_t alternate_task;
bool show_host; bool show_host;
bool show_task; bool show_task;
bool show_thread; bool show_thread;

View File

@ -35,7 +35,7 @@ void MachTimeValueToTimeval(const time_value& mach, timeval* tv) {
tv->tv_usec = mach.microseconds; 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_address_t* address,
mach_vm_size_t* size, mach_vm_size_t* size,
natural_t* depth, 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_); INITIALIZATION_STATE_SET_INITIALIZING(initialized_);
pid_t pid; pid_t pid;

View File

@ -64,7 +64,7 @@ class ProcessReader {
mach_vm_address_t stack_region_address; mach_vm_address_t stack_region_address;
mach_vm_size_t stack_region_size; mach_vm_size_t stack_region_size;
mach_vm_address_t thread_specific_data_address; mach_vm_address_t thread_specific_data_address;
mach_port_t port; task_t port;
int suspend_count; int suspend_count;
int priority; int priority;
}; };
@ -101,7 +101,7 @@ class ProcessReader {
//! \return `true` on success, indicating that this object will respond //! \return `true` on success, indicating that this object will respond
//! validly to further method calls. `false` on failure. On failure, no //! validly to further method calls. `false` on failure. On failure, no
//! further method calls should be made. //! 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. //! \return `true` if the target task is a 64-bit process.
bool Is64Bit() const { return is_64_bit_; } bool Is64Bit() const { return is_64_bit_; }
@ -205,7 +205,7 @@ class ProcessReader {
std::vector<Thread> threads_; // owns send rights std::vector<Thread> threads_; // owns send rights
std::vector<Module> modules_; std::vector<Module> modules_;
scoped_ptr<TaskMemory> task_memory_; scoped_ptr<TaskMemory> task_memory_;
mach_port_t task_; // weak task_t task_; // weak
InitializationStateDcheck initialized_; InitializationStateDcheck initialized_;
// This shadows a bit in kern_proc_info_, but its accessed so frequently that // This shadows a bit in kern_proc_info_, but its accessed so frequently that

View File

@ -154,7 +154,7 @@ TEST(ProcessReader, SelfOneThread) {
EXPECT_EQ(PthreadToThreadID(pthread_self()), threads[0].id); 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(thread_self, threads[0].port);
EXPECT_EQ(0, threads[0].suspend_count); 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. // to exit, and joins each thread, blocking until they have all exited.
~TestThreadPool() { ~TestThreadPool() {
for (ThreadInfo* thread_info : thread_infos_) { 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) { while (thread_info->suspend_count > 0) {
kern_return_t kr = thread_resume(thread_port); kern_return_t kr = thread_resume(thread_port);
EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume"); EXPECT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "thread_resume");
@ -220,7 +220,7 @@ class TestThreadPool {
for (size_t thread_index = 1; for (size_t thread_index = 1;
thread_index < thread_infos_.size() && thread_index < 4; thread_index < thread_infos_.size() && thread_index < 4;
++thread_index) { ++thread_index) {
mach_port_t thread_port = thread_t thread_port =
pthread_mach_thread_np(thread_infos_[thread_index]->pthread); pthread_mach_thread_np(thread_infos_[thread_index]->pthread);
for (size_t suspend_count = 0; for (size_t suspend_count = 0;
suspend_count < thread_index; suspend_count < thread_index;
@ -419,7 +419,7 @@ TEST(ProcessReader, SelfSeveralThreads) {
// When testing in-process, verify that when this thread shows up in the // 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 // vector, it has the expected thread port, and that this thread port only
// shows up once. // shows up once.
mach_port_t thread_self = MachThreadSelf(); thread_t thread_self = MachThreadSelf();
bool found_thread_self = false; bool found_thread_self = false;
for (const ProcessReader::Thread& thread : threads) { for (const ProcessReader::Thread& thread : threads) {
if (thread.port == thread_self) { if (thread.port == thread_self) {

View File

@ -38,8 +38,8 @@ using namespace testing;
// places. // places.
const mach_port_t kClientRemotePort = 0x01010101; const mach_port_t kClientRemotePort = 0x01010101;
const mach_port_t kServerLocalPort = 0x02020202; const mach_port_t kServerLocalPort = 0x02020202;
const mach_port_t kExceptionThreadPort = 0x03030303; const thread_t kExceptionThreadPort = 0x03030303;
const mach_port_t kExceptionTaskPort = 0x04040404; const task_t kExceptionTaskPort = 0x04040404;
// Other fake exception values. // Other fake exception values.
const exception_type_t kExceptionType = EXC_BAD_ACCESS; const exception_type_t kExceptionType = EXC_BAD_ACCESS;

View File

@ -21,8 +21,8 @@
namespace crashpad { namespace crashpad {
mach_port_t MachThreadSelf() { thread_t MachThreadSelf() {
// The pthreads library keeps its own copy of the mach_port_t. Using it does // The pthreads library keeps its own copy of the thread port. Using it does
// not increment its reference count. // not increment its reference count.
return pthread_mach_thread_np(pthread_self()); return pthread_mach_thread_np(pthread_self());
} }

View File

@ -65,7 +65,7 @@ const exception_type_t kMachExceptionSimulated = 'CPsx';
//! count. The returned port must not be deallocated by //! count. The returned port must not be deallocated by
//! `mach_port_deallocate()`. The returned value is valid as long as the //! `mach_port_deallocate()`. The returned value is valid as long as the
//! thread continues to exist as a `pthread_t`. //! 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 //! \brief The value for `EXC_MASK_ALL` appropriate for the operating system at
//! run time. //! run time.

View File

@ -133,8 +133,6 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface,
(options & MACH_SEND_TRAILER) ? (max_reply_size + MAX_TRAILER_SIZE) (options & MACH_SEND_TRAILER) ? (max_reply_size + MAX_TRAILER_SIZE)
: max_reply_size); : max_reply_size);
mach_port_t self = mach_task_self();
kern_return_t kr; kern_return_t kr;
do { do {
@ -146,7 +144,7 @@ mach_msg_return_t MachMessageServer::Run(Interface* interface,
while (!request_scoper.address()) { while (!request_scoper.address()) {
vm_address_t request_addr; vm_address_t request_addr;
kr = vm_allocate(self, kr = vm_allocate(mach_task_self(),
&request_addr, &request_addr,
this_request_alloc, this_request_alloc,
VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG)); 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; vm_address_t reply_addr;
kr = vm_allocate(self, kr = vm_allocate(mach_task_self(),
&reply_addr, &reply_addr,
reply_alloc, reply_alloc,
VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG)); VM_FLAGS_ANYWHERE | VM_MAKE_TAG(VM_MEMORY_MACH_MSG));

View File

@ -64,7 +64,7 @@ TaskMemory::MappedMemory::MappedMemory(vm_address_t vm_address,
DCHECK_LE(user_end, vm_end); 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) { bool TaskMemory::Read(mach_vm_address_t address, size_t size, void* buffer) {

View File

@ -88,7 +88,7 @@ class TaskMemory {
//! \param[in] task A send right to the target tasks task port. This object //! \param[in] task A send right to the target tasks task port. This object
//! does not take ownership of the send right. //! does not take ownership of the send right.
explicit TaskMemory(mach_port_t task); explicit TaskMemory(task_t task);
~TaskMemory() {} ~TaskMemory() {}
@ -167,7 +167,7 @@ class TaskMemory {
mach_vm_size_t size, mach_vm_size_t size,
std::string* string); std::string* string);
mach_port_t task_; // weak task_t task_; // weak
DISALLOW_COPY_AND_ASSIGN(TaskMemory); DISALLOW_COPY_AND_ASSIGN(TaskMemory);
}; };

View File

@ -115,7 +115,7 @@ mach_port_t MachMultiprocess::RemotePort() const {
return info_->remote_port; return info_->remote_port;
} }
mach_port_t MachMultiprocess::ChildTask() const { task_t MachMultiprocess::ChildTask() const {
EXPECT_NE(kMachPortNull, info_->child_task); EXPECT_NE(kMachPortNull, info_->child_task);
return info_->child_task; return info_->child_task;
} }

View File

@ -68,7 +68,7 @@ class MachMultiprocess : public Multiprocess {
//! \brief Returns a send right for the childs task port. //! \brief Returns a send right for the childs task port.
//! //!
//! This method may only be called by the parent process. //! This method may only be called by the parent process.
mach_port_t ChildTask() const; task_t ChildTask() const;
private: private:
// Multiprocess: // Multiprocess: