Index: util/mach/mach_message.cc |
diff --git a/util/mach/mach_message.cc b/util/mach/mach_message.cc |
index 698bd1ffd79167ba36d01ea54ee817c4702f27ce..30c3a8cf4208dd2a645f18252142a36777163ab0 100644 |
--- a/util/mach/mach_message.cc |
+++ b/util/mach/mach_message.cc |
@@ -20,6 +20,7 @@ |
#include <limits> |
#include "base/logging.h" |
+#include "base/mac/mach_logging.h" |
#include "util/misc/clock.h" |
#include "util/misc/implicit_cast.h" |
@@ -249,4 +250,37 @@ pid_t AuditPIDFromMachMessageTrailer(const mach_msg_trailer_t* trailer) { |
return audit_pid; |
} |
+bool MachMessageDestroyReceivedPort(mach_port_t port, |
+ mach_msg_type_name_t port_right_type) { |
+ // This implements a subset of 10.10.5 |
+ // xnu-2782.40.9/libsyscall/mach/mach_msg.c mach_msg_destroy_port() that deals |
+ // only with port rights that can be received in Mach messages. |
+ switch (port_right_type) { |
+ case MACH_MSG_TYPE_PORT_RECEIVE: { |
+ kern_return_t kr = mach_port_mod_refs( |
+ mach_task_self(), port, MACH_PORT_RIGHT_RECEIVE, -1); |
+ if (kr != KERN_SUCCESS) { |
+ MACH_LOG(ERROR, kr) << "mach_port_mod_refs"; |
+ return false; |
+ } |
+ return true; |
+ } |
+ |
+ case MACH_MSG_TYPE_PORT_SEND: |
+ case MACH_MSG_TYPE_PORT_SEND_ONCE: { |
+ kern_return_t kr = mach_port_deallocate(mach_task_self(), port); |
+ if (kr != KERN_SUCCESS) { |
+ MACH_LOG(ERROR, kr) << "mach_port_deallocate"; |
+ return false; |
+ } |
+ return true; |
+ } |
+ |
+ default: { |
+ LOG(ERROR) << "unexpected port right type " << port_right_type; |
+ return false; |
+ } |
+ } |
+} |
+ |
} // namespace crashpad |