Cog will require changes to JIT on the next version of Mac

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Cog will require changes to JIT on the next version of Mac

Ryan Macnak
 
Cog will need to be signed with the JIT entitlement and to pass MAP_JIT when it allocates executable memory.

Reply | Threaded
Open this post in threaded view
|

Re: Cog will require changes to JIT on the next version of Mac

Tobias Pape
 
Hi

> On 14.08.2019, at 04:29, Ryan Macnak <[hidden email]> wrote:
>
> Cog will need to be signed with the JIT entitlement and to pass MAP_JIT when it allocates executable memory.
>
> https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-jit

Interesting.

It seems the ideas of OpenBSD W^X finally reached Mac OS X [1], but in a different way.

Other JITs handle that by
 * mmap-ing the to-be-written code region R/W
 * jitting to that region
 * when done mprotect to remove the w and add the x

Example: Firefox [2].

I have no idea why Apple came up with MAP_JIT. If we used the above,
maybe we don't need to be singend to at least run…

Best regards
        -Tobias


[1]: https://en.wikipedia.org/wiki/W%5EX , https://www.openbsd.org/33.html 
[2]: https://jandemooij.nl/blog/2015/12/29/wx-jit-code-enabled-in-firefox/
Reply | Threaded
Open this post in threaded view
|

Re: Cog will require changes to JIT on the next version of Mac

Clément Béra
 


On Wed, Aug 14, 2019 at 8:22 AM Tobias Pape <[hidden email]> wrote:
 
Hi

> On 14.08.2019, at 04:29, Ryan Macnak <[hidden email]> wrote:
>
> Cog will need to be signed with the JIT entitlement and to pass MAP_JIT when it allocates executable memory.
>
> https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_security_cs_allow-jit

Interesting.

It seems the ideas of OpenBSD W^X finally reached Mac OS X [1], but in a different way.

Other JITs handle that by
 * mmap-ing the to-be-written code region R/W
 * jitting to that region
 * when done mprotect to remove the w and add the x

Example: Firefox [2].

That is a significant change to Cog's JIT. On the top of my head:
1. When jitting, one would need to control per page the rights inside the machine code zone and write each CogMethod within a page boundary with a 1-to-1 mapping CogMethod per page (likely memory overhead induced).
2. Inline cache logic (Mono, closedPIC and openPIC) should be changed not to edit the instructions in the machine code zone but a RW structure (likely execution time overhead induced), or to change page protection for relinking (which is think is disallowed, once it is executable it cannot go back to be W).
3. Machine code zone GC should be changed not to edit the machine code zone to update literals but a RW located structure, which is particulary nasty on back-ends where inlined literals are forced (x86_32) or to change page protection for relinking  (which is think is disallowed, once it is executable it cannot go back to be W).
 
I'd say MAP_JIT is the cheap option unless someone has budget to invest in this change.


I have no idea why Apple came up with MAP_JIT. If we used the above,
maybe we don't need to be singend to at least run…

Best regards
        -Tobias


[1]: https://en.wikipedia.org/wiki/W%5EX , https://www.openbsd.org/33.html
[2]: https://jandemooij.nl/blog/2015/12/29/wx-jit-code-enabled-in-firefox/


--
Reply | Threaded
Open this post in threaded view
|

Re: Cog will require changes to JIT on the next version of Mac

Jan Vrany
 
> 2. Inline cache logic (Mono, closedPIC and openPIC) should be changed
> not to edit the instructions in the machine code zone but a RW
> structure (likely execution time overhead induced)

Do you have any performance measurements or references?

I must admit I dislike patching PICs in instruction stream and I
wonder if it's worth on modern CPUs...

Thanks, Jan


Reply | Threaded
Open this post in threaded view
|

Re: Cog will require changes to JIT on the next version of Mac

Bruce O'Neel-2
In reply to this post by Ryan Macnak
 
Hi,

On the Island flavored versions of MacOS today:

squeak.cog.spur_macos64x64_201908071924 -- seems to work fine.
squeak.cog.spur-cmake-minhdls_macos64x64_201908071924 -- Open file dialog opens, but, doesn't bring up the main window.
squeak.cog.spur+sdl2-cmake-minhdls_macos64x64_201908071924 -- seems to work fine.

In all cases you have to do the alt click open dance the first time since it's not notarized.  Sigh...

So it's possible that the new JIT stuff hasn't been shipped yet.

cheers

bruce
 

14 August 2019 04:29 Ryan Macnak <[hidden email]> wrote:
<>
Cog will need to be signed with the JIT entitlement and to pass MAP_JIT when it allocates executable memory.


Reply | Threaded
Open this post in threaded view
|

Re: Cog will require changes to JIT on the next version of Mac

Clément Béra
In reply to this post by Jan Vrany
 


On Wed, Aug 14, 2019 at 2:32 PM Jan Vrany <[hidden email]> wrote:
> 2. Inline cache logic (Mono, closedPIC and openPIC) should be changed
> not to edit the instructions in the machine code zone but a RW
> structure (likely execution time overhead induced)

Do you have any performance measurements or references?

I must admit I dislike patching PICs in instruction stream and I
wonder if it's worth on modern CPUs...

No,

I talked with multiple Java/JS VM implementors who said they could not 
have a page writable and executable (security policy) so they did not even 
try Cog's design. 

I think you have to try :-(


Thanks, Jan




--