| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ipc/ipc_channel_posix.h" | 5 #include "ipc/ipc_channel_posix.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stddef.h> | 9 #include <stddef.h> |
| 10 #include <sys/socket.h> | 10 #include <sys/socket.h> |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 // with ".." elements in the path in order to reach the real | 425 // with ".." elements in the path in order to reach the real |
| 426 // filesystem. | 426 // filesystem. |
| 427 } | 427 } |
| 428 | 428 |
| 429 msgh.msg_control = buf; | 429 msgh.msg_control = buf; |
| 430 msgh.msg_controllen = CMSG_SPACE(sizeof(int) * num_fds); | 430 msgh.msg_controllen = CMSG_SPACE(sizeof(int) * num_fds); |
| 431 cmsg = CMSG_FIRSTHDR(&msgh); | 431 cmsg = CMSG_FIRSTHDR(&msgh); |
| 432 cmsg->cmsg_level = SOL_SOCKET; | 432 cmsg->cmsg_level = SOL_SOCKET; |
| 433 cmsg->cmsg_type = SCM_RIGHTS; | 433 cmsg->cmsg_type = SCM_RIGHTS; |
| 434 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); | 434 cmsg->cmsg_len = CMSG_LEN(sizeof(int) * num_fds); |
| 435 msg->file_descriptor_set()->GetDescriptors( | 435 msg->file_descriptor_set()->PeekDescriptors( |
| 436 reinterpret_cast<int*>(CMSG_DATA(cmsg))); | 436 reinterpret_cast<int*>(CMSG_DATA(cmsg))); |
| 437 msgh.msg_controllen = cmsg->cmsg_len; | 437 msgh.msg_controllen = cmsg->cmsg_len; |
| 438 | 438 |
| 439 // DCHECK_LE above already checks that | 439 // DCHECK_LE above already checks that |
| 440 // num_fds < kMaxDescriptorsPerMessage so no danger of overflow. | 440 // num_fds < kMaxDescriptorsPerMessage so no danger of overflow. |
| 441 msg->header()->num_fds = static_cast<uint16>(num_fds); | 441 msg->header()->num_fds = static_cast<uint16>(num_fds); |
| 442 | 442 |
| 443 #if defined(IPC_USES_READWRITE) | 443 #if defined(IPC_USES_READWRITE) |
| 444 if (!IsHelloMessage(*msg)) { | 444 if (!IsHelloMessage(*msg)) { |
| 445 // Only the Hello message sends the file descriptor with the message. | 445 // Only the Hello message sends the file descriptor with the message. |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 // Create the Hello message | 762 // Create the Hello message |
| 763 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, | 763 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, |
| 764 HELLO_MESSAGE_TYPE, | 764 HELLO_MESSAGE_TYPE, |
| 765 IPC::Message::PRIORITY_NORMAL)); | 765 IPC::Message::PRIORITY_NORMAL)); |
| 766 if (!msg->WriteInt(GetHelloMessageProcId())) { | 766 if (!msg->WriteInt(GetHelloMessageProcId())) { |
| 767 NOTREACHED() << "Unable to pickle hello message proc id"; | 767 NOTREACHED() << "Unable to pickle hello message proc id"; |
| 768 } | 768 } |
| 769 #if defined(IPC_USES_READWRITE) | 769 #if defined(IPC_USES_READWRITE) |
| 770 scoped_ptr<Message> hello; | 770 scoped_ptr<Message> hello; |
| 771 if (remote_fd_pipe_ != -1) { | 771 if (remote_fd_pipe_ != -1) { |
| 772 if (!msg->WriteFileDescriptor(base::FileDescriptor(remote_fd_pipe_, | 772 if (!msg->WriteBorrowingFile(remote_fd_pipe_)) { |
| 773 false))) { | |
| 774 NOTREACHED() << "Unable to pickle hello message file descriptors"; | 773 NOTREACHED() << "Unable to pickle hello message file descriptors"; |
| 775 } | 774 } |
| 776 DCHECK_EQ(msg->file_descriptor_set()->size(), 1U); | 775 DCHECK_EQ(msg->file_descriptor_set()->size(), 1U); |
| 777 } | 776 } |
| 778 #endif // IPC_USES_READWRITE | 777 #endif // IPC_USES_READWRITE |
| 779 output_queue_.push(msg.release()); | 778 output_queue_.push(msg.release()); |
| 780 } | 779 } |
| 781 | 780 |
| 782 ChannelPosix::ReadState ChannelPosix::ReadData( | 781 ChannelPosix::ReadState ChannelPosix::ReadData( |
| 783 char* buffer, | 782 char* buffer, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 << " message-type:" << msg->type() | 888 << " message-type:" << msg->type() |
| 890 << " header()->num_fds:" << header_fds; | 889 << " header()->num_fds:" << header_fds; |
| 891 // Abort the connection. | 890 // Abort the connection. |
| 892 ClearInputFDs(); | 891 ClearInputFDs(); |
| 893 return false; | 892 return false; |
| 894 } | 893 } |
| 895 | 894 |
| 896 // The shenaniganery below with &foo.front() requires input_fds_ to have | 895 // The shenaniganery below with &foo.front() requires input_fds_ to have |
| 897 // contiguous underlying storage (such as a simple array or a std::vector). | 896 // contiguous underlying storage (such as a simple array or a std::vector). |
| 898 // This is why the header warns not to make input_fds_ a deque<>. | 897 // This is why the header warns not to make input_fds_ a deque<>. |
| 899 msg->file_descriptor_set()->SetDescriptors(&input_fds_.front(), | 898 msg->file_descriptor_set()->AddDescriptorsToOwn(&input_fds_.front(), |
| 900 header_fds); | 899 header_fds); |
| 901 input_fds_.erase(input_fds_.begin(), input_fds_.begin() + header_fds); | 900 input_fds_.erase(input_fds_.begin(), input_fds_.begin() + header_fds); |
| 902 return true; | 901 return true; |
| 903 } | 902 } |
| 904 | 903 |
| 905 bool ChannelPosix::DidEmptyInputBuffers() { | 904 bool ChannelPosix::DidEmptyInputBuffers() { |
| 906 // When the input data buffer is empty, the fds should be too. If this is | 905 // When the input data buffer is empty, the fds should be too. If this is |
| 907 // not the case, we probably have a rogue renderer which is trying to fill | 906 // not the case, we probably have a rogue renderer which is trying to fill |
| 908 // our descriptor table. | 907 // our descriptor table. |
| 909 return input_fds_.empty(); | 908 return input_fds_.empty(); |
| 910 } | 909 } |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 984 int pid; | 983 int pid; |
| 985 if (!msg.ReadInt(&iter, &pid)) | 984 if (!msg.ReadInt(&iter, &pid)) |
| 986 NOTREACHED(); | 985 NOTREACHED(); |
| 987 | 986 |
| 988 #if defined(IPC_USES_READWRITE) | 987 #if defined(IPC_USES_READWRITE) |
| 989 if (mode_ & MODE_SERVER_FLAG) { | 988 if (mode_ & MODE_SERVER_FLAG) { |
| 990 // With IPC_USES_READWRITE, the Hello message from the client to the | 989 // With IPC_USES_READWRITE, the Hello message from the client to the |
| 991 // server also contains the fd_pipe_, which will be used for all | 990 // server also contains the fd_pipe_, which will be used for all |
| 992 // subsequent file descriptor passing. | 991 // subsequent file descriptor passing. |
| 993 DCHECK_EQ(msg.file_descriptor_set()->size(), 1U); | 992 DCHECK_EQ(msg.file_descriptor_set()->size(), 1U); |
| 994 base::FileDescriptor descriptor; | 993 base::ScopedFD descriptor; |
| 995 if (!msg.ReadFileDescriptor(&iter, &descriptor)) { | 994 if (!msg.ReadFile(&iter, &descriptor)) { |
| 996 NOTREACHED(); | 995 NOTREACHED(); |
| 997 } | 996 } |
| 998 fd_pipe_ = descriptor.fd; | 997 fd_pipe_ = descriptor.release(); |
| 999 CHECK(descriptor.auto_close); | |
| 1000 } | 998 } |
| 1001 #endif // IPC_USES_READWRITE | 999 #endif // IPC_USES_READWRITE |
| 1002 peer_pid_ = pid; | 1000 peer_pid_ = pid; |
| 1003 listener()->OnChannelConnected(pid); | 1001 listener()->OnChannelConnected(pid); |
| 1004 break; | 1002 break; |
| 1005 | 1003 |
| 1006 #if defined(OS_MACOSX) | 1004 #if defined(OS_MACOSX) |
| 1007 case Channel::CLOSE_FD_MESSAGE_TYPE: | 1005 case Channel::CLOSE_FD_MESSAGE_TYPE: |
| 1008 int fd, hops; | 1006 int fd, hops; |
| 1009 if (!msg.ReadInt(&iter, &hops)) | 1007 if (!msg.ReadInt(&iter, &hops)) |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1090 } | 1088 } |
| 1091 | 1089 |
| 1092 #if defined(OS_LINUX) | 1090 #if defined(OS_LINUX) |
| 1093 // static | 1091 // static |
| 1094 void Channel::SetGlobalPid(int pid) { | 1092 void Channel::SetGlobalPid(int pid) { |
| 1095 ChannelPosix::SetGlobalPid(pid); | 1093 ChannelPosix::SetGlobalPid(pid); |
| 1096 } | 1094 } |
| 1097 #endif // OS_LINUX | 1095 #endif // OS_LINUX |
| 1098 | 1096 |
| 1099 } // namespace IPC | 1097 } // namespace IPC |
| OLD | NEW |