Managed EXE file loading and execution process in the previous article has done a brief introduction, now combined with the content of this chapter for detailed analysis.
When the managed EXE file is started, it is first loaded by the PE loader. PE Loader load EXE file, will analyze the PE file header Data Directory table, if the value within Clr_header is not 0, means that the file is a managed PE file, PE Loader will immediately load MsCorEE.dll, and execute The _CorExeMain () function within the MsCorEE.dll.
If it is a previous version of Windows XP operating system (such as Windows 2000), when Windows 2000 Loader the EXE file, it checks the PE Header's Data directory table and the import table The recorded data is loaded into memory, which is MsCorEE.dll. Then find the entry point of the program in the PE header and execute the code here. This is the x86 machine code, automatically generated by the compiler, only one instruction (6 bytes), "FF 25 00 20 40 00", translated into x86 assembly language is "JMP DWORD PTR [402000]", where 0x00400000 is an EXE file of the IMA GE base, and 0x2000 is the RVA of the Import Address table (here is the offset of _CorExeMain ()), so the result of executing "JMP DWORD PTR [402000]" jumps to MsCorEE.dll _c Orexemain ().
After the _CorExeMain () is executed, the code first determines the version of the CLR that needs to be loaded.
After the CLR starts, the next step is to initialize the work, establish processes for managed programs, request memory space, build thread pools and application domains. The first established application domain is called the default AppDomain.
After initialization, load the MsCorLib.dll component and the modules therein.
After the module is loaded, the class loader is invoked to load the related class within the MsCorLib. The class order of loading is:
1) System.Object
2) system.icloneable
3) System.Collections.IEnumerable
4) ...
5) System.AppDomain
6) System.loaderoptimization
7) System.runtime.remoting.proxies.__transparentproxy
Note that the class is not loaded in the MsCorLib at this time, only the class that is currently required.
After the class is loaded, the CLR generates the main thread, which generates the main thread and needs to load the following classes:
System.Threading.Monitor
System.iappdomainsetup
System.appdomainsetup
System.Char
System.Runtime.InteropServices.RuntimeEnvironment
System.runtimefieldhandle
System.Runtime.CompilerServices.RuntimeHelpers
System.Environment
The mainline mechanical engineer is loaded into the application's component into the application domain before it really enters the application's main function.
After entering the main () function, the JIT compiler is invoked to compile the IL code to execute the cost code.
Author: Hyun-Soul
Source: http://www.cnblogs.com/xuanhun/
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/net/