summaryrefslogtreecommitdiffstats
path: root/base/mach_ipc_mac.h
diff options
context:
space:
mode:
authorrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-17 12:28:32 +0000
committerrohitrao@chromium.org <rohitrao@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-09-17 12:28:32 +0000
commitb88a7498e267ac265b141a2c7693cc37a55c4e9b (patch)
tree9a27b031d474def81658bdadad42ed05778af6d5 /base/mach_ipc_mac.h
parent35e55bffc4738b3dbd68be3f01aa918e56133bc8 (diff)
downloadchromium_src-b88a7498e267ac265b141a2c7693cc37a55c4e9b.zip
chromium_src-b88a7498e267ac265b141a2c7693cc37a55c4e9b.tar.gz
chromium_src-b88a7498e267ac265b141a2c7693cc37a55c4e9b.tar.bz2
[Mac] Replace the existing browser-child mach ipc with a long-lived listener on a well-known port.
Before this CL: Before fork()ing a child, the browser process creates a mach receive port with a random name. After the fork() but before exec(), the child uses mach ipc to transmit send rights to its task port. The child has access to the random name because it inherits it from the browser process. Unfortunately, some of the library functions involved in sending a mach message are not safe to call after fork(). After this CL: Before forking the first child, the browser spins off a new thread that listens on a well-known port for mach ipc from any process. This well-known port is "com.google.Chrome.<browserpid>". When a child process starts up, it sends a mach message to its parent browser's well-known port. On the browser side, we listen for said message, extract the pid of the sending process, and ignore any messages from processes we did not personally fork(). This check is necessary because any arbitrary process on the system could send mach ipc to that port. BUG=35374 TEST=Browser should still start up. The task manager should still show correct cpu/memory data. There should be no perf regressions. TEST=Mac ui_tests and browser_tests should be less flaky. Review URL: http://codereview.chromium.org/3443002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@59782 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mach_ipc_mac.h')
-rw-r--r--base/mach_ipc_mac.h33
1 files changed, 17 insertions, 16 deletions
diff --git a/base/mach_ipc_mac.h b/base/mach_ipc_mac.h
index 5836c3a..91b9729 100644
--- a/base/mach_ipc_mac.h
+++ b/base/mach_ipc_mac.h
@@ -20,7 +20,7 @@
//
// The three main classes of interest are
//
-// MachMessage: a wrapper for a mach message of the following form
+// MachMessage: a wrapper for a Mach message of the following form
// mach_msg_header_t
// mach_msg_body_t
// optional descriptors
@@ -30,10 +30,10 @@
// and are used instead of MachMessage which is an abstract base class
//
// ReceivePort:
-// Represents a mach port for which we have receive rights
+// Represents a Mach port for which we have receive rights
//
// MachPortSender:
-// Represents a mach port for which we have send rights
+// Represents a Mach port for which we have send rights
//
// Here's an example to receive a message on a server port:
//
@@ -127,7 +127,7 @@ class MachMsgPortDescriptor : public mach_msg_port_descriptor_t {
};
//==============================================================================
-// MachMessage: a wrapper for a mach message
+// MachMessage: a wrapper for a Mach message
// (mach_msg_header_t, mach_msg_body_t, extra data)
//
// This considerably simplifies the construction of a message for sending
@@ -165,7 +165,7 @@ class MachMessage {
int32_t GetMessageID() { return EndianU32_LtoN(GetDataPacket()->id); }
- // Adds a descriptor (typically a mach port) to be translated
+ // Adds a descriptor (typically a Mach port) to be translated
// returns true if successful, otherwise not enough space
bool AddDescriptor(const MachMsgPortDescriptor &desc);
@@ -175,7 +175,7 @@ class MachMessage {
MachMsgPortDescriptor *GetDescriptor(int n);
- // Convenience method which gets the mach port described by the descriptor
+ // Convenience method which gets the Mach port described by the descriptor
mach_port_t GetTranslatedPort(int n);
// A simple message is one with no descriptors
@@ -212,7 +212,7 @@ class MachMessage {
int CalculateSize();
// Returns total storage size that this object can grow to, this is inclusive
- // of the mach header.
+ // of the Mach header.
size_t MaxSize() const { return storage_length_bytes_; }
protected:
@@ -242,7 +242,7 @@ class MachMessage {
//==============================================================================
// MachReceiveMessage and MachSendMessage are useful to separate the idea
-// of a mach message being sent and being received, and adds increased type
+// of a Mach message being sent and being received, and adds increased type
// safety:
// ReceivePort::WaitForMessage() only accepts a MachReceiveMessage
// MachPortSender::SendMessage() only accepts a MachSendMessage
@@ -271,26 +271,27 @@ class MachSendMessage : public MachMessage {
};
//==============================================================================
-// Represents a mach port for which we have receive rights
+// Represents a Mach port for which we have receive rights
class ReceivePort {
public:
- // Creates a new mach port for receiving messages and registers a name for it
+ // Creates a new Mach port for receiving messages and registers a name for it
explicit ReceivePort(const char *receive_port_name);
- // Given an already existing mach port, use it. We take ownership of the
+ // Given an already existing Mach port, use it. We take ownership of the
// port and deallocate it in our destructor.
explicit ReceivePort(mach_port_t receive_port);
- // Create a new mach port for receiving messages
+ // Create a new Mach port for receiving messages
ReceivePort();
~ReceivePort();
- // Waits on the mach port until message received or timeout
+ // Waits on the Mach port until message received or timeout. If |timeout| is
+ // MACH_MSG_TIMEOUT_NONE, this method waits forever.
kern_return_t WaitForMessage(MachReceiveMessage *out_message,
mach_msg_timeout_t timeout);
- // The underlying mach port that we wrap
+ // The underlying Mach port that we wrap
mach_port_t GetPort() const { return port_; }
private:
@@ -301,14 +302,14 @@ class ReceivePort {
};
//==============================================================================
-// Represents a mach port for which we have send rights
+// Represents a Mach port for which we have send rights
class MachPortSender {
public:
// get a port with send rights corresponding to a named registered service
explicit MachPortSender(const char *receive_port_name);
- // Given an already existing mach port, use it. Does not take ownership of
+ // Given an already existing Mach port, use it. Does not take ownership of
// |send_port|.
explicit MachPortSender(mach_port_t send_port);