| 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, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 #include "util/mach/child_port_handshake.h" | 15 #include "util/mach/child_port_handshake.h" |
| 16 | 16 |
| 17 #include <errno.h> | 17 #include <errno.h> |
| 18 #include <pthread.h> | 18 #include <pthread.h> |
| 19 #include <sys/event.h> | 19 #include <sys/event.h> |
| 20 #include <sys/socket.h> | 20 #include <sys/socket.h> |
| 21 #include <sys/time.h> | 21 #include <sys/time.h> |
| 22 #include <sys/types.h> | 22 #include <sys/types.h> |
| 23 #include <unistd.h> | 23 #include <unistd.h> |
| 24 | 24 |
| 25 #include <algorithm> | 25 #include <algorithm> |
| 26 #include <utility> |
| 26 | 27 |
| 27 #include "base/logging.h" | 28 #include "base/logging.h" |
| 28 #include "base/mac/mach_logging.h" | 29 #include "base/mac/mach_logging.h" |
| 29 #include "base/mac/scoped_mach_port.h" | 30 #include "base/mac/scoped_mach_port.h" |
| 30 #include "base/posix/eintr_wrapper.h" | 31 #include "base/posix/eintr_wrapper.h" |
| 31 #include "base/rand_util.h" | 32 #include "base/rand_util.h" |
| 32 #include "base/strings/stringprintf.h" | 33 #include "base/strings/stringprintf.h" |
| 33 #include "util/file/file_io.h" | 34 #include "util/file/file_io.h" |
| 34 #include "util/mach/child_port.h" | 35 #include "util/mach/child_port.h" |
| 35 #include "util/mach/child_port_server.h" | 36 #include "util/mach/child_port_server.h" |
| 36 #include "util/mach/mach_extensions.h" | 37 #include "util/mach/mach_extensions.h" |
| 37 #include "util/mach/mach_message.h" | 38 #include "util/mach/mach_message.h" |
| 38 #include "util/mach/mach_message_server.h" | 39 #include "util/mach/mach_message_server.h" |
| 39 #include "util/misc/implicit_cast.h" | 40 #include "util/misc/implicit_cast.h" |
| 40 #include "util/stdlib/move.h" | |
| 41 #include "util/misc/random_string.h" | 41 #include "util/misc/random_string.h" |
| 42 | 42 |
| 43 namespace crashpad { | 43 namespace crashpad { |
| 44 namespace { | 44 namespace { |
| 45 | 45 |
| 46 class ChildPortHandshakeServer final : public ChildPortServer::Interface { | 46 class ChildPortHandshakeServer final : public ChildPortServer::Interface { |
| 47 public: | 47 public: |
| 48 ChildPortHandshakeServer(); | 48 ChildPortHandshakeServer(); |
| 49 ~ChildPortHandshakeServer(); | 49 ~ChildPortHandshakeServer(); |
| 50 | 50 |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 346 SO_NOSIGPIPE, | 346 SO_NOSIGPIPE, |
| 347 &value, | 347 &value, |
| 348 sizeof(value)) == 0) << "setsockopt"; | 348 sizeof(value)) == 0) << "setsockopt"; |
| 349 } | 349 } |
| 350 | 350 |
| 351 ChildPortHandshake::~ChildPortHandshake() { | 351 ChildPortHandshake::~ChildPortHandshake() { |
| 352 } | 352 } |
| 353 | 353 |
| 354 base::ScopedFD ChildPortHandshake::ClientReadFD() { | 354 base::ScopedFD ChildPortHandshake::ClientReadFD() { |
| 355 DCHECK(client_read_fd_.is_valid()); | 355 DCHECK(client_read_fd_.is_valid()); |
| 356 return crashpad::move(client_read_fd_); | 356 return std::move(client_read_fd_); |
| 357 } | 357 } |
| 358 | 358 |
| 359 base::ScopedFD ChildPortHandshake::ServerWriteFD() { | 359 base::ScopedFD ChildPortHandshake::ServerWriteFD() { |
| 360 DCHECK(server_write_fd_.is_valid()); | 360 DCHECK(server_write_fd_.is_valid()); |
| 361 return crashpad::move(server_write_fd_); | 361 return std::move(server_write_fd_); |
| 362 } | 362 } |
| 363 | 363 |
| 364 mach_port_t ChildPortHandshake::RunServer(PortRightType port_right_type) { | 364 mach_port_t ChildPortHandshake::RunServer(PortRightType port_right_type) { |
| 365 client_read_fd_.reset(); | 365 client_read_fd_.reset(); |
| 366 return RunServerForFD(crashpad::move(server_write_fd_), port_right_type); | 366 return RunServerForFD(std::move(server_write_fd_), port_right_type); |
| 367 } | 367 } |
| 368 | 368 |
| 369 bool ChildPortHandshake::RunClient(mach_port_t port, | 369 bool ChildPortHandshake::RunClient(mach_port_t port, |
| 370 mach_msg_type_name_t right_type) { | 370 mach_msg_type_name_t right_type) { |
| 371 server_write_fd_.reset(); | 371 server_write_fd_.reset(); |
| 372 return RunClientForFD(crashpad::move(client_read_fd_), port, right_type); | 372 return RunClientForFD(std::move(client_read_fd_), port, right_type); |
| 373 } | 373 } |
| 374 | 374 |
| 375 // static | 375 // static |
| 376 mach_port_t ChildPortHandshake::RunServerForFD(base::ScopedFD server_write_fd, | 376 mach_port_t ChildPortHandshake::RunServerForFD(base::ScopedFD server_write_fd, |
| 377 PortRightType port_right_type) { | 377 PortRightType port_right_type) { |
| 378 ChildPortHandshakeServer server; | 378 ChildPortHandshakeServer server; |
| 379 return server.RunServer(crashpad::move(server_write_fd), port_right_type); | 379 return server.RunServer(std::move(server_write_fd), port_right_type); |
| 380 } | 380 } |
| 381 | 381 |
| 382 // static | 382 // static |
| 383 bool ChildPortHandshake::RunClientForFD(base::ScopedFD client_read_fd, | 383 bool ChildPortHandshake::RunClientForFD(base::ScopedFD client_read_fd, |
| 384 mach_port_t port, | 384 mach_port_t port, |
| 385 mach_msg_type_name_t right_type) { | 385 mach_msg_type_name_t right_type) { |
| 386 DCHECK(client_read_fd.is_valid()); | 386 DCHECK(client_read_fd.is_valid()); |
| 387 | 387 |
| 388 // Read the token and the service name from the read side of the pipe. | 388 // Read the token and the service name from the read side of the pipe. |
| 389 child_port_token_t token; | 389 child_port_token_t token; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 server_port.get(), token, port, right_type); | 441 server_port.get(), token, port, right_type); |
| 442 if (kr != KERN_SUCCESS) { | 442 if (kr != KERN_SUCCESS) { |
| 443 MACH_LOG(ERROR, kr) << "child_port_check_in"; | 443 MACH_LOG(ERROR, kr) << "child_port_check_in"; |
| 444 return false; | 444 return false; |
| 445 } | 445 } |
| 446 | 446 |
| 447 return true; | 447 return true; |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace crashpad | 450 } // namespace crashpad |
| OLD | NEW |