JIT编译和DEP [英] JIT compilation and DEP
问题描述
我当时正在考虑尝试一些jit编译(仅出于学习目的),并且因为它可以在家里运行所有主要的三款产品(Windows,OS X,Linux),所以它可以跨平台运行会很好. . 考虑到这一点,我想知道是否有任何方法可以摆脱使用虚拟内存窗口函数来分配具有执行权限的内存的问题.最好只使用malloc或new并将处理器指向这样的块.
有什么提示吗?
一种可能是要求将运行程序的Windows安装配置为DEP AlwaysOff(不好的主意)或DEP OptOut(更好的主意). /p>
可以通过将boot.ini文件更改为以下设置来配置(至少在WinXp SP2 +和Win2k3 SP1 +下):
/noexecute=OptOut
,然后通过选择(在XP下)将个人程序配置为退出:
Start button
Control Panel
System
Advanced tab
Performance Settings button
Data Execution Prevention tab
这应该使您能够在malloc()
块中动态创建的程序中执行代码.
请记住,这会使您的程序更容易受到DEP旨在防止的攻击.</p>
在Windows 2008中,使用以下命令似乎也可以做到这一点:
bcdedit.exe /set {current} nx OptOut
但是,说实话,如果您只想最小化与平台相关的代码,那么只需将代码隔离到一个函数中就可以轻松实现,例如:
void *MallocWithoutDep(size_t sz) {
#if defined _IS_WINDOWS
return VirtualMalloc(sz, OPT_DEP_OFF); // or whatever
#elif defined IS_LINUX
// Do linuxy thing
#elif defined IS_MACOS
// Do something almost certainly inexplicable
#endif
}
如果将所有与平台相关的功能放在各自的文件中,则其余代码将自动与平台无关.
I was thinking of trying my hand at some jit compilataion (just for the sake of learning) and it would be nice to have it work cross platform since I run all the major three at home (windows, os x, linux). With that in mind, I want to know if there is any way to get out of using the virtual memory windows functions to allocate memory with execution permissions. Would be nice to just use malloc or new and point the processor at such a block.
Any tips?
One possibility is to make it a requirement that Windows installations running your program be either configured for DEP AlwaysOff (bad idea) or DEP OptOut (better idea).
This can be configured (under WinXp SP2+ and Win2k3 SP1+ at least) by changing the boot.ini file to have the setting:
/noexecute=OptOut
and then configuring your individual program to opt out by choosing (under XP):
Start button
Control Panel
System
Advanced tab
Performance Settings button
Data Execution Prevention tab
This should allow you to execute code from within your program that's created on the fly in malloc()
blocks.
Keep in mind that this makes your program more susceptible to attacks that DEP was meant to prevent.
It looks like this is also possible in Windows 2008 with the command:
bcdedit.exe /set {current} nx OptOut
But, to be honest, if you just want to minimise platform-dependent code, that's easy to do just by isolating the code into a single function, something like:
void *MallocWithoutDep(size_t sz) {
#if defined _IS_WINDOWS
return VirtualMalloc(sz, OPT_DEP_OFF); // or whatever
#elif defined IS_LINUX
// Do linuxy thing
#elif defined IS_MACOS
// Do something almost certainly inexplicable
#endif
}
If you put all your platform dependent functions in their own files, the rest of your code is automatically platform-agnostic.
这篇关于JIT编译和DEP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!