Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | |
| 2 // | |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
| 4 // you may not use this file except in compliance with the License. | |
| 5 // You may obtain a copy of the License at | |
| 6 // | |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | |
| 8 // | |
| 9 // Unless required by applicable law or agreed to in writing, software | |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 12 // See the License for the specific language governing permissions and | |
| 13 // limitations under the License. | |
| 14 | |
| 15 #ifndef CRASHPAD_UTIL_MACH_NOTIFY_SERVER_H_ | |
| 16 #define CRASHPAD_UTIL_MACH_NOTIFY_SERVER_H_ | |
| 17 | |
| 18 #include <mach/mach.h> | |
| 19 | |
| 20 #include <set> | |
| 21 | |
| 22 #include "base/basictypes.h" | |
| 23 #include "util/mach/mach_message_server.h" | |
| 24 | |
| 25 namespace crashpad { | |
| 26 | |
| 27 //! \brief A server interface for the `notify` Mach subsystem. | |
| 28 //! | |
| 29 //! The <a | |
| 30 //! href="https://lists.apple.com/archives/darwin-development/2001/Sep/msg00451. html">mach | |
| 31 //! port notifications</a> thread on the <a | |
| 32 //! href="https://lists.apple.com/archives/darwin-development/">darwin-developme nt</a> | |
| 33 //! mailing list (now known as <a | |
| 34 //! href="https://lists.apple.com/mailman/listinfo/darwin-dev">darwin-dev</a>) | |
| 35 //! is good background for the various notification types. | |
| 36 class NotifyServer : public MachMessageServer::Interface { | |
| 37 public: | |
| 38 //! \brief An interface that the request message that is a part of the | |
|
Robert Sesek
2014/12/15 21:27:16
This sentence is awkward.
| |
| 39 //! `notify` Mach subsystem can be dispatched to. | |
| 40 class Interface { | |
| 41 public: | |
| 42 //! \brief Handles port-deleted notifications sent by | |
| 43 //! `mach_notify_port_deleted()`. | |
| 44 //! | |
| 45 //! A port-deleted notification is generated when a port with a dead-name | |
| 46 //! notification request is destroyed and the port name becomes available | |
| 47 //! for reuse. | |
| 48 //! | |
| 49 //! This behaves equivalently to a `do_mach_notify_port_deleted()` function | |
| 50 //! used with `notify_server()`. | |
| 51 //! | |
| 52 //! \param[in] trailer The trailer received with the request message. | |
| 53 virtual kern_return_t DoMachNotifyPortDeleted( | |
| 54 notify_port_t notify, | |
| 55 mach_port_name_t name, | |
| 56 const mach_msg_trailer_t* trailer) = 0; | |
| 57 | |
| 58 //! \brief Handles port-destroyed notifications sent by | |
| 59 //! `mach_notify_port_destroyed()`. | |
| 60 //! | |
| 61 //! A port-destroyed notification is generated when a receive right with a | |
| 62 //! port-destroyed notification request is destroyed. Rather than destroying | |
| 63 //! the receive right, it is transferred via this notification’s \a rights | |
| 64 //! parameter. | |
| 65 //! | |
| 66 //! This behaves equivalently to a `do_mach_notify_port_destroyed()` | |
| 67 //! function used with `notify_server()`. | |
| 68 //! | |
| 69 //! \param[in] trailer The trailer received with the request message. | |
| 70 //! \param[out] destroy_request `true` if the request message is to be | |
| 71 //! destroyed even when this method returns success. See | |
| 72 //! MachMessageServer::Interface. | |
| 73 virtual kern_return_t DoMachNotifyPortDestroyed( | |
| 74 notify_port_t notify, | |
| 75 mach_port_t rights, | |
|
Robert Sesek
2014/12/15 21:27:16
I'd document all the parameters here. Do I need to
| |
| 76 const mach_msg_trailer_t* trailer, | |
| 77 bool* destroy_request) = 0; | |
| 78 | |
| 79 //! \brief Handles no-senders notifications sent by | |
| 80 //! `mach_notify_no_senders()`. | |
| 81 //! | |
| 82 //! A no-senders notification is generated when a receive right with a | |
| 83 //! no-senders notification request loses its last corresponding send right. | |
| 84 //! | |
| 85 //! This behaves equivalently to a `do_mach_notify_no_senders()` function | |
| 86 //! used with `notify_server()`. | |
| 87 //! | |
| 88 //! \param[in] trailer The trailer received with the request message. | |
| 89 virtual kern_return_t DoMachNotifyNoSenders( | |
| 90 notify_port_t notify, | |
| 91 mach_port_mscount_t mscount, | |
| 92 const mach_msg_trailer_t* trailer) = 0; | |
| 93 | |
| 94 //! \brief Handles send-once notifications sent by | |
| 95 //! `mach_notify_send_once()`. | |
| 96 //! | |
| 97 //! A send-once notification is generated when a send-once right is | |
| 98 //! destroyed without being used. | |
| 99 //! | |
| 100 //! This behaves equivalently to a `do_mach_notify_send_once()` function | |
| 101 //! used with `notify_server()`. | |
| 102 //! | |
| 103 //! \param[in] trailer The trailer received with the request message. | |
| 104 //! | |
| 105 //! \note Unlike the other notifications in the `notify` subsystem, | |
| 106 //! send-once notifications are not generated as a result of a | |
| 107 //! notification request, but are generated any time a send-once right | |
| 108 //! is destroyed rather than being used. The notification is sent via | |
| 109 //! the send-once right to its receiver. These notifications are more | |
| 110 //! useful for clients, not servers. Send-once notifications are | |
| 111 //! normally handled by MIG-generated client routines, which make | |
| 112 //! send-once rights for their reply ports and interpret send-once | |
| 113 //! notifications as a signal that there will be no reply. Although not | |
| 114 //! expected to be primarily useful for servers, this method is provided | |
| 115 //! because send-once notifications are defined as a part of the | |
| 116 //! `notify` subsystem. | |
| 117 virtual kern_return_t DoMachNotifySendOnce( | |
| 118 notify_port_t notify, | |
| 119 const mach_msg_trailer_t* trailer) = 0; | |
| 120 | |
| 121 //! \brief Handles dead-name notifications sent by | |
| 122 //! `mach_notify_dead_name()`. | |
| 123 //! | |
| 124 //! A dead-name notification is generated when a port with a dead-name | |
| 125 //! notification request is destroyed and the right becomes a dead name. | |
| 126 //! | |
| 127 //! This behaves equivalently to a `do_mach_notify_dead_name()` function | |
| 128 //! used with `notify_server()`. | |
| 129 //! | |
| 130 //! \param[in] trailer The trailer received with the request message. | |
| 131 //! | |
| 132 //! \note When a dead-name notification is generated, the user reference | |
| 133 //! count of the dead name is incremented. A send right with one | |
| 134 //! reference that becomes a dead name will have one dead-name | |
| 135 //! reference, and the dead-name notification will add another dead-name | |
| 136 //! reference, for a total of 2. DoMachNotifyDeadName() implementations | |
| 137 //! must take care to deallocate this extra reference. There is no \a | |
| 138 //! destroy_request parameter to simplify this operation because | |
| 139 //! dead-name notifications carry a port name only (\a name is of type | |
| 140 //! `mach_port_name_t`) without transferring port rights, and are thus | |
| 141 //! not complex Mach messages. | |
| 142 virtual kern_return_t DoMachNotifyDeadName( | |
| 143 notify_port_t notify, | |
| 144 mach_port_name_t name, | |
| 145 const mach_msg_trailer_t* trailer) = 0; | |
| 146 | |
| 147 protected: | |
| 148 ~Interface() {} | |
| 149 }; | |
| 150 | |
| 151 //! \brief Constructs an object of this class. | |
| 152 //! | |
| 153 //! \param[in] interface The interface to dispatch requests to. Weak. | |
| 154 explicit NotifyServer(Interface* interface); | |
| 155 | |
| 156 // MachMessageServer::Interface: | |
| 157 | |
| 158 bool MachMessageServerFunction(const mach_msg_header_t* in_header, | |
| 159 mach_msg_header_t* out_header, | |
| 160 bool* destroy_complex_request) override; | |
| 161 | |
|
Robert Sesek
2014/12/15 21:27:16
nit: I don't think you normally put blank lines be
Mark Mentovai
2014/12/15 23:04:56
Robert Sesek wrote:
Robert Sesek
2014/12/16 18:49:31
I meant in the project/according to style.
| |
| 162 std::set<mach_msg_id_t> MachMessageServerRequestIDs() override; | |
| 163 | |
| 164 mach_msg_size_t MachMessageServerRequestSize() override; | |
| 165 mach_msg_size_t MachMessageServerReplySize() override; | |
| 166 | |
| 167 private: | |
| 168 Interface* interface_; // weak | |
| 169 | |
| 170 DISALLOW_COPY_AND_ASSIGN(NotifyServer); | |
| 171 }; | |
| 172 | |
| 173 } // namespace crashpad | |
| 174 | |
| 175 #endif // CRASHPAD_UTIL_MACH_NOTIFY_SERVER_H_ | |
| OLD | NEW |