大于2GB的PE文件
我正在阅读 Windows via c/c++。我只是想知道一个大文件可以映射到内存。
当我们执行一个应用程序时,PE文件会映射它们的进程地址(用户分区)。
在32位Windows中,大文件(大于2GB)可以加载到用户分区吗?否则会失败?
如果可能的话,分页文件是否有助于加载?
I'm reading Windows via c/c++. And I just wonder a large file can be mapped to memory.
When we execute an application, a PE file is mapped their process address(user partition).
In 32bit Windows, a Large file(larger than 2GB) can be loaded to user partition? or it will be failed?
If it is possible, Does Paging file help the loading?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,你不能 - 无论页面文件设置如何,你都会耗尽 VA 空间。
No, you can't - you will exhaust your VA space, regardless of the paging file setting.
您将无法在 32 位 Windows 上执行此操作。任何想要执行此操作的程序将至少加载 3 个模块:
yourApplication.exe 默认情况下将加载到 0x00400000.exe,尽管您可以更改该地址。 ntdll.dll 和 kernel32.dll 将在其通常的加载地址(高 0x7Dxx0000 范围内)加载。
在 Vista 和更高版本的操作系统上,上述段落并不正确,因为加载地址是随机的,但 dll 仍将出现在前 2GB 内存中它们自己的地址处。
因此,即使您使用 /3GB 开关启动 Windows,您也不会在任何地方有足够的连续空间来加载特别大的 PE 文件。
如果您想了解各种 DLL 的加载位置,请使用 VMValidator (免费)可视化应用程序的地址空间。虚拟内存视图以图形方式显示内存(每 4Kb 页 1 个像素)。页面和段落视图显示每个内存页面和内存段落的实际虚拟内存状态。
对于 64 位 Windows,您可能能够加载 2GB 64 位 PE 文件 - 当然应该有足够的连续空间以允许其加载到内存中。至于是否有效,我不能说,你必须测试它。
You will not be able to do this on 32 bit Windows. Any program running that wants to do this will have at minimum 3 modules loaded:
yourApplication.exe will by default load at 0x00400000.exe, although you can change that address. ntdll.dll and kernel32.dll will load at their usual load addresses in the high 0x7Dxx0000 range.
On Vista and later operating systems the above paragraph isn't true as the load addresses are randomised, but the dlls will still be present at their own address in the first 2GB of memory.
Thus you will not have enough contiguous space anywhere to load your exceptionally large PE file, even if you start Windows with the /3GB switch.
If you want a good idea of where the various DLLs will load, use VMValidator (free) to visualize the address space of your app. The Virtual Memory View shows you a graphical representation (1 pixel per 4Kb page) of memory. The Pages and Paragraph views show you the actual Virtual Memory status of each memory page and memory paragraph.
For 64 bit Windows, you may be able to load a 2GB 64 bit PE file - there certainly should be enopugh contiguous space to allow it to load in memory. As for whether it would then work I cannot say, you will have to test it.
我不认为整个文件都被映射,只映射了可执行映像的大小(如 PE 标头中列出的)。所以自解压存档> 2GB应该是可以的。该代码必须使用标准文件 I/O 从文件的后半部分提取数据,紧随 PE 映像的末尾。
I don't think the entire file is mapped, only up to the size of the executable image (as listed in the PE header). So a self-extracting archive > 2GB should be possible. The code would have to use the standard file I/Os to extract its data from the latter part of the file, following the end of the PE image.