bugMIT/GNU Scheme - Bugs: bug #60267, Possible method of resolving the...


bug #60267: Possible method of resolving the Apple M-1 W^X issue

Submitter:  John Cowan <johnwcowan>
Submitted:  Mon 22 Mar 2021 03:03:27 AM UTC
Category:  None Severity:  3 - Normal
Priority:  5 - Normal Item Group:  None
Status:  None Privacy:  Public
Assigned to:  None Originator Name: 
Open/Closed:  Open
* Mandatory Fields

Add a New Comment (Rich Markup)

Sat 04 Jun 2022 09:16:00 PM UTC, comment #1: 

We would certainly have to use this approach, but it's not enough because at any given time you can only toggle between W xor X -- you can't have both set at the same time.

Currently compiled code (executable data) and mutable objects (writable data) are both stored in the same heap.  What we need to do is have a separate heap for compiled code, and whenever we make (or load) compiled code:

1. Toggle the compiled-code heap from executable to writable.
2. Run a GC and move any new compiled-code blocks from the object heap where they were created into the compiled-code heap (GC is needed both to free up unreferenced compiled-code blocks and ensure pointers in the object heap to new compiled-code blocks are relocated to point at the compiled-code heap instead).
3. Toggle the compiled-code heap back from writable to executable.

Other systems like NetBSD will use a slightly different approach: create two virtual address windows into the same anonymous mapping, one mapped executable and the other mapped writable (and maybe only created while the GC is happening).

It's doable, just a pain to deal with all the bookkeeping, which is why I haven't bothered.  (I started drafting some logic to do it back in 2020 but I can't find it now.  Not sure I got far enough to bother looking instead of just starting over, though.)

Taylor R. Campbell <riastradh>
Group Member
Mon 22 Mar 2021 03:03:27 AM UTC, original submission:  

Apple has posted a method for supporting JITs on Apple M-1 machines.  Basically one must allocate a segment with mmap using the MAP_JIT option.  Then the function pthread_jit_write_protect_np must be called with a boolean argument:  false turns off write-protection and enables execution, and true turns turns on write-protection and disables execution.

I hope this is helpful.

John Cowan <johnwcowan>


(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:

No files currently attached


Depends on the following items: None found

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by riastradh (Posted a comment)
  • -email is unavailable- added by johnwcowan (Submitted the item)

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.





    No changes have been made to this item

    Back to the top

    Powered by Savane 3.11