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

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

Issue 1117883002: Reduce resource leak code for StartNaClExecution. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « components/nacl/browser/nacl_process_host.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 void NaClListener::OnStart(const nacl::NaClStartParams& params) { 329 void NaClListener::OnStart(const nacl::NaClStartParams& params) {
330 is_started_ = true; 330 is_started_ = true;
331 #if defined(OS_LINUX) || defined(OS_MACOSX) 331 #if defined(OS_LINUX) || defined(OS_MACOSX)
332 int urandom_fd = dup(base::GetUrandomFD()); 332 int urandom_fd = dup(base::GetUrandomFD());
333 if (urandom_fd < 0) { 333 if (urandom_fd < 0) {
334 LOG(ERROR) << "Failed to dup() the urandom FD"; 334 LOG(ERROR) << "Failed to dup() the urandom FD";
335 return; 335 return;
336 } 336 }
337 NaClChromeMainSetUrandomFd(urandom_fd); 337 NaClChromeMainSetUrandomFd(urandom_fd);
338 #endif 338 #endif
339
340 // Before starting the launching process, verify if FDs/HANDLEs are properly
341 // transferred to here.
342 // These can be stale, if some unexpected error happens in the sender
343 // process. It sends the IPC message regardless of the errors with deferring
344 // the error handle to the callee for releasing FDs/HANDLEs properly.
345 CHECK(params.nexe_file != IPC::InvalidPlatformFileForTransit());
346 CHECK(params.imc_bootstrap_handle != IPC::InvalidPlatformFileForTransit());
347 CHECK(params.irt_handle != IPC::InvalidPlatformFileForTransit());
348 #if defined(OS_MACOSX)
349 CHECK(params.mac_shm_fd != IPC::InvalidPlatformFileForTransit());
350 #endif
351 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle));
352
339 struct NaClApp* nap = NULL; 353 struct NaClApp* nap = NULL;
340 NaClChromeMainInit(); 354 NaClChromeMainInit();
341 355
342 CHECK(base::SharedMemory::IsHandleValid(params.crash_info_shmem_handle));
343 crash_info_shmem_.reset(new base::SharedMemory( 356 crash_info_shmem_.reset(new base::SharedMemory(
344 params.crash_info_shmem_handle, false /* not readonly */)); 357 params.crash_info_shmem_handle, false /* not readonly */));
345 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize)); 358 CHECK(crash_info_shmem_->Map(nacl::kNaClCrashInfoShmemSize));
346 NaClSetFatalErrorCallback(&FatalLogHandler); 359 NaClSetFatalErrorCallback(&FatalLogHandler);
347 360
348 nap = NaClAppCreate(); 361 nap = NaClAppCreate();
349 if (nap == NULL) { 362 if (nap == NULL) {
350 LOG(ERROR) << "NaClAppCreate() failed"; 363 LOG(ERROR) << "NaClAppCreate() failed";
351 return; 364 return;
352 } 365 }
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate(); 408 struct NaClChromeMainArgs* args = NaClChromeMainArgsCreate();
396 if (args == NULL) { 409 if (args == NULL) {
397 LOG(ERROR) << "NaClChromeMainArgsCreate() failed"; 410 LOG(ERROR) << "NaClChromeMainArgsCreate() failed";
398 return; 411 return;
399 } 412 }
400 413
401 #if defined(OS_LINUX) || defined(OS_MACOSX) 414 #if defined(OS_LINUX) || defined(OS_MACOSX)
402 args->number_of_cores = number_of_cores_; 415 args->number_of_cores = number_of_cores_;
403 args->create_memory_object_func = CreateMemoryObject; 416 args->create_memory_object_func = CreateMemoryObject;
404 # if defined(OS_MACOSX) 417 # if defined(OS_MACOSX)
405 CHECK(params.mac_shm_fd != IPC::InvalidPlatformFileForTransit());
406 g_shm_fd = IPC::PlatformFileForTransitToPlatformFile(params.mac_shm_fd); 418 g_shm_fd = IPC::PlatformFileForTransitToPlatformFile(params.mac_shm_fd);
407 # endif 419 # endif
408 #endif 420 #endif
409 421
410 DCHECK(params.process_type != nacl::kUnknownNaClProcessType); 422 DCHECK(params.process_type != nacl::kUnknownNaClProcessType);
411 CHECK(params.irt_handle != IPC::InvalidPlatformFileForTransit());
412 NaClHandle irt_handle = 423 NaClHandle irt_handle =
413 IPC::PlatformFileForTransitToPlatformFile(params.irt_handle); 424 IPC::PlatformFileForTransitToPlatformFile(params.irt_handle);
414 425
415 #if defined(OS_WIN) 426 #if defined(OS_WIN)
416 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle), 427 args->irt_fd = _open_osfhandle(reinterpret_cast<intptr_t>(irt_handle),
417 _O_RDONLY | _O_BINARY); 428 _O_RDONLY | _O_BINARY);
418 if (args->irt_fd < 0) { 429 if (args->irt_fd < 0) {
419 LOG(ERROR) << "_open_osfhandle() failed"; 430 LOG(ERROR) << "_open_osfhandle() failed";
420 return; 431 return;
421 } 432 }
422 #else 433 #else
423 args->irt_fd = irt_handle; 434 args->irt_fd = irt_handle;
424 #endif 435 #endif
425 436
426 if (params.validation_cache_enabled) { 437 if (params.validation_cache_enabled) {
427 // SHA256 block size. 438 // SHA256 block size.
428 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64); 439 CHECK_EQ(params.validation_cache_key.length(), (size_t) 64);
429 // The cache structure is not freed and exists until the NaCl process exits. 440 // The cache structure is not freed and exists until the NaCl process exits.
430 args->validation_cache = CreateValidationCache( 441 args->validation_cache = CreateValidationCache(
431 new BrowserValidationDBProxy(this), params.validation_cache_key, 442 new BrowserValidationDBProxy(this), params.validation_cache_key,
432 params.version); 443 params.version);
433 } 444 }
434 445
435 CHECK(params.imc_bootstrap_handle != IPC::InvalidPlatformFileForTransit());
436 args->imc_bootstrap_handle = 446 args->imc_bootstrap_handle =
437 IPC::PlatformFileForTransitToPlatformFile(params.imc_bootstrap_handle); 447 IPC::PlatformFileForTransitToPlatformFile(params.imc_bootstrap_handle);
438 args->enable_debug_stub = params.enable_debug_stub; 448 args->enable_debug_stub = params.enable_debug_stub;
439 449
440 // Now configure parts that depend on process type. 450 // Now configure parts that depend on process type.
441 // Start with stricter settings. 451 // Start with stricter settings.
442 args->enable_exception_handling = 0; 452 args->enable_exception_handling = 0;
443 args->enable_dyncode_syscalls = 0; 453 args->enable_dyncode_syscalls = 0;
444 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls). 454 // pnacl_mode=1 mostly disables things (IRT interfaces and syscalls).
445 args->pnacl_mode = 1; 455 args->pnacl_mode = 1;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 } 517 }
508 518
509 void NaClListener::OnFileTokenResolved( 519 void NaClListener::OnFileTokenResolved(
510 uint64_t token_lo, 520 uint64_t token_lo,
511 uint64_t token_hi, 521 uint64_t token_hi,
512 IPC::PlatformFileForTransit ipc_fd, 522 IPC::PlatformFileForTransit ipc_fd,
513 base::FilePath file_path) { 523 base::FilePath file_path) {
514 resolved_cb_.Run(ipc_fd, file_path); 524 resolved_cb_.Run(ipc_fd, file_path);
515 resolved_cb_.Reset(); 525 resolved_cb_.Reset();
516 } 526 }
OLDNEW
« no previous file with comments | « components/nacl/browser/nacl_process_host.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698