Example #1
0
static int StartApp(struct NaClApp *nap, struct NaClChromeMainArgs *args) {
  int ret_code;
  struct NaClEnvCleanser env_cleanser;
  char const *const *envp;

  NACL_FI_FATAL("BeforeEnvCleanserCtor");

  NaClEnvCleanserCtor(&env_cleanser, 1, 0);
  if (!NaClEnvCleanserInit(&env_cleanser, NaClGetEnviron(), NULL)) {
    NaClLog(LOG_FATAL, "Failed to initialise env cleanser\n");
  }
  envp = NaClEnvCleanserEnvironment(&env_cleanser);

  if (NACL_FI_ERROR_COND(
          "CreateMainThread",
          !NaClCreateMainThread(nap, args->argc, args->argv, envp))) {
    NaClLog(LOG_FATAL, "creating main thread failed\n");
  }
  NACL_FI_FATAL("BeforeEnvCleanserDtor");

  NaClEnvCleanserDtor(&env_cleanser);

  ret_code = NaClWaitForMainThreadToExit(nap);

  if (NACL_ABI_WIFEXITED(nap->exit_status)) {
    /*
     * Under Chrome, a call to _exit() often indicates that something
     * has gone awry, so we report it here to aid debugging.
     *
     * This conditional does not run if the NaCl process was
     * terminated forcibly, which is the normal case under Chrome.
     * This forcible exit is triggered by the renderer closing the
     * trusted SRPC channel, which we record as NACL_ABI_SIGKILL
     * internally.
     */
    NaClLog(LOG_INFO, "NaCl untrusted code called _exit(0x%x)\n", ret_code);
  }
  return ret_code;
}
Example #2
0
int NaClReportExitStatus(struct NaClApp *nap, int exit_status) {
  int           rv = 0;
  NaClSrpcError rpc_result;

  NaClXMutexLock(&nap->mu);
  /*
   * If several threads are exiting/reporting signals at once, we should
   * let only one thread to pass through. This way we can use exit code
   * without synchronization once we know that running==0.
   */
  if (!nap->running) {
    NaClXMutexUnlock(&nap->mu);
    return 0;
  }

  if (NACL_REVERSE_CHANNEL_INITIALIZED ==
      nap->reverse_channel_initialization_state) {
    /* TODO(halyavin) update NaCl plugin to accept full exit_status value */
    if (NACL_ABI_WIFEXITED(exit_status)) {
      rpc_result = NaClSrpcInvokeBySignature(&nap->reverse_channel,
                                             NACL_REVERSE_CONTROL_REPORT_STATUS,
                                             NACL_ABI_WEXITSTATUS(exit_status));
      rv = NACL_SRPC_RESULT_OK == rpc_result;
    }
    /*
     * Due to cross-repository checkins, the Cr-side might not yet
     * implement this RPC.  We return whether shutdown was reported.
     */
  }
  nap->exit_status = exit_status;
  nap->running = 0;
  NaClXCondVarSignal(&nap->cv);

  NaClXMutexUnlock(&nap->mu);

  return rv;
}