robertmuth/Cwerg

Mingw: exited with code -1073741819

Closed this issue · 4 comments

Hello , Cwerg is a good project. I like it , But i met some problems.
demo: jit_cpu_a32/jit_cpu_a64/jit_cpu_x64/ jit_ir_a32/jit_ir_a64/jit_ir_x64 all report:

exited with code -1073741819

and I found it occurs at

FunPtr f = reinterpret_cast<FunPtr>(memory);
  for (unsigned i = 0; i < 10; ++i) {
    std::cout << std::dec << i << " " << f(i) << "\n";
  }

Why ?

I do not think this will/can work on a Windows/Mingw for various reasons:

  1. assuming you are on a x86-64 only the x64 version (jit_ir_x64.cc) will work at all (the others are for Arm CPUs)
  2. I do not think the mmap call in line 39 will do the right thing
  3. the calling convention used implicitly used by f(x) in line 69 might also have problems on Windows

Please try to reproduce the issues on a Linux system (a VM might work).

@robertmuth I had change mmap to simple malloc. So that it can run. And I run it on inter cpu with x64. But jit_ir_x64 not work.
on ubuntu it run ok.
And If I want to run on mingw, How should I can fix it ?

malloc is NOT good enough because you also need executable permission for the memory so you can run the code.
Unfortunately, I do not have much knowledge of Windows, so I cannot help you much.

I found this on stackoverflow: https://stackoverflow.com/questions/40936534/how-to-alloc-a-executable-memory-buffer
Maybe it helps.

@robertmuth thanks, I will try it later.