OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/nacl/loader/nacl_listener.h" | 5 #include "components/nacl/loader/nacl_listener.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #if defined(OS_POSIX) | 10 #if defined(OS_POSIX) |
11 #include <unistd.h> | 11 #include <unistd.h> |
12 #endif | 12 #endif |
13 | 13 |
14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
17 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
18 #include "base/rand_util.h" | 18 #include "base/rand_util.h" |
19 #include "components/nacl/common/nacl_messages.h" | 19 #include "components/nacl/common/nacl_messages.h" |
20 #include "components/nacl/loader/nacl_ipc_adapter.h" | 20 #include "components/nacl/loader/nacl_ipc_adapter.h" |
21 #include "components/nacl/loader/nacl_validation_db.h" | 21 #include "components/nacl/loader/nacl_validation_db.h" |
22 #include "components/nacl/loader/nacl_validation_query.h" | 22 #include "components/nacl/loader/nacl_validation_query.h" |
23 #include "ipc/ipc_channel_handle.h" | 23 #include "ipc/ipc_channel_handle.h" |
24 #include "ipc/ipc_switches.h" | 24 #include "ipc/ipc_switches.h" |
25 #include "ipc/ipc_sync_channel.h" | 25 #include "ipc/ipc_sync_channel.h" |
26 #include "ipc/ipc_sync_message_filter.h" | 26 #include "ipc/ipc_sync_message_filter.h" |
27 #include "native_client/src/public/nacl_app.h" | |
teravest
2014/02/04 22:21:06
Presumably this is gated on some change to native_
hidehiko
2014/02/05 06:30:16
Yes, this is based on crrev.com/153453002, and I'l
| |
27 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" | 28 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" |
28 #include "native_client/src/trusted/validator/nacl_file_info.h" | 29 #include "native_client/src/trusted/validator/nacl_file_info.h" |
29 | 30 |
30 #if defined(OS_POSIX) | 31 #if defined(OS_POSIX) |
31 #include "base/file_descriptor_posix.h" | 32 #include "base/file_descriptor_posix.h" |
32 #endif | 33 #endif |
33 | 34 |
34 #if defined(OS_LINUX) | 35 #if defined(OS_LINUX) |
35 #include "components/nacl/loader/nonsfi/nonsfi_main.h" | 36 #include "components/nacl/loader/nonsfi/nonsfi_main.h" |
36 #include "content/public/common/child_process_sandbox_support_linux.h" | 37 #include "content/public/common/child_process_sandbox_support_linux.h" |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
101 std::string info_string(reinterpret_cast<const char*>(info), info_size); | 102 std::string info_string(reinterpret_cast<const char*>(info), info_size); |
102 bool result = false; | 103 bool result = false; |
103 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( | 104 if (!g_listener->Send(new NaClProcessMsg_AttachDebugExceptionHandler( |
104 info_string, &result))) | 105 info_string, &result))) |
105 return false; | 106 return false; |
106 return result; | 107 return result; |
107 } | 108 } |
108 | 109 |
109 #endif | 110 #endif |
110 | 111 |
112 // Creates the PPAPI IPC channel between the NaCl IRT and the host | |
113 // (browser/renderer) process, and starts to listen it on the thread where | |
114 // the given message_loop_proxy runs. | |
115 // Also, creates and sets the corresponding NaClDesc to the given nap with | |
116 // the FD #. | |
117 void SetUpIPCAdapter(IPC::ChannelHandle* handle, | |
118 scoped_refptr<base::MessageLoopProxy> message_loop_proxy, | |
119 struct NaClApp* nap, | |
120 int nacl_fd) { | |
121 scoped_refptr<NaClIPCAdapter> ipc_adapter( | |
122 new NaClIPCAdapter(*handle, message_loop_proxy.get())); | |
123 ipc_adapter->ConnectChannel(); | |
124 #if defined(OS_POSIX) | |
125 handle->socket = | |
126 base::FileDescriptor(ipc_adapter->TakeClientFileDescriptor(), true); | |
127 #endif | |
128 | |
129 NaClAppSetDesc(nap, nacl_fd, ipc_adapter->MakeNaClDesc()); | |
130 } | |
131 | |
111 } // namespace | 132 } // namespace |
112 | 133 |
113 class BrowserValidationDBProxy : public NaClValidationDB { | 134 class BrowserValidationDBProxy : public NaClValidationDB { |
114 public: | 135 public: |
115 explicit BrowserValidationDBProxy(NaClListener* listener) | 136 explicit BrowserValidationDBProxy(NaClListener* listener) |
116 : listener_(listener) { | 137 : listener_(listener) { |
117 } | 138 } |
118 | 139 |
119 virtual bool QueryKnownToValidate(const std::string& signature) OVERRIDE { | 140 virtual bool QueryKnownToValidate(const std::string& signature) OVERRIDE { |
120 // Initialize to false so that if the Send fails to write to the return | 141 // Initialize to false so that if the Send fails to write to the return |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 247 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
227 bool handled = true; | 248 bool handled = true; |
228 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 249 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
229 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 250 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
230 IPC_MESSAGE_UNHANDLED(handled = false) | 251 IPC_MESSAGE_UNHANDLED(handled = false) |
231 IPC_END_MESSAGE_MAP() | 252 IPC_END_MESSAGE_MAP() |
232 return handled; | 253 return handled; |
233 } | 254 } |
234 | 255 |
235 void NaClListener::OnStart(const nacl::NaClStartParams& params) { | 256 void NaClListener::OnStart(const nacl::NaClStartParams& params) { |
236 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); | 257 NaClChromeMainInit(); |
258 | |
259 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | |
237 if (args == NULL) { | 260 if (args == NULL) { |
238 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 261 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
239 return; | 262 return; |
240 } | 263 } |
241 | 264 |
265 struct NaClApp* nap = NaClAppMake(); | |
266 DCHECK(nap != NULL); | |
teravest
2014/02/04 22:21:06
I think you want to LOG(ERROR) and return if nap i
hidehiko
2014/02/05 06:30:16
Done, but the method won't seem to return NULL (i.
| |
242 if (params.enable_ipc_proxy) { | 267 if (params.enable_ipc_proxy) { |
243 // Create the initial PPAPI IPC channel between the NaCl IRT and the | 268 // Create the PPAPI IPC channels between the NaCl IRT and the hosts |
244 // browser process. The IRT uses this channel to communicate with the | 269 // (browser/renderer) processes. The IRT uses these channels to communicate |
245 // browser and to create additional IPC channels to renderer processes. | 270 // with the host and to initialize the IPC dispatchers. |
246 IPC::ChannelHandle handle = | 271 IPC::ChannelHandle browser_handle = |
247 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 272 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
248 scoped_refptr<NaClIPCAdapter> ipc_adapter( | 273 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), |
249 new NaClIPCAdapter(handle, io_thread_.message_loop_proxy().get())); | 274 nap, NACL_CHROME_DESC_BASE); |
250 ipc_adapter->ConnectChannel(); | |
251 | 275 |
252 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 276 IPC::ChannelHandle renderer_handle = |
253 // NaClIPCAdapter. | 277 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
254 args->initial_ipc_desc = ipc_adapter->MakeNaClDesc(); | 278 SetUpIPCAdapter(&renderer_handle, io_thread_.message_loop_proxy(), |
255 #if defined(OS_POSIX) | 279 nap, NACL_CHROME_DESC_BASE + 1); |
256 handle.socket = base::FileDescriptor( | 280 |
257 ipc_adapter->TakeClientFileDescriptor(), true); | 281 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
258 #endif | 282 browser_handle, renderer_handle))) |
259 if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(handle))) | |
260 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 283 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
261 } | 284 } |
262 | 285 |
263 std::vector<nacl::FileDescriptor> handles = params.handles; | 286 std::vector<nacl::FileDescriptor> handles = params.handles; |
264 | 287 |
265 #if defined(OS_LINUX) || defined(OS_MACOSX) | 288 #if defined(OS_LINUX) || defined(OS_MACOSX) |
266 args->urandom_fd = dup(base::GetUrandomFD()); | 289 args->urandom_fd = dup(base::GetUrandomFD()); |
267 if (args->urandom_fd < 0) { | 290 if (args->urandom_fd < 0) { |
268 LOG(ERROR) << "Failed to dup() the urandom FD"; | 291 LOG(ERROR) << "Failed to dup() the urandom FD"; |
269 return; | 292 return; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 356 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
334 #endif | 357 #endif |
335 | 358 |
336 #if defined(OS_LINUX) | 359 #if defined(OS_LINUX) |
337 if (params.enable_nonsfi_mode) { | 360 if (params.enable_nonsfi_mode) { |
338 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); | 361 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); |
339 NOTREACHED(); | 362 NOTREACHED(); |
340 return; | 363 return; |
341 } | 364 } |
342 #endif | 365 #endif |
343 NaClChromeMainStart(args); | 366 NaClChromeMainStartApp(nap, args); |
344 NOTREACHED(); | 367 NOTREACHED(); |
345 } | 368 } |
OLD | NEW |