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,
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<const char*> show_bootstrap;
std::vector<ExceptionHandlerDescription> set_handler;
pid_t pid;
mach_port_t alternate_task;
task_t alternate_task;
bool show_host;
bool show_task;
bool show_thread;

View File

@ -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;

View File

@ -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<Thread> threads_; // owns send rights
std::vector<Module> modules_;
scoped_ptr<TaskMemory> task_memory_;
mach_port_t task_; // weak
task_t task_; // weak
InitializationStateDcheck initialized_;
// 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);
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) {

View File

@ -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;

View File

@ -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());
}

View File

@ -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.

View File

@ -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));

View File

@ -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) {

View File

@ -88,7 +88,7 @@ class TaskMemory {
//! \param[in] task A send right to the target tasks 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);
};

View File

@ -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;
}

View File

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