Index: mojo/monacl/monacl_sel_main.cc |
diff --git a/mojo/monacl/monacl_sel_main.cc b/mojo/monacl/monacl_sel_main.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..782fa186b45a08b11232a2d043498114a80ea70e |
--- /dev/null |
+++ b/mojo/monacl/monacl_sel_main.cc |
@@ -0,0 +1,112 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "mojo/monacl/monacl_sel_main.h" |
+ |
+#include "mojo/monacl/mojo_syscall.h" |
+#include "native_client/src/public/nacl_app.h" |
+// For opening IRT |
+#include "native_client/src/trusted/desc/nacl_desc_io.h" |
+// For opening IRT |
+#include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" |
+// For loading main nexe |
+#include "native_client/src/trusted/service_runtime/load_file.h" |
+#include "native_client/src/trusted/service_runtime/nacl_all_modules.h" |
+#include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error_reporter.h" |
+#include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h" |
+#include "native_client/src/trusted/service_runtime/sel_ldr.h" |
+#include "native_client/src/trusted/service_runtime/sel_main_common.h" |
+#include "native_client/src/trusted/service_runtime/sel_qualify.h" |
+ |
+int LaunchNaCl(const char *nexe_file, const char *irt_file, |
+ int app_argc, char *app_argv[]) { |
+ // Default to error. |
+ int ret_code = 1; |
+ NaClErrorCode errcode; |
+ struct NaClDesc *blob_file = NULL; |
+ |
+ const char *env = NULL; |
+ |
+ NaClAllModulesInit(); |
+ |
+ struct NaClApp* nap = NaClAppCreate(); |
+ if (nap == NULL) { |
+ NaClLog(LOG_ERROR, "NaClAppCreate() failed"); |
+ return ret_code; |
+ } |
+ |
+ int skip_qualification = 0; |
+ if (skip_qualification) { |
+ NaClLog(LOG_WARNING, "PLATFORM QUALIFICATION DISABLED - " |
+ "Native Client's sandbox will be unreliable!\n"); |
+ } else { |
+ // HACK no fault injection. |
+ errcode = NaClRunSelQualificationTests(); |
+ if (LOAD_OK != errcode) { |
+ nap->module_load_status = errcode; |
+ fprintf(stderr, "Error while loading in SelMain: %s\n", |
+ NaClErrorString(errcode)); |
+ } |
+ } |
+ |
+ NaClBootstrapChannelErrorReporterInit(); |
+ NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap); |
+ |
+ //NaClFileNameForValgrind(irt_file); |
+ blob_file = (struct NaClDesc *) NaClDescIoDescOpen( |
+ irt_file, NACL_ABI_O_RDONLY, 0); |
+ if (NULL == blob_file) { |
+ perror("sel_main"); |
+ fprintf(stderr, "Cannot open \"%s\".\n", irt_file); |
+ exit(1); |
+ } |
+ |
+ NaClAppInitialDescriptorHookup(nap); |
+ |
+ InjectMojo(nap); |
+ |
+ errcode = NaClAppLoadFileFromFilename(nap, nexe_file); |
+ if (LOAD_OK != errcode) { |
+ fprintf(stderr, "Error while loading \"%s\": %s\n", |
+ nexe_file, |
+ NaClErrorString(errcode)); |
+ fprintf(stderr, |
+ ("Using the wrong type of nexe (nacl-x86-32" |
+ " on an x86-64 or vice versa)\n" |
+ "or a corrupt nexe file may be" |
+ " responsible for this error.\n")); |
+ } |
+ |
+ errcode = NaClMainLoadIrt(nap, blob_file, NULL); |
+ if (LOAD_OK != errcode) { |
+ fprintf(stderr, "Error while loading \"%s\": %s\n", |
+ irt_file, |
+ NaClErrorString(errcode)); |
+ } |
+ |
+ NaClAppStartModule(nap, NULL, NULL); |
+ |
+ if (!NaClAppLaunchServiceThreads(nap)) { |
+ fprintf(stderr, "Launch service threads failed\n"); |
+ goto done; |
+ } |
+ |
+ if (!NaClCreateMainThread(nap, |
+ app_argc, |
+ app_argv, |
+ &env)) { |
+ fprintf(stderr, "creating main thread failed\n"); |
+ goto done; |
+ } |
+ |
+ { |
+ fprintf(stderr, "waiting for main thread\n"); |
+ ret_code = NaClWaitForMainThreadToExit(nap); |
+ fprintf(stderr, "ret code %d\n", ret_code); |
+ } |
+ |
+ done: |
+ NaClAllModulesFini(); |
+ return ret_code; |
+} |