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