Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Side by Side Diff: mojo/edk/embedder/platform_channel_pair_posix.cc

Issue 2039713004: [mojo-edk] Make the Mojo EDK compile under NaCl. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/edk/embedder/embedder.cc ('k') | mojo/edk/embedder/platform_channel_utils_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <sys/socket.h>
11 #include <sys/types.h> 10 #include <sys/types.h>
12 #include <unistd.h> 11 #include <unistd.h>
13 12
14 #include <limits> 13 #include <limits>
15 14
16 #include "base/command_line.h" 15 #include "base/command_line.h"
17 #include "base/logging.h" 16 #include "base/logging.h"
18 #include "base/posix/global_descriptors.h" 17 #include "base/posix/global_descriptors.h"
19 #include "base/rand_util.h" 18 #include "base/rand_util.h"
20 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
21 #include "build/build_config.h" 20 #include "build/build_config.h"
22 #include "mojo/edk/embedder/platform_handle.h" 21 #include "mojo/edk/embedder/platform_handle.h"
23 22
23 #if !defined(OS_NACL) || defined(OS_NACL_NONSFI)
24 #include <sys/socket.h>
25 #else
26 #include "native_client/src/public/imc_syscalls.h"
27 #endif
28
24 #if !defined(SO_PEEK_OFF) 29 #if !defined(SO_PEEK_OFF)
25 #define SO_PEEK_OFF 42 30 #define SO_PEEK_OFF 42
26 #endif 31 #endif
27 32
28 namespace mojo { 33 namespace mojo {
29 namespace edk { 34 namespace edk {
30 35
31 namespace { 36 namespace {
32 37
33 bool IsTargetDescriptorUsed( 38 bool IsTargetDescriptorUsed(
34 const base::FileHandleMappingVector& file_handle_mapping, 39 const base::FileHandleMappingVector& file_handle_mapping,
35 int target_fd) { 40 int target_fd) {
36 for (size_t i = 0; i < file_handle_mapping.size(); i++) { 41 for (size_t i = 0; i < file_handle_mapping.size(); i++) {
37 if (file_handle_mapping[i].second == target_fd) 42 if (file_handle_mapping[i].second == target_fd)
38 return true; 43 return true;
39 } 44 }
40 return false; 45 return false;
41 } 46 }
42 47
43 } // namespace 48 } // namespace
44 49
45 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) { 50 PlatformChannelPair::PlatformChannelPair(bool client_is_blocking) {
46 // Create the Unix domain socket. 51 // Create the Unix domain socket.
47 int fds[2]; 52 int fds[2];
48 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails. 53 // TODO(vtl): Maybe fail gracefully if |socketpair()| fails.
49 54
55 #if defined(OS_NACL) && !defined(OS_NACL_NONSFI)
56 PCHECK(imc_socketpair(fds) == 0);
57 #else
50 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0); 58 PCHECK(socketpair(AF_UNIX, SOCK_STREAM, 0, fds) == 0);
51 59
52 // Set the ends to nonblocking. 60 // Set the ends to nonblocking.
53 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0); 61 PCHECK(fcntl(fds[0], F_SETFL, O_NONBLOCK) == 0);
54 if (!client_is_blocking) 62 if (!client_is_blocking)
55 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0); 63 PCHECK(fcntl(fds[1], F_SETFL, O_NONBLOCK) == 0);
56 64
57 #if defined(OS_MACOSX) 65 #if defined(OS_MACOSX)
58 // This turns off |SIGPIPE| when writing to a closed socket (causing it to 66 // 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 67 // fail with |EPIPE| instead). On Linux, we have to use |send...()| with
60 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead. 68 // |MSG_NOSIGNAL| -- which is not supported on Mac -- instead.
61 int no_sigpipe = 1; 69 int no_sigpipe = 1;
62 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, 70 PCHECK(setsockopt(fds[0], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
63 sizeof(no_sigpipe)) == 0); 71 sizeof(no_sigpipe)) == 0);
64 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe, 72 PCHECK(setsockopt(fds[1], SOL_SOCKET, SO_NOSIGPIPE, &no_sigpipe,
65 sizeof(no_sigpipe)) == 0); 73 sizeof(no_sigpipe)) == 0);
66 #endif // defined(OS_MACOSX) 74 #endif // defined(OS_MACOSX)
75 #endif // defined(OS_NACL) && !defined(OS_NACL_NONSFI)
67 76
68 server_handle_.reset(PlatformHandle(fds[0])); 77 server_handle_.reset(PlatformHandle(fds[0]));
69 DCHECK(server_handle_.is_valid()); 78 DCHECK(server_handle_.is_valid());
70 client_handle_.reset(PlatformHandle(fds[1])); 79 client_handle_.reset(PlatformHandle(fds[1]));
71 DCHECK(client_handle_.is_valid()); 80 DCHECK(client_handle_.is_valid());
72 } 81 }
73 82
74 // static 83 // static
75 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess( 84 ScopedPlatformHandle PlatformChannelPair::PassClientHandleFromParentProcess(
76 const base::CommandLine& command_line) { 85 const base::CommandLine& command_line) {
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd)) 138 while (IsTargetDescriptorUsed(*handle_passing_info, target_fd))
130 target_fd++; 139 target_fd++;
131 140
132 handle_passing_info->push_back( 141 handle_passing_info->push_back(
133 std::pair<int, int>(client_handle_.get().handle, target_fd)); 142 std::pair<int, int>(client_handle_.get().handle, target_fd));
134 return base::IntToString(target_fd); 143 return base::IntToString(target_fd);
135 } 144 }
136 145
137 } // namespace edk 146 } // namespace edk
138 } // namespace mojo 147 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/embedder/embedder.cc ('k') | mojo/edk/embedder/platform_channel_utils_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698