OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2011 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2011 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/include/portability.h" | 7 #include "native_client/src/include/portability.h" |
8 #include "native_client/src/include/portability_io.h" | 8 #include "native_client/src/include/portability_io.h" |
9 | 9 |
10 #if NACL_OSX | 10 #if NACL_OSX |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 (*NACL_VTBL(Gio, gio_desc)->Dtor)(gio_desc); | 98 (*NACL_VTBL(Gio, gio_desc)->Dtor)(gio_desc); |
99 } | 99 } |
100 | 100 |
101 void NaClMainForChromium(int handle_count, const NaClHandle *handles, | 101 void NaClMainForChromium(int handle_count, const NaClHandle *handles, |
102 int debug) { | 102 int debug) { |
103 char *av[1]; | 103 char *av[1]; |
104 int ac = 1; | 104 int ac = 1; |
105 const char **envp; | 105 const char **envp; |
106 struct NaClApp state; | 106 struct NaClApp state; |
107 int export_addr_to = kSrpcFd; /* Used to be set by -X. */ | 107 int export_addr_to = kSrpcFd; /* Used to be set by -X. */ |
108 struct NaClApp *nap; | 108 struct NaClApp *nap = &state; |
109 NaClErrorCode errcode; | 109 NaClErrorCode errcode = LOAD_INTERNAL; |
110 int ret_code = 1; | 110 int ret_code = 1; |
111 struct NaClEnvCleanser env_cleanser; | 111 struct NaClEnvCleanser env_cleanser; |
112 int skip_qualification; | 112 int skip_qualification; |
113 | 113 |
114 #if NACL_OSX | 114 #if NACL_OSX |
115 /* Mac dynamic libraries cannot access the environ variable directly. */ | 115 /* Mac dynamic libraries cannot access the environ variable directly. */ |
116 envp = (const char **) *_NSGetEnviron(); | 116 envp = (const char **) *_NSGetEnviron(); |
117 #else | 117 #else |
118 /* Overzealous code style check is overzealous. */ | 118 /* Overzealous code style check is overzealous. */ |
119 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */ | 119 /* @IGNORE_LINES_FOR_CODE_HYGIENE[1] */ |
120 extern char **environ; | 120 extern char **environ; |
121 envp = (const char **) environ; | 121 envp = (const char **) environ; |
122 #endif | 122 #endif |
123 | 123 |
124 NaClAllModulesInit(); | 124 NaClAllModulesInit(); |
125 | 125 |
126 /* to be passed to NaClMain, eventually... */ | 126 /* to be passed to NaClMain, eventually... */ |
127 av[0] = "NaClMain"; | 127 av[0] = "NaClMain"; |
128 | 128 |
129 if (!NaClAppCtor(&state)) { | 129 if (!NaClAppCtor(&state)) { |
130 fprintf(stderr, "Error while constructing app state\n"); | 130 fprintf(stderr, "Error while constructing app state\n"); |
131 goto done; | 131 goto done_ctor; |
132 } | 132 } |
133 | 133 |
134 nap = &state; | |
135 errcode = LOAD_OK; | 134 errcode = LOAD_OK; |
136 | 135 |
137 NaClAppInitialDescriptorHookup(nap); | 136 NaClAppInitialDescriptorHookup(nap); |
138 | 137 |
139 /* | 138 /* |
140 * NACL_SERVICE_PORT_DESCRIPTOR and NACL_SERVICE_ADDRESS_DESCRIPTOR | 139 * NACL_SERVICE_PORT_DESCRIPTOR and NACL_SERVICE_ADDRESS_DESCRIPTOR |
141 * are 3 and 4. | 140 * are 3 and 4. |
142 */ | 141 */ |
143 | 142 |
144 /* import IMC handle - used to be "-i" */ | 143 /* import IMC handle - used to be "-i" */ |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 /* | 289 /* |
291 * exit_group or equiv kills any still running threads while module | 290 * exit_group or equiv kills any still running threads while module |
292 * addr space is still valid. otherwise we'd have to kill threads | 291 * addr space is still valid. otherwise we'd have to kill threads |
293 * before we clean up the address space. | 292 * before we clean up the address space. |
294 */ | 293 */ |
295 NaClExit(ret_code); | 294 NaClExit(ret_code); |
296 | 295 |
297 done: | 296 done: |
298 fflush(stdout); | 297 fflush(stdout); |
299 | 298 |
| 299 /* |
| 300 * If there is a secure command channel, we sent an RPC reply with |
| 301 * the reason that the nexe was rejected. If we exit now, that |
| 302 * reply may still be in-flight and the various channel closure (esp |
| 303 * reverse channel) may be detected first. This would result in a |
| 304 * crash being reported, rather than the error in the RPC reply. |
| 305 * Instead, we wait for the hard-shutdown on the command channel. |
| 306 */ |
| 307 if (LOAD_OK != errcode) { |
| 308 NaClBlockIfCommandChannelExists(nap); |
| 309 } |
| 310 |
| 311 done_ctor: |
| 312 |
300 NaClAllModulesFini(); | 313 NaClAllModulesFini(); |
301 | 314 |
302 NaClExit(ret_code); | 315 NaClExit(ret_code); |
303 } | 316 } |
OLD | NEW |