Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(125)

Side by Side Diff: components/nacl/loader/nacl_listener.cc

Issue 1085583005: Refactor params of NaClProcessMsg_Start. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 277 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 int urandom_fd = dup(base::GetUrandomFD()); 288 int urandom_fd = dup(base::GetUrandomFD());
289 if (urandom_fd < 0) { 289 if (urandom_fd < 0) {
290 LOG(ERROR) << "Failed to dup() the urandom FD"; 290 LOG(ERROR) << "Failed to dup() the urandom FD";
291 return; 291 return;
292 } 292 }
293 NaClChromeMainSetUrandomFd(urandom_fd); 293 NaClChromeMainSetUrandomFd(urandom_fd);
294 #endif 294 #endif
295 struct NaClApp* nap = NULL; 295 struct NaClApp* nap = NULL;
296 NaClChromeMainInit(); 296 NaClChromeMainInit();
297 297
298 crash_info_shmem_.reset(new base::SharedMemory(params.crash_info_shmem_handle, 298 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle));
299 false)); 299 crash_info_shmem_.reset(new base::SharedMemory(
300 params.crash_info_shmem_handle, false /* not readonly */));
300 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 301 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
301 NaClSetFatalErrorCallback(&FatalLogHandler); 302 NaClSetFatalErrorCallback(&FatalLogHandler);
302 303
303 nap = NaClAppCreate(); 304 nap = NaClAppCreate();
304 if (nap == NULL) { 305 if (nap == NULL) {
305 LOG(ERROR) << "NaClAppCreate() failed"; 306 LOG(ERROR) << "NaClAppCreate() failed";
306 return; 307 return;
307 } 308 }
308 309
309 IPC::ChannelHandle browser_handle; 310 IPC::ChannelHandle browser_handle;
(...skipping 26 matching lines...) Expand all
336 IPC::Channel::GenerateVerifiedChannelID("nacl"), 337 IPC::Channel::GenerateVerifiedChannelID("nacl"),
337 io_thread_.message_loop_proxy().get(), 338 io_thread_.message_loop_proxy().get(),
338 &shutdown_event_); 339 &shutdown_event_);
339 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated( 340 if (!Send(new NaClProcessHostMsg_PpapiChannelsCreated(
340 browser_handle, 341 browser_handle,
341 ppapi_renderer_handle, 342 ppapi_renderer_handle,
342 trusted_listener_->TakeClientChannelHandle(), 343 trusted_listener_->TakeClientChannelHandle(),
343 manifest_service_handle))) 344 manifest_service_handle)))
344 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost."; 345 LOG(ERROR) << "Failed to send IPC channel handle to NaClProcessHost.";
345 346
346 std::vector<nacl::FileDescriptor> handles = params.handles;
347 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); 347 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate();
348 if (args == NULL) { 348 if (args == NULL) {
349 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 349 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
350 return; 350 return;
351 } 351 }
352 352
353 #if defined(OS_LINUX) || defined(OS_MACOSX) 353 #if defined(OS_LINUX) || defined(OS_MACOSX)
354 args->number_of_cores = number_of_cores_; 354 args->number_of_cores = number_of_cores_;
355 args->create_memory_object_func = CreateMemoryObject; 355 args->create_memory_object_func = CreateMemoryObject;
356 # if defined(OS_MACOSX) 356 # if defined(OS_MACOSX)
Mark Seaborn 2015/04/24 00:53:25 You could move this outside "#if defined(OS_LINUX)
hidehiko 2015/04/24 10:05:18 Acknowledged.
357 CHECK(handles.size() >= 1); 357 CHECK(params.mac_shm_fd != IPC::InvalidPlatformFileForTransit());
358 g_shm_fd = nacl::ToNativeHandle(handles[handles.size() - 1]); 358 g_shm_fd = IPC::PlatformFileForTransitToPlatformFile(params.mac_shm_fd);
359 handles.pop_back(); 359 # else
360 CHECK(params.mac_shm_fd == IPC::InvalidPlatformFileForTransit());
Mark Seaborn 2015/04/24 00:53:25 Note that you're doing this check on OS_LINUX but
hidehiko 2015/04/24 10:05:18 Now the field is guraded by OS_MACOSX #ifdef, so I
360 # endif 361 # endif
361 #endif 362 #endif
362 363
363 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); 364 DCHECK(params.process_type != nacl::kUnknownNaClProcessType);
364 CHECK(handles.size() >= 1); 365 CHECK(params.irt_handle != IPC::InvalidPlatformFileForTransit());
365 NaClHandle irt_handle = nacl::ToNativeHandle(handles[handles.size() - 1]); 366 NaClHandle irt_handle =
366 handles.pop_back(); 367 IPC::PlatformFileForTransitToPlatformFile(params.irt_handle);
367 368
368 #if defined(OS_WIN) 369 #if defined(OS_WIN)
369 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), 370 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle),
370 _O_RDONLY | _O_BINARY); 371 _O_RDONLY | _O_BINARY);
371 if (args->irt_fd < 0) { 372 if (args->irt_fd < 0) {
372 LOG(ERROR) << "_open_osfhandle() failed"; 373 LOG(ERROR) << "_open_osfhandle() failed";
373 return; 374 return;
374 } 375 }
375 #else 376 #else
376 args->irt_fd = irt_handle; 377 args->irt_fd = irt_handle;
377 #endif 378 #endif
378 379
379 if (params.validation_cache_enabled) { 380 if (params.validation_cache_enabled) {
380 // SHA256 block size. 381 // SHA256 block size.
381 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); 382 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64);
382 // The cache structure is not freed and exists until the NaCl process exits. 383 // The cache structure is not freed and exists until the NaCl process exits.
383 args->validation_cache = CreateValidationCache( 384 args->validation_cache = CreateValidationCache(
384 new BrowserValidationDBProxy(this), params.validation_cache_key, 385 new BrowserValidationDBProxy(this), params.validation_cache_key,
385 params.version); 386 params.version);
386 } 387 }
387 388
388 CHECK(handles.size() == 1); 389 CHECK(params.imc_bootstrap_handle != IPC::InvalidPlatformFileForTransit());
389 args->imc_bootstrap_handle = nacl::ToNativeHandle(handles[0]); 390 args->imc_bootstrap_handle =
391 IPC::PlatformFileForTransitToPlatformFile(params.imc_bootstrap_handle);
390 args->enable_debug_stub = params.enable_debug_stub; 392 args->enable_debug_stub = params.enable_debug_stub;
391 393
392 // Now configure parts that depend on process type. 394 // Now configure parts that depend on process type.
393 // Start with stricter settings. 395 // Start with stricter settings.
394 args->enable_exception_handling = 0; 396 args->enable_exception_handling = 0;
395 args->enable_dyncode_syscalls = 0; 397 args->enable_dyncode_syscalls = 0;
396 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). 398 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls).
397 args->pnacl_mode = 1; 399 args->pnacl_mode = 1;
398 // Bound the initial nexe's code segment size under PNaCl to reduce the 400 // Bound the initial nexe's code segment size under PNaCl to reduce the
399 // chance of a code spraying attack succeeding (see 401 // chance of a code spraying attack succeeding (see
400 // https://code.google.com/p/nativeclient/issues/detail?id=3572). 402 // https://code.google.com/p/nativeclient/issues/detail?id=3572).
401 // We can't apply this arbitrary limit outside of PNaCl because it might 403 // We can't apply this arbitrary limit outside of PNaCl because it might
402 // break existing NaCl apps, and this limit is only useful if the dyncode 404 // break existing NaCl apps, and this limit is only useful if the dyncode
403 // syscalls are disabled. 405 // syscalls are disabled.
404 args->initial_nexe_max_code_bytes = 64 << 20; // 64 MB. 406 args->initial_nexe_max_code_bytes = 64 << 20; // 64 MB.
405 407
406 if (params.process_type == nacl::kNativeNaClProcessType) { 408 if (params.process_type == nacl::kNativeNaClProcessType) {
407 args->enable_exception_handling = 1; 409 args->enable_exception_handling = 1;
408 args->enable_dyncode_syscalls = 1; 410 args->enable_dyncode_syscalls = 1;
409 args->pnacl_mode = 0; 411 args->pnacl_mode = 0;
410 args->initial_nexe_max_code_bytes = 0; 412 args->initial_nexe_max_code_bytes = 0;
411 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) { 413 } else if (params.process_type == nacl::kPNaClTranslatorProcessType) {
412 // Transitioning the PNaCl translators to use the IRT again: 414 // Transitioning the PNaCl translators to use the IRT again:
413 // https://code.google.com/p/nativeclient/issues/detail?id=3914. 415 // https://code.google.com/p/nativeclient/issues/detail?id=3914.
414 // Once done, this can be removed. 416 // Once done, this can be removed.
415 args->irt_load_optional = 1; 417 args->irt_load_optional = 1;
416 args->pnacl_mode = 0; 418 args->pnacl_mode = 0;
417 } 419 }
418 420
419 #if defined(OS_LINUX) || defined(OS_MACOSX) 421 #if defined(OS_POSIX)
420 args->debug_stub_server_bound_socket_fd = nacl::ToNativeHandle( 422 args->debug_stub_server_bound_socket_fd =
421 params.debug_stub_server_bound_socket); 423 IPC::PlatformFileForTransitToPlatformFile(
424 params.debug_stub_server_bound_socket);
425 #else
426 CHECK(params.debug_stub_server_bound_socket ==
427 IPC::InvalidPlatformFileForTransit());
422 #endif 428 #endif
423 #if defined(OS_WIN) 429 #if defined(OS_WIN)
424 args->broker_duplicate_handle_func = BrokerDuplicateHandle; 430 args->broker_duplicate_handle_func = BrokerDuplicateHandle;
425 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler; 431 args->attach_debug_exception_handler_func = AttachDebugExceptionHandler;
426 args->debug_stub_server_port_selected_handler_func = 432 args->debug_stub_server_port_selected_handler_func =
427 DebugStubPortSelectedHandler; 433 DebugStubPortSelectedHandler;
428 #endif 434 #endif
429 args->load_status_handler_func = LoadStatusCallback; 435 args->load_status_handler_func = LoadStatusCallback;
430 #if defined(OS_LINUX) 436 #if defined(OS_LINUX)
431 args->prereserved_sandbox_size = prereserved_sandbox_size_; 437 args->prereserved_sandbox_size = prereserved_sandbox_size_;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 } 477 }
472 478
473 void NaClListener::OnFileTokenResolved( 479 void NaClListener::OnFileTokenResolved(
474 uint64_t token_lo, 480 uint64_t token_lo,
475 uint64_t token_hi, 481 uint64_t token_hi,
476 IPC::PlatformFileForTransit ipc_fd, 482 IPC::PlatformFileForTransit ipc_fd,
477 base::FilePath file_path) { 483 base::FilePath file_path) {
478 resolved_cb_.Run(ipc_fd, file_path); 484 resolved_cb_.Run(ipc_fd, file_path);
479 resolved_cb_.Reset(); 485 resolved_cb_.Reset();
480 } 486 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698