void NCValidateSegment(uint8_t *mbase, NaClPcAddress vbase, size_t sz,
                       struct NCValidatorState *vstate) {
  if (sz == 0) {
    ValidatePrintError(0, "Bad text segment (zero size)", vstate);
    Stats_SegFault(vstate);
    return;
  }
  GetCPUFeatures(&(vstate->cpufeatures));
  /* The name of the flag is misleading; f_386 requires not just    */
  /* 386 instructions but also the CPUID instruction is supported.  */
  if (!vstate->cpufeatures.f_386) {
    ValidatePrintError(0, "CPU does not support CPUID", vstate);
    Stats_BadCPU(vstate);
    return;
  }
#if (0)
  /* TODO(bradchen): enable this check */
  if (!vstate->cpufeatures.f_whitelisted) {
    ValidatePrintError(0, "CPU does not support CPUID", vstate);
    Stats_BadCPU(vstate);
    return;
  }
#endif
  NCDecodeSegment(mbase, vbase, sz, vstate);
}
void NaClDisassembleSegment(uint8_t* mbase, NaClPcAddress vbase,
                            NaClMemorySize size, NaClDisassembleFlags flags) {
  if (NaClHasBit(flags, NACL_DISASSEMBLE_FLAG(NaClDisassembleFull))) {
    if (NaClHasBit(flags,
                   NACL_DISASSEMBLE_FLAG(NaClDisassembleValidatorDecoder))) {
      gprintf(NaClLogGetGio(),
              "Error: can't specify both full and validator disassembly,\n"
              "       assuming full disassembly.\n");
    }
    NaClDisassembleSegmentUsingTables(mbase, vbase, size, flags,
                                      kNaClDecoderTables);
  } else if (NaClHasBit
             (flags,
              NACL_DISASSEMBLE_FLAG(NaClDisassembleValidatorDecoder))) {
    if (64 == NACL_TARGET_SUBARCH) {
      NaClDisassembleSegmentUsingTables(mbase, vbase, size, flags,
                                        kNaClValDecoderTables);
    } else {
      NCDecodeSegment(mbase, vbase, size);
    }
  } else {
    gprintf(NaClLogGetGio(),
            "Error: No decoder tables specified, can't disassemble\n");
  }
}
示例#3
0
static void FixUpSection(uintptr_t load_address,
                         unsigned char *code,
                         size_t code_size) {
  struct NCValidatorState *vstate;
  int bundle_size = 32;
  vstate = NCValidateInit(load_address, load_address + code_size, bundle_size);
  CHECK(vstate != NULL);
  vstate->do_stub_out = 1;

  /*
   * We should not stub out any instructions based on the features
   * of the CPU we are executing on now.
   */
  memset(&vstate->cpufeatures, 0xff, sizeof(vstate->cpufeatures));

  NCDecodeSegment(code, load_address, code_size, vstate);
  /*
   * We do not need to call NCValidateFinish() because it is
   * normal for validation to fail.
   */
  NCValidateFreeState(&vstate);
}