| 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 #ifndef IPC_IPC_CHANNEL_POSIX_H_ | 5 #ifndef IPC_IPC_CHANNEL_POSIX_H_ |
| 6 #define IPC_IPC_CHANNEL_POSIX_H_ | 6 #define IPC_IPC_CHANNEL_POSIX_H_ |
| 7 | 7 |
| 8 #include "ipc/ipc_channel.h" | 8 #include "ipc/ipc_channel.h" |
| 9 | 9 |
| 10 #include <sys/socket.h> // for CMSG macros | 10 #include <sys/socket.h> // for CMSG macros |
| 11 | 11 |
| 12 #include <queue> | 12 #include <queue> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
| 18 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 19 #include "base/process/process.h" | 19 #include "base/process/process.h" |
| 20 #include "ipc/file_descriptor_set_posix.h" | |
| 21 #include "ipc/ipc_channel_reader.h" | 20 #include "ipc/ipc_channel_reader.h" |
| 21 #include "ipc/ipc_message_attachment_set.h" |
| 22 | 22 |
| 23 #if !defined(OS_MACOSX) | 23 #if !defined(OS_MACOSX) |
| 24 // On Linux, the seccomp sandbox makes it very expensive to call | 24 // On Linux, the seccomp sandbox makes it very expensive to call |
| 25 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which | 25 // recvmsg() and sendmsg(). The restriction on calling read() and write(), which |
| 26 // are cheap, is that we can't pass file descriptors over them. | 26 // are cheap, is that we can't pass file descriptors over them. |
| 27 // | 27 // |
| 28 // As we cannot anticipate when the sender will provide us with file | 28 // As we cannot anticipate when the sender will provide us with file |
| 29 // descriptors, we have to make the decision about whether we call read() or | 29 // descriptors, we have to make the decision about whether we call read() or |
| 30 // recvmsg() before we actually make the call. The easiest option is to | 30 // recvmsg() before we actually make the call. The easiest option is to |
| 31 // create a dedicated socketpair() for exchanging file descriptors. Any file | 31 // create a dedicated socketpair() for exchanging file descriptors. Any file |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // the pipe. On POSIX it's used as a key in a local map of file descriptors. | 171 // the pipe. On POSIX it's used as a key in a local map of file descriptors. |
| 172 std::string pipe_name_; | 172 std::string pipe_name_; |
| 173 | 173 |
| 174 // Messages to be sent are queued here. | 174 // Messages to be sent are queued here. |
| 175 std::queue<Message*> output_queue_; | 175 std::queue<Message*> output_queue_; |
| 176 | 176 |
| 177 // We assume a worst case: kReadBufferSize bytes of messages, where each | 177 // We assume a worst case: kReadBufferSize bytes of messages, where each |
| 178 // message has no payload and a full complement of descriptors. | 178 // message has no payload and a full complement of descriptors. |
| 179 static const size_t kMaxReadFDs = | 179 static const size_t kMaxReadFDs = |
| 180 (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * | 180 (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * |
| 181 FileDescriptorSet::kMaxDescriptorsPerMessage; | 181 MessageAttachmentSet::kMaxDescriptorsPerMessage; |
| 182 | 182 |
| 183 // Buffer size for file descriptors used for recvmsg. On Mac the CMSG macros | 183 // Buffer size for file descriptors used for recvmsg. On Mac the CMSG macros |
| 184 // don't seem to be constant so we have to pick a "large enough" value. | 184 // don't seem to be constant so we have to pick a "large enough" value. |
| 185 #if defined(OS_MACOSX) | 185 #if defined(OS_MACOSX) |
| 186 static const size_t kMaxReadFDBuffer = 1024; | 186 static const size_t kMaxReadFDBuffer = 1024; |
| 187 #else | 187 #else |
| 188 static const size_t kMaxReadFDBuffer = CMSG_SPACE(sizeof(int) * kMaxReadFDs); | 188 static const size_t kMaxReadFDBuffer = CMSG_SPACE(sizeof(int) * kMaxReadFDs); |
| 189 #endif | 189 #endif |
| 190 | 190 |
| 191 // Temporary buffer used to receive the file descriptors from recvmsg. | 191 // Temporary buffer used to receive the file descriptors from recvmsg. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 216 // If non-zero, overrides the process ID sent in the hello message. | 216 // If non-zero, overrides the process ID sent in the hello message. |
| 217 static int global_pid_; | 217 static int global_pid_; |
| 218 #endif // OS_LINUX | 218 #endif // OS_LINUX |
| 219 | 219 |
| 220 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); | 220 DISALLOW_IMPLICIT_CONSTRUCTORS(ChannelPosix); |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 } // namespace IPC | 223 } // namespace IPC |
| 224 | 224 |
| 225 #endif // IPC_IPC_CHANNEL_POSIX_H_ | 225 #endif // IPC_IPC_CHANNEL_POSIX_H_ |
| OLD | NEW |