is fork() supported?

Andrew Haley aph@redhat.com
Wed Aug 25 09:27:03 GMT 2021


On 8/24/21 10:58 PM, Jay K via Libffi-discuss wrote:

> I believe MacOSX also has this as an extension like this, in that
> instead of giving an fd to map, you can give an address, to another
> function, I cannot find the name. This can be used, I guess, to
> avoid remapping the entire .so.

Mac solves the problem in a much nicer way, one that is JIT-friendly
but does not allow pages to be both W and X.

Here's how it works:

    Call mmap with the MAP_JIT option to create a memory region for
    the new machine instructions.

    Call pthread_jit_write_protect_np() with the value false to disable
    JIT write protections for the memory region in the current thread.

    Write the machine instructions to the memory region.

Note that this is *per thread*. other threads will simply continue to
execute code in the JITted region. The JIT can generate code, but can
not execute any JITted code until it calls
pthread_jit_write_protect_np(true). Of course this requires threads to
have differently-mapped regions. It would be very nice to have in
Linux. It is the right way to do it.

https://developer.apple.com/documentation/apple-silicon/porting-just-in-time-compilers-to-apple-silicon

-- 
Andrew Haley  (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671



More information about the Libffi-discuss mailing list