mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Use the correct null constants for Mach threads, tasks, and hosts.
This uses THREAD_NULL, TASK_NULL, and HOST_NULL in preference to MACH_PORT_NULL and kMachPortNull. These constants are correctly-typed (thread_t, task_t, and host_t) and result in more readable source code, especially where thread and task parameters appear together as they do in exc_*_variants. TEST=util_test R=rsesek@chromium.org Review URL: https://codereview.chromium.org/649713002
This commit is contained in:
parent
8f23d3e475
commit
8c7872e9e0
@ -180,8 +180,8 @@ bool ParseHandlerString(const char* handler_string_ro,
|
||||
// value, which can then be associated with handlers shown by
|
||||
// ShowExceptionPorts(). Any send rights obtained by this function are added to
|
||||
// |mach_send_right_pool|.
|
||||
void ShowBootstrapService(
|
||||
const std::string& service_name, MachSendRightPool* mach_send_right_pool) {
|
||||
void ShowBootstrapService(const std::string& service_name,
|
||||
MachSendRightPool* mach_send_right_pool) {
|
||||
mach_port_t service_port;
|
||||
kern_return_t kr = bootstrap_look_up(
|
||||
bootstrap_port, const_cast<char*>(service_name.c_str()), &service_port);
|
||||
@ -517,7 +517,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
|
||||
// Show the original exception ports.
|
||||
if (options.show_host) {
|
||||
ShowExceptionPorts(
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeHost, MACH_PORT_NULL),
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeHost, HOST_NULL),
|
||||
options.numeric,
|
||||
false,
|
||||
&mach_send_right_pool);
|
||||
@ -531,7 +531,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
|
||||
}
|
||||
if (options.show_thread) {
|
||||
ShowExceptionPorts(
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeThread, MACH_PORT_NULL),
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeThread, THREAD_NULL),
|
||||
options.numeric,
|
||||
false,
|
||||
&mach_send_right_pool);
|
||||
@ -544,7 +544,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
|
||||
&description,
|
||||
description.target_type == ExceptionPorts::kTargetTypeTask
|
||||
? options.alternate_task
|
||||
: MACH_PORT_NULL)) {
|
||||
: TASK_NULL)) {
|
||||
return kExitFailure;
|
||||
}
|
||||
}
|
||||
@ -552,7 +552,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
|
||||
// Show changed exception ports.
|
||||
if (options.show_new_host) {
|
||||
ShowExceptionPorts(
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeHost, MACH_PORT_NULL),
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeHost, HOST_NULL),
|
||||
options.numeric,
|
||||
true,
|
||||
&mach_send_right_pool);
|
||||
@ -567,7 +567,7 @@ int ExceptionPortToolMain(int argc, char* argv[]) {
|
||||
}
|
||||
if (options.show_new_thread) {
|
||||
ShowExceptionPorts(
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeThread, MACH_PORT_NULL),
|
||||
ExceptionPorts(ExceptionPorts::kTargetTypeThread, THREAD_NULL),
|
||||
options.numeric,
|
||||
true,
|
||||
&mach_send_right_pool);
|
||||
|
@ -78,7 +78,7 @@ ProcessReader::Thread::Thread()
|
||||
stack_region_address(0),
|
||||
stack_region_size(0),
|
||||
thread_specific_data_address(0),
|
||||
port(MACH_PORT_NULL),
|
||||
port(THREAD_NULL),
|
||||
suspend_count(0),
|
||||
priority(0) {
|
||||
}
|
||||
@ -95,7 +95,7 @@ ProcessReader::ProcessReader()
|
||||
modules_(),
|
||||
module_readers_(),
|
||||
task_memory_(),
|
||||
task_(MACH_PORT_NULL),
|
||||
task_(TASK_NULL),
|
||||
initialized_(),
|
||||
is_64_bit_(false),
|
||||
initialized_threads_(false),
|
||||
|
@ -44,7 +44,7 @@ namespace crashpad {
|
||||
//! exception message will carry identity information, when it has the value
|
||||
//! value `EXCEPTION_DEFAULT` or `EXCEPTION_STATE_IDENTITY`, possibly with
|
||||
//! `MACH_EXCEPTION_CODES` also set. In other cases, these parameters are unused
|
||||
//! and may be set to `MACH_PORT_NULL`.
|
||||
//! and may be set to `THREAD_NULL` and `TASK_NULL`, respectively.
|
||||
//!
|
||||
//! \a flavor, \a old_state, \a old_state_count, \a new_state, and \a
|
||||
//! new_state_count are only used when \a behavior indicates that the exception
|
||||
|
@ -70,11 +70,11 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
EXPECT_EQ(LocalPort(), exception_port);
|
||||
|
||||
if (HasIdentity()) {
|
||||
EXPECT_NE(kMachPortNull, thread);
|
||||
EXPECT_NE(THREAD_NULL, thread);
|
||||
EXPECT_EQ(ChildTask(), task);
|
||||
} else {
|
||||
EXPECT_EQ(kMachPortNull, thread);
|
||||
EXPECT_EQ(kMachPortNull, task);
|
||||
EXPECT_EQ(THREAD_NULL, thread);
|
||||
EXPECT_EQ(TASK_NULL, task);
|
||||
}
|
||||
|
||||
mach_exception_code_t expect_code = exception_code_;
|
||||
@ -153,8 +153,8 @@ class TestExcClientVariants : public UniversalMachExcServer,
|
||||
exception_subcode_
|
||||
};
|
||||
|
||||
thread_t thread = MACH_PORT_NULL;
|
||||
task_t task = MACH_PORT_NULL;
|
||||
thread_t thread = THREAD_NULL;
|
||||
task_t task = TASK_NULL;
|
||||
if (all_fields_ || HasIdentity()) {
|
||||
thread = MachThreadSelf();
|
||||
task = mach_task_self();
|
||||
|
@ -515,8 +515,8 @@ kern_return_t SimplifiedExcServer::CatchExceptionRaiseState(
|
||||
bool destroy_complex_request = false;
|
||||
return interface_->CatchException(EXCEPTION_STATE,
|
||||
exception_port,
|
||||
MACH_PORT_NULL,
|
||||
MACH_PORT_NULL,
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
exception,
|
||||
code,
|
||||
code_count,
|
||||
@ -602,8 +602,8 @@ kern_return_t SimplifiedMachExcServer::CatchMachExceptionRaiseState(
|
||||
bool destroy_complex_request = false;
|
||||
return interface_->CatchMachException(EXCEPTION_STATE | MACH_EXCEPTION_CODES,
|
||||
exception_port,
|
||||
MACH_PORT_NULL,
|
||||
MACH_PORT_NULL,
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
exception,
|
||||
code,
|
||||
code_count,
|
||||
|
@ -603,8 +603,8 @@ TEST(ExcServerVariants, MockExceptionRaiseState) {
|
||||
MockCatchMachException(
|
||||
kExceptionBehavior,
|
||||
kServerLocalPort,
|
||||
MACH_PORT_NULL,
|
||||
MACH_PORT_NULL,
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
kExceptionType,
|
||||
AreExceptionCodes(kTestExceptonCodes[0], kTestExceptonCodes[1]),
|
||||
Pointee(Eq(kThreadStateFlavor)),
|
||||
@ -727,8 +727,8 @@ TEST(ExcServerVariants, MockMachExceptionRaiseState) {
|
||||
server,
|
||||
MockCatchMachException(kExceptionBehavior,
|
||||
kServerLocalPort,
|
||||
MACH_PORT_NULL,
|
||||
MACH_PORT_NULL,
|
||||
THREAD_NULL,
|
||||
TASK_NULL,
|
||||
kExceptionType,
|
||||
AreExceptionCodes(kTestMachExceptionCodes[0],
|
||||
kTestMachExceptionCodes[1]),
|
||||
@ -898,11 +898,11 @@ class TestExcServerVariants : public UniversalMachExcServer,
|
||||
EXPECT_EQ(LocalPort(), exception_port);
|
||||
|
||||
if (ExceptionBehaviorHasIdentity(behavior)) {
|
||||
EXPECT_NE(kMachPortNull, thread);
|
||||
EXPECT_NE(THREAD_NULL, thread);
|
||||
EXPECT_EQ(ChildTask(), task);
|
||||
} else {
|
||||
EXPECT_EQ(kMachPortNull, thread);
|
||||
EXPECT_EQ(kMachPortNull, task);
|
||||
EXPECT_EQ(THREAD_NULL, thread);
|
||||
EXPECT_EQ(TASK_NULL, task);
|
||||
}
|
||||
|
||||
EXPECT_EQ(EXC_CRASH, exception);
|
||||
|
@ -26,7 +26,7 @@ ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port)
|
||||
get_exception_ports_ = host_get_exception_ports;
|
||||
set_exception_ports_ = host_set_exception_ports;
|
||||
target_name_ = "host";
|
||||
if (target_port_ == MACH_PORT_NULL) {
|
||||
if (target_port_ == HOST_NULL) {
|
||||
target_port_ = mach_host_self();
|
||||
dealloc_target_port_ = true;
|
||||
}
|
||||
@ -36,7 +36,7 @@ ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port)
|
||||
get_exception_ports_ = task_get_exception_ports;
|
||||
set_exception_ports_ = task_set_exception_ports;
|
||||
target_name_ = "task";
|
||||
if (target_port_ == MACH_PORT_NULL) {
|
||||
if (target_port_ == TASK_NULL) {
|
||||
target_port_ = mach_task_self();
|
||||
// Don’t deallocate mach_task_self().
|
||||
}
|
||||
@ -46,7 +46,7 @@ ExceptionPorts::ExceptionPorts(TargetType target_type, mach_port_t target_port)
|
||||
get_exception_ports_ = thread_get_exception_ports;
|
||||
set_exception_ports_ = thread_set_exception_ports;
|
||||
target_name_ = "thread";
|
||||
if (target_port_ == MACH_PORT_NULL) {
|
||||
if (target_port_ == THREAD_NULL) {
|
||||
target_port_ = mach_thread_self();
|
||||
dealloc_target_port_ = true;
|
||||
}
|
||||
|
@ -97,10 +97,11 @@ class ExceptionPorts {
|
||||
//! port must be a send right to a port of the type specified in \a
|
||||
//! target_type. In this case, ownership of \a target_port is not given to
|
||||
//! the new ExceptionPorts object. \a target_port may also be
|
||||
//! `MACH_PORT_NULL`, in which case `mach_host_self()`,
|
||||
//! `mach_task_self()`, or `mach_thread_self()` will be used as the target
|
||||
//! port depending on the value of \a target_type. In this case, ownership
|
||||
//! of the target port will be managed appropriately for \a target_type.
|
||||
//! `HOST_NULL`, `TASK_NULL`, or `THREAD_NULL`, in which case
|
||||
//! `mach_host_self()`, `mach_task_self()`, or `mach_thread_self()` will
|
||||
//! be used as the target port depending on the value of \a target_type.
|
||||
//! In this case, ownership of the target port will be managed
|
||||
//! appropriately for \a target_type.
|
||||
ExceptionPorts(TargetType target_type, mach_port_t target_port);
|
||||
|
||||
~ExceptionPorts();
|
||||
@ -172,10 +173,10 @@ class ExceptionPorts {
|
||||
mach_port_t target_port_;
|
||||
|
||||
// If true, target_port_ will be deallocated in the destructor. This will
|
||||
// always be false when the user provides a non-MACH_PORT_NULL target_port to
|
||||
// the constructor. It will also be false when target_type is kTargetTypeTask,
|
||||
// even with a MACH_PORT_NULL target_port, because it is incorrect to
|
||||
// deallocate the result of mach_task_self().
|
||||
// always be false when the user provides a non-null target_port to the
|
||||
// constructor. It will also be false when target_type is kTargetTypeTask,
|
||||
// even with a TASK_NULL target_port, because it is incorrect to deallocate
|
||||
// the result of mach_task_self().
|
||||
bool dealloc_target_port_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ExceptionPorts);
|
||||
|
@ -212,9 +212,9 @@ class TestExceptionPorts : public UniversalMachExcServer,
|
||||
|
||||
void Run() {
|
||||
ExceptionPorts self_task_ports(ExceptionPorts::kTargetTypeTask,
|
||||
MACH_PORT_NULL);
|
||||
TASK_NULL);
|
||||
ExceptionPorts self_thread_ports(ExceptionPorts::kTargetTypeThread,
|
||||
MACH_PORT_NULL);
|
||||
THREAD_NULL);
|
||||
|
||||
mach_port_t remote_port = test_exception_ports_->RemotePort();
|
||||
|
||||
@ -285,7 +285,7 @@ class TestExceptionPorts : public UniversalMachExcServer,
|
||||
// Runs the “other” thread.
|
||||
void* ThreadMain() {
|
||||
ExceptionPorts self_thread_ports(ExceptionPorts::kTargetTypeThread,
|
||||
MACH_PORT_NULL);
|
||||
THREAD_NULL);
|
||||
mach_port_t remote_port = test_exception_ports_->RemotePort();
|
||||
|
||||
// Set this thread’s exception handler, if appropriate.
|
||||
@ -560,7 +560,7 @@ TEST(ExceptionPorts, HostExceptionPorts) {
|
||||
}
|
||||
|
||||
ExceptionPorts implicit_host_ports(ExceptionPorts::kTargetTypeHost,
|
||||
MACH_PORT_NULL);
|
||||
HOST_NULL);
|
||||
EXPECT_EQ("host", implicit_host_ports.TargetTypeName());
|
||||
|
||||
rv = implicit_host_ports.GetExceptionPorts(
|
||||
|
@ -55,7 +55,8 @@ struct MachMultiprocessInfo {
|
||||
: service_name(),
|
||||
local_port(MACH_PORT_NULL),
|
||||
remote_port(MACH_PORT_NULL),
|
||||
child_task(MACH_PORT_NULL) {}
|
||||
child_task(TASK_NULL) {
|
||||
}
|
||||
|
||||
std::string service_name;
|
||||
base::mac::ScopedMachReceiveRight local_port;
|
||||
@ -112,7 +113,7 @@ mach_port_t MachMultiprocess::RemotePort() const {
|
||||
}
|
||||
|
||||
task_t MachMultiprocess::ChildTask() const {
|
||||
EXPECT_NE(kMachPortNull, info_->child_task);
|
||||
EXPECT_NE(TASK_NULL, info_->child_task);
|
||||
return info_->child_task;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user