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 26 matching lines...) Expand all Loading... |
37 #include "native_client/src/trusted/service_runtime/sel_ldr.h" | 37 #include "native_client/src/trusted/service_runtime/sel_ldr.h" |
38 #include "native_client/src/trusted/service_runtime/sel_main_common.h" | 38 #include "native_client/src/trusted/service_runtime/sel_main_common.h" |
39 #include "native_client/src/trusted/service_runtime/sel_qualify.h" | 39 #include "native_client/src/trusted/service_runtime/sel_qualify.h" |
40 #include "native_client/src/trusted/service_runtime/win/exception_patch/ntdll_pa
tch.h" | 40 #include "native_client/src/trusted/service_runtime/win/exception_patch/ntdll_pa
tch.h" |
41 #include "native_client/src/trusted/validator/rich_file_info.h" | 41 #include "native_client/src/trusted/validator/rich_file_info.h" |
42 #include "native_client/src/trusted/validator/validation_metadata.h" | 42 #include "native_client/src/trusted/validator/validation_metadata.h" |
43 | 43 |
44 static int g_initialized = 0; | 44 static int g_initialized = 0; |
45 | 45 |
46 static void (*g_fatal_error_handler)(const char *data, size_t bytes) = NULL; | 46 static void (*g_fatal_error_handler)(const char *data, size_t bytes) = NULL; |
| 47 static void (*g_load_status_callback)(int load_status) = NULL; |
47 | 48 |
48 static const int default_argc = 1; | 49 static const int default_argc = 1; |
49 static const char *const default_argv[1] = {"NaClMain"}; | 50 static const char *const default_argv[1] = {"NaClMain"}; |
50 | 51 |
51 #if NACL_LINUX || NACL_OSX | 52 #if NACL_LINUX || NACL_OSX |
52 void NaClChromeMainSetUrandomFd(int urandom_fd) { | 53 void NaClChromeMainSetUrandomFd(int urandom_fd) { |
53 CHECK(!g_initialized); | 54 CHECK(!g_initialized); |
54 NaClSecureRngModuleSetUrandomFd(urandom_fd); | 55 NaClSecureRngModuleSetUrandomFd(urandom_fd); |
55 } | 56 } |
56 #endif | 57 #endif |
(...skipping 12 matching lines...) Expand all Loading... |
69 } | 70 } |
70 | 71 |
71 void NaClSetFatalErrorCallback(void (*func)(const char *data, size_t bytes)) { | 72 void NaClSetFatalErrorCallback(void (*func)(const char *data, size_t bytes)) { |
72 CHECK(g_initialized); | 73 CHECK(g_initialized); |
73 if (g_fatal_error_handler != NULL) | 74 if (g_fatal_error_handler != NULL) |
74 NaClLog(LOG_FATAL, "NaClSetFatalErrorCallback called twice.\n"); | 75 NaClLog(LOG_FATAL, "NaClSetFatalErrorCallback called twice.\n"); |
75 g_fatal_error_handler = func; | 76 g_fatal_error_handler = func; |
76 NaClErrorLogHookInit(NaClFatalErrorHandlerCallback, NULL); | 77 NaClErrorLogHookInit(NaClFatalErrorHandlerCallback, NULL); |
77 } | 78 } |
78 | 79 |
| 80 void NaClSetLoadStatusCallback(void (*func)(int load_status)) { |
| 81 CHECK(g_initialized); |
| 82 if (g_load_status_callback != NULL) |
| 83 NaClLog(LOG_FATAL, "NaClSetLoadStatusCallback called twice.\n"); |
| 84 g_load_status_callback = func; |
| 85 } |
| 86 |
79 struct NaClChromeMainArgs *NaClChromeMainArgsCreate(void) { | 87 struct NaClChromeMainArgs *NaClChromeMainArgsCreate(void) { |
80 struct NaClChromeMainArgs *args; | 88 struct NaClChromeMainArgs *args; |
81 | 89 |
82 CHECK(g_initialized); | 90 CHECK(g_initialized); |
83 args = malloc(sizeof(*args)); | 91 args = malloc(sizeof(*args)); |
84 if (args == NULL) | 92 if (args == NULL) |
85 return NULL; | 93 return NULL; |
86 args->imc_bootstrap_handle = NACL_INVALID_HANDLE; | 94 args->imc_bootstrap_handle = NACL_INVALID_HANDLE; |
87 args->irt_fd = -1; | 95 args->irt_fd = -1; |
88 args->irt_desc = NULL; | 96 args->irt_desc = NULL; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 if (!NaClDebugInit(nap)) { | 372 if (!NaClDebugInit(nap)) { |
365 goto done; | 373 goto done; |
366 } | 374 } |
367 #if NACL_WINDOWS | 375 #if NACL_WINDOWS |
368 if (NULL != args->debug_stub_server_port_selected_handler_func) { | 376 if (NULL != args->debug_stub_server_port_selected_handler_func) { |
369 args->debug_stub_server_port_selected_handler_func(nap->debug_stub_port); | 377 args->debug_stub_server_port_selected_handler_func(nap->debug_stub_port); |
370 } | 378 } |
371 #endif | 379 #endif |
372 } | 380 } |
373 | 381 |
| 382 if (g_load_status_callback != NULL) { |
| 383 g_load_status_callback(LOAD_OK); |
| 384 } |
374 return LOAD_OK; | 385 return LOAD_OK; |
375 | 386 |
376 done: | 387 done: |
377 fflush(stdout); | 388 fflush(stdout); |
378 | 389 |
379 /* | 390 /* |
380 * If there is a secure command channel, we sent an RPC reply with | 391 * If there is a load_status_callback, call that now. TODO(jvoung): remove |
381 * the reason that the nexe was rejected. If we exit now, that | 392 * NaClBlockIfCommandChannelExists() and just call g_load_status_callback |
382 * reply may still be in-flight and the various channel closure (esp | 393 * to indicate the load_status. |
383 * reverse channel) may be detected first. This would result in a | 394 */ |
384 * crash being reported, rather than the error in the RPC reply. | 395 if (g_load_status_callback != NULL) { |
| 396 /* Don't return LOAD_OK if we had some failure loading. */ |
| 397 if (LOAD_OK == errcode) { |
| 398 errcode = LOAD_INTERNAL; |
| 399 } |
| 400 g_load_status_callback(errcode); |
| 401 NaClLog(LOG_ERROR, "reap logs\n"); |
| 402 NaClLogRunAbortBehavior(); |
| 403 return errcode; |
| 404 } |
| 405 /* |
| 406 * If there is no load_status_callback, but there is a secure command channel, |
| 407 * we sent an RPC reply with the reason that the nexe was rejected. |
| 408 * If we exit now, that reply may still be in-flight and the various |
| 409 * channel closure (esp reverse channel) may be detected first. This would |
| 410 * result in a crash being reported, rather than the error in the RPC reply. |
385 * Instead, we wait for the hard-shutdown on the command channel. | 411 * Instead, we wait for the hard-shutdown on the command channel. |
386 */ | 412 */ |
387 if (LOAD_OK != errcode) { | 413 if (LOAD_OK != errcode) { |
388 NaClBlockIfCommandChannelExists(nap); | 414 NaClBlockIfCommandChannelExists(nap); |
389 } else { | 415 } else { |
390 /* | 416 /* |
391 * Don't return LOAD_OK if we had some failure loading. | 417 * Don't return LOAD_OK if we had some failure loading. |
392 */ | 418 */ |
393 errcode = LOAD_INTERNAL; | 419 errcode = LOAD_INTERNAL; |
394 } | 420 } |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 int NaClChromeMainStart(struct NaClApp *nap, | 464 int NaClChromeMainStart(struct NaClApp *nap, |
439 struct NaClChromeMainArgs *args, | 465 struct NaClChromeMainArgs *args, |
440 int *exit_status) { | 466 int *exit_status) { |
441 int load_ok = LOAD_OK == LoadApp(nap, args); | 467 int load_ok = LOAD_OK == LoadApp(nap, args); |
442 if (load_ok) { | 468 if (load_ok) { |
443 *exit_status = StartApp(nap, args); | 469 *exit_status = StartApp(nap, args); |
444 } | 470 } |
445 free(args); | 471 free(args); |
446 return load_ok; | 472 return load_ok; |
447 } | 473 } |
OLD | NEW |