Use MAP_JIT on macOS 10.14

Issue #253 resolved
Ronald Oussoren
repo owner created an issue

MAP_JIT is a mmap flag that’s apparently introduced in 10.14. The slides at https://developer.apple.com/videos/play/wwdc2018/702/ mention this flag and the hardened runtime.

With the hardened runtime and code signing mapping memory as writable and executable causes an error.

To check: what happens when using MAP_JIT on older versions of macOS (10.9 - 10.13)?

Also: File issue with CPython for the same thing in ctypes when I have a proper solution for PyObjC.

Comments (5)

  1. Ronald Oussoren reporter

    The attached program works without problems on 10.14 and 10.13 (when compiled on 10.14):

    #include <sys/mman.h>
    #include <stdio.h>
    
    int main(void)
    {
        void* mem = mmap(0, 1<<12, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_ANON|MAP_JIT, -1, 0);
        if (mem == MAP_FAILED) {
            perror("mmap");
            return 1;
        }
        printf("ok\n");
        return 0;
    }
    

    Still need to test on older versions.

  2. Log in to comment