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

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

Issue 135853021: NaCl: Expose NaClApp to embedding layer. (Closed) Base URL: https://chromium.googlesource.com/native_client/src/native_client.git@master
Patch Set: Update test also Created 6 years, 11 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
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 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h" 7 #include "native_client/src/trusted/service_runtime/sel_main_chrome.h"
8 8
9 #include "native_client/src/include/portability.h" 9 #include "native_client/src/include/portability.h"
10 #include "native_client/src/include/portability_io.h" 10 #include "native_client/src/include/portability_io.h"
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 if (errcode != LOAD_OK) { 117 if (errcode != LOAD_OK) {
118 NaClLog(LOG_FATAL, 118 NaClLog(LOG_FATAL,
119 "NaClLoadIrt: Failed to load the integrated runtime (IRT): %s\n", 119 "NaClLoadIrt: Failed to load the integrated runtime (IRT): %s\n",
120 NaClErrorString(errcode)); 120 NaClErrorString(errcode));
121 } 121 }
122 122
123 NaClMetadataDtor(&metadata); 123 NaClMetadataDtor(&metadata);
124 NaClDescUnref(nd); 124 NaClDescUnref(nd);
125 } 125 }
126 126
127 void NaClChromeMainStart(struct NaClChromeMainArgs *args) { 127 struct NaClApp* NaClAppCreate(void) {
Mark Seaborn 2014/01/17 16:42:06 Spacing style should be " *" in NaCl-side code (sa
128 struct NaClApp* nap = (struct NaClApp*)malloc(sizeof(struct NaClApp));
129 if (!nap)
Mark Seaborn 2014/01/17 16:42:06 NaCl style is "nap == NULL"
130 return NULL;
131
132 memset(nap, 0, sizeof(struct NaClApp));
133 if (NaClAppCtor(nap) != 0) {
Mark Seaborn 2014/01/17 16:42:06 There's a correctness problem here. If NaClAppCre
134 free(nap);
135 return NULL;
136 }
137 return nap;
138 }
139
140 void NaClChromeMainStartApp(struct NaClApp *nap,
141 struct NaClChromeMainArgs *args) {
128 char *av[1]; 142 char *av[1];
129 int ac = 1; 143 int ac = 1;
130 const char **envp; 144 const char **envp;
131 struct NaClApp state;
132 struct NaClApp *nap = &state;
133 NaClErrorCode errcode = LOAD_INTERNAL; 145 NaClErrorCode errcode = LOAD_INTERNAL;
134 int ret_code = 1; 146 int ret_code = 1;
135 struct NaClEnvCleanser env_cleanser; 147 struct NaClEnvCleanser env_cleanser;
136 int skip_qualification; 148 int skip_qualification;
137 149
138 #if NACL_OSX 150 #if NACL_OSX
139 /* Mac dynamic libraries cannot access the environ variable directly. */ 151 /* Mac dynamic libraries cannot access the environ variable directly. */
140 envp = (const char **) *_NSGetEnviron(); 152 envp = (const char **) *_NSGetEnviron();
141 #else 153 #else
142 /* Overzealous code style check is overzealous. */ 154 /* Overzealous code style check is overzealous. */
143 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */ 155 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */
144 extern char **environ; 156 extern char **environ;
145 envp = (const char **) environ; 157 envp = (const char **) environ;
146 #endif 158 #endif
147 159
148 #if NACL_LINUX || NACL_OSX 160 #if NACL_LINUX || NACL_OSX
149 /* This needs to happen before NaClAllModulesInit(). */ 161 /* This needs to happen before NaClAllModulesInit(). */
150 if (args->urandom_fd != -1) 162 if (args->urandom_fd != -1)
151 NaClSecureRngModuleSetUrandomFd(args->urandom_fd); 163 NaClSecureRngModuleSetUrandomFd(args->urandom_fd);
152 #endif 164 #endif
153 165
154 /* 166 /*
155 * Clear state so that NaClBootstrapChannelErrorReporter will be 167 * Clear state so that NaClBootstrapChannelErrorReporter will be
156 * able to know if the bootstrap channel is available or not. 168 * able to know if the bootstrap channel is available or not.
157 */ 169 */
158 memset(&state, 0, sizeof state);
159 NaClAllModulesInit(); 170 NaClAllModulesInit();
160 NaClBootstrapChannelErrorReporterInit(); 171 NaClBootstrapChannelErrorReporterInit();
161 NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, &state); 172 NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap);
162 173
163 /* to be passed to NaClMain, eventually... */ 174 /* to be passed to NaClMain, eventually... */
164 av[0] = "NaClMain"; 175 av[0] = "NaClMain";
165 176
166 if (NACL_FI_ERROR_COND("AppCtor", !NaClAppCtor(&state))) {
167 NaClLog(LOG_FATAL, "Error while constructing app state\n");
168 goto done;
169 }
170
171 errcode = LOAD_OK; 177 errcode = LOAD_OK;
172 178
173 /* Allow or disallow dyncode API based on args. */ 179 /* Allow or disallow dyncode API based on args. */
174 nap->enable_dyncode_syscalls = args->enable_dyncode_syscalls; 180 nap->enable_dyncode_syscalls = args->enable_dyncode_syscalls;
175 nap->initial_nexe_max_code_bytes = args->initial_nexe_max_code_bytes; 181 nap->initial_nexe_max_code_bytes = args->initial_nexe_max_code_bytes;
176 182
177 #if NACL_LINUX 183 #if NACL_LINUX
178 g_prereserved_sandbox_size = args->prereserved_sandbox_size; 184 g_prereserved_sandbox_size = args->prereserved_sandbox_size;
179 #endif 185 #endif
180 #if NACL_LINUX || NACL_OSX 186 #if NACL_LINUX || NACL_OSX
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 args->attach_debug_exception_handler_func; 268 args->attach_debug_exception_handler_func;
263 #else 269 #else
264 # error Unknown host OS 270 # error Unknown host OS
265 #endif 271 #endif
266 } 272 }
267 #if NACL_LINUX 273 #if NACL_LINUX
268 NaClSignalHandlerInit(); 274 NaClSignalHandlerInit();
269 #endif 275 #endif
270 276
271 /* Give debuggers a well known point at which xlate_base is known. */ 277 /* Give debuggers a well known point at which xlate_base is known. */
272 NaClGdbHook(&state); 278 NaClGdbHook(nap);
273 279
274 NaClCreateServiceSocket(nap); 280 NaClCreateServiceSocket(nap);
275 /* 281 /*
276 * LOG_FATAL errors that occur before NaClSetUpBootstrapChannel will 282 * LOG_FATAL errors that occur before NaClSetUpBootstrapChannel will
277 * not be reported via the crash log mechanism (for Chromium 283 * not be reported via the crash log mechanism (for Chromium
278 * embedding of NaCl, shown in the JavaScript console). 284 * embedding of NaCl, shown in the JavaScript console).
279 * 285 *
280 * Some errors, such as due to NaClRunSelQualificationTests, do not 286 * Some errors, such as due to NaClRunSelQualificationTests, do not
281 * trigger a LOG_FATAL but instead set module_load_status to be sent 287 * trigger a LOG_FATAL but instead set module_load_status to be sent
282 * in the start_module RPC reply. Log messages associated with such 288 * in the start_module RPC reply. Log messages associated with such
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 * Instead, we wait for the hard-shutdown on the command channel. 405 * Instead, we wait for the hard-shutdown on the command channel.
400 */ 406 */
401 if (LOAD_OK != errcode) { 407 if (LOAD_OK != errcode) {
402 NaClBlockIfCommandChannelExists(nap); 408 NaClBlockIfCommandChannelExists(nap);
403 } 409 }
404 410
405 NaClAllModulesFini(); 411 NaClAllModulesFini();
406 412
407 NaClExit(ret_code); 413 NaClExit(ret_code);
408 } 414 }
415
416 void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
417 struct NaClApp *nap = NaClAppCreate();
dmichael (off chromium) 2014/01/16 21:30:26 Is there a need to do it on the heap here? Could y
dmichael (off chromium) 2014/01/17 16:00:46 Okay, we just chatted. Since: 1) This code is goin
418 if (!nap) {
419 NaClLog(LOG_FATAL, "NaClChromeMainStart: Could not create NaClApp.\n");
420 }
421 NaClChromeMainStartApp(nap, args);
422 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698