示例#1
0
static void FixUpSection(uintptr_t load_address,
                         unsigned char *code,
                         size_t code_size) {
  struct NaClValidatorState *vstate;
  int bundle_size = 32;
  vstate = NaClValidatorStateCreate(load_address, code_size, bundle_size,
                                    RegR15);
  CHECK(vstate != NULL);
  NaClValidatorStateSetDoStubOut(vstate, TRUE);
  NaClValidateSegment(code, load_address, code_size, vstate);
  NaClValidatorStateDestroy(vstate);
}
示例#2
0
文件: ncvalidate.c 项目: camuel/zvm
NaClValidationStatus NaClApplyValidatorStubout_x86_64(
    uintptr_t guest_addr,
    uint8_t *data,
    size_t size,
    int bundle_size,
    Bool local_cpu) {
  CPUFeatures features;
  struct NaClValidatorState *vstate =
      NaClValidatorStateCreate(guest_addr, size, bundle_size, RegR15);
  if (vstate == NULL) return NaClValidationFailedOutOfMemory;
  NaClValidatorStateSetDoStubOut(vstate, TRUE);
  if (!local_cpu) {
    NaClSetAllCPUFeatures(&features);
    NaClValidatorStateSetCPUFeatures(vstate, &features);
  }
  NaClValidateSegment(data, guest_addr, size, vstate);
  NaClValidatorStateDestroy(vstate);
  return NaClValidationSucceeded;
}
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;
}
示例#4
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;
}