DLL基地址

发布于 2024-12-04 03:53:08 字数 1160 浏览 2 评论 0原文

我有一个小型测试解决方案,其中包含一个 exe 和三个 Dll,exe 分别调用三个 Dll 一次。 我已将 Dll1.dll、Dll2.dll 和 Dll3.dll 的“Build->Advanced->DLL Base Address”设置分别设置为 0x41000000、0x42000000 和 0x43000000。我已经运行了

ngen install ConsoleApplication1.exe

,这已经成功生成了应用程序以及三个 Dll。我真的不想生成 exe,但到目前为止,这是产生任何结果的唯一方法。

在运行时,我使用 VMMap 来监视虚拟地址空间,它显示 ngen 的 Dll 位于虚拟内存的一致范围内,但是它们仍然在该范围内跳跃,每次运行时加载到稍微不同的地址他们。 VMMap 显示在我尝试加载图像的地址上没有分配任何内容,因此这种跳跃行为不是由地址冲突引起的。

我一直在保存日志:

   Dll1       Dll2       Dll3
0x40140000 0x411D0000 0x42810000 
0x40580000 0x41EB0000 0x426B0000 
0x40190000 0x41FB0000 0x42380000 
0x40F30000 0x41FD0000 0x42050000 
0x409B0000 0x41BF0000 0x42910000 
0x408E0000 0x41860000 0x42050000 
0x40B50000 0x41280000 0x42A80000

请注意,在所有运行中,所有三个 Dll 的地址前两位数字保持一致。

我的实际问题:这是成功的指标吗?我有点困惑,因为我认为 Dll 正好位于 0x41000000、0x42000000 和 0x43000000。结果显示,他们在该区域闲逛,但从未真正坐在我要求他们坐的地方。我的理解是,您希望 Dll 准确地加载到您要求的地址,这样它们就不必经历昂贵的变基操作(当您的 Dll 已被加载时,这是非常非常昂贵的)恩根)。但是,这不正是正在发生的事情吗?当然,我的 Dll 徘徊在某个区域,但它们并不完全位于我要求它们所在的位置,因此每次运行时肯定会执行昂贵的变基操作吗?这正是我想要避免的。

注意:我对支持/反对 rebase 和 ngen 的争论不感兴趣。我只是想知道发生了什么以及如何让它发挥作用。

干杯吧!

I've got a small test solution with one exe and three Dlls, the exe calling the three Dlls once each.
I've set the Build->Advanced->DLL Base Address setting to 0x41000000, 0x42000000 and 0x43000000 for Dll1.dll, Dll2.dll and Dll3.dll respectively. I've run

ngen install ConsoleApplication1.exe

and this has successfully ngen'd the application along with the three Dlls. I didn't really want to ngen the exe but so far this is the only way to produce any results at all.

At runtime I use VMMap to monitor the virtual address space and it reveals that the ngen'd Dlls are sitting within a consistant range of virtual memory, however they are still jumping around within that range, loading at a slightly differnt address every time I run them. VMMap reveals that there is nothing allocated at the addresses where I'm trying to load the images, so this jumpy behaviour is not being caused by address collisions.

I've been keeping logs:

   Dll1       Dll2       Dll3
0x40140000 0x411D0000 0x42810000 
0x40580000 0x41EB0000 0x426B0000 
0x40190000 0x41FB0000 0x42380000 
0x40F30000 0x41FD0000 0x42050000 
0x409B0000 0x41BF0000 0x42910000 
0x408E0000 0x41860000 0x42050000 
0x40B50000 0x41280000 0x42A80000

Notice that the first two digits of the address remain consistant for all three Dlls across all runs.

My actual question: Is this an indicator of success? I'm a bit confused because I thought the Dlls were going to be sitting exactly at 0x41000000, 0x42000000 and 0x43000000. The results show that they hang around that area, but never actually sit where I asked them to sit. My understanding is that you want the Dlls to be loaded exactly at the address you ask them to so that they don't have to undergo the expensive rebasing operation (which is very very expensive when your Dlls have been ngen'd). But, isn't this exactly what's happening? Sure, my Dlls are hanging around in a certain area, but they aren't sitting exactly where I asked them to sit, so surely the expensive rebasing operation is being peformed at each run time? This is exactly what I wanted to avoid.

Note: I'm not interested in arguments for/against rebasing and ngen. I just want to know what's going on and how to get it working.

Cheers SO!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

長街聽風 2024-12-11 03:53:08

Could be ASLR (addres space layout randomization) - check out links from http://social.msdn.microsoft.com/Forums/en/vcgeneral/thread/bac7e300-f3df-4087-9c4b-847880d625ad

沩ん囻菔务 2024-12-11 03:53:08

NGEN 工具是否不限制为其为程序集生成的二进制映像指定基址。据我所知,您必须将“首选基地址”编译到程序集本身中。 http://msdn.microsoft.com/en-us/magazine/cc163610.aspx

编辑*

但是,如果加载程序无法将模块放置在所需的地址
(因为它已经与另一个模块或数据重叠
已加载或已分配),该模块被重新设置基址,这意味着它被加载于
其他一些地址。这意味着内的所有地址
可执行映像需要修复。

另外看看互联网,似乎许多开发人员都希望有此功能,但问题是保留不与其他开发人员程序集冲突的基地址。您期望的地址上还有哪些其他 DLL?

Doesn't the NGEN tool restrict specifying a base address for the binary image it makes for an assembly. Afaik you have to compile the “preferred base address” into the assembly itself. http://msdn.microsoft.com/en-us/magazine/cc163610.aspx

Edit *

However, if the loader cannot place the module at the desired address
(because it overlaps with another module or piece of data already
loaded or allocated), the module is rebased, meaning it is loaded at
some other address. This implies that all addresses within the
executable image need to be fixed up.

Also looking at the internet it seems many developers wish for this feature but the problem is reserving base addresses that dont conflict with other developers assembly's. What other DLLs are sitting at the addresses you expected yours to be at?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文