1// Licensed to the .NET Foundation under one or more agreements.
2// The .NET Foundation licenses this file to you under the MIT license.
3// See the LICENSE file in the project root for more information.
4//*****************************************************************************
5// Stubs.h
6//
7// This file contains a template for the default entry point stubs of a COM+
8// IL only program. One can emit these stubs (with some fix-ups) and make
9// the code supplied the entry point value for the image. The fix-ups will
10// in turn cause mscoree.dll to be loaded and the correct entry point to be
11// called.
12//
13// Note: Although these stubs contain x86 specific code, they are used
14// for all platforms
15//
16//*****************************************************************************
17#ifndef __STUBS_H__
18#define __STUBS_H__
19
20//*****************************************************************************
21// This stub is designed for a x86 Windows application. It will call the
22// _CorExeMain function in mscoree.dll. This entry point will in turn load
23// and run the IL program.
24//
25// jump _CorExeMain();
26//
27// The code jumps to the imported function _CorExeMain using the iat.
28// The address in the template is address of the iat entry which is
29// fixed up by the loader when the image is paged in.
30//*****************************************************************************
31
32SELECTANY const BYTE ExeMainX86Template[] =
33{
34 // Jump through IAT to _CorExeMain
35 0xFF, 0x25, // jmp [iat:_CorDllMain entry]
36 0x00, 0x00, 0x00, 0x00, // address to replace
37
38};
39
40#define ExeMainX86TemplateSize sizeof(ExeMainX86Template)
41#define CorExeMainX86IATOffset 2
42
43//*****************************************************************************
44// This stub is designed for a x86 Windows application. It will call the
45// _CorDllMain function in mscoree.dll with with the base entry point for
46// the loaded DLL. This entry point will in turn load and run the IL program.
47//
48// jump _CorDllMain
49//
50// The code jumps to the imported function _CorExeMain using the iat.
51// The address in the template is address of the iat entry which is
52// fixed up by the loader when the image is paged in.
53//*****************************************************************************
54
55SELECTANY const BYTE DllMainX86Template[] =
56{
57 // Jump through IAT to CorDllMain
58 0xFF, 0x25, // jmp [iat:_CorDllMain entry]
59 0x00, 0x00, 0x00, 0x00, // address to replace
60};
61
62#define DllMainX86TemplateSize sizeof(DllMainX86Template)
63#define CorDllMainX86IATOffset 2
64
65//*****************************************************************************
66// This stub is designed for a AMD64 Windows application. It will call the
67// _CorExeMain function in mscoree.dll. This entry point will in turn load
68// and run the IL program.
69//
70// mov rax, _CorExeMain();
71// jmp [rax]
72//
73// The code jumps to the imported function _CorExeMain using the iat.
74// The address in the template is address of the iat entry which is
75// fixed up by the loader when the image is paged in.
76//*****************************************************************************
77
78SELECTANY const BYTE ExeMainAMD64Template[] =
79{
80 // Jump through IAT to _CorExeMain
81 0x48, 0xA1, // rex.w rex.b mov rax,[following address]
82 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//address of iat:_CorExeMain entry
83 0xFF, 0xE0 // jmp [rax]
84};
85
86#define ExeMainAMD64TemplateSize sizeof(ExeMainAMD64Template)
87#define CorExeMainAMD64IATOffset 2
88
89//*****************************************************************************
90// This stub is designed for a AMD64 Windows application. It will call the
91// _CorDllMain function in mscoree.dll with with the base entry point for
92// the loaded DLL. This entry point will in turn load and run the IL program.
93//
94// mov rax, _CorDllMain();
95// jmp [rax]
96//
97// The code jumps to the imported function _CorDllMain using the iat.
98// The address in the template is address of the iat entry which is
99// fixed up by the loader when the image is paged in.
100//*****************************************************************************
101
102SELECTANY const BYTE DllMainAMD64Template[] =
103{
104 // Jump through IAT to CorDllMain
105 0x48, 0xA1, // rex.w rex.b mov rax,[following address]
106 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,//address of iat:_CorDllMain entry
107 0xFF, 0xE0 // jmp [rax]
108};
109
110#define DllMainAMD64TemplateSize sizeof(DllMainAMD64Template)
111#define CorDllMainAMD64IATOffset 2
112
113//*****************************************************************************
114// This stub is designed for an ia64 Windows application. It will call the
115// _CorExeMain function in mscoree.dll. This entry point will in turn load
116// and run the IL program.
117//
118// jump _CorExeMain();
119//
120// The code jumps to the imported function _CorExeMain using the iat.
121// We set the value of gp to point at the iat table entry for _CorExeMain
122//*****************************************************************************
123
124SELECTANY const BYTE ExeMainIA64Template[] =
125{
126 // ld8 r9 = [gp] ;;
127 // ld8 r10 = [r9],8
128 // nop.i ;;
129 // ld8 gp = [r9]
130 // mov b6 = r10
131 // br.cond.sptk.few b6
132 //
133 0x0B, 0x48, 0x00, 0x02, 0x18, 0x10, 0xA0, 0x40,
134 0x24, 0x30, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00,
135 0x10, 0x08, 0x00, 0x12, 0x18, 0x10, 0x60, 0x50,
136 0x04, 0x80, 0x03, 0x00, 0x60, 0x00, 0x80, 0x00
137};
138
139#define ExeMainIA64TemplateSize sizeof(ExeMainIA64Template)
140
141//*****************************************************************************
142// This stub is designed for an ia64 Windows application. It will call the
143// _CorDllMain function in mscoree.dll with with the base entry point for
144// the loaded DLL. This entry point will in turn load and run the IL program.
145//
146// jump _CorDllMain
147//
148// The code jumps to the imported function _CorExeMain using the iat.
149// We set the value of gp to point at the iat table entry for _CorExeMain
150//*****************************************************************************
151
152SELECTANY const BYTE DllMainIA64Template[] =
153{
154 // ld8 r9 = [gp] ;;
155 // ld8 r10 = [r9],8
156 // nop.i ;;
157 // ld8 gp = [r9]
158 // mov b6 = r10
159 // br.cond.sptk.few b6
160 //
161 0x0B, 0x48, 0x00, 0x02, 0x18, 0x10, 0xA0, 0x40,
162 0x24, 0x30, 0x28, 0x00, 0x00, 0x00, 0x04, 0x00,
163 0x10, 0x08, 0x00, 0x12, 0x18, 0x10, 0x60, 0x50,
164 0x04, 0x80, 0x03, 0x00, 0x60, 0x00, 0x80, 0x00
165};
166
167#define DllMainIA64TemplateSize sizeof(DllMainIA64Template)
168
169#endif // __STUBS_H__
170