Exemplo n.º 1
0
int main(int argc, char* argv[]) {
  using namespace asmjit;

  Performance perf;
  uint32_t kNumRepeats = 10;
  uint32_t kNumIterations = 10000;

  JitRuntime runtime;
  X86Assembler a(&runtime);
  X86Compiler c(&runtime);

  uint32_t r, i;

  // --------------------------------------------------------------------------
  // [Bench - Opcode]
  // --------------------------------------------------------------------------

  perf.reset();
  for (r = 0; r < kNumRepeats; r++) {
    perf.start();
    for (i = 0; i < kNumIterations; i++) {
      asmgen::opcode(a);

      void *p = a.make();
      runtime.release(p);

      a.reset();
    }
    perf.end();
  }

  printf("Opcode   | Time: %-6u [ms] | Speed: %-9u [inst/s]\n",
    perf.best, instPerMs(perf.best, kNumIterations, asmgen::kGenOpCodeInstCount));

  // --------------------------------------------------------------------------
  // [Bench - Blend]
  // --------------------------------------------------------------------------

  perf.reset();
  for (r = 0; r < kNumRepeats; r++) {
    perf.start();
    for (i = 0; i < kNumIterations; i++) {
      asmgen::blend(c);

      void* p = c.make();
      runtime.release(p);

      c.reset();
    }
    perf.end();
  }

  printf("Blend    | Time: %-6u [ms] | Speed: %-9u [inst/s]\n",
    perf.best, instPerMs(perf.best, kNumIterations, asmgen::kGenBlendInstCount));

  return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[]) {
  using namespace asmjit;
  using namespace asmjit::host;

  FileLogger logger(stdout);
  logger.setOption(kLoggerOptionBinaryForm, true);

  JitRuntime runtime;
  Assembler a(&runtime);

  a.setLogger(&logger);
  asmgen::opcode(a);

  VoidFunc p = asmjit_cast<VoidFunc>(a.make());
  p();
  runtime.release((void*)p);

  return 0;
}
Exemplo n.º 3
0
BOOL
MakeLdrLoadDllCall32(HANDLE ProcessHandle,
                     PVOID RemoteCode,
                     PVOID LdrLoadDllProc,
                     PVOID RemotePathToFile,
                     PVOID RemoteFlags,
                     PVOID RemoteModuleFileName,
                     PVOID RemoteModuleHandle,
                     PVOID RemoteReturnValue)
{
    using namespace asmjit;
    BOOL result;
    JitRuntime runtime;
    X86Assembler a(&runtime, kArchX86);
    PVOID codeBase;

    a.push((uint32_t)RemoteModuleHandle);
    a.push((uint32_t)RemoteModuleFileName);
    a.push((uint32_t)0);
    a.push((uint32_t)RemotePathToFile);
    a.mov(x86::eax, (uint32_t)LdrLoadDllProc);
    a.call(x86::eax);
    a.mov(x86::edx, (uint32_t)RemoteReturnValue);
    a.mov(x86::dword_ptr(x86::edx), x86::eax);
    a.ret();

    codeBase = a.make();

    if (!codeBase)
    {
        return FALSE;
    }

    result = IlWrite(ProcessHandle,
                     RemoteCode,
                     codeBase,
                     a.getCodeSize());

    runtime.release(codeBase);

    return result;
}
Exemplo n.º 4
0
int main(int argc, char* argv[]) {
  using namespace asmjit;
  using namespace asmjit::host;

  JitRuntime runtime;
  FileLogger logger(stderr);
  logger.setOption(kLoggerOptionBinaryForm, true);

  Compiler c(&runtime);
  c.setLogger(&logger);

  c.addFunc(kFuncConvHost, FuncBuilder0<int>());
  c.endFunc();

  MyFunc func = asmjit_cast<MyFunc>(c.make());
  func();

  runtime.release((void*)func);
  return 0;
}