可执行文件映射到内存中的具体过程?该怎么解决
发布时间:2011-06-23 14:27:20 文章来源:www.iduyao.cn 采编人员:星星草
可执行文件映射到内存中的具体过程?
最近在看《Windows核心编程》,有一点很疑惑的地方:
可执行文件被存储在磁盘上,当要运行这个程序的时候,可执行文件中的内容会被映射到内存中,然后 CPU读取内存中的内容来执行指令。
我的疑惑在于可执行文件映射的时候是怎么一个过程,在《Windows核心编程》中提到了内存映射和虚拟内存的内容,我疑惑地方在于不知道映射内存的时候是直接映射到物理内存上呢,还是映射到虚拟内存上?
------解决方案--------------------
Loading the library
To emulate the PE loader, we must first understand, which steps are neccessary to load the file to memory and prepare the structures so they can be called from other programs.
When issuing the API call LoadLibrary, Windows basically performs these tasks:
Open the given file and check the DOS and PE headers.
Try to allocate a memory block of PEHeader.OptionalHeader.SizeOfImage bytes at position PEHeader.OptionalHeader.ImageBase.
Parse section headers and copy sections to their addresses. The destination address for each section, relative to the base of the allocated memory block, is stored in the VirtualAddress attribute of the IMAGE_SECTION_HEADER structure.
If the allocated memory block differs from ImageBase, various references in the code and/or data sections must be adjusted. This is called Base relocation.
The required imports for the library must be resolved by loading the corresponding libraries.
The memory regions of the different sections must be protected depending on the section’s characteristics. Some sections are marked as discardable and therefore can be safely freed at this point. These sections normally contain temporary data that is only needed during the import, like the informations for the base relocation.
Now the library is loaded completely. It must be notified about this by calling the entry point using the flag DLL_PROCESS_ATTACH.
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。
其他相似内容:
-
关于visual studio 2005的工程文件*.vcproj的问题
请问:Visual Studio 2005 新建一个工程之后,会自动生产一个*.vcproj的一个文件,这...
-
用MFC画图的问题
我现在要用随机数产生300个固定的点保存在数组中,并在ondraw里画出这300个点,而且通过定时器使这300个点做运动。...
-
VS2010中的C++怎么连接数据库?
之前一直用VC++6.0的、现在想学学用最新的VS、但是感觉连接数据库和之前不一样了、具体应该怎么弄...
-
CLI编程 高手帮忙
我现在用C++/CLI 混编,
我有一个方法, 是调用一个C 的类库 得到一个 char * 的值
现在我...
-
新手求教::VC.NET2003里面的"添加变量"菜单变灰了,怎么弄?
最近学着用.net写程序,以前用的是6.0,不知道为什么我设计的EDIT Con...
-
刚学习vc.net 请教一个String做参数的问题,请高手指教一下
下面的代码为什么不能编译呢,出现这个错误呢
.\clr.cpp(12) : error C3...
-
VS2003中通过ADO取SQL2003中bigint 负值变正值的问题,求助!
在SQL2003中 数据库中假设 一个bigint类型的数据位-1234这样的值,通过如...
-
新手学习VC用那个版本的编译器好!
新手学习VC用那个版本的编译器好!?
------解决方案--------------------
VC++6.0
------解决...
-
正则表达式
有这样的字符串
"1,',2"",3"
希望将单个的"替换成单引号,将连续两个的""替换成一个双引号。
正则表达式该如何写。
...
-
为什么<<精通MFC>>附带的源程序不能编译成功
vc2010编译后有两个错误提示,分别如下,
错误一:
1>c:\program files\microsoft vi...