At Mon, 4 Apr 2016 17:47:15 -0400, George Neuner wrote: > On 4/4/2016 4:57 PM, 'John Clements' via users-redirect wrote: > > FWIW, it appears that the restriction here is much simpler; > > specifically, pages can’t be writable and executable *simultaneously.* > > Moreover, a comment by Matthew on the github bug suggests that this > > might … have a relatively straightforward fix? > > There are those who interpret W^X more severely as "once writable - > *never* executable". That is fine for static loaded code and even for > generated interpreter code [because that is just data]. But this > severe interpretation of W^X is incompatible with runtime native code > generation. > > I agree that the simpler "not simultaneously" interpretation is just a > performance issue: a kernel call to change protection costs many > thousands of executed instructions. Obviously the overhead can be > amortized by changing more pages in a single call, but JIT systems that > compile in small units: e.g., function by function as they are 1st > called - may suffer significant performance loss. [An issue now that > CPU cores aren't getting any faster.]
There's another issue, which is that a thread might be executing JITted code while new code is bring written. Since, as you note, units of JIT generation tend to be smaller than a page, this creates trouble if JITted code running in one thread is allocated on the same page as JITting in progress in another thread. Closures for callbacks via libffi have the same problem. It looks like libffi solves the problem by * creating a temporary file F; * mapping a region of F to executable memory; and * mapping the same region of F to writable memory. So, write to the latter address, and the code at the former address changes. (At this point, I've definitely lost track of what problem "W^X" is supposed to solve.) I think the JIT can be adapted to this strategy, but it will require threading both write and execute pointers through the implementation and adjusting some GC interactions. Maybe it won't be difficult, and maybe I'll try eventually. Meanwhile, a pull request would be welcome. -- You received this message because you are subscribed to the Google Groups "Racket Users" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-users+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.