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// File: crosscomp.cpp
6//
7
8// ===========================================================================
9// This file contains stubbed out implementations for cross-platform NGen.
10//
11// The stubbed out implementations are concentrated in this file to reduce number
12// of ifdefs that has to be sprinkled through the code.
13// ===========================================================================
14
15#include "common.h"
16
17#include "comdelegate.h"
18#include "compile.h"
19#include "invokeutil.h"
20#include "comcallablewrapper.h"
21
22//---------------------------------------------------------------------------------------
23//
24// Pull in some implementation files from other places in the tree
25//
26
27#include "../../dlls/mscoree/mscoree.cpp"
28
29//---------------------------------------------------------------------------------------
30//
31// Helper function for features unsupported under crossgen
32//
33
34#undef ExitProcess
35
36void CrossGenNotSupported(const char * message)
37{
38 _ASSERTE(!"CrossGenNotSupported");
39 fprintf(stderr, "Fatal error: %s\n", message);
40 ExitProcess(CORSECATTR_E_BAD_ACTION);
41}
42
43//---------------------------------------------------------------------------------------
44//
45// There is always only one thread and one appdomain in crossgen.
46//
47
48extern CompilationDomain * theDomain;
49
50AppDomain * GetAppDomain()
51{
52 return theDomain;
53}
54
55Thread theThread;
56
57Thread * GetThread()
58{
59 return (Thread*)&theThread;
60}
61
62Thread * GetThreadNULLOk()
63{
64 return GetThread();
65}
66
67#ifdef _DEBUG
68BOOL Debug_IsLockedViaThreadSuspension()
69{
70 LIMITED_METHOD_CONTRACT;
71 return FALSE;
72}
73#endif // _DEBUG
74
75//---------------------------------------------------------------------------------------
76//
77// All locks are nops because of there is always only one thread.
78//
79
80void CrstBase::InitWorker(INDEBUG_COMMA(CrstType crstType) CrstFlags flags)
81{
82 m_dwFlags = flags;
83}
84
85void CrstBase::Destroy()
86{
87}
88
89void CrstBase::Enter(INDEBUG(enum CrstBase::NoLevelCheckFlag))
90{
91}
92
93void CrstBase::Leave()
94{
95}
96
97BOOL __SwitchToThread(DWORD, DWORD)
98{
99 return TRUE;
100}
101
102//---------------------------------------------------------------------------------------
103//
104// Globals and misc other
105//
106
107GPTR_IMPL(IGCHeap,g_pGCHeap);
108
109BOOL g_fEEOtherStartup=FALSE;
110BOOL g_fEEComActivatedStartup=FALSE;
111
112GVAL_IMPL_INIT(DWORD, g_fHostConfig, 0);
113
114GVAL_IMPL_INIT(GCHeapType, g_heap_type, GC_HEAP_WKS);
115
116void UpdateGCSettingFromHost()
117{
118}
119
120HRESULT GetExceptionHResult(OBJECTREF throwable)
121{
122 return E_FAIL;
123}
124
125//---------------------------------------------------------------------------------------
126//
127// Dynamically unreachable implementation of profiler callbacks. Note that we can't just
128// disable PROFILING_SUPPORTED for crossgen because of it affects data layout and FCall tables.
129//
130
131UINT_PTR EEToProfInterfaceImpl::EEFunctionIDMapper(FunctionID funcId, BOOL * pbHookFunction)
132{
133 UNREACHABLE();
134}
135
136HRESULT EEToProfInterfaceImpl::JITInlining(
137 /* [in] */ FunctionID callerId,
138 /* [in] */ FunctionID calleeId,
139 /* [out] */ BOOL * pfShouldInline)
140{
141 UNREACHABLE();
142}
143
144HRESULT EEToProfInterfaceImpl::ModuleLoadStarted(ModuleID moduleId)
145{
146 UNREACHABLE();
147}
148
149HRESULT EEToProfInterfaceImpl::ModuleLoadFinished(
150 ModuleID moduleId,
151 HRESULT hrStatus)
152{
153 UNREACHABLE();
154}
155
156HRESULT EEToProfInterfaceImpl::ModuleUnloadStarted(
157 ModuleID moduleId)
158{
159 UNREACHABLE();
160}
161
162HRESULT EEToProfInterfaceImpl::ModuleUnloadFinished(
163 ModuleID moduleId,
164 HRESULT hrStatus)
165{
166 UNREACHABLE();
167}
168
169HRESULT EEToProfInterfaceImpl::ModuleAttachedToAssembly(
170 ModuleID moduleId,
171 AssemblyID AssemblyId)
172{
173 UNREACHABLE();
174}
175
176HRESULT EEToProfInterfaceImpl::ClassLoadStarted(
177 ClassID classId)
178{
179 UNREACHABLE();
180}
181
182HRESULT EEToProfInterfaceImpl::ClassLoadFinished(
183 ClassID classId,
184 HRESULT hrStatus)
185{
186 UNREACHABLE();
187}
188
189HRESULT EEToProfInterfaceImpl::AppDomainCreationFinished(
190 AppDomainID appDomainId,
191 HRESULT hrStatus)
192{
193 UNREACHABLE();
194}
195
196HRESULT EEToProfInterfaceImpl::AppDomainCreationStarted(
197 AppDomainID appDomainId)
198{
199 UNREACHABLE();
200}
201
202HRESULT EEToProfInterfaceImpl::AppDomainShutdownFinished(
203 AppDomainID appDomainId,
204 HRESULT hrStatus)
205{
206 UNREACHABLE();
207}
208
209HRESULT EEToProfInterfaceImpl::AppDomainShutdownStarted(
210 AppDomainID appDomainId)
211{
212 UNREACHABLE();
213}
214
215HRESULT EEToProfInterfaceImpl::AssemblyLoadStarted(
216 AssemblyID assemblyId)
217{
218 UNREACHABLE();
219}
220
221HRESULT EEToProfInterfaceImpl::AssemblyLoadFinished(
222 AssemblyID assemblyId,
223 HRESULT hrStatus)
224{
225 UNREACHABLE();
226}
227
228ClassID TypeHandleToClassID(TypeHandle th)
229{
230 UNREACHABLE();
231}
232
233//---------------------------------------------------------------------------------------
234//
235// Stubed-out implementations of functions that can do anything useful only when we are actually running managed code
236//
237
238FuncPtrStubs::FuncPtrStubs()
239 : m_hashTableCrst(CrstFuncPtrStubs, CRST_UNSAFE_ANYMODE)
240{
241}
242
243PCODE MethodDesc::GetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags)
244{
245 return 0x321;
246}
247
248PCODE MethodDesc::TryGetMultiCallableAddrOfCode(CORINFO_ACCESS_FLAGS accessFlags)
249{
250 return 0x321;
251}
252
253#ifdef _TARGET_AMD64_
254INT32 rel32UsingJumpStub(INT32 UNALIGNED * pRel32, PCODE target, MethodDesc *pMethod,
255 LoaderAllocator *pLoaderAllocator /* = NULL */, bool throwOnOutOfMemoryWithinRange /*= true*/)
256{
257 // crossgen does not have jump stubs
258 return 0;
259}
260
261INT32 rel32UsingPreallocatedJumpStub(INT32 UNALIGNED * pRel32, PCODE target, PCODE jumpStubAddr, bool emitJump)
262{
263 // crossgen does not have jump stubs
264 return 0;
265}
266#endif
267
268
269CORINFO_GENERIC_HANDLE JIT_GenericHandleWorker(MethodDesc * pMD, MethodTable * pMT, LPVOID signature, DWORD dictionaryIndexAndSlot, Module* pModule)
270{
271 UNREACHABLE();
272}
273
274void CrawlFrame::GetExactGenericInstantiations(Instantiation *pClassInst, Instantiation *pMethodInst)
275{
276 UNREACHABLE();
277}
278
279BOOL Object::SupportsInterface(OBJECTREF pObj, MethodTable* pInterfaceMT)
280{
281 UNREACHABLE();
282}
283
284GCFrame::GCFrame(OBJECTREF *pObjRefs, UINT numObjRefs, BOOL maybeInterior)
285{
286}
287
288void GCFrame::GcScanRoots(promote_func *fn, ScanContext* sc)
289{
290 UNREACHABLE();
291}
292
293void HijackFrame::GcScanRoots(promote_func *fn, ScanContext* sc)
294{
295 UNREACHABLE();
296}
297
298VOID GCFrame::Pop()
299{
300}
301
302void Frame::Push()
303{
304}
305
306void Frame::Pop()
307{
308}
309
310PCODE COMDelegate::GetSecureInvoke(MethodDesc* pMD)
311{
312 return (PCODE)(0x12345);
313}
314
315Assembly * SystemDomain::GetCallersAssembly(StackCrawlMark * stackMark, AppDomain ** ppAppDomain)
316{
317 return NULL;
318}
319
320void EnableStressHeapHelper()
321{
322 UNREACHABLE();
323}
324
325void ReflectionModule::CaptureModuleMetaDataToMemory()
326{
327}
328
329//---------------------------------------------------------------------------------------
330//
331// Empty implementations of shutdown-related functions. We don't do any cleanup for shutdown during crossgen.
332//
333
334Assembly::~Assembly()
335{
336}
337
338void Assembly::StartUnload()
339{
340}
341
342void Module::StartUnload()
343{
344}
345
346void DynamicMethodTable::Destroy()
347{
348}
349
350void SyncClean::AddEEHashTable(EEHashEntry** entry)
351{
352}
353
354void SyncClean::AddHashMap(Bucket *bucket)
355{
356}
357
358#ifdef FEATURE_COMINTEROP
359LONG ComCallWrapperTemplate::Release()
360{
361 UNREACHABLE();
362}
363#endif
364
365extern "C" UINT_PTR STDCALL GetCurrentIP()
366{
367 return 0;
368}
369
370void EEPolicy::HandleFatalError(UINT exitCode, UINT_PTR address, LPCWSTR pszMessage, PEXCEPTION_POINTERS pExceptionInfo, LPCWSTR errorSource, LPCWSTR argExceptionString)
371{
372 fprintf(stderr, "Fatal error: %08x\n", exitCode);
373 ExitProcess(exitCode);
374}
375
376//---------------------------------------------------------------------------------------
377
378Assembly * AppDomain::RaiseAssemblyResolveEvent(AssemblySpec * pSpec)
379{
380 return NULL;
381}
382
383Assembly * AppDomain::RaiseResourceResolveEvent(DomainAssembly* pAssembly, LPCSTR szName)
384{
385 return NULL;
386}
387
388DomainAssembly * AppDomain::RaiseTypeResolveEventThrowing(DomainAssembly* pAssembly, LPCSTR szName, ASSEMBLYREF *pResultingAssemblyRef)
389{
390 return NULL;
391}
392
393void AppDomain::RaiseLoadingAssemblyEvent(DomainAssembly *pAssembly)
394{
395}
396