Exemplo n.º 1
0
// Allocates RW memory,
// emits the code into it and sets it to RX before executing.
void emit_to_rw_run_from_rx() {
    void* m = alloc_writable_memory(SIZE);
    emit_code_into_memory(static_cast<unsigned char*>(m));
    make_memory_executable(m, SIZE);

    JittedFunc func = reinterpret_cast<JittedFunc>(m);
    int result = func(2);
    printf("result = %d\n", result);
}
Exemplo n.º 2
0
// Allocates RW memory, emits the code into it and sets it to RX before
// executing.
int emit_to_rw_run_from_rx(unsigned char *code) {
  void* m = alloc_writable_memory(SIZE);
  emit_code_into_memory(m, code);
  make_memory_executable(m, SIZE);

  JittedFunc func = m;
  int result = func(4);
  return result;
}