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

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

Issue 153453002: Expose NaClAppSetDesc() to Chromium for use at startup (Closed) Base URL: svn://svn.chromium.org/native_client/trunk/src/native_client
Patch Set: Rebase and fix Created 6 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « src/trusted/service_runtime/sel_ldr.c ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "native_client/src/include/portability_sockets.h" 11 #include "native_client/src/include/portability_sockets.h"
12 12
13 #if NACL_OSX 13 #if NACL_OSX
14 #include <crt_externs.h> 14 #include <crt_externs.h>
15 #endif 15 #endif
16 16
17 #include <stdio.h> 17 #include <stdio.h>
18 #include <string.h> 18 #include <string.h>
19 19
20 #include "native_client/src/include/nacl_macros.h" 20 #include "native_client/src/include/nacl_macros.h"
21 #include "native_client/src/public/nacl_app.h"
21 #include "native_client/src/shared/platform/nacl_check.h" 22 #include "native_client/src/shared/platform/nacl_check.h"
22 #include "native_client/src/shared/platform/nacl_exit.h" 23 #include "native_client/src/shared/platform/nacl_exit.h"
23 #include "native_client/src/shared/platform/nacl_log.h" 24 #include "native_client/src/shared/platform/nacl_log.h"
24 #include "native_client/src/shared/platform/nacl_secure_random.h" 25 #include "native_client/src/shared/platform/nacl_secure_random.h"
25 #include "native_client/src/shared/platform/nacl_sync.h" 26 #include "native_client/src/shared/platform/nacl_sync.h"
26 #include "native_client/src/shared/platform/nacl_sync_checked.h" 27 #include "native_client/src/shared/platform/nacl_sync_checked.h"
27 #include "native_client/src/trusted/desc/nacl_desc_io.h" 28 #include "native_client/src/trusted/desc/nacl_desc_io.h"
28 #include "native_client/src/trusted/fault_injection/fault_injection.h" 29 #include "native_client/src/trusted/fault_injection/fault_injection.h"
29 #include "native_client/src/trusted/gio/gio_nacl_desc.h" 30 #include "native_client/src/trusted/gio/gio_nacl_desc.h"
30 #include "native_client/src/trusted/service_runtime/env_cleanser.h" 31 #include "native_client/src/trusted/service_runtime/env_cleanser.h"
31 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h" 32 #include "native_client/src/trusted/service_runtime/include/sys/fcntl.h"
32 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h" 33 #include "native_client/src/trusted/service_runtime/nacl_all_modules.h"
33 #include "native_client/src/trusted/service_runtime/nacl_app.h" 34 #include "native_client/src/trusted/service_runtime/nacl_app.h"
34 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error _reporter.h" 35 #include "native_client/src/trusted/service_runtime/nacl_bootstrap_channel_error _reporter.h"
35 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h" 36 #include "native_client/src/trusted/service_runtime/nacl_error_log_hook.h"
36 #include "native_client/src/trusted/service_runtime/nacl_globals.h" 37 #include "native_client/src/trusted/service_runtime/nacl_globals.h"
37 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h" 38 #include "native_client/src/trusted/service_runtime/nacl_debug_init.h"
38 #include "native_client/src/trusted/service_runtime/nacl_signal.h" 39 #include "native_client/src/trusted/service_runtime/nacl_signal.h"
39 #include "native_client/src/trusted/service_runtime/osx/mach_exception_handler.h " 40 #include "native_client/src/trusted/service_runtime/osx/mach_exception_handler.h "
40 #include "native_client/src/trusted/service_runtime/sel_addrspace.h" 41 #include "native_client/src/trusted/service_runtime/sel_addrspace.h"
41 #include "native_client/src/trusted/service_runtime/sel_ldr.h" 42 #include "native_client/src/trusted/service_runtime/sel_ldr.h"
42 #include "native_client/src/trusted/service_runtime/sel_qualify.h" 43 #include "native_client/src/trusted/service_runtime/sel_qualify.h"
43 #include "native_client/src/trusted/service_runtime/win/exception_patch/ntdll_pa tch.h" 44 #include "native_client/src/trusted/service_runtime/win/exception_patch/ntdll_pa tch.h"
44 #include "native_client/src/trusted/validator/validation_metadata.h" 45 #include "native_client/src/trusted/validator/validation_metadata.h"
45 46
47 static int g_initialized = 0;
48
49 #if NACL_LINUX || NACL_OSX
50 void NaClChromeMainSetUrandomFd(int urandom_fd) {
51 NaClSecureRngModuleSetUrandomFd(urandom_fd);
52 }
53 #endif
54
55 void NaClChromeMainInit(void) {
56 CHECK(!g_initialized);
57 NaClAllModulesInit();
58 g_initialized = 1;
59 }
60
46 struct NaClChromeMainArgs *NaClChromeMainArgsCreate(void) { 61 struct NaClChromeMainArgs *NaClChromeMainArgsCreate(void) {
47 struct NaClChromeMainArgs *args = malloc(sizeof(*args)); 62 struct NaClChromeMainArgs *args = malloc(sizeof(*args));
48 if (args == NULL) 63 if (args == NULL)
49 return NULL; 64 return NULL;
50 args->imc_bootstrap_handle = NACL_INVALID_HANDLE; 65 args->imc_bootstrap_handle = NACL_INVALID_HANDLE;
51 args->irt_fd = -1; 66 args->irt_fd = -1;
52 args->initial_ipc_desc = NULL; 67 args->initial_ipc_desc = NULL;
53 args->enable_exception_handling = 0; 68 args->enable_exception_handling = 0;
54 args->enable_debug_stub = 0; 69 args->enable_debug_stub = 0;
55 args->enable_dyncode_syscalls = 1; 70 args->enable_dyncode_syscalls = 1;
(...skipping 10 matching lines...) Expand all
66 #if NACL_LINUX || NACL_OSX 81 #if NACL_LINUX || NACL_OSX
67 args->urandom_fd = -1; 82 args->urandom_fd = -1;
68 args->number_of_cores = -1; /* unknown */ 83 args->number_of_cores = -1; /* unknown */
69 #endif 84 #endif
70 #if NACL_LINUX 85 #if NACL_LINUX
71 args->prereserved_sandbox_size = 0; 86 args->prereserved_sandbox_size = 0;
72 #endif 87 #endif
73 88
74 /* 89 /*
75 * Initialize NaClLog so that Chromium can call 90 * Initialize NaClLog so that Chromium can call
76 * NaClDescMakeCustomDesc() between calling 91 * NaClDescMakeCustomDesc(), before NaClAllModulesInit() gets
77 * NaClChromeMainArgsCreate() and NaClChromeMainStart(). 92 * called.
93 *
94 * TODO(mseaborn): Remove this once Chromium calls
95 * NaClChromeMainInit() before NaClChromeMainArgsCreate().
78 */ 96 */
79 NaClLogModuleInit(); 97 NaClLogModuleInit();
80 98
81 return args; 99 return args;
82 } 100 }
83 101
84 static char kFakeIrtName[] = "\0IRT"; 102 static char kFakeIrtName[] = "\0IRT";
85 103
86 static void NaClLoadIrt(struct NaClApp *nap, int irt_fd) { 104 static void NaClLoadIrt(struct NaClApp *nap, int irt_fd) {
87 int file_desc; 105 int file_desc;
(...skipping 29 matching lines...) Expand all
117 if (errcode != LOAD_OK) { 135 if (errcode != LOAD_OK) {
118 NaClLog(LOG_FATAL, 136 NaClLog(LOG_FATAL,
119 "NaClLoadIrt: Failed to load the integrated runtime (IRT): %s\n", 137 "NaClLoadIrt: Failed to load the integrated runtime (IRT): %s\n",
120 NaClErrorString(errcode)); 138 NaClErrorString(errcode));
121 } 139 }
122 140
123 NaClMetadataDtor(&metadata); 141 NaClMetadataDtor(&metadata);
124 NaClDescUnref(nd); 142 NaClDescUnref(nd);
125 } 143 }
126 144
127 void NaClChromeMainStart(struct NaClChromeMainArgs *args) { 145 void NaClChromeMainStartApp(struct NaClApp *nap,
146 struct NaClChromeMainArgs *args) {
128 char *av[1]; 147 char *av[1];
129 int ac = 1; 148 int ac = 1;
130 const char **envp; 149 const char **envp;
131 struct NaClApp state;
132 struct NaClApp *nap = &state;
133 NaClErrorCode errcode = LOAD_INTERNAL; 150 NaClErrorCode errcode = LOAD_INTERNAL;
134 int ret_code = 1; 151 int ret_code = 1;
135 struct NaClEnvCleanser env_cleanser; 152 struct NaClEnvCleanser env_cleanser;
136 int skip_qualification; 153 int skip_qualification;
137 154
138 #if NACL_OSX 155 #if NACL_OSX
139 /* Mac dynamic libraries cannot access the environ variable directly. */ 156 /* Mac dynamic libraries cannot access the environ variable directly. */
140 envp = (const char **) *_NSGetEnviron(); 157 envp = (const char **) *_NSGetEnviron();
141 #else 158 #else
142 /* Overzealous code style check is overzealous. */ 159 /* Overzealous code style check is overzealous. */
143 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */ 160 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */
144 extern char **environ; 161 extern char **environ;
145 envp = (const char **) environ; 162 envp = (const char **) environ;
146 #endif 163 #endif
147 164
148 #if NACL_LINUX || NACL_OSX 165 #if NACL_LINUX || NACL_OSX
149 /* This needs to happen before NaClAllModulesInit(). */ 166 /* This needs to happen before NaClAllModulesInit(). */
150 if (args->urandom_fd != -1) 167 if (args->urandom_fd != -1)
151 NaClSecureRngModuleSetUrandomFd(args->urandom_fd); 168 NaClSecureRngModuleSetUrandomFd(args->urandom_fd);
152 #endif 169 #endif
170 /* TODO(mseaborn): Remove this when NaClChromeMainStart() is removed. */
171 if (nap == NULL) {
172 NaClChromeMainInit();
173 nap = NaClAppCreate();
174 }
153 175
154 /*
155 * Clear state so that NaClBootstrapChannelErrorReporter will be
156 * able to know if the bootstrap channel is available or not.
157 */
158 memset(&state, 0, sizeof state);
159 NaClAllModulesInit();
160 NaClBootstrapChannelErrorReporterInit(); 176 NaClBootstrapChannelErrorReporterInit();
161 NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, &state); 177 NaClErrorLogHookInit(NaClBootstrapChannelErrorReporter, nap);
162 178
163 /* to be passed to NaClMain, eventually... */ 179 /* to be passed to NaClMain, eventually... */
164 av[0] = "NaClMain"; 180 av[0] = "NaClMain";
165 181
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; 182 errcode = LOAD_OK;
172 183
173 /* Allow or disallow dyncode API based on args. */ 184 /* Allow or disallow dyncode API based on args. */
174 nap->enable_dyncode_syscalls = args->enable_dyncode_syscalls; 185 nap->enable_dyncode_syscalls = args->enable_dyncode_syscalls;
175 nap->initial_nexe_max_code_bytes = args->initial_nexe_max_code_bytes; 186 nap->initial_nexe_max_code_bytes = args->initial_nexe_max_code_bytes;
176 187
177 #if NACL_LINUX 188 #if NACL_LINUX
178 g_prereserved_sandbox_size = args->prereserved_sandbox_size; 189 g_prereserved_sandbox_size = args->prereserved_sandbox_size;
179 #endif 190 #endif
180 #if NACL_LINUX || NACL_OSX 191 #if NACL_LINUX || NACL_OSX
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 args->attach_debug_exception_handler_func; 273 args->attach_debug_exception_handler_func;
263 #else 274 #else
264 # error Unknown host OS 275 # error Unknown host OS
265 #endif 276 #endif
266 } 277 }
267 #if NACL_LINUX 278 #if NACL_LINUX
268 NaClSignalHandlerInit(); 279 NaClSignalHandlerInit();
269 #endif 280 #endif
270 281
271 /* Give debuggers a well known point at which xlate_base is known. */ 282 /* Give debuggers a well known point at which xlate_base is known. */
272 NaClGdbHook(&state); 283 NaClGdbHook(nap);
273 284
274 NaClCreateServiceSocket(nap); 285 NaClCreateServiceSocket(nap);
275 /* 286 /*
276 * LOG_FATAL errors that occur before NaClSetUpBootstrapChannel will 287 * LOG_FATAL errors that occur before NaClSetUpBootstrapChannel will
277 * not be reported via the crash log mechanism (for Chromium 288 * not be reported via the crash log mechanism (for Chromium
278 * embedding of NaCl, shown in the JavaScript console). 289 * embedding of NaCl, shown in the JavaScript console).
279 * 290 *
280 * Some errors, such as due to NaClRunSelQualificationTests, do not 291 * Some errors, such as due to NaClRunSelQualificationTests, do not
281 * trigger a LOG_FATAL but instead set module_load_status to be sent 292 * 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 293 * 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. 410 * Instead, we wait for the hard-shutdown on the command channel.
400 */ 411 */
401 if (LOAD_OK != errcode) { 412 if (LOAD_OK != errcode) {
402 NaClBlockIfCommandChannelExists(nap); 413 NaClBlockIfCommandChannelExists(nap);
403 } 414 }
404 415
405 NaClAllModulesFini(); 416 NaClAllModulesFini();
406 417
407 NaClExit(ret_code); 418 NaClExit(ret_code);
408 } 419 }
420
421 void NaClChromeMainStart(struct NaClChromeMainArgs *args) {
422 NaClChromeMainStartApp(NULL, args);
423 }
OLDNEW
« no previous file with comments | « src/trusted/service_runtime/sel_ldr.c ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698