From 6c0d42ce9dee55eaa906865191e28df35b32910d Mon Sep 17 00:00:00 2001 From: Mark Mentovai Date: Tue, 20 Oct 2015 11:03:25 -0400 Subject: [PATCH] Mach port scopers should use get() instead of type conversion operators MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In https://codereview.chromium.org/1411523006, the Mach port scopers are becoming better ScopedGenerics and are losing the type conversion operators in the process. This is needed to adapt to that change. get() is ugly, but being explicit about conversion isn’t a bad thing, and these scopers will gain functionality such as Pass() as part of the switch. As a bonus, some would-be uses of get() to check for valid port rights are becoming a more descriptive is_valid(). R=rsesek@chromium.org Review URL: https://codereview.chromium.org/1405273002 . --- client/crashpad_client_mac.cc | 10 +- client/simulate_crash_mac.cc | 2 +- handler/mac/crash_report_exception_handler.cc | 4 +- handler/mac/exception_handler_server.cc | 14 +-- handler/mac/exception_handler_server.h | 2 +- test/mac/mach_multiprocess.cc | 22 ++--- tools/mac/catch_exception_tool.cc | 2 +- tools/mac/exception_port_tool.cc | 4 +- util/mach/child_port_handshake.cc | 19 ++-- util/mach/exception_ports_test.cc | 7 +- util/mach/mach_extensions_test.cc | 8 +- util/mach/mach_message_server_test.cc | 8 +- util/mach/mach_message_test.cc | 4 +- util/mach/notify_server_test.cc | 98 ++++++++++--------- 14 files changed, 104 insertions(+), 100 deletions(-) diff --git a/client/crashpad_client_mac.cc b/client/crashpad_client_mac.cc index a180fd19..5797fba8 100644 --- a/client/crashpad_client_mac.cc +++ b/client/crashpad_client_mac.cc @@ -92,7 +92,7 @@ bool CrashpadClient::StartHandler( const std::string& url, const std::map& annotations, const std::vector& arguments) { - DCHECK_EQ(exception_port_, kMachPortNull); + DCHECK(!exception_port_.is_valid()); // Set up the arguments for execve() first. These aren’t needed until execve() // is called, but it’s dangerous to do this in a child process after fork(). @@ -211,13 +211,13 @@ bool CrashpadClient::StartHandler( // Rendezvous with the handler running in the grandchild process. exception_port_.reset(child_port_handshake.RunServer()); - return exception_port_ ? true : false; + return exception_port_.is_valid(); } bool CrashpadClient::UseHandler() { - DCHECK_NE(exception_port_, kMachPortNull); + DCHECK(exception_port_.is_valid()); - return SetCrashExceptionPorts(exception_port_); + return SetCrashExceptionPorts(exception_port_.get()); } // static @@ -227,7 +227,7 @@ void CrashpadClient::UseSystemDefaultHandler() { // Proceed even if SystemCrashReporterHandler() failed, setting MACH_PORT_NULL // to clear the current exception ports. - if (!SetCrashExceptionPorts(system_crash_reporter_handler)) { + if (!SetCrashExceptionPorts(system_crash_reporter_handler.get())) { SetCrashExceptionPorts(MACH_PORT_NULL); } } diff --git a/client/simulate_crash_mac.cc b/client/simulate_crash_mac.cc index cda6b76d..71d5d904 100644 --- a/client/simulate_crash_mac.cc +++ b/client/simulate_crash_mac.cc @@ -221,7 +221,7 @@ void SimulateCrash(const NativeCPUContext& cpu_context) { DCHECK_LE(handlers.size(), 1u); if (handlers.size() == 1) { DCHECK(handlers[0].mask & EXC_MASK_CRASH); - success = DeliverException(thread, + success = DeliverException(thread.get(), mach_task_self(), exception, codes, diff --git a/handler/mac/crash_report_exception_handler.cc b/handler/mac/crash_report_exception_handler.cc index a54cd0dd..288148e9 100644 --- a/handler/mac/crash_report_exception_handler.cc +++ b/handler/mac/crash_report_exception_handler.cc @@ -186,7 +186,7 @@ kern_return_t CrashReportExceptionHandler::CatchMachException( // vendor. base::mac::ScopedMachSendRight system_crash_reporter_handler(SystemCrashReporterHandler()); - if (system_crash_reporter_handler) { + if (system_crash_reporter_handler.get()) { // Make copies of mutable out parameters so that the system crash reporter // can’t influence the state returned by this method. thread_state_flavor_t flavor_forward = *flavor; @@ -205,7 +205,7 @@ kern_return_t CrashReportExceptionHandler::CatchMachException( // will be available. kern_return_t kr = UniversalExceptionRaise( EXCEPTION_STATE_IDENTITY | MACH_EXCEPTION_CODES, - system_crash_reporter_handler, + system_crash_reporter_handler.get(), thread, task, exception, diff --git a/handler/mac/exception_handler_server.cc b/handler/mac/exception_handler_server.cc index 39348ec4..52da8faa 100644 --- a/handler/mac/exception_handler_server.cc +++ b/handler/mac/exception_handler_server.cc @@ -41,7 +41,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, exception_port_(exception_port), notify_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)), running_(true) { - CHECK_NE(notify_port_, kMachPortNull); + CHECK(notify_port_.is_valid()); composite_mach_message_server_.AddHandler(&mach_exc_server_); composite_mach_message_server_.AddHandler(¬ify_server_); @@ -61,7 +61,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, exception_port_, MACH_NOTIFY_NO_SENDERS, 0, - notify_port_, + notify_port_.get(), MACH_MSG_TYPE_MAKE_SEND_ONCE, &previous); MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_request_notification"; @@ -83,11 +83,11 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, NewMachPort(MACH_PORT_RIGHT_PORT_SET)); kr = mach_port_insert_member( - mach_task_self(), exception_port_, server_port_set); + mach_task_self(), exception_port_, server_port_set.get()); MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_insert_member"; kr = mach_port_insert_member( - mach_task_self(), notify_port_, server_port_set); + mach_task_self(), notify_port_.get(), server_port_set.get()); MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_insert_member"; // Run the server in kOneShot mode so that running_ can be reevaluated after @@ -98,7 +98,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, // DoMachNotifyNoSenders() as appropriate. mach_msg_return_t mr = MachMessageServer::Run(&composite_mach_message_server_, - server_port_set, + server_port_set.get(), kMachMessageReceiveAuditTrailer, MachMessageServer::kOneShot, MachMessageServer::kReceiveLargeIgnore, @@ -221,7 +221,7 @@ class ExceptionHandlerServerRun : public UniversalMachExcServer::Interface, ExceptionHandlerServer::ExceptionHandlerServer() : receive_port_(NewMachPort(MACH_PORT_RIGHT_RECEIVE)) { - CHECK_NE(receive_port_, kMachPortNull); + CHECK(receive_port_.is_valid()); } ExceptionHandlerServer::~ExceptionHandlerServer() { @@ -229,7 +229,7 @@ ExceptionHandlerServer::~ExceptionHandlerServer() { void ExceptionHandlerServer::Run( UniversalMachExcServer::Interface* exception_interface) { - ExceptionHandlerServerRun run(receive_port_, exception_interface); + ExceptionHandlerServerRun run(receive_port_.get(), exception_interface); run.Run(); } diff --git a/handler/mac/exception_handler_server.h b/handler/mac/exception_handler_server.h index 37c61a0f..83e131be 100644 --- a/handler/mac/exception_handler_server.h +++ b/handler/mac/exception_handler_server.h @@ -57,7 +57,7 @@ class ExceptionHandlerServer { //! //! The caller does not take ownership of this port. The caller must not use //! this port for any purpose other than to make send rights for clients. - mach_port_t receive_port() const { return receive_port_; } + mach_port_t receive_port() const { return receive_port_.get(); } private: base::mac::ScopedMachReceiveRight receive_port_; diff --git a/test/mac/mach_multiprocess.cc b/test/mac/mach_multiprocess.cc index 6d410d38..65ea46df 100644 --- a/test/mac/mach_multiprocess.cc +++ b/test/mac/mach_multiprocess.cc @@ -98,22 +98,22 @@ void MachMultiprocess::PreFork() { } info_->local_port = BootstrapCheckIn(info_->service_name); - ASSERT_NE(kMachPortNull, info_->local_port); + ASSERT_TRUE(info_->local_port.is_valid()); } mach_port_t MachMultiprocess::LocalPort() const { - EXPECT_NE(kMachPortNull, info_->local_port); - return info_->local_port; + EXPECT_TRUE(info_->local_port.is_valid()); + return info_->local_port.get(); } mach_port_t MachMultiprocess::RemotePort() const { - EXPECT_NE(kMachPortNull, info_->remote_port); - return info_->remote_port; + EXPECT_TRUE(info_->remote_port.is_valid()); + return info_->remote_port.get(); } task_t MachMultiprocess::ChildTask() const { - EXPECT_NE(TASK_NULL, info_->child_task); - return info_->child_task; + EXPECT_TRUE(info_->child_task.is_valid()); + return info_->child_task.get(); } void MachMultiprocess::MultiprocessParent() { @@ -123,7 +123,7 @@ void MachMultiprocess::MultiprocessParent() { MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, 0, sizeof(message), - info_->local_port, + info_->local_port.get(), MACH_MSG_TIMEOUT_NONE, MACH_PORT_NULL); ASSERT_EQ(MACH_MSG_SUCCESS, kr) << MachErrorMessage(kr, "mach_msg"); @@ -198,7 +198,7 @@ void MachMultiprocess::MultiprocessParent() { // Verify that the child’s task port is what it purports to be. int mach_pid; - kr = pid_for_task(info_->child_task, &mach_pid); + kr = pid_for_task(info_->child_task.get(), &mach_pid); ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "pid_for_task"); ASSERT_EQ(ChildPID(), mach_pid); @@ -229,8 +229,8 @@ void MachMultiprocess::MultiprocessChild() { MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND, MACH_MSG_TYPE_MAKE_SEND) | MACH_MSGH_BITS_COMPLEX; message.header.msgh_size = sizeof(message); - message.header.msgh_remote_port = info_->remote_port; - message.header.msgh_local_port = info_->local_port; + message.header.msgh_remote_port = info_->remote_port.get(); + message.header.msgh_local_port = info_->local_port.get(); message.body.msgh_descriptor_count = 1; message.port_descriptor.name = mach_task_self(); message.port_descriptor.disposition = MACH_MSG_TYPE_COPY_SEND; diff --git a/tools/mac/catch_exception_tool.cc b/tools/mac/catch_exception_tool.cc index b70ce0a5..32c6aed2 100644 --- a/tools/mac/catch_exception_tool.cc +++ b/tools/mac/catch_exception_tool.cc @@ -301,7 +301,7 @@ int CatchExceptionToolMain(int argc, char* argv[]) { } mach_msg_return_t mr = MachMessageServer::Run(&universal_mach_exc_server, - service_port, + service_port.get(), MACH_MSG_OPTION_NONE, options.persistent, receive_large, diff --git a/tools/mac/exception_port_tool.cc b/tools/mac/exception_port_tool.cc index e26c1bb0..b873e68b 100644 --- a/tools/mac/exception_port_tool.cc +++ b/tools/mac/exception_port_tool.cc @@ -195,7 +195,7 @@ void ShowBootstrapService(const std::string& service_name, return; } - mach_send_right_pool->AddSendRight(service_port); + mach_send_right_pool->AddSendRight(service_port.get()); printf("service %s %#x\n", service_name.c_str(), service_port.get()); } @@ -300,7 +300,7 @@ bool SetExceptionPort(const ExceptionHandlerDescription* description, ExceptionPorts exception_ports(description->target_type, target_port); if (!exception_ports.SetExceptionPort(description->mask, - service_port, + service_port.get(), description->behavior, description->flavor)) { return false; diff --git a/util/mach/child_port_handshake.cc b/util/mach/child_port_handshake.cc index b01af7a7..119a53c0 100644 --- a/util/mach/child_port_handshake.cc +++ b/util/mach/child_port_handshake.cc @@ -105,7 +105,7 @@ mach_port_t ChildPortHandshake::RunServer() { // Check the new service in with the bootstrap server, obtaining a receive // right for it. base::mac::ScopedMachReceiveRight server_port(BootstrapCheckIn(service_name)); - CHECK_NE(server_port, kMachPortNull); + CHECK(server_port.is_valid()); // Share the service name with the client via the pipe. uint32_t service_name_length = service_name.size(); @@ -125,10 +125,10 @@ mach_port_t ChildPortHandshake::RunServer() { // requires a port set. Create a new port set and add the receive right to it. base::mac::ScopedMachPortSet server_port_set( NewMachPort(MACH_PORT_RIGHT_PORT_SET)); - CHECK_NE(server_port_set, kMachPortNull); + CHECK(server_port_set.is_valid()); - kern_return_t kr = - mach_port_insert_member(mach_task_self(), server_port, server_port_set); + kern_return_t kr = mach_port_insert_member( + mach_task_self(), server_port.get(), server_port_set.get()); MACH_CHECK(kr == KERN_SUCCESS, kr) << "mach_port_insert_member"; // Set up a kqueue to monitor both the server’s receive right and the write @@ -140,7 +140,7 @@ mach_port_t ChildPortHandshake::RunServer() { struct kevent changelist[2]; EV_SET(&changelist[0], - server_port_set, + server_port_set.get(), EVFILT_MACHPORT, EV_ADD | EV_CLEAR, 0, @@ -194,7 +194,7 @@ mach_port_t ChildPortHandshake::RunServer() { switch (event.filter) { case EVFILT_MACHPORT: { // There’s something to receive on the port set. - DCHECK_EQ(event.ident, server_port_set); + DCHECK_EQ(event.ident, server_port_set.get()); // Run the message server in an inner loop instead of using // MachMessageServer::kPersistent. This allows the loop to exit as soon @@ -207,7 +207,7 @@ mach_port_t ChildPortHandshake::RunServer() { // this will call HandleChildPortCheckIn(). mach_msg_return_t mr = MachMessageServer::Run(&child_port_server, - server_port_set, + server_port_set.get(), MACH_MSG_OPTION_NONE, MachMessageServer::kOneShot, MachMessageServer::kReceiveLargeIgnore, @@ -329,10 +329,11 @@ void ChildPortHandshake::RunClientInternal_SendCheckIn( // Get a send right to the server by looking up the service with the bootstrap // server by name. base::mac::ScopedMachSendRight server_port(BootstrapLookUp(service_name)); - CHECK_NE(server_port, kMachPortNull); + CHECK(server_port.is_valid()); // Check in with the server. - kern_return_t kr = child_port_check_in(server_port, token, port, right_type); + kern_return_t kr = + child_port_check_in(server_port.get(), token, port, right_type); MACH_CHECK(kr == KERN_SUCCESS, kr) << "child_port_check_in"; } diff --git a/util/mach/exception_ports_test.cc b/util/mach/exception_ports_test.cc index 7384c022..e6e1d56d 100644 --- a/util/mach/exception_ports_test.cc +++ b/util/mach/exception_ports_test.cc @@ -376,9 +376,9 @@ class TestExceptionPorts : public MachMultiprocess, threads_need_owners.Disarm(); ExceptionPorts main_thread_ports(ExceptionPorts::kTargetTypeThread, - main_thread); + main_thread.get()); ExceptionPorts other_thread_ports(ExceptionPorts::kTargetTypeThread, - other_thread); + other_thread.get()); EXPECT_STREQ("thread", main_thread_ports.TargetTypeName()); EXPECT_STREQ("thread", other_thread_ports.TargetTypeName()); @@ -586,7 +586,8 @@ TEST(ExceptionPorts, HostExceptionPorts) { const bool expect_success = geteuid() == 0; base::mac::ScopedMachSendRight host(mach_host_self()); - ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, host); + ExceptionPorts explicit_host_ports(ExceptionPorts::kTargetTypeHost, + host.get()); EXPECT_STREQ("host", explicit_host_ports.TargetTypeName()); ExceptionPorts::ExceptionHandlerVector explicit_handlers; diff --git a/util/mach/mach_extensions_test.cc b/util/mach/mach_extensions_test.cc index 2b987b37..04af5dfe 100644 --- a/util/mach/mach_extensions_test.cc +++ b/util/mach/mach_extensions_test.cc @@ -34,7 +34,7 @@ TEST(MachExtensions, NewMachPort_Receive) { ASSERT_NE(kMachPortNull, port); mach_port_type_t type; - kern_return_t kr = mach_port_type(mach_task_self(), port, &type); + kern_return_t kr = mach_port_type(mach_task_self(), port.get(), &type); ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "mach_port_get_type"); EXPECT_EQ(MACH_PORT_TYPE_RECEIVE, type); @@ -45,7 +45,7 @@ TEST(MachExtensions, NewMachPort_PortSet) { ASSERT_NE(kMachPortNull, port); mach_port_type_t type; - kern_return_t kr = mach_port_type(mach_task_self(), port, &type); + kern_return_t kr = mach_port_type(mach_task_self(), port.get(), &type); ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "mach_port_get_type"); EXPECT_EQ(MACH_PORT_TYPE_PORT_SET, type); @@ -56,7 +56,7 @@ TEST(MachExtensions, NewMachPort_DeadName) { ASSERT_NE(kMachPortNull, port); mach_port_type_t type; - kern_return_t kr = mach_port_type(mach_task_self(), port, &type); + kern_return_t kr = mach_port_type(mach_task_self(), port.get(), &type); ASSERT_EQ(KERN_SUCCESS, kr) << MachErrorMessage(kr, "mach_port_get_type"); EXPECT_EQ(MACH_PORT_TYPE_DEAD_NAME, type); @@ -173,7 +173,7 @@ TEST(MachExtensions, BootstrapCheckInAndLookUp) { TEST(MachExtensions, SystemCrashReporterHandler) { base::mac::ScopedMachSendRight system_crash_reporter_handler(SystemCrashReporterHandler()); - EXPECT_TRUE(system_crash_reporter_handler); + EXPECT_TRUE(system_crash_reporter_handler.is_valid()); } } // namespace diff --git a/util/mach/mach_message_server_test.cc b/util/mach/mach_message_server_test.cc index 6878cf95..daa64a93 100644 --- a/util/mach/mach_message_server_test.cc +++ b/util/mach/mach_message_server_test.cc @@ -467,8 +467,8 @@ class TestMachMessageServer : public MachMessageServer::Interface, // carried in the request message to the server. By the time the server // looks at the right, it will have become a dead name. local_receive_port_owner.reset(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, local_receive_port_owner); - request.header.msgh_local_port = local_receive_port_owner; + ASSERT_TRUE(local_receive_port_owner.is_valid()); + request.header.msgh_local_port = local_receive_port_owner.get(); break; } } @@ -479,8 +479,8 @@ class TestMachMessageServer : public MachMessageServer::Interface, // properly handles ownership of resources received in complex messages. request.body.msgh_descriptor_count = 1; child_complex_message_port_.reset(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, child_complex_message_port_); - request.port_descriptor.name = child_complex_message_port_; + ASSERT_TRUE(child_complex_message_port_.is_valid()); + request.port_descriptor.name = child_complex_message_port_.get(); request.port_descriptor.disposition = MACH_MSG_TYPE_MAKE_SEND; request.port_descriptor.type = MACH_MSG_PORT_DESCRIPTOR; } else { diff --git a/util/mach/mach_message_test.cc b/util/mach/mach_message_test.cc index a3fca519..5e79b212 100644 --- a/util/mach/mach_message_test.cc +++ b/util/mach/mach_message_test.cc @@ -115,7 +115,7 @@ TEST(MachMessage, AuditPIDFromMachMessageTrailer) { mach_msg_empty_send_t send = {}; send.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND_ONCE, 0); send.header.msgh_size = sizeof(send); - send.header.msgh_remote_port = port; + send.header.msgh_remote_port = port.get(); mach_msg_return_t mr = MachMessageWithDeadline(&send.header, MACH_SEND_MSG, @@ -138,7 +138,7 @@ TEST(MachMessage, AuditPIDFromMachMessageTrailer) { mr = MachMessageWithDeadline(&receive.header, MACH_RCV_MSG | kMachMessageReceiveAuditTrailer, sizeof(receive), - port, + port.get(), kMachMessageDeadlineNonblocking, MACH_PORT_NULL, false); diff --git a/util/mach/notify_server_test.cc b/util/mach/notify_server_test.cc index a852bd0e..445e35bf 100644 --- a/util/mach/notify_server_test.cc +++ b/util/mach/notify_server_test.cc @@ -256,12 +256,12 @@ class NotifyServerTestBase : public testing::Test, //! established for the current test. On failure, returns `MACH_PORT_NULL` //! with a gtest failure added. mach_port_t ServerPort() { - if (!server_port_) { + if (!server_port_.is_valid()) { server_port_.reset(NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - EXPECT_NE(kMachPortNull, server_port_); + EXPECT_TRUE(server_port_.is_valid()); } - return server_port_; + return server_port_.get(); } // testing::Test: @@ -309,14 +309,14 @@ TEST_F(NotifyServerTest, NoNotification) { TEST_F(NotifyServerTest, MachNotifyPortDeleted) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); base::mac::ScopedMachSendRight send_once_right( - SendOnceRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_once_right); + SendOnceRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_once_right.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); + ASSERT_TRUE(RequestMachPortNotification( + send_once_right.get(), MACH_NOTIFY_DEAD_NAME, 0)); EXPECT_CALL( *this, @@ -336,10 +336,10 @@ TEST_F(NotifyServerTest, MachNotifyPortDeleted) { TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); ASSERT_TRUE(RequestMachPortNotification( - receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); + receive_right.get(), MACH_NOTIFY_PORT_DESTROYED, 0)); EXPECT_CALL( *this, @@ -360,10 +360,10 @@ TEST_F(NotifyServerTest, MachNotifyPortDestroyed) { TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); ASSERT_TRUE(RequestMachPortNotification( - receive_right, MACH_NOTIFY_PORT_DESTROYED, 0)); + receive_right.get(), MACH_NOTIFY_PORT_DESTROYED, 0)); RunServer(); } @@ -373,10 +373,10 @@ TEST_F(NotifyServerTest, MachNotifyPortDestroyed_NoNotification) { TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 0)); + ASSERT_TRUE(RequestMachPortNotification( + receive_right.get(), MACH_NOTIFY_NO_SENDERS, 0)); EXPECT_CALL(*this, DoMachNotifyNoSenders( @@ -393,14 +393,14 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_NoSendRight) { TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); base::mac::ScopedMachSendRight send_right( - SendRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_right); + SendRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_right.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 1)); + ASSERT_TRUE(RequestMachPortNotification( + receive_right.get(), MACH_NOTIFY_NO_SENDERS, 1)); EXPECT_CALL(*this, DoMachNotifyNoSenders( @@ -418,25 +418,25 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_SendRightDeallocated) { TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); base::mac::ScopedMachSendRight send_right_0( - SendRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_right_0); + SendRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_right_0.is_valid()); base::mac::ScopedMachSendRight send_right_1( - SendRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_right_1); + SendRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_right_1.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(receive_right, MACH_NOTIFY_NO_SENDERS, 1)); + ASSERT_TRUE(RequestMachPortNotification( + receive_right.get(), MACH_NOTIFY_NO_SENDERS, 1)); send_right_1.reset(); RunServer(); - EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_RECEIVE)); - EXPECT_EQ(1u, RightRefCount(receive_right, MACH_PORT_RIGHT_SEND)); + EXPECT_EQ(1u, RightRefCount(receive_right.get(), MACH_PORT_RIGHT_RECEIVE)); + EXPECT_EQ(1u, RightRefCount(receive_right.get(), MACH_PORT_RIGHT_SEND)); } // When a send-once right is deallocated without being used, a send-once @@ -444,7 +444,7 @@ TEST_F(NotifyServerTest, MachNotifyNoSenders_NoNotification) { TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { base::mac::ScopedMachSendRight send_once_right( SendOnceRightFromReceiveRight(ServerPort())); - ASSERT_NE(kMachPortNull, send_once_right); + ASSERT_TRUE(send_once_right.is_valid()); EXPECT_CALL(*this, DoMachNotifySendOnce(ServerPort(), @@ -463,13 +463,13 @@ TEST_F(NotifyServerTest, MachNotifySendOnce_ExplicitDeallocation) { TEST_F(NotifyServerTest, MachNotifySendOnce_ImplicitDeallocation) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); mach_msg_empty_send_t message = {}; message.header.msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MAKE_SEND, MACH_MSG_TYPE_MAKE_SEND_ONCE); message.header.msgh_size = sizeof(message); - message.header.msgh_remote_port = receive_right; + message.header.msgh_remote_port = receive_right.get(); message.header.msgh_local_port = ServerPort(); mach_msg_return_t mr = mach_msg(&message.header, MACH_SEND_MSG | MACH_SEND_TIMEOUT, @@ -497,14 +497,14 @@ TEST_F(NotifyServerTest, MachNotifySendOnce_ImplicitDeallocation) { TEST_F(NotifyServerTest, MachNotifyDeadName) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); base::mac::ScopedMachSendRight send_once_right( - SendOnceRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_once_right); + SendOnceRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_once_right.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); + ASSERT_TRUE(RequestMachPortNotification( + send_once_right.get(), MACH_NOTIFY_DEAD_NAME, 0)); // send_once_right becomes a dead name with the send-once right’s original // user reference count of 1, but the dead-name notification increments the @@ -523,10 +523,11 @@ TEST_F(NotifyServerTest, MachNotifyDeadName) { RunServer(); - EXPECT_TRUE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); + EXPECT_TRUE(IsRight(send_once_right.get(), MACH_PORT_TYPE_DEAD_NAME)); - EXPECT_EQ(0u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); - EXPECT_EQ(1u, DeadNameRightRefCount(send_once_right)); + EXPECT_EQ(0u, + RightRefCount(send_once_right.get(), MACH_PORT_RIGHT_SEND_ONCE)); + EXPECT_EQ(1u, DeadNameRightRefCount(send_once_right.get())); } // When the receive right corresponding to a send-once right with a dead-name @@ -535,21 +536,22 @@ TEST_F(NotifyServerTest, MachNotifyDeadName) { TEST_F(NotifyServerTest, MachNotifyDeadName_NoNotification) { base::mac::ScopedMachReceiveRight receive_right( NewMachPort(MACH_PORT_RIGHT_RECEIVE)); - ASSERT_NE(kMachPortNull, receive_right); + ASSERT_TRUE(receive_right.is_valid()); base::mac::ScopedMachSendRight send_once_right( - SendOnceRightFromReceiveRight(receive_right)); - ASSERT_NE(kMachPortNull, send_once_right); + SendOnceRightFromReceiveRight(receive_right.get())); + ASSERT_TRUE(send_once_right.is_valid()); - ASSERT_TRUE( - RequestMachPortNotification(send_once_right, MACH_NOTIFY_DEAD_NAME, 0)); + ASSERT_TRUE(RequestMachPortNotification( + send_once_right.get(), MACH_NOTIFY_DEAD_NAME, 0)); RunServer(); - EXPECT_FALSE(IsRight(send_once_right, MACH_PORT_TYPE_DEAD_NAME)); + EXPECT_FALSE(IsRight(send_once_right.get(), MACH_PORT_TYPE_DEAD_NAME)); - EXPECT_EQ(1u, RightRefCount(send_once_right, MACH_PORT_RIGHT_SEND_ONCE)); - EXPECT_EQ(0u, DeadNameRightRefCount(send_once_right)); + EXPECT_EQ(1u, + RightRefCount(send_once_right.get(), MACH_PORT_RIGHT_SEND_ONCE)); + EXPECT_EQ(0u, DeadNameRightRefCount(send_once_right.get())); } } // namespace