Create code at runtime on iOS: possible any more?

I'm the developer of 8th (https://8th-dev.com), which compiles the program at run-time, on the device. There used to be an iOS version which worked, but it seems things have changed since then.

I'm trying to distribute an iOS version of an app written in 8th, and am encountering "SIGKILL - CODESIGNING" when trying to execute freshly compiled code. I am doing the 'sys_icache_invalidate' thing after writing into a mmap'ed bit of memory (rwx).

I'm not writing into memory that was codesigned, so I don't know why the error is that.

Anyway, the question is: is it possible any more to do what I used to be able to do?

Answered by endecotp in 794805022

This page is worth reading:

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

describes how it works on MacOS.

I believe that iOS likely works much the same, except crucially that our apps cannot get the required entitlement.

As far as I know it is not allowed. Which version had this working?

Are you sure this worked on an unmodified iOS device? That seems unlikely to me. mmaping executable memory is specifically disallowed, with a very limited exception that Safari uses to JIT Javascript.

This page is worth reading:

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

describes how it works on MacOS.

I believe that iOS likely works much the same, except crucially that our apps cannot get the required entitlement.

Yes. When I ported to the M1, I had to do some things differently; but it works like a champ (on Apple Silicon macOS).

+1 to everything endecotp said above, plus…

iOS does not allow general apps to generate code on the fly. AFAICT the only exception to that rule is third-party web browsers, as described in Protecting code compiled just in time.

One option you might explore is WASM. If your language can generate WASM then that expands your options:

  • You can run the WASM with a non-JIT interpreter. These can be surprisingly fast.

  • If you have a web view handy for other reasons, you can probably [1] run it in there.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] “probably” because I’ve not actually tried that myself.

Create code at runtime on iOS: possible any more?
 
 
Q