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/chrome_main.h" | |
9 #include "native_client/src/public/nacl_app.h" | |
10 // For opening IRT | |
11 #include "native_client/src/trusted/desc/nacl_desc_io.h" | |
12 // For opening IRT | |
13 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" | |
14 // For loading main nexe | |
15 #include "native_client/src/trusted/service_runtime/load_file.h" | |
16 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" | |
17 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error _reporter.h" | |
18 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h" | |
19 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | |
20 #include "native_client/src/trusted/service_runtime/sel_main_common.h" | |
21 #include "native_client/src/trusted/service_runtime/sel_qualify.h" | |
22 | |
23 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.
| |
24 struct NaClApp *nap, | |
25 struct NaClChromeMainArgs *args, | |
26 const char *nexe_file, | |
27 const char *irt_file, | |
28 struct NaClDesc *irt_desc) { | |
29 NaClErrorCode errcode; | |
30 | |
31 NaClBootstrapChannelErrorReporterInit(); | |
32 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.
| |
33 NaClAppInitialDescriptorHookup(nap); | |
34 | |
35 int skip_qualification = 0; | |
36 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.
| |
37 NaClLog(LOG_WARNING, "PLATFORM QUALIFICATION DISABLED - " | |
38 "Native Client's sandbox will be unreliable!\n"); | |
39 } else { | |
40 // 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.
| |
41 errcode = NaClRunSelQualificationTests(); | |
42 if (LOAD_OK != errcode) { | |
43 nap->module_load_status = errcode; | |
44 fprintf(stderr, "Error while loading in SelMain: %s\n", | |
45 NaClErrorString(errcode)); | |
46 } | |
47 } | |
48 | |
49 NaClAppLoadModule(nap, args->nexe_desc, NULL, NULL); | |
50 NaClDescUnref(args->nexe_desc); | |
51 args->nexe_desc = NULL; | |
52 errcode = NaClWaitForLoadModuleStatus(nap); | |
53 | |
54 if (LOAD_OK != errcode) { | |
55 fprintf(stderr, "Error while loading \"%s\": %s\n", | |
56 nexe_file, | |
57 NaClErrorString(errcode)); | |
58 fprintf(stderr, | |
59 ("Using the wrong type of nexe (nacl-x86-32" | |
60 " on an x86-64 or vice versa)\n" | |
61 "or a corrupt nexe file may be" | |
62 " responsible for this error.\n")); | |
63 } | |
64 | |
65 NaClAppStartModule(nap, NULL, NULL); | |
66 | |
67 errcode = NaClMainLoadIrt(nap, irt_desc, NULL); | |
68 if (LOAD_OK != errcode) { | |
69 fprintf(stderr, "Error while loading \"%s\": %s\n", | |
70 irt_file, | |
71 NaClErrorString(errcode)); | |
72 } | |
73 | |
74 if (!NaClAppLaunchServiceThreads(nap)) { | |
75 fprintf(stderr, "Launch service threads failed\n"); | |
76 return 0; | |
77 } | |
78 return 1; | |
79 } | |
80 | |
81 static int MoNaClStartApp( | |
82 struct NaClApp *nap, | |
83 int app_argc, | |
84 char *app_argv[], | |
85 const char **env){ | |
86 if (!NaClCreateMainThread(nap, app_argc, app_argv, env)) { | |
87 fprintf(stderr, "creating main thread failed\n"); | |
88 return 1; | |
89 } | |
90 return NaClWaitForMainThreadToExit(nap); | |
91 } | |
92 | |
93 int LaunchNaCl(const char *nexe_file, const char *irt_file, | |
94 int app_argc, char *app_argv[]) { | |
95 const char *env = NULL; | |
96 | |
97 NaClChromeMainInit(); | |
98 | |
99 // Load the IRT | |
100 //NaClFileNameForValgrind(irt_file); | |
101 struct NaClDesc *irt_desc = (struct NaClDesc *) NaClDescIoDescOpen( | |
102 irt_file, NACL_ABI_O_RDONLY, 0); | |
103 if (NULL == irt_desc) { | |
104 perror("sel_main"); | |
105 fprintf(stderr, "Cannot open \"%s\".\n", irt_file); | |
106 exit(1); | |
107 } | |
108 | |
109 struct NaClDesc *nexe_desc = (struct NaClDesc *) NaClDescIoDescOpen( | |
110 nexe_file, NACL_ABI_O_RDONLY, 0); | |
111 if (NULL == nexe_desc) { | |
112 perror("sel_main"); | |
113 fprintf(stderr, "Cannot open \"%s\".\n", nexe_file); | |
114 exit(1); | |
115 } | |
116 | |
117 struct NaClChromeMainArgs *args = NaClChromeMainArgsCreate(); | |
118 args->nexe_desc = nexe_desc; | |
119 | |
120 struct NaClApp* nap = NaClAppCreate(); | |
121 InjectMojo(nap); | |
122 MoNaClLoadApp(nap, args, nexe_file, irt_file, irt_desc); | |
123 int ret_code = MoNaClStartApp(nap, app_argc, app_argv, &env); | |
124 | |
125 // 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.
| |
126 | |
127 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.
| |
128 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.
| |
129 } | |
OLD | NEW |