OLD | NEW |
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/public/chrome_main.h" | 7 #include "native_client/src/public/chrome_main.h" |
8 | 8 |
9 #include "native_client/src/include/build_config.h" | 9 #include "native_client/src/include/build_config.h" |
10 #include "native_client/src/include/portability.h" | 10 #include "native_client/src/include/portability.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 #endif | 100 #endif |
101 #if NACL_WINDOWS | 101 #if NACL_WINDOWS |
102 args->debug_stub_server_port_selected_handler_func = NULL; | 102 args->debug_stub_server_port_selected_handler_func = NULL; |
103 #endif | 103 #endif |
104 args->create_memory_object_func = NULL; | 104 args->create_memory_object_func = NULL; |
105 args->validation_cache = NULL; | 105 args->validation_cache = NULL; |
106 #if NACL_WINDOWS | 106 #if NACL_WINDOWS |
107 args->broker_duplicate_handle_func = NULL; | 107 args->broker_duplicate_handle_func = NULL; |
108 args->attach_debug_exception_handler_func = NULL; | 108 args->attach_debug_exception_handler_func = NULL; |
109 #endif | 109 #endif |
| 110 args->load_status_handler_func = NULL; |
110 #if NACL_LINUX || NACL_OSX | 111 #if NACL_LINUX || NACL_OSX |
111 args->number_of_cores = -1; /* unknown */ | 112 args->number_of_cores = -1; /* unknown */ |
112 #endif | 113 #endif |
113 #if NACL_LINUX | 114 #if NACL_LINUX |
114 args->prereserved_sandbox_size = 0; | 115 args->prereserved_sandbox_size = 0; |
115 #endif | 116 #endif |
116 args->nexe_desc = NULL; | 117 args->nexe_desc = NULL; |
117 | 118 |
118 args->argc = default_argc; | 119 args->argc = default_argc; |
119 args->argv = (char **) default_argv; | 120 args->argv = (char **) default_argv; |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 if (!NaClDebugInit(nap)) { | 365 if (!NaClDebugInit(nap)) { |
365 goto done; | 366 goto done; |
366 } | 367 } |
367 #if NACL_WINDOWS | 368 #if NACL_WINDOWS |
368 if (NULL != args->debug_stub_server_port_selected_handler_func) { | 369 if (NULL != args->debug_stub_server_port_selected_handler_func) { |
369 args->debug_stub_server_port_selected_handler_func(nap->debug_stub_port); | 370 args->debug_stub_server_port_selected_handler_func(nap->debug_stub_port); |
370 } | 371 } |
371 #endif | 372 #endif |
372 } | 373 } |
373 | 374 |
| 375 if (args->load_status_handler_func != NULL) { |
| 376 args->load_status_handler_func(LOAD_OK); |
| 377 } |
374 return LOAD_OK; | 378 return LOAD_OK; |
375 | 379 |
376 done: | 380 done: |
377 fflush(stdout); | 381 fflush(stdout); |
378 | 382 |
379 /* | 383 /* |
| 384 * If there is a load status callback, call that now and transfer logs |
| 385 * in preparation for process exit. |
| 386 */ |
| 387 if (args->load_status_handler_func != NULL) { |
| 388 /* Don't return LOAD_OK if we had some failure loading. */ |
| 389 if (LOAD_OK == errcode) { |
| 390 errcode = LOAD_INTERNAL; |
| 391 } |
| 392 args->load_status_handler_func(errcode); |
| 393 NaClLog(LOG_ERROR, "NaCl LoadApp failed. Transferring logs before exit.\n"); |
| 394 NaClLogRunAbortBehavior(); |
| 395 /* |
| 396 * Fall through and run NaClBlockIfCommandChannelExists. |
| 397 * TODO(jvoung): remove NaClBlockIfCommandChannelExists() and use the |
| 398 * callback to indicate the load_status after Chromium no longer calls |
| 399 * start_module. We also need to change Chromium so that it does not |
| 400 * attempt to set up the command channel if there is a known load error. |
| 401 * Otherwise there is a race between this process's exit / load error |
| 402 * reporting, and the command channel setup on the Chromium side (plus |
| 403 * the associated reporting). Thus this could end up with two different |
| 404 * load errors being reported (1) the real load error from here, and |
| 405 * (2) the command channel setup failure because the process exited in |
| 406 * the middle of setting up the command channel. |
| 407 */ |
| 408 } |
| 409 /* |
380 * If there is a secure command channel, we sent an RPC reply with | 410 * If there is a secure command channel, we sent an RPC reply with |
381 * the reason that the nexe was rejected. If we exit now, that | 411 * the reason that the nexe was rejected. If we exit now, that |
382 * reply may still be in-flight and the various channel closure (esp | 412 * reply may still be in-flight and the various channel closure (esp |
383 * reverse channel) may be detected first. This would result in a | 413 * reverse channel) may be detected first. This would result in a |
384 * crash being reported, rather than the error in the RPC reply. | 414 * crash being reported, rather than the error in the RPC reply. |
385 * Instead, we wait for the hard-shutdown on the command channel. | 415 * Instead, we wait for the hard-shutdown on the command channel. |
386 */ | 416 */ |
387 if (LOAD_OK != errcode) { | 417 if (LOAD_OK != errcode) { |
388 NaClBlockIfCommandChannelExists(nap); | 418 NaClBlockIfCommandChannelExists(nap); |
389 } else { | 419 } else { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 int NaClChromeMainStart(struct NaClApp *nap, | 468 int NaClChromeMainStart(struct NaClApp *nap, |
439 struct NaClChromeMainArgs *args, | 469 struct NaClChromeMainArgs *args, |
440 int *exit_status) { | 470 int *exit_status) { |
441 int load_ok = LOAD_OK == LoadApp(nap, args); | 471 int load_ok = LOAD_OK == LoadApp(nap, args); |
442 if (load_ok) { | 472 if (load_ok) { |
443 *exit_status = StartApp(nap, args); | 473 *exit_status = StartApp(nap, args); |
444 } | 474 } |
445 free(args); | 475 free(args); |
446 return load_ok; | 476 return load_ok; |
447 } | 477 } |
OLD | NEW |