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) |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 } | 193 } |
194 | 194 |
195 private: | 195 private: |
196 // The listener never dies, otherwise this might be a dangling reference. | 196 // The listener never dies, otherwise this might be a dangling reference. |
197 NaClListener* listener_; | 197 NaClListener* listener_; |
198 }; | 198 }; |
199 | 199 |
200 | 200 |
201 NaClListener::NaClListener() : shutdown_event_(true, false), | 201 NaClListener::NaClListener() : shutdown_event_(true, false), |
202 io_thread_("NaCl_IOThread"), | 202 io_thread_("NaCl_IOThread"), |
203 uses_nonsfi_mode_(false), | |
203 #if defined(OS_LINUX) | 204 #if defined(OS_LINUX) |
204 prereserved_sandbox_size_(0), | 205 prereserved_sandbox_size_(0), |
205 #endif | 206 #endif |
206 #if defined(OS_POSIX) | 207 #if defined(OS_POSIX) |
207 number_of_cores_(-1), // unknown/error | 208 number_of_cores_(-1), // unknown/error |
208 #endif | 209 #endif |
209 main_loop_(NULL) { | 210 main_loop_(NULL) { |
210 io_thread_.StartWithOptions( | 211 io_thread_.StartWithOptions( |
211 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); | 212 base::Thread::Options(base::MessageLoop::TYPE_IO, 0)); |
212 #if defined(OS_WIN) | 213 #if defined(OS_WIN) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 251 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
251 bool handled = true; | 252 bool handled = true; |
252 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 253 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
253 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 254 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
254 IPC_MESSAGE_UNHANDLED(handled = false) | 255 IPC_MESSAGE_UNHANDLED(handled = false) |
255 IPC_END_MESSAGE_MAP() | 256 IPC_END_MESSAGE_MAP() |
256 return handled; | 257 return handled; |
257 } | 258 } |
258 | 259 |
259 void NaClListener::OnStart(const nacl::NaClStartParams& params) { | 260 void NaClListener::OnStart(const nacl::NaClStartParams& params) { |
261 #if !defined(OS_LINUX) | |
262 CHECK(!uses_nonsfi_mode_) << "Non-SFI NaCl is only supported on Linux"; | |
263 #endif | |
260 #if defined(OS_LINUX) || defined(OS_MACOSX) | 264 #if defined(OS_LINUX) || defined(OS_MACOSX) |
261 int urandom_fd = dup(base::GetUrandomFD()); | 265 int urandom_fd = dup(base::GetUrandomFD()); |
262 if (urandom_fd < 0) { | 266 if (urandom_fd < 0) { |
263 LOG(ERROR) << "Failed to dup() the urandom FD"; | 267 LOG(ERROR) << "Failed to dup() the urandom FD"; |
264 return; | 268 return; |
265 } | 269 } |
266 NaClChromeMainSetUrandomFd(urandom_fd); | 270 NaClChromeMainSetUrandomFd(urandom_fd); |
267 #endif | 271 #endif |
268 | 272 |
269 NaClChromeMainInit(); | 273 NaClChromeMainInit(); |
(...skipping 10 matching lines...) Expand all Loading... | |
280 } | 284 } |
281 | 285 |
282 IPC::ChannelHandle browser_handle; | 286 IPC::ChannelHandle browser_handle; |
283 IPC::ChannelHandle ppapi_renderer_handle; | 287 IPC::ChannelHandle ppapi_renderer_handle; |
284 | 288 |
285 if (params.enable_ipc_proxy) { | 289 if (params.enable_ipc_proxy) { |
286 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | 290 browser_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); |
287 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); | 291 ppapi_renderer_handle = IPC::Channel::GenerateVerifiedChannelID("nacl"); |
288 | 292 |
289 #if defined(OS_LINUX) | 293 #if defined(OS_LINUX) |
290 if (params.uses_nonsfi_mode) { | 294 if (uses_nonsfi_mode_) { |
295 #endif | |
Mark Seaborn
2014/04/02 05:45:16
You can't move the #endif to here.
hamaji
2014/04/02 08:38:39
Done.
| |
291 // In non-SFI mode, we neither intercept nor rewrite the message using | 296 // In non-SFI mode, we neither intercept nor rewrite the message using |
292 // NaClIPCAdapter, and the channels are connected between the plugin and | 297 // NaClIPCAdapter, and the channels are connected between the plugin and |
293 // the hosts directly. So, the IPC::Channel instances will be created in | 298 // the hosts directly. So, the IPC::Channel instances will be created in |
294 // the plugin side, because the IPC::Listener needs to live on the | 299 // the plugin side, because the IPC::Listener needs to live on the |
295 // plugin's main thread. However, on initialization (i.e. before loading | 300 // plugin's main thread. However, on initialization (i.e. before loading |
296 // the plugin binary), the FD needs to be passed to the hosts. So, here | 301 // the plugin binary), the FD needs to be passed to the hosts. So, here |
297 // we create raw FD pairs, and pass the client side FDs to the hosts, | 302 // we create raw FD pairs, and pass the client side FDs to the hosts, |
298 // and the server side FDs to the plugin. | 303 // and the server side FDs to the plugin. |
299 int browser_server_ppapi_fd; | 304 int browser_server_ppapi_fd; |
300 int browser_client_ppapi_fd; | 305 int browser_client_ppapi_fd; |
(...skipping 10 matching lines...) Expand all Loading... | |
311 // Set the plugin IPC channel FDs. | 316 // Set the plugin IPC channel FDs. |
312 SetIPCFileDescriptors( | 317 SetIPCFileDescriptors( |
313 browser_server_ppapi_fd, renderer_server_ppapi_fd); | 318 browser_server_ppapi_fd, renderer_server_ppapi_fd); |
314 | 319 |
315 // Send back to the client side IPC channel FD to the host. | 320 // Send back to the client side IPC channel FD to the host. |
316 browser_handle.socket = | 321 browser_handle.socket = |
317 base::FileDescriptor(browser_client_ppapi_fd, true); | 322 base::FileDescriptor(browser_client_ppapi_fd, true); |
318 ppapi_renderer_handle.socket = | 323 ppapi_renderer_handle.socket = |
319 base::FileDescriptor(renderer_client_ppapi_fd, true); | 324 base::FileDescriptor(renderer_client_ppapi_fd, true); |
320 } else { | 325 } else { |
321 #endif | |
322 // Create the PPAPI IPC channels between the NaCl IRT and the host | 326 // Create the PPAPI IPC channels between the NaCl IRT and the host |
323 // (browser/renderer) processes. The IRT uses these channels to | 327 // (browser/renderer) processes. The IRT uses these channels to |
324 // communicate with the host and to initialize the IPC dispatchers. | 328 // communicate with the host and to initialize the IPC dispatchers. |
325 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), | 329 SetUpIPCAdapter(&browser_handle, io_thread_.message_loop_proxy(), |
326 nap, NACL_CHROME_DESC_BASE); | 330 nap, NACL_CHROME_DESC_BASE); |
327 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), | 331 SetUpIPCAdapter(&ppapi_renderer_handle, io_thread_.message_loop_proxy(), |
328 nap, NACL_CHROME_DESC_BASE + 1); | 332 nap, NACL_CHROME_DESC_BASE + 1); |
329 #if defined(OS_LINUX) | 333 #if defined(OS_LINUX) |
330 } | 334 } |
331 #endif | 335 #endif |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
413 params.debug_stub_server_bound_socket); | 417 params.debug_stub_server_bound_socket); |
414 #endif | 418 #endif |
415 #if defined(OS_WIN) | 419 #if defined(OS_WIN) |
416 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 420 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
417 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 421 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
418 #endif | 422 #endif |
419 #if defined(OS_LINUX) | 423 #if defined(OS_LINUX) |
420 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 424 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
421 #endif | 425 #endif |
422 | 426 |
423 #if defined(OS_LINUX) | 427 if (uses_nonsfi_mode_) { |
Mark Seaborn
2014/04/02 05:45:16
You can't remove this #if/#endif either.
hamaji
2014/04/02 08:38:39
Done.
| |
424 if (params.uses_nonsfi_mode) { | |
425 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); | 428 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); |
426 return; | 429 return; |
427 } | 430 } |
428 #endif | |
429 NaClChromeMainStartApp(nap, args); | 431 NaClChromeMainStartApp(nap, args); |
430 NOTREACHED(); | 432 NOTREACHED(); |
431 } | 433 } |
OLD | NEW |