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 #include "util/mach/child_port_server.h" | |
| 16 | |
| 17 #include "base/logging.h" | |
| 18 #include "util/mach/child_portServer.h" | |
| 19 #include "util/mach/mig.h" | |
| 20 | |
| 21 extern "C" { | |
| 22 | |
| 23 // This function is not used, and is in fact obsoleted by the other | |
| 24 // functionality implemented in this file. The standard MIG-generated | |
| 25 // child_port_server() (in child_portServer.c) server dispatch routine usable | |
| 26 // with the standard mach_msg_server() function calls out to this functions. | |
|
Robert Sesek
2014/11/25 14:48:25
nit: functions. (extra 's')
| |
| 27 // child_port_server() is unused and is replaced by the more flexible | |
| 28 // ChildPortServer, but the linker still needs to see this function definition. | |
| 29 | |
| 30 kern_return_t handle_child_port_check_in(child_port_server_t server, | |
| 31 child_port_token_t token, | |
| 32 mach_port_t port, | |
| 33 mach_msg_type_name_t right_type) { | |
| 34 NOTREACHED(); | |
| 35 return KERN_FAILURE; | |
| 36 } | |
| 37 | |
| 38 } // extern "C" | |
| 39 | |
| 40 namespace { | |
| 41 | |
| 42 // There is no predefined constant for this. | |
| 43 enum MachMessageID : mach_msg_id_t { | |
| 44 kMachMessageIDChildPortCheckIn = 10011, | |
| 45 }; | |
| 46 | |
| 47 // The MIG-generated __MIG_check__Request__*() functions are not declared as | |
| 48 // accepting const data, but they could have been because they in fact do not | |
| 49 // modify the data. This wrapper function is provided to bridge the const gap | |
| 50 // between the code in this file, which is const-correct and treats request | |
| 51 // message data as const, and the generated function. | |
| 52 | |
| 53 kern_return_t MIGCheckRequestChildPortCheckIn( | |
| 54 const __Request__child_port_check_in_t* in_request) { | |
| 55 using Request = __Request__child_port_check_in_t; | |
| 56 return __MIG_check__Request__child_port_check_in_t( | |
| 57 const_cast<Request*>(in_request)); | |
| 58 } | |
| 59 | |
| 60 } // namespace | |
| 61 | |
| 62 namespace crashpad { | |
| 63 | |
| 64 ChildPortServer::ChildPortServer(ChildPortServer::Interface* interface) | |
| 65 : MachMessageServer::Interface(), | |
| 66 interface_(interface) { | |
| 67 } | |
| 68 | |
| 69 bool ChildPortServer::MachMessageServerFunction( | |
| 70 const mach_msg_header_t* in_header, | |
| 71 mach_msg_header_t* out_header, | |
| 72 bool* destroy_complex_request) { | |
| 73 PrepareMIGReplyFromRequest(in_header, out_header); | |
| 74 | |
| 75 switch (in_header->msgh_id) { | |
| 76 case kMachMessageIDChildPortCheckIn: { | |
| 77 // child_port_check_in(), handle_child_port_check_in(). | |
| 78 using Request = __Request__child_port_check_in_t; | |
| 79 const Request* in_request = reinterpret_cast<const Request*>(in_header); | |
| 80 kern_return_t kr = MIGCheckRequestChildPortCheckIn(in_request); | |
| 81 if (kr != MACH_MSG_SUCCESS) { | |
| 82 SetMIGReplyError(out_header, kr); | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 86 using Reply = __Reply__child_port_check_in_t; | |
| 87 Reply* out_reply = reinterpret_cast<Reply*>(out_header); | |
| 88 out_reply->RetCode = | |
| 89 interface_->HandleChildPortCheckIn(in_header->msgh_local_port, | |
| 90 in_request->token, | |
| 91 in_request->port.name, | |
| 92 in_request->port.disposition, | |
| 93 destroy_complex_request); | |
| 94 return true; | |
| 95 } | |
| 96 } | |
| 97 | |
| 98 SetMIGReplyError(out_header, MIG_BAD_ID); | |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 mach_msg_size_t ChildPortServer::MachMessageServerRequestSize() { | |
| 103 return sizeof(__RequestUnion__handle_child_port_subsystem); | |
| 104 } | |
| 105 | |
| 106 mach_msg_size_t ChildPortServer::MachMessageServerReplySize() { | |
| 107 return sizeof(__ReplyUnion__handle_child_port_subsystem); | |
| 108 } | |
| 109 | |
| 110 } // namespace crashpad | |
| OLD | NEW |