MSDN Updates

Get Microsoft Silverlight

Thursday, June 16, 2005

Inputs from Nikhilesh

To support the CLR, Microsoft has extended the PE/COFF file format to include metadata and IL code. The CLR uses metadata to determine how to load classes and uses the IL code to turn it into native code for execution. The extensions that Microsoft has added to the normal PE format include the CLR header and CLR data. The CLR header mainly stores relative virtual addresses (RVA) to locations that hold pertinent information to help the CLR manage program execution. The CLR data portion contains metadata and IL code, both of which determine how the program will be executed. Compilers that target the CLR must emit both the CLR header and data information into the generated PE file, otherwise the resulting PE file will not run under the CLR.

Looking at this text dump of a .NET PE file, you can see that a PE file starts off with the MS-DOS/COFF header, which all Windows programs must include. Following this header, you will find the PE header that supports Windows 32-bit programs. Immediately after the PE headers, you can find the code section for this program. The raw data (RAW DATA #1) of this section stores the CLR header, as follows:
RAW DATA #1 . . . clr Header: /* CLR HEADER */ 48 cb 2.00 runtime version 207C [ 214] RVA [size] of MetaData Directory 1 flags 6000001 entry point token 0 [ 0] RVA [size] of Resources Directory 0 [ 0] RVA [size] of StrongNameSignature Directory 0 [ 0] RVA [size] of CodeManagerTable Directory 0 [ 0] RVA [size] of VTableFixups Directory 0 [ 0] RVA [size] of ExportAddressTableJumps Directory
Section contains the following imports: mscoree.dll . . . 0 _CorExeMain . . .As mentioned earlier, the CLR header holds a number of pertinent details required by the runtime, including:
Runtime version Indicates the runtime version that is required to run this program
MetaData directory Is important because it indicates the location of the metadata needed by the CLR at runtime
Entry point token Is even more important because, for a single file assembly, this is the token that signifies the entry point, such as Main( ), that the CLR executes
Below the CLR Header, note that there is an imported function called _CorExeMain, which is implemented by mscoree.dll, the core execution engine of the CLR.[2] At the time of this writing, Windows 98, 2000, and Me have an OS loader that knows how to load standard PE files. To prevent massive changes to these operating systems and still allow .NET applications to run on them, Microsoft has updated the OS loaders for all these platforms. The updated loaders know how to check for the CLR header, and, if this header exists, it executes _CorExeMain, thus not only jumpstarting the CLR but also surrendering to it. You can then guess that the CLR will call Main( ), since it can find the entry point token within the CLR header.[3]

The common language runtime can either run garbage collection concurrently on a separate thread or on the same thread as the application. Use the element to specify how the runtime should run garbage collection. For example:
By default, the runtime runs garbage collection concurrently, which reduces performance. If your application is single-threaded and involves heavy user interaction, leave concurrent garbage collection enabled so the application does not pause to perform garbage collection. If your application is an ASP.NET server application, you do not need to alter the default value of the element.

A delegate is a data structure that refers to a static method or to an object instance and an instance method ofthat object.

A component container is a specialized class that acts as a means of organizing and containing components. Through a container you can track your components, communicate with them via the Site that hosts the component, and provide a means of common disposal after they are no longer needed.

No comments: