Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(287)

Unified Diff: util/mach/mach_message.cc

Issue 1408473002: ChildPortHandshake: allow receive rights to be received (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Address review feedback Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/mach/mach_message.h ('k') | util/mach/mach_message_server_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « util/mach/mach_message.h ('k') | util/mach/mach_message_server_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698