Chromium Code Reviews| 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..c3c343ad66f90ec1727412e4efe9f04fcafe5ec6 |
| --- /dev/null |
| +++ b/mojo/monacl/monacl_sel_main.cc |
| @@ -0,0 +1,129 @@ |
| +// 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/chrome_main.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" |
| + |
| +static int MoNaClLoadApp( |
|
Mark Seaborn
2014/08/26 16:25:53
Nit: Chromium style is to use an anon namespace in
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + struct NaClApp *nap, |
| + struct NaClChromeMainArgs *args, |
| + const char *nexe_file, |
| + const char *irt_file, |
| + struct NaClDesc *irt_desc) { |
| + NaClErrorCode errcode; |
| + |
| + NaClBootstrapChannelErrorReporterInit(); |
| + NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap); |
|
Mark Seaborn
2014/08/26 16:25:53
You don't need to reference the IMC bootstrap chan
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + NaClAppInitialDescriptorHookup(nap); |
| + |
| + int skip_qualification = 0; |
| + if (skip_qualification) { |
|
Mark Seaborn
2014/08/26 16:25:53
Always 0, so remove this branch.
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + NaClLog(LOG_WARNING, "PLATFORM QUALIFICATION DISABLED - " |
| + "Native Client's sandbox will be unreliable!\n"); |
| + } else { |
| + // HACK no fault injection. |
|
Mark Seaborn
2014/08/26 16:25:53
Remove "HACK" comment
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + errcode = NaClRunSelQualificationTests(); |
| + if (LOAD_OK != errcode) { |
| + nap->module_load_status = errcode; |
| + fprintf(stderr, "Error while loading in SelMain: %s\n", |
| + NaClErrorString(errcode)); |
| + } |
| + } |
| + |
| + NaClAppLoadModule(nap, args->nexe_desc, NULL, NULL); |
| + NaClDescUnref(args->nexe_desc); |
| + args->nexe_desc = NULL; |
| + errcode = NaClWaitForLoadModuleStatus(nap); |
| + |
| + 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")); |
| + } |
| + |
| + NaClAppStartModule(nap, NULL, NULL); |
| + |
| + errcode = NaClMainLoadIrt(nap, irt_desc, NULL); |
| + if (LOAD_OK != errcode) { |
| + fprintf(stderr, "Error while loading \"%s\": %s\n", |
| + irt_file, |
| + NaClErrorString(errcode)); |
| + } |
| + |
| + if (!NaClAppLaunchServiceThreads(nap)) { |
| + fprintf(stderr, "Launch service threads failed\n"); |
| + return 0; |
| + } |
| + return 1; |
| +} |
| + |
| +static int MoNaClStartApp( |
| + struct NaClApp *nap, |
| + int app_argc, |
| + char *app_argv[], |
| + const char **env){ |
| + if (!NaClCreateMainThread(nap, app_argc, app_argv, env)) { |
| + fprintf(stderr, "creating main thread failed\n"); |
| + return 1; |
| + } |
| + return NaClWaitForMainThreadToExit(nap); |
| +} |
| + |
| +int LaunchNaCl(const char *nexe_file, const char *irt_file, |
| + int app_argc, char *app_argv[]) { |
| + const char *env = NULL; |
| + |
| + NaClChromeMainInit(); |
| + |
| + // Load the IRT |
| + //NaClFileNameForValgrind(irt_file); |
| + struct NaClDesc *irt_desc = (struct NaClDesc *) NaClDescIoDescOpen( |
| + irt_file, NACL_ABI_O_RDONLY, 0); |
| + if (NULL == irt_desc) { |
| + perror("sel_main"); |
| + fprintf(stderr, "Cannot open \"%s\".\n", irt_file); |
| + exit(1); |
| + } |
| + |
| + struct NaClDesc *nexe_desc = (struct NaClDesc *) NaClDescIoDescOpen( |
| + nexe_file, NACL_ABI_O_RDONLY, 0); |
| + if (NULL == nexe_desc) { |
| + perror("sel_main"); |
| + fprintf(stderr, "Cannot open \"%s\".\n", nexe_file); |
| + exit(1); |
| + } |
| + |
| + struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); |
| + args->nexe_desc = nexe_desc; |
| + |
| + struct NaClApp* nap = NaClAppCreate(); |
| + InjectMojo(nap); |
| + MoNaClLoadApp(nap, args, nexe_file, irt_file, irt_desc); |
| + int ret_code = MoNaClStartApp(nap, app_argc, app_argv, &env); |
| + |
| + // TODO free nap? |
|
Mark Seaborn
2014/08/26 16:25:54
Not if you're exiting. You can remove this commen
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + |
| + NaClAllModulesFini(); |
|
Mark Seaborn
2014/08/26 16:25:53
Not safe because threads can be running.
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| + return ret_code; |
|
Mark Seaborn
2014/08/26 16:25:53
Calling exit() is not safe because it does some te
Nick Bray (chromium)
2014/09/03 23:45:03
Done.
|
| +} |