OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "mojo/edk/embedder/platform_channel_pair.h" | 5 #include "mojo/edk/embedder/platform_channel_pair.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #if !defined(OS_NACL) || defined(OS_NACL_NONSFI) | |
Ken Rockot(use gerrit already)
2016/06/06 02:58:33
nit: The style guide doesn't make a clear statemen
Anand Mistry (off Chromium)
2016/06/06 03:47:02
Done.
| |
10 #include <sys/socket.h> | 11 #include <sys/socket.h> |
12 #endif | |
11 #include <sys/types.h> | 13 #include <sys/types.h> |
12 #include <unistd.h> | 14 #include <unistd.h> |
13 | 15 |
14 #include <limits> | 16 #include <limits> |
15 | 17 |
16 #include "base/command_line.h" | 18 #include "base/command_line.h" |
17 #include "base/logging.h" | 19 #include "base/logging.h" |
18 #include "base/posix/global_descriptors.h" | 20 #include "base/posix/global_descriptors.h" |
19 #include "base/rand_util.h" | 21 #include "base/rand_util.h" |
20 #include "base/strings/string_number_conversions.h" | 22 #include "base/strings/string_number_conversions.h" |
21 #include "build/build_config.h" | 23 #include "build/build_config.h" |
22 #include "mojo/edk/embedder/platform_handle.h" | 24 #include "mojo/edk/embedder/platform_handle.h" |
23 | 25 |
26 #if defined(OS_NACL) | |
27 #include "native_client/src/public/imc_syscalls.h" | |
28 #endif | |
29 | |
24 #if !defined(SO_PEEK_OFF) | 30 #if !defined(SO_PEEK_OFF) |
25 #define SO_PEEK_OFF 42 | 31 #define SO_PEEK_OFF 42 |
26 #endif | 32 #endif |
27 | 33 |
28 namespace mojo { | 34 namespace mojo { |
29 namespace edk { | 35 namespace edk { |
30 | 36 |
31 namespace { | 37 namespace { |
32 | 38 |
33 bool IsTargetDescriptorUsed( | 39 bool IsTargetDescriptorUsed( |
34 const base::FileHandleMappingVector& file_handle_mapping, | 40 const base::FileHandleMappingVector& file_handle_mapping, |
35 int target_fd) { | 41 int target_fd) { |
36 for (size_t i = 0; i < file_handle_mapping.size(); i++) { | 42 for (size_t i = 0; i < file_handle_mapping.size(); i++) { |
37 if (file_handle_mapping[i].second == target_fd) | 43 if (file_handle_mapping[i].second == target_fd) |
38 return true; | 44 return true; |
39 } | 45 } |
40 return false; | 46 return false; |
41 } | 47 } |
42 | 48 |
43 } // namespace | 49 } // namespace |
44 | 50 |
45 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) { | 51 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) { |
46 // Create the Unix domain socket. | 52 // Create the Unix domain socket. |
47 int fds[2]; | 53 int fds[2]; |
48 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. | 54 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. |
49 | 55 |
56 #if defined(OS_NACL) && !defined(OS_NACL_NONSFI) | |
57 PCHECK(imc_socketpair(fds) == 0); | |
58 #else | |
50 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); | 59 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); |
51 | 60 |
52 // Set the ends to nonblocking. | 61 // Set the ends to nonblocking. |
53 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); | 62 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); |
54 if (!client_is_blocking) | 63 if (!client_is_blocking) |
55 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); | 64 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); |
56 | 65 |
57 #if defined(OS_MACOSX) | 66 #if defined(OS_MACOSX) |
58 // This turns off |SIGPIPE| when writing to a closed socket (causing it to | 67 // This turns off |SIGPIPE| when writing to a closed socket (causing it to |
59 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with | 68 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with |
60 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. | 69 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. |
61 int no_sigpipe = 1; | 70 int no_sigpipe = 1; |
62 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, | 71 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
63 sizeof(no_sigpipe)) == 0); | 72 sizeof(no_sigpipe)) == 0); |
64 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, | 73 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, |
65 sizeof(no_sigpipe)) == 0); | 74 sizeof(no_sigpipe)) == 0); |
66 #endif // defined(OS_MACOSX) | 75 #endif // defined(OS_MACOSX) |
76 #endif // defined(OS_NACL) && !defined(OS_NACL_NONSFI) | |
67 | 77 |
68 server_handle_.reset(PlatformHandle(fds[0])); | 78 server_handle_.reset(PlatformHandle(fds[0])); |
69 DCHECK(server_handle_.is_valid()); | 79 DCHECK(server_handle_.is_valid()); |
70 client_handle_.reset(PlatformHandle(fds[1])); | 80 client_handle_.reset(PlatformHandle(fds[1])); |
71 DCHECK(client_handle_.is_valid()); | 81 DCHECK(client_handle_.is_valid()); |
72 } | 82 } |
73 | 83 |
74 // static | 84 // static |
75 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( | 85 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( |
76 const base::CommandLine& command_line) { | 86 const base::CommandLine& command_line) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
129 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd)) | 139 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd)) |
130 target_fd++; | 140 target_fd++; |
131 | 141 |
132 handle_passing_info->push_back( | 142 handle_passing_info->push_back( |
133 std::pair<int, int>(client_handle_.get().handle, target_fd)); | 143 std::pair<int, int>(client_handle_.get().handle, target_fd)); |
134 return base::IntToString(target_fd); | 144 return base::IntToString(target_fd); |
135 } | 145 } |
136 | 146 |
137 } // namespace edk | 147 } // namespace edk |
138 } // namespace mojo | 148 } // namespace mojo |
OLD | NEW |