| 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/trusted/service_runtime/sel_main_chrome.h" | 27 #include "native_client/src/public/chrome_main.h" |
| 28 #include "native_client/src/public/nacl_app.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" |
| 37 #endif | 38 #endif |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { | 227 bool NaClListener::OnMessageReceived(const IPC::Message& msg) { |
| 227 bool handled = true; | 228 bool handled = true; |
| 228 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) | 229 IPC_BEGIN_MESSAGE_MAP(NaClListener, msg) |
| 229 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) | 230 IPC_MESSAGE_HANDLER(NaClProcessMsg_Start, OnStart) |
| 230 IPC_MESSAGE_UNHANDLED(handled = false) | 231 IPC_MESSAGE_UNHANDLED(handled = false) |
| 231 IPC_END_MESSAGE_MAP() | 232 IPC_END_MESSAGE_MAP() |
| 232 return handled; | 233 return handled; |
| 233 } | 234 } |
| 234 | 235 |
| 235 void NaClListener::OnStart(const nacl::NaClStartParams& params) { | 236 void NaClListener::OnStart(const nacl::NaClStartParams& params) { |
| 237 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 238 int urandom_fd = dup(base::GetUrandomFD()); |
| 239 if (urandom_fd < 0) { |
| 240 LOG(ERROR) << "Failed to dup() the urandom FD"; |
| 241 return; |
| 242 } |
| 243 NaClChromeMainSetUrandomFd(urandom_fd); |
| 244 #endif |
| 245 |
| 246 NaClChromeMainInit(); |
| 236 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); | 247 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); |
| 237 if (args == NULL) { | 248 if (args == NULL) { |
| 238 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 249 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
| 239 return; | 250 return; |
| 240 } | 251 } |
| 252 struct NaClApp *nap = NaClAppCreate(); |
| 253 if (nap == NULL) { |
| 254 LOG(ERROR) << "NaClAppCreate() failed"; |
| 255 return; |
| 256 } |
| 241 | 257 |
| 242 if (params.enable_ipc_proxy) { | 258 if (params.enable_ipc_proxy) { |
| 243 // Create the initial PPAPI IPC channel between the NaCl IRT and the | 259 // Create the initial PPAPI IPC channel between the NaCl IRT and the |
| 244 // browser process. The IRT uses this channel to communicate with the | 260 // browser process. The IRT uses this channel to communicate with the |
| 245 // browser and to create additional IPC channels to renderer processes. | 261 // browser and to create additional IPC channels to renderer processes. |
| 246 IPC::ChannelHandle handle = | 262 IPC::ChannelHandle handle = |
| 247 IPC::Channel::GenerateVerifiedChannelID("nacl"); | 263 IPC::Channel::GenerateVerifiedChannelID("nacl"); |
| 248 scoped_refptr<NaClIPCAdapter> ipc_adapter( | 264 scoped_refptr<NaClIPCAdapter> ipc_adapter( |
| 249 new NaClIPCAdapter(handle, io_thread_.message_loop_proxy().get())); | 265 new NaClIPCAdapter(handle, io_thread_.message_loop_proxy().get())); |
| 250 ipc_adapter->ConnectChannel(); | 266 ipc_adapter->ConnectChannel(); |
| 251 | 267 |
| 252 // Pass a NaClDesc to the untrusted side. This will hold a ref to the | 268 // Pass a NaClDesc to the untrusted side. This will hold a ref to the |
| 253 // NaClIPCAdapter. | 269 // NaClIPCAdapter. |
| 254 args->initial_ipc_desc = ipc_adapter->MakeNaClDesc(); | 270 NaClAppSetDesc(nap, NACL_CHROME_DESC_BASE, ipc_adapter->MakeNaClDesc()); |
| 255 #if defined(OS_POSIX) | 271 #if defined(OS_POSIX) |
| 256 handle.socket = base::FileDescriptor( | 272 handle.socket = base::FileDescriptor( |
| 257 ipc_adapter->TakeClientFileDescriptor(), true); | 273 ipc_adapter->TakeClientFileDescriptor(), true); |
| 258 #endif | 274 #endif |
| 259 if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(handle))) | 275 if (!Send(new NaClProcessHostMsg_PpapiChannelCreated(handle))) |
| 260 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 276 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
| 261 } | 277 } |
| 262 | 278 |
| 263 std::vector<nacl::FileDescriptor> handles = params.handles; | 279 std::vector<nacl::FileDescriptor> handles = params.handles; |
| 264 | 280 |
| 265 #if defined(OS_LINUX) || defined(OS_MACOSX) | 281 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 266 args->urandom_fd = dup(base::GetUrandomFD()); | |
| 267 if (args->urandom_fd < 0) { | |
| 268 LOG(ERROR) << "Failed to dup() the urandom FD"; | |
| 269 return; | |
| 270 } | |
| 271 args->number_of_cores = number_of_cores_; | 282 args->number_of_cores = number_of_cores_; |
| 272 args->create_memory_object_func = CreateMemoryObject; | 283 args->create_memory_object_func = CreateMemoryObject; |
| 273 # if defined(OS_MACOSX) | 284 # if defined(OS_MACOSX) |
| 274 CHECK(handles.size() >= 1); | 285 CHECK(handles.size() >= 1); |
| 275 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); | 286 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); |
| 276 handles.pop_back(); | 287 handles.pop_back(); |
| 277 # endif | 288 # endif |
| 278 #endif | 289 #endif |
| 279 | 290 |
| 280 if (params.uses_irt) { | 291 if (params.uses_irt) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 344 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
| 334 #endif | 345 #endif |
| 335 | 346 |
| 336 #if defined(OS_LINUX) | 347 #if defined(OS_LINUX) |
| 337 if (params.enable_nonsfi_mode) { | 348 if (params.enable_nonsfi_mode) { |
| 338 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); | 349 nacl::nonsfi::MainStart(args->imc_bootstrap_handle); |
| 339 NOTREACHED(); | 350 NOTREACHED(); |
| 340 return; | 351 return; |
| 341 } | 352 } |
| 342 #endif | 353 #endif |
| 343 NaClChromeMainStart(args); | 354 NaClChromeMainStartApp(nap, args); |
| 344 NOTREACHED(); | 355 NOTREACHED(); |
| 345 } | 356 } |
| OLD | NEW |