8 ms·
I'd assume Rosetta works for newly marked executable pages by not actually flagging them as executable. When control flow attempts to transfer there, a page fau
by jsmith45 5y ago
I'd assume Rosetta works for newly marked executable pages by not actually flagging them as executable. When control flow attempts to transfer there, a page fault will occur since the page is not actually executable, this is the interrupt that allows Rosetta to step in, see what code was about to be executed, and write out a new ARM equivalent of the code to other memory, and redirect execution to the new equivalent ARM code, before resuming.
This basic sort of support is needed for any application that targeting x86 that uses any form of dynamic code generation, which is probably a whole lot more than most people think (even some forms of dynamic linking utilize small amounts of generated code, due to being more efficient than calling a method though a pointer to a pointer to the method).
- a-dub 5y agoso every write to an executable page would have to clear that bit then, triggering an interrupt on jump to let the translator jump in? i'd venture a guess that the rosetta jit stuff probably does some kind of prelinking. kinda makes me wish i had an m1 mac to play with...
- anyfoo 5y agox86 code is never actually marked as executable from the CPU's point of view, since that CPU does not know how to execute x86 code. The pages which contain the translated code are, but those are not something the x86 code knows about.
- chrisseaton 5y ago> x86 code is never actually marked as executable from the CPU's point of view, since that CPU does not know how to execute x86 code. The pages which contain the translated code are, but those are not something the x86 code knows about. No, pages and the executable bit are something that the processor knows about.
- a-dub 5y agoyou think that x86 pages are marked executable by the arm processor? probably not. maybe arm pages with an arm wrapper that calls the jit for big literals filled with x86 code are, or arm pages loaded with stubs that jump into the jit to compile x86 code sitting in data pages are... but if the arm processor cannot execute x86 pages directly, then it wouldn't make a lot of sense for them to be marked executable, would it?
- chrisseaton 5y agoNo the AMD64 page executable bit system is implemented in software by Rosetta.
- saagarjha 5y agoNo, it doesn't need to. Rosetta only emulates userspace, so it just needs to give the illusion of protections to the program.
- anyfoo 5y agoAh, in this case I took "x86 execution semantics" just as how it behaves from user space, i.e. what permissions you can set and that they behave the same from an x86 observer (no matter what shenanigans is actually going behind the scenes).
- deleted 5y ago[deleted]
- anyfoo 5y agoSorry, I don't understand what you are trying to say. Of course the CPU knows about pages and the executable bit? But there is no executable bit on a page filled with x86 code running on an ARM CPU, because the ARM CPU cannot execute that. It can only execute the translated ARM code that sits somewhere else, essentially out of sight for the x86 program.