Reputation: 5054
JIT compilers, by definition, generate code on the fly for execution. But in, say, Windows, we have all kinds of protection that prevent self modifying code or executing from data memory (DEP).
So how is it possible for JIT compilers to generate code on the fly?
Upvotes: 4
Views: 516
Reputation: 47058
They ask the OS for some memory which is readable, writeable and executable.
e.g. you can allocate such memory using mmap()
with PROT_READ | PROT_WRITE | PROT_EXEC
(POSIX), or VirtualAlloc()
with PAGE_EXECUTE_READWRITE
(Windows).
For a real example, see LLVM's llvm::sys::Memory::AllocateRWX
(Unix implementation; Windows implementation).
Upvotes: 7