Comment 2 for bug 1914849

Revision history for this message
hikalium (hikalium) wrote :

I hit the same problem and did some initial investigation with Toshifumi.

Here is a more exhaustive test program I wrote based on the post on the Apple Developer Forums and the result shows that very interesting behavior of mmap and mprotect since macOS 11.2.

https://gist.github.com/hikalium/75ae822466ee4da13cbbe486498a191f

I and my friend confirmed that all mmap & following mprotect calls with any protection bit combinations are succeeded up to 11.1 on M1 Mac but starting from 11.2 mprotect starts failing if we call mmap with PROT_WRITE + PROT_EXEC. (Surprisingly, mmap itself is not failing even on those patterns.)

It looks like the allocation of code gen buffer in QEMU uses this combination at mmap call:
https://github.com/qemu/qemu/blob/master/accel/tcg/translate-all.c#L1294

So maybe we need to specify PROT_NONE instead on the initial mmap and change it appropriately afterwards to make it working on M1 Mac after 11.2.

(We tried to fix it but we have no sufficient knowledge about tcg... Could you take a look into it?)