| OLD | NEW |
| 1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with 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 | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 #include "base/posix/eintr_wrapper.h" | 30 #include "base/posix/eintr_wrapper.h" |
| 31 #include "base/rand_util.h" | 31 #include "base/rand_util.h" |
| 32 #include "base/strings/stringprintf.h" | 32 #include "base/strings/stringprintf.h" |
| 33 #include "util/file/file_io.h" | 33 #include "util/file/file_io.h" |
| 34 #include "util/mach/child_port.h" | 34 #include "util/mach/child_port.h" |
| 35 #include "util/mach/child_port_server.h" | 35 #include "util/mach/child_port_server.h" |
| 36 #include "util/mach/mach_extensions.h" | 36 #include "util/mach/mach_extensions.h" |
| 37 #include "util/mach/mach_message.h" | 37 #include "util/mach/mach_message.h" |
| 38 #include "util/mach/mach_message_server.h" | 38 #include "util/mach/mach_message_server.h" |
| 39 #include "util/misc/implicit_cast.h" | 39 #include "util/misc/implicit_cast.h" |
| 40 #include "util/misc/random_string.h" |
| 40 | 41 |
| 41 namespace crashpad { | 42 namespace crashpad { |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 class ChildPortHandshakeServer final : public ChildPortServer::Interface { | 45 class ChildPortHandshakeServer final : public ChildPortServer::Interface { |
| 45 public: | 46 public: |
| 46 ChildPortHandshakeServer(); | 47 ChildPortHandshakeServer(); |
| 47 ~ChildPortHandshakeServer(); | 48 ~ChildPortHandshakeServer(); |
| 48 | 49 |
| 49 mach_port_t RunServer(base::ScopedFD server_write_fd, | 50 mach_port_t RunServer(base::ScopedFD server_write_fd, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return MACH_PORT_NULL; | 91 return MACH_PORT_NULL; |
| 91 } | 92 } |
| 92 | 93 |
| 93 // Create a unique name for the bootstrap service mapping. Make it unguessable | 94 // Create a unique name for the bootstrap service mapping. Make it unguessable |
| 94 // to prevent outsiders from grabbing the name first, which would cause | 95 // to prevent outsiders from grabbing the name first, which would cause |
| 95 // bootstrap_check_in() to fail. | 96 // bootstrap_check_in() to fail. |
| 96 uint64_t thread_id; | 97 uint64_t thread_id; |
| 97 errno = pthread_threadid_np(pthread_self(), &thread_id); | 98 errno = pthread_threadid_np(pthread_self(), &thread_id); |
| 98 PCHECK(errno == 0) << "pthread_threadid_np"; | 99 PCHECK(errno == 0) << "pthread_threadid_np"; |
| 99 std::string service_name = base::StringPrintf( | 100 std::string service_name = base::StringPrintf( |
| 100 "org.chromium.crashpad.child_port_handshake.%d.%llu.%016llx", | 101 "org.chromium.crashpad.child_port_handshake.%d.%llu.%s", |
| 101 getpid(), | 102 getpid(), |
| 102 thread_id, | 103 thread_id, |
| 103 base::RandUint64()); | 104 RandomString().c_str()); |
| 104 | 105 |
| 105 // Check the new service in with the bootstrap server, obtaining a receive | 106 // Check the new service in with the bootstrap server, obtaining a receive |
| 106 // right for it. | 107 // right for it. |
| 107 base::mac::ScopedMachReceiveRight server_port(BootstrapCheckIn(service_name)); | 108 base::mac::ScopedMachReceiveRight server_port(BootstrapCheckIn(service_name)); |
| 108 CHECK(server_port.is_valid()); | 109 CHECK(server_port.is_valid()); |
| 109 | 110 |
| 110 // Share the service name with the client via the pipe. | 111 // Share the service name with the client via the pipe. |
| 111 uint32_t service_name_length = service_name.size(); | 112 uint32_t service_name_length = service_name.size(); |
| 112 if (!LoggingWriteFile(server_write_fd.get(), | 113 if (!LoggingWriteFile(server_write_fd.get(), |
| 113 &service_name_length, | 114 &service_name_length, |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 439 server_port.get(), token, port, right_type); | 440 server_port.get(), token, port, right_type); |
| 440 if (kr != KERN_SUCCESS) { | 441 if (kr != KERN_SUCCESS) { |
| 441 MACH_LOG(ERROR, kr) << "child_port_check_in"; | 442 MACH_LOG(ERROR, kr) << "child_port_check_in"; |
| 442 return false; | 443 return false; |
| 443 } | 444 } |
| 444 | 445 |
| 445 return true; | 446 return true; |
| 446 } | 447 } |
| 447 | 448 |
| 448 } // namespace crashpad | 449 } // namespace crashpad |
| OLD | NEW |