| 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 <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <stdlib.h> | 9 #include <stdlib.h> |
| 10 #include <string.h> | 10 #include <string.h> |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 int urandom_fd = dup(base::GetUrandomFD()); | 282 int urandom_fd = dup(base::GetUrandomFD()); |
| 283 if (urandom_fd < 0) { | 283 if (urandom_fd < 0) { |
| 284 LOG(ERROR) << "Failed to dup() the urandom FD"; | 284 LOG(ERROR) << "Failed to dup() the urandom FD"; |
| 285 return; | 285 return; |
| 286 } | 286 } |
| 287 NaClChromeMainSetUrandomFd(urandom_fd); | 287 NaClChromeMainSetUrandomFd(urandom_fd); |
| 288 #endif | 288 #endif |
| 289 struct NaClApp* nap = NULL; | 289 struct NaClApp* nap = NULL; |
| 290 NaClChromeMainInit(); | 290 NaClChromeMainInit(); |
| 291 | 291 |
| 292 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle)); |
| 292 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, | 293 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, |
| 293 false)); | 294 false)); |
| 294 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); | 295 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); |
| 295 NaClSetFatalErrorCallback(&FatalLogHandler); | 296 NaClSetFatalErrorCallback(&FatalLogHandler); |
| 296 | 297 |
| 297 nap = NaClAppCreate(); | 298 nap = NaClAppCreate(); |
| 298 if (nap == NULL) { | 299 if (nap == NULL) { |
| 299 LOG(ERROR) << "NaClAppCreate() failed"; | 300 LOG(ERROR) << "NaClAppCreate() failed"; |
| 300 return; | 301 return; |
| 301 } | 302 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 330 IPC::Channel::GenerateVerifiedChannelID("nacl"), | 331 IPC::Channel::GenerateVerifiedChannelID("nacl"), |
| 331 io_thread_.message_loop_proxy().get(), | 332 io_thread_.message_loop_proxy().get(), |
| 332 &shutdown_event_); | 333 &shutdown_event_); |
| 333 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( | 334 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( |
| 334 browser_handle, | 335 browser_handle, |
| 335 ppapi_renderer_handle, | 336 ppapi_renderer_handle, |
| 336 trusted_listener_->TakeClientChannelHandle(), | 337 trusted_listener_->TakeClientChannelHandle(), |
| 337 manifest_service_handle))) | 338 manifest_service_handle))) |
| 338 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; | 339 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; |
| 339 | 340 |
| 340 std::vector<nacl::FileDescriptor> handles = params.handles; | |
| 341 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); | 341 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); |
| 342 if (args == NULL) { | 342 if (args == NULL) { |
| 343 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; | 343 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; |
| 344 return; | 344 return; |
| 345 } | 345 } |
| 346 | 346 |
| 347 #if defined(OS_LINUX) || defined(OS_MACOSX) | 347 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 348 args->number_of_cores = number_of_cores_; | 348 args->number_of_cores = number_of_cores_; |
| 349 args->create_memory_object_func = CreateMemoryObject; | 349 args->create_memory_object_func = CreateMemoryObject; |
| 350 # if defined(OS_MACOSX) | 350 # if defined(OS_MACOSX) |
| 351 CHECK(handles.size() >= 1); | 351 CHECK(params.mac_shm_fd != IPC::InvalidPlatformFileForTransit()); |
| 352 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); | 352 g_shm_fd = IPC::PlatformFileForTransitToPlatformFile(params.mac_shm_fd); |
| 353 handles.pop_back(); | |
| 354 # endif | 353 # endif |
| 355 #endif | 354 #endif |
| 356 | 355 |
| 357 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); | 356 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); |
| 358 CHECK(handles.size() >= 1); | 357 CHECK(params.irt_handle != IPC::InvalidPlatformFileForTransit()); |
| 359 NaClHandle irt_handle = nacl::ToNativeHandle(handles[handles.size() - 1]); | 358 NaClHandle irt_handle = |
| 360 handles.pop_back(); | 359 IPC::PlatformFileForTransitToPlatformFile(params.irt_handle); |
| 361 | |
| 362 #if defined(OS_WIN) | 360 #if defined(OS_WIN) |
| 363 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), | 361 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), |
| 364 _O_RDONLY | _O_BINARY); | 362 _O_RDONLY | _O_BINARY); |
| 365 if (args->irt_fd < 0) { | 363 if (args->irt_fd < 0) { |
| 366 LOG(ERROR) << "_open_osfhandle() failed"; | 364 LOG(ERROR) << "_open_osfhandle() failed"; |
| 367 return; | 365 return; |
| 368 } | 366 } |
| 369 #else | 367 #else |
| 370 args->irt_fd = irt_handle; | 368 args->irt_fd = irt_handle; |
| 371 #endif | 369 #endif |
| 372 | 370 |
| 373 if (params.validation_cache_enabled) { | 371 if (params.validation_cache_enabled) { |
| 374 // SHA256 block size. | 372 // SHA256 block size. |
| 375 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); | 373 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); |
| 376 // The cache structure is not freed and exists until the NaCl process exits. | 374 // The cache structure is not freed and exists until the NaCl process exits. |
| 377 args->validation_cache = CreateValidationCache( | 375 args->validation_cache = CreateValidationCache( |
| 378 new BrowserValidationDBProxy(this), params.validation_cache_key, | 376 new BrowserValidationDBProxy(this), params.validation_cache_key, |
| 379 params.version); | 377 params.version); |
| 380 } | 378 } |
| 381 | 379 |
| 382 CHECK(handles.size() == 1); | 380 CHECK(params.imc_bootstrap_handle != IPC::InvalidPlatformFileForTransit()); |
| 383 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); | 381 args->imc_bootstrap_handle = |
| 382 IPC::PlatformFileForTransitToPlatformFile(params.imc_bootstrap_handle); |
| 384 args->enable_debug_stub = params.enable_debug_stub; | 383 args->enable_debug_stub = params.enable_debug_stub; |
| 385 | 384 |
| 386 // Now configure parts that depend on process type. | 385 // Now configure parts that depend on process type. |
| 387 // Start with stricter settings. | 386 // Start with stricter settings. |
| 388 args->enable_exception_handling = 0; | 387 args->enable_exception_handling = 0; |
| 389 args->enable_dyncode_syscalls = 0; | 388 args->enable_dyncode_syscalls = 0; |
| 390 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). | 389 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). |
| 391 args->pnacl_mode = 1; | 390 args->pnacl_mode = 1; |
| 392 // Bound the initial nexe's code segment size under PNaCl to reduce the | 391 // Bound the initial nexe's code segment size under PNaCl to reduce the |
| 393 // chance of a code spraying attack succeeding (see | 392 // chance of a code spraying attack succeeding (see |
| (...skipping 10 matching lines...) Expand all Loading... |
| 404 args->initial_nexe_max_code_bytes = 0; | 403 args->initial_nexe_max_code_bytes = 0; |
| 405 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) { | 404 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) { |
| 406 // Transitioning the PNaCl translators to use the IRT again: | 405 // Transitioning the PNaCl translators to use the IRT again: |
| 407 // https://code.google.com/p/nativeclient/issues/detail?id=3914. | 406 // https://code.google.com/p/nativeclient/issues/detail?id=3914. |
| 408 // Once done, this can be removed. | 407 // Once done, this can be removed. |
| 409 args->irt_load_optional = 1; | 408 args->irt_load_optional = 1; |
| 410 args->pnacl_mode = 0; | 409 args->pnacl_mode = 0; |
| 411 } | 410 } |
| 412 | 411 |
| 413 #if defined(OS_LINUX) || defined(OS_MACOSX) | 412 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 414 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( | 413 args->debug_stub_server_bound_socket_fd = |
| 415 params.debug_stub_server_bound_socket); | 414 IPC::PlatformFileForTransitToPlatformFile( |
| 415 params.debug_stub_server_bound_socket); |
| 416 #endif | 416 #endif |
| 417 #if defined(OS_WIN) | 417 #if defined(OS_WIN) |
| 418 args->broker_duplicate_handle_func = BrokerDuplicateHandle; | 418 args->broker_duplicate_handle_func = BrokerDuplicateHandle; |
| 419 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; | 419 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; |
| 420 args->debug_stub_server_port_selected_handler_func = | 420 args->debug_stub_server_port_selected_handler_func = |
| 421 DebugStubPortSelectedHandler; | 421 DebugStubPortSelectedHandler; |
| 422 #endif | 422 #endif |
| 423 #if defined(OS_LINUX) | 423 #if defined(OS_LINUX) |
| 424 args->prereserved_sandbox_size = prereserved_sandbox_size_; | 424 args->prereserved_sandbox_size = prereserved_sandbox_size_; |
| 425 #endif | 425 #endif |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 } | 464 } |
| 465 | 465 |
| 466 void NaClListener::OnFileTokenResolved( | 466 void NaClListener::OnFileTokenResolved( |
| 467 uint64_t token_lo, | 467 uint64_t token_lo, |
| 468 uint64_t token_hi, | 468 uint64_t token_hi, |
| 469 IPC::PlatformFileForTransit ipc_fd, | 469 IPC::PlatformFileForTransit ipc_fd, |
| 470 base::FilePath file_path) { | 470 base::FilePath file_path) { |
| 471 resolved_cb_.Run(ipc_fd, file_path); | 471 resolved_cb_.Run(ipc_fd, file_path); |
| 472 resolved_cb_.Reset(); | 472 resolved_cb_.Reset(); |
| 473 } | 473 } |
| OLD | NEW |