根据定义,JIT编译器会即时生成代码以供执行。但是,在Windows中,我们有各种保护,防止自我修改代码或从数据存储器(DEP)执行。
那么如何可能的JIT编译器
解决方案他们要求操作系统提供一些可读,可写和可执行的内存。
例如您可以使用 mmap()与 PROT_READ | PROT_WRITE | PROD_EXEC (POSIX)或 VirtualAlloc()与 PAGE_EXECUTE_READWRITE p>
有关示例,请参见LLVM的 llvm: :sys :: Memory :: AllocateRWX ( Unix实现; Windows实施)。
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?
解决方案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).
更多推荐
JIT编译器如何操作
发布评论