2 ms·
> Once it's JIT'd anyway it won't ever be changed, That's not necessarily how it works. JITs often use inline caches that get populated at runtime. JITs usuall
by the8472 11y ago
> Once it's JIT'd anyway it won't ever be changed,
That's not necessarily how it works. JITs often use inline caches that get populated at runtime. JITs usually implement W^X by mapping the same physical memory into two different address ranges. Once as RW for modification and once as RX for execution.
Having a single mapping is possible, but comes with performance penalties because execution needs to reach a safe/bailout point where that can happen instead of just atomically patching the code.
- simcop2387 11y agoDoesn't mapping the same physical memory into two places actually end up defeating the W^X bit entirely? Since you can write to the RW mapped page and have it change the RX page?
- the8472 11y agoThose pages would be mapped at a different, random address while the executing code has an instruction pointer pointing right at the RX page. It's much more difficult getting access to the JIT's internal data structures, traversing them to find the correct RW page, then modify it, then jump to the same place in the RX page. If you already have that much control you're probably not far from getting the JIT to emit arbitrary code anyway. Note that writing to ICs can happen from a different thread, so the current thread stack does not need to know much of the JIT's internal data.