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

Side by Side Diff: src/trusted/service_runtime/sel_main.c

Issue 12226119: Factor out duplicated GioMemoryFileSnapshotCtor() + NaClAppLoadFile() calls (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The Native Client Authors. All rights reserved. 2 * Copyright (c) 2012 The Native Client Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be 3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file. 4 * found in the LICENSE file.
5 */ 5 */
6 6
7 /* 7 /*
8 * NaCl Simple/secure ELF loader (NaCl SEL). 8 * NaCl Simple/secure ELF loader (NaCl SEL).
9 */ 9 */
10 #include "native_client/src/include/portability.h" 10 #include "native_client/src/include/portability.h"
(...skipping 18 matching lines...) Expand all
29 #include "native_client/src/shared/platform/nacl_log.h" 29 #include "native_client/src/shared/platform/nacl_log.h"
30 #include "native_client/src/shared/platform/nacl_sync.h" 30 #include "native_client/src/shared/platform/nacl_sync.h"
31 #include "native_client/src/shared/platform/nacl_sync_checked.h" 31 #include "native_client/src/shared/platform/nacl_sync_checked.h"
32 #include "native_client/src/shared/srpc/nacl_srpc.h" 32 #include "native_client/src/shared/srpc/nacl_srpc.h"
33 33
34 #include "native_client/src/trusted/fault_injection/fault_injection.h" 34 #include "native_client/src/trusted/fault_injection/fault_injection.h"
35 #include "native_client/src/trusted/fault_injection/test_injection.h" 35 #include "native_client/src/trusted/fault_injection/test_injection.h"
36 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h" 36 #include "native_client/src/trusted/perf_counter/nacl_perf_counter.h"
37 #include "native_client/src/trusted/service_runtime/env_cleanser.h" 37 #include "native_client/src/trusted/service_runtime/env_cleanser.h"
38 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 38 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
39 #include "native_client/src/trusted/service_runtime/load_file.h"
39 #include "native_client/src/trusted/service_runtime/nacl_app.h" 40 #include "native_client/src/trusted/service_runtime/nacl_app.h"
40 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" 41 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h"
41 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error _reporter.h" 42 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error _reporter.h"
42 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h" 43 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h"
43 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h" 44 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h"
44 #include "native_client/src/trusted/service_runtime/nacl_globals.h" 45 #include "native_client/src/trusted/service_runtime/nacl_globals.h"
45 #include "native_client/src/trusted/service_runtime/nacl_signal.h" 46 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
46 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h" 47 #include "native_client/src/trusted/service_runtime/nacl_syscall_common.h"
47 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h" 48 #include "native_client/src/trusted/service_runtime/nacl_valgrind_hooks.h"
48 #include "native_client/src/trusted/service_runtime/osx/mach_exception_handler.h " 49 #include "native_client/src/trusted/service_runtime/osx/mach_exception_handler.h "
(...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 fprintf(stderr, "Cannot open \"%s\".\n", blob_library_file); 546 fprintf(stderr, "Cannot open \"%s\".\n", blob_library_file);
546 exit(1); 547 exit(1);
547 } 548 }
548 NaClPerfCounterMark(&time_all_main, "SnapshotBlob"); 549 NaClPerfCounterMark(&time_all_main, "SnapshotBlob");
549 NaClPerfCounterIntervalLast(&time_all_main); 550 NaClPerfCounterIntervalLast(&time_all_main);
550 } 551 }
551 552
552 NaClAppInitialDescriptorHookup(nap); 553 NaClAppInitialDescriptorHookup(nap);
553 554
554 if (!rpc_supplies_nexe) { 555 if (!rpc_supplies_nexe) {
555 struct GioMemoryFileSnapshot main_file;
556
557 NaClFileNameForValgrind(nacl_file);
558 if (0 == GioMemoryFileSnapshotCtor(&main_file, nacl_file)) {
559 perror("sel_main");
560 fprintf(stderr, "Cannot open \"%s\".\n", nacl_file);
561 exit(1);
562 }
563 NaClPerfCounterMark(&time_all_main, "SnapshotNaclFile");
564 NaClPerfCounterIntervalLast(&time_all_main);
565
566 if (LOAD_OK == errcode) { 556 if (LOAD_OK == errcode) {
567 NaClLog(2, "Loading nacl file %s (non-RPC)\n", nacl_file); 557 NaClLog(2, "Loading nacl file %s (non-RPC)\n", nacl_file);
568 errcode = NaClAppLoadFile((struct Gio *) &main_file, nap); 558 errcode = NaClAppLoadFileFromFilename(nap, nacl_file);
569 if (LOAD_OK != errcode) { 559 if (LOAD_OK != errcode) {
570 fprintf(stderr, "Error while loading \"%s\": %s\n", 560 fprintf(stderr, "Error while loading \"%s\": %s\n",
571 nacl_file, 561 nacl_file,
572 NaClErrorString(errcode)); 562 NaClErrorString(errcode));
573 fprintf(stderr, 563 fprintf(stderr,
574 ("Using the wrong type of nexe (nacl-x86-32" 564 ("Using the wrong type of nexe (nacl-x86-32"
575 " on an x86-64 or vice versa)\n" 565 " on an x86-64 or vice versa)\n"
576 "or a corrupt nexe file may be" 566 "or a corrupt nexe file may be"
577 " responsible for this error.\n")); 567 " responsible for this error.\n"));
578 } 568 }
579 NaClPerfCounterMark(&time_all_main, "AppLoadEnd"); 569 NaClPerfCounterMark(&time_all_main, "AppLoadEnd");
580 NaClPerfCounterIntervalLast(&time_all_main); 570 NaClPerfCounterIntervalLast(&time_all_main);
581 571
582 NaClXMutexLock(&nap->mu); 572 NaClXMutexLock(&nap->mu);
583 nap->module_load_status = errcode; 573 nap->module_load_status = errcode;
584 NaClXCondVarBroadcast(&nap->cv); 574 NaClXCondVarBroadcast(&nap->cv);
585 NaClXMutexUnlock(&nap->mu); 575 NaClXMutexUnlock(&nap->mu);
586 } 576 }
587 577
588 if (-1 == (*((struct Gio *) &main_file)->vtbl->Close)((struct Gio *)
589 &main_file)) {
590 fprintf(stderr, "Error while closing \"%s\".\n", nacl_file);
591 }
592 (*((struct Gio *) &main_file)->vtbl->Dtor)((struct Gio *) &main_file);
593
594 if (fuzzing_quit_after_load) { 578 if (fuzzing_quit_after_load) {
595 exit(0); 579 exit(0);
596 } 580 }
597 } 581 }
598 582
599 /* 583 /*
600 * Execute additional I/O redirections. NB: since the NaClApp 584 * Execute additional I/O redirections. NB: since the NaClApp
601 * takes ownership of host / IMC socket descriptors, all but 585 * takes ownership of host / IMC socket descriptors, all but
602 * the first run will not get access if the NaClApp closes 586 * the first run will not get access if the NaClApp closes
603 * them. Currently a normal NaClApp process exit does not 587 * them. Currently a normal NaClApp process exit does not
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 fflush(stdout); 843 fflush(stdout);
860 844
861 if (handle_signals) NaClSignalHandlerFini(); 845 if (handle_signals) NaClSignalHandlerFini();
862 NaClAllModulesFini(); 846 NaClAllModulesFini();
863 847
864 NaClExit(ret_code); 848 NaClExit(ret_code);
865 849
866 /* Unreachable, but having the return prevents a compiler error. */ 850 /* Unreachable, but having the return prevents a compiler error. */
867 return ret_code; 851 return ret_code;
868 } 852 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/mmap_test.c ('k') | src/trusted/service_runtime/service_runtime.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698