OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "mojo/monacl/monacl_sel_main.h" |
| 6 |
| 7 #include "mojo/monacl/mojo_syscall.h" |
| 8 #include "native_client/src/public/nacl_app.h" |
| 9 // For opening IRT |
| 10 #include "native_client/src/trusted/desc/nacl_desc_io.h" |
| 11 // For opening IRT |
| 12 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
| 13 // For loading main nexe |
| 14 #include "native_client/src/trusted/service_runtime/load_file.h" |
| 15 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" |
| 16 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error
_reporter.h" |
| 17 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h" |
| 18 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
| 19 #include "native_client/src/trusted/service_runtime/sel_main_common.h" |
| 20 #include "native_client/src/trusted/service_runtime/sel_qualify.h" |
| 21 |
| 22 int LaunchNaCl(const char *nexe_file, const char *irt_file, |
| 23 int app_argc, char *app_argv[]) { |
| 24 // Default to error. |
| 25 int ret_code = 1; |
| 26 NaClErrorCode errcode; |
| 27 struct NaClDesc *blob_file = NULL; |
| 28 |
| 29 const char *env = NULL; |
| 30 |
| 31 NaClAllModulesInit(); |
| 32 |
| 33 struct NaClApp* nap = NaClAppCreate(); |
| 34 if (nap == NULL) { |
| 35 NaClLog(LOG_ERROR, "NaClAppCreate() failed"); |
| 36 return ret_code; |
| 37 } |
| 38 |
| 39 int skip_qualification = 0; |
| 40 if (skip_qualification) { |
| 41 NaClLog(LOG_WARNING, "PLATFORM QUALIFICATION DISABLED - " |
| 42 "Native Client's sandbox will be unreliable!\n"); |
| 43 } else { |
| 44 // HACK no fault injection. |
| 45 errcode = NaClRunSelQualificationTests(); |
| 46 if (LOAD_OK != errcode) { |
| 47 nap->module_load_status = errcode; |
| 48 fprintf(stderr, "Error while loading in SelMain: %s\n", |
| 49 NaClErrorString(errcode)); |
| 50 } |
| 51 } |
| 52 |
| 53 NaClBootstrapChannelErrorReporterInit(); |
| 54 NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap); |
| 55 |
| 56 //NaClFileNameForValgrind(irt_file); |
| 57 blob_file = (struct NaClDesc *) NaClDescIoDescOpen( |
| 58 irt_file, NACL_ABI_O_RDONLY, 0); |
| 59 if (NULL == blob_file) { |
| 60 perror("sel_main"); |
| 61 fprintf(stderr, "Cannot open \"%s\".\n", irt_file); |
| 62 exit(1); |
| 63 } |
| 64 |
| 65 NaClAppInitialDescriptorHookup(nap); |
| 66 |
| 67 InjectMojo(nap); |
| 68 |
| 69 errcode = NaClAppLoadFileFromFilename(nap, nexe_file); |
| 70 if (LOAD_OK != errcode) { |
| 71 fprintf(stderr, "Error while loading \"%s\": %s\n", |
| 72 nexe_file, |
| 73 NaClErrorString(errcode)); |
| 74 fprintf(stderr, |
| 75 ("Using the wrong type of nexe (nacl-x86-32" |
| 76 " on an x86-64 or vice versa)\n" |
| 77 "or a corrupt nexe file may be" |
| 78 " responsible for this error.\n")); |
| 79 } |
| 80 |
| 81 errcode = NaClMainLoadIrt(nap, blob_file, NULL); |
| 82 if (LOAD_OK != errcode) { |
| 83 fprintf(stderr, "Error while loading \"%s\": %s\n", |
| 84 irt_file, |
| 85 NaClErrorString(errcode)); |
| 86 } |
| 87 |
| 88 NaClAppStartModule(nap, NULL, NULL); |
| 89 |
| 90 if (!NaClAppLaunchServiceThreads(nap)) { |
| 91 fprintf(stderr, "Launch service threads failed\n"); |
| 92 goto done; |
| 93 } |
| 94 |
| 95 if (!NaClCreateMainThread(nap, |
| 96 app_argc, |
| 97 app_argv, |
| 98 &env)) { |
| 99 fprintf(stderr, "creating main thread failed\n"); |
| 100 goto done; |
| 101 } |
| 102 |
| 103 { |
| 104 fprintf(stderr, "waiting for main thread\n"); |
| 105 ret_code = NaClWaitForMainThreadToExit(nap); |
| 106 fprintf(stderr, "ret code %d\n", ret_code); |
| 107 } |
| 108 |
| 109 done: |
| 110 NaClAllModulesFini(); |
| 111 return ret_code; |
| 112 } |
OLD | NEW |