Beispiel #1
0
void ReportDtor(int zvm_ret)
{
  SetExitCode(zvm_ret);

  /*
   * patch to show special messages instead of signals 24, 25
   * and do not calculate etag if session failed
   */
  if(zvm_code != 0)
  {
    SpecSignals();
    ZLOGS(LOG_ERROR, "SESSION %d FAILED WITH ERROR %d: %s",
        gnap->manifest == NULL ? 0 : gnap->manifest->node,
        zvm_code, strerror(zvm_code));
  }

  if(zvm_code != 0) FinalDump(gnap);

  AccountingDtor(gnap);
  ChannelsDtor(gnap->manifest);
  Report(gnap);
  NaClAppDtor(gnap); /* free user space and globals */
  ManifestDtor(gnap->manifest); /* dispose manifest and channels */
  FreeDispatchThunk();
  ZLogDtor();

  _exit(zvm_code);
}
Beispiel #2
0
void ReportDtor(int zvm_ret)
{
    SetExitCode(zvm_ret);

    /* broken session */
    if(zvm_code != 0)
    {
        ZLOGS(LOG_ERROR, "SESSION %d FAILED WITH ERROR %d: %s",
              gnap->manifest == NULL ? 0 : gnap->manifest->node,
              zvm_code, strerror(zvm_code));
        FinalDump(gnap);
        ZTrace("[final dump]");
    }

    ChannelsDtor(gnap->manifest);
    ZTrace("[channels destruction]");
    Report(gnap);
    ZTrace("[report]");
    NaClAppDtor(gnap); /* free user space and globals */
    ZTrace("[untrusted context closing]");
    ManifestDtor(gnap->manifest); /* dispose manifest and channels */
    ZTrace("[manifest deallocating]");
    FreeDispatchThunk();
    ZTrace("[thunk deallocating]");
    ZLogDtor();
    ZTrace("[zlog deallocating]");

    /* free local resources and exit */
    g_string_free(digests, TRUE);
    g_string_free(cmd, TRUE);
    g_free(zvm_state);

    ZTrace("[exit]");
    ZTraceDtor(1);
    ZTraceNameDtor();
    _exit(zvm_code);
}
Beispiel #3
0
/* parse given command line and initialize NaClApp object */
static void ParseCommandLine(struct NaClApp *nap, int argc, char **argv)
{
  int opt;
  char *manifest_name = NULL;

  /* set defaults */
  nap->skip_qualification = 0;
  nap->quit_after_load = 0;
  nap->handle_signals = 1;
  nap->storage_limit = ZEROVM_IO_LIMIT;

  /* construct zlog with default verbosity */
  ZLogCtor(LOG_ERROR);

  /* todo(d'b): revise switches and rename them */
  while((opt = getopt(argc, argv, "+FeQsSv:M:l:")) != -1)
  {
    switch(opt)
    {
      case 'M':
        manifest_name = optarg;
        break;
      case 's':
        nap->skip_validator = 1;
        ZLOG(LOG_ERROR, "validation disabled by -s");
        break;
      case 'F':
        nap->quit_after_load = 1;
        break;
      case 'e':
        TagEngineCtor();
        nap->user_tag = TagCtor();
        break;
      case 'S':
        /* d'b: disable signals handling */
        nap->handle_signals = 0;
        break;
      case 'l':
        /* calculate hard limit in Gb and don't allow it less then "big enough" */
        nap->storage_limit = ATOI(optarg) * ZEROVM_IO_LIMIT_UNIT;
        ZLOGFAIL(nap->storage_limit < ZEROVM_IO_LIMIT_UNIT, EFAULT,
            "invalid storage limit: %d", nap->storage_limit);
        break;
      case 'v':
        ZLogDtor();
        ZLogCtor(ATOI(optarg));
        break;
      case 'Q':
        nap->skip_qualification = 1;
        ZLOGS(LOG_ERROR, "PLATFORM QUALIFICATION DISABLED BY -Q - "
            "Native Client's sandbox will be unreliable!");
        break;
      default:
        ZLOGS(LOG_ERROR, "ERROR: unknown option: [%c]", opt);
        puts(HELP_SCREEN);
        exit(EINVAL);
        break;
    }
  }

  /* show zerovm command line */
  ZVMCommandLine(argc, argv);

  /* parse manifest file specified in cmdline */
  if(manifest_name == NULL)
  {
    puts(HELP_SCREEN);
    exit(EINVAL);
  }
  ZLOGFAIL(ManifestCtor(manifest_name), EFAULT, "Invalid manifest '%s'", manifest_name);

  /* set available nap and manifest fields */
  assert(nap->system_manifest != NULL);
  nap->system_manifest->nexe = GetValueByKey("Nexe");
  ZLOGFAIL(GetFileSize(nap->system_manifest->nexe) < 0, ENOENT, "nexe open error");
  syscallback = 0;
}