コード例 #1
0
Bool NaClInstValidates(uint8_t* mbase,
                       uint8_t size,
                       NaClPcAddress vbase,
                       NaClInstStruct* inst) {
  NaClSegment segment;
  NaClValidatorState* state;
  Bool validates = FALSE;
  NaClCPUFeaturesX86 cpu_features;

  NaClGetCurrentCPUFeaturesX86((NaClCPUFeatures *) &cpu_features);
  NACL_FLAGS_unsafe_single_inst_mode = TRUE;
  state = NaClValidatorStateCreate(vbase, (NaClMemorySize) size, RegR15, FALSE,
                                   &cpu_features);
  do {
    NaClSegmentInitialize(mbase, vbase, (NaClMemorySize) size, &segment);
    NaClBaseRegisterMemoryInitialize(state);
    state->cur_iter = NaClInstIterCreate(kNaClDecoderTables, &segment);
    if (NULL == state->cur_iter) break;
    state->cur_inst_state = NaClInstIterGetState(state->cur_iter);
    state->cur_inst = NaClInstStateInst(state->cur_inst_state);
    state->cur_inst_vector = NaClInstStateExpVector(state->cur_inst_state);
    NaClValidateInstructionLegal(state);
    NaClBaseRegisterValidator(state);
    /* induce call to NaClMaybeReportPreviousBad() */
    NaClBaseRegisterSummarize(state);
    NaClMemoryReferenceValidator(state);
    NaClJumpValidator(state);
    validates = NaClValidatesOk(state);
    NaClInstIterDestroy(state->cur_iter);
    state->cur_iter = NULL;
    state->cur_inst_state = NULL;
    state->cur_inst = NULL;
    state->cur_inst_vector = NULL;
  } while(0);
  NaClValidatorStateDestroy(state);
  /* Strictly speaking this shouldn't be necessary, as the mode */
  /* should only be used from tests. Disabling it here as a     */
  /* defensive tactic. */
  NACL_FLAGS_unsafe_single_inst_mode = FALSE;
  return validates;
}
コード例 #2
0
ファイル: ncvalidate.c プロジェクト: camuel/zvm
static NaClValidationStatus NaClApplyValidatorSilently_x86_64(
    uintptr_t guest_addr,
    uint8_t *data,
    size_t size,
    int bundle_size,
    Bool local_cpu) {
  CPUFeatures features;
  int is_ok;
  struct NaClValidatorState *vstate =
      NaClValidatorStateCreate(guest_addr, size, bundle_size, RegR15);
  if (vstate == NULL) return NaClValidationFailedOutOfMemory;
  NaClValidatorStateSetLogVerbosity(vstate, LOG_ERROR);
  if (!local_cpu) {
    NaClSetAllCPUFeatures(&features);
    NaClValidatorStateSetCPUFeatures(vstate, &features);
  }
  NaClValidateSegment(data, guest_addr, size, vstate);
  is_ok = NaClValidatesOk(vstate);
  NaClValidatorStateDestroy(vstate);
  return is_ok ? NaClValidationSucceeded : NaClValidationFailed;
}