2 // Copyright (c) Microsoft. All rights reserved.
3 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 //*****************************************************************************
11 // Class factories are used by the pluming in COM to activate new objects.
12 // This module contains the class factory code to instantiate the debugger
13 // objects described in <cordb.h>.
15 //*****************************************************************************
17 #ifndef __CorHost__h__
18 #define __CorHost__h__
21 #include "windows.h" // worth to include before mscoree.h so we are guaranteed to pick few definitions
22 #ifdef CreateSemaphore
23 #undef CreateSemaphore
28 #include "clrinternal.h"
30 #include "ivehandler.h"
31 #include "ivalidator.h"
37 #if defined(FEATURE_HOSTED_BINDER)
38 #include "clrprivhosting.h"
41 #ifdef FEATURE_COMINTEROP
42 #include "activation.h" // WinRT activation.
45 class DangerousNonHostedSpinLock;
47 #define INVALID_STACK_BASE_MARKER_FOR_CHECK_STATE 2
50 #if (_WIN32_WINNT < 0x0500)
51 typedef VOID (__stdcall *WAITORTIMERCALLBACK)(PVOID, BOOL);
58 #if !defined(FEATURE_CORECLR)
59 class CorThreadpool : public ICorThreadpool
62 HRESULT STDMETHODCALLTYPE CorRegisterWaitForSingleObject(PHANDLE phNewWaitObject,
64 WAITORTIMERCALLBACK Callback,
70 HRESULT STDMETHODCALLTYPE CorBindIoCompletionCallback(HANDLE fileHandle, LPOVERLAPPED_COMPLETION_ROUTINE callback);
72 HRESULT STDMETHODCALLTYPE CorUnregisterWait(HANDLE hWaitObject,HANDLE CompletionEvent, BOOL* pResult);
74 HRESULT STDMETHODCALLTYPE CorQueueUserWorkItem(LPTHREAD_START_ROUTINE Function,PVOID Context,BOOL executeOnlyOnce, BOOL* pResult );
76 HRESULT STDMETHODCALLTYPE CorCallOrQueueUserWorkItem(LPTHREAD_START_ROUTINE Function,PVOID Context,BOOL* pResult );
78 HRESULT STDMETHODCALLTYPE CorCreateTimer(PHANDLE phNewTimer,
79 WAITORTIMERCALLBACK Callback,
85 HRESULT STDMETHODCALLTYPE CorDeleteTimer(HANDLE Timer, HANDLE CompletionEvent, BOOL* pResult);
87 HRESULT STDMETHODCALLTYPE CorChangeTimer(HANDLE Timer,ULONG DueTime,ULONG Period, BOOL* pResult);
89 HRESULT STDMETHODCALLTYPE CorSetMaxThreads(DWORD MaxWorkerThreads,
90 DWORD MaxIOCompletionThreads);
92 HRESULT STDMETHODCALLTYPE CorGetMaxThreads(DWORD *MaxWorkerThreads,
93 DWORD *MaxIOCompletionThreads);
95 HRESULT STDMETHODCALLTYPE CorGetAvailableThreads(DWORD *AvailableWorkerThreads,
96 DWORD *AvailableIOCompletionThreads);
99 class CorGCHost : public IGCHost2
103 STDMETHODIMP STDMETHODCALLTYPE SetGCStartupLimits(
107 STDMETHODIMP STDMETHODCALLTYPE Collect(
110 STDMETHODIMP STDMETHODCALLTYPE GetStats(
111 COR_GC_STATS *pStats);
113 STDMETHODIMP STDMETHODCALLTYPE GetThreadStats(
115 COR_GC_THREAD_STATS *pStats);
117 STDMETHODIMP STDMETHODCALLTYPE SetVirtualMemLimit(
118 SIZE_T sztMaxVirtualMemMB);
121 STDMETHODIMP STDMETHODCALLTYPE SetGCStartupLimitsEx(
127 HRESULT _SetGCSegmentSize(SIZE_T SegmentSize);
128 HRESULT _SetGCMaxGen0Size(SIZE_T MaxGen0Size);
131 class CorConfiguration : public ICorConfiguration
134 virtual HRESULT STDMETHODCALLTYPE SetGCThreadControl(
135 /* [in] */ IGCThreadControl __RPC_FAR *pGCThreadControl);
137 virtual HRESULT STDMETHODCALLTYPE SetGCHostControl(
138 /* [in] */ IGCHostControl __RPC_FAR *pGCHostControl);
140 virtual HRESULT STDMETHODCALLTYPE SetDebuggerThreadControl(
141 /* [in] */ IDebuggerThreadControl __RPC_FAR *pDebuggerThreadControl);
143 virtual HRESULT STDMETHODCALLTYPE AddDebuggerSpecialThread(
144 /* [in] */ DWORD dwSpecialThreadId);
146 // This mechanism isn't thread-safe with respect to reference counting, because
147 // the runtime will use the cached pointer without adding extra refcounts to protect
148 // itself. So if one thread calls GetGCThreadControl & another thread calls
149 // ICorHost::SetGCThreadControl, we have a race.
150 static IGCThreadControl *GetGCThreadControl()
152 LIMITED_METHOD_CONTRACT;
154 return m_CachedGCThreadControl;
157 static IGCHostControl *GetGCHostControl()
159 LIMITED_METHOD_CONTRACT;
161 return m_CachedGCHostControl;
164 static IDebuggerThreadControl *GetDebuggerThreadControl()
166 LIMITED_METHOD_CONTRACT;
168 return m_CachedDebuggerThreadControl;
171 static DWORD GetDebuggerSpecialThreadCount()
173 LIMITED_METHOD_CONTRACT;
178 static DWORD *GetDebuggerSpecialThreadArray()
180 LIMITED_METHOD_CONTRACT;
185 // Helper function that returns true if the thread is in the debugger special thread list
186 static BOOL IsDebuggerSpecialThread(DWORD dwThreadId);
188 // Helper function to update the thread list in the debugger control block
189 static HRESULT RefreshDebuggerSpecialThreadList();
191 // Clean up debugger thread control object, called at shutdown
192 static void CleanupDebuggerThreadControl();
195 // Cache the IGCThreadControl interface until the EE is started, at which point
196 // we pass it through.
197 static IGCThreadControl *m_CachedGCThreadControl;
198 static IGCHostControl *m_CachedGCHostControl;
199 static IDebuggerThreadControl *m_CachedDebuggerThreadControl;
201 // Array of ID's of threads that should be considered "special" to
202 // the debugging services.
203 static DWORD *m_DSTArray;
204 static DWORD m_DSTArraySize;
205 static DWORD m_DSTCount;
208 class CorValidator : public IValidator
211 CorValidator() {LIMITED_METHOD_CONTRACT;}
214 STDMETHODIMP STDMETHODCALLTYPE Validate(
216 IUnknown *pAppDomain,
217 unsigned long ulFlags,
218 unsigned long ulMaxError,
220 __in_z LPWSTR fileName,
222 unsigned long ulSize);
224 STDMETHODIMP STDMETHODCALLTYPE FormatEventInfo(
227 __out_ecount(ulMaxLength) LPWSTR msg,
228 unsigned long ulMaxLength,
232 class CLRValidator : public ICLRValidator
235 CLRValidator() {LIMITED_METHOD_CONTRACT;}
238 STDMETHODIMP STDMETHODCALLTYPE Validate(
240 unsigned long ulAppDomainId,
241 unsigned long ulFlags,
242 unsigned long ulMaxError,
244 __in_z LPWSTR fileName,
246 unsigned long ulSize);
248 STDMETHODIMP STDMETHODCALLTYPE FormatEventInfo(
251 __out_ecount(ulMaxLength) LPWSTR msg,
252 unsigned long ulMaxLength,
256 class CorDebuggerInfo : public IDebuggerInfo
259 STDMETHODIMP IsDebuggerAttached(BOOL *pbAttached);
261 #endif // !defined(FEATURE_CORECLR)
263 class CorExecutionManager
264 : public ICLRExecutionManager
267 CorExecutionManager();
269 STDMETHODIMP STDMETHODCALLTYPE Pause(DWORD dwAppDomainId, DWORD dwFlags);
270 STDMETHODIMP STDMETHODCALLTYPE Resume(DWORD dwAppDomainId);
273 DWORD m_dwFlags; //flags passed to the last Pause call.
274 INT64 m_pauseStartTime;
277 class CorRuntimeHostBase
283 #ifdef FEATURE_CORECLR
285 #endif // FEATURE_CORECLR
286 {LIMITED_METHOD_CONTRACT;}
288 STDMETHODIMP_(ULONG) AddRef(void);
290 // Starts the runtime. This is equivalent to CoInitializeCor()
291 STDMETHODIMP Start();
293 #ifdef FEATURE_COMINTEROP
294 // Creates a domain in the runtime. The identity array is
295 // a pointer to an array TYPE containing IIdentity objects defining
296 // the security identity.
297 STDMETHODIMP CreateDomain(LPCWSTR pwzFriendlyName, // Optional
298 IUnknown* pIdentityArray, // Optional
299 IUnknown ** pAppDomain);
301 // Returns the default domain.
302 STDMETHODIMP GetDefaultDomain(IUnknown ** pAppDomain);
304 // Enumerate currently existing domains.
305 STDMETHODIMP EnumDomains(HDOMAINENUM *hEnum);
307 // Returns S_FALSE when there are no more domains. A domain
308 // is passed out only when S_OK is returned.
309 STDMETHODIMP NextDomain(HDOMAINENUM hEnum,
310 IUnknown** pAppDomain);
312 // Close the enumeration releasing resources
313 STDMETHODIMP CloseEnum(HDOMAINENUM hEnum);
315 STDMETHODIMP CreateDomainEx(LPCWSTR pwzFriendlyName,
316 IUnknown* pSetup, // Optional
317 IUnknown* pEvidence, // Optional
318 IUnknown ** pAppDomain);
320 // Create appdomain setup object that can be passed into CreateDomainEx
321 STDMETHODIMP CreateDomainSetup(IUnknown** pAppDomainSetup);
323 // Create Evidence object that can be passed into CreateDomainEx
324 STDMETHODIMP CreateEvidence(IUnknown** pEvidence);
326 // Unload a domain, releasing the reference will only release the
327 // the wrapper to the domain not unload the domain.
328 STDMETHODIMP UnloadDomain(IUnknown* pAppDomain);
330 // Returns the threads domain if there is one.
331 STDMETHODIMP CurrentDomain(IUnknown ** pAppDomain);
332 #endif // FEATURE_COMINTEROP
334 STDMETHODIMP MapFile( // Return code.
335 HANDLE hFile, // [in] Handle for file
336 HMODULE *hMapAddress // [out] HINSTANCE for mapped file
339 STDMETHODIMP LocksHeldByLogicalThread( // Return code.
340 DWORD *pCount // [out] Number of locks that the current thread holds.
344 BOOL m_Started; // Has START been called?
346 LONG m_cRef; // Ref count.
348 #ifdef FEATURE_CORECLR
349 // This flag will be used to ensure that a CoreCLR host can invoke Start/Stop in pairs only.
351 BOOL m_fAppDomainCreated; // this flag is used when an appdomain can only create a single appdomain
352 #endif // FEATURE_CORECLR
354 static ULONG m_Version; // Version of ICorRuntimeHost.
355 // Some functions are only available in ICLRRuntimeHost.
356 // Some functions are no-op in ICLRRuntimeHost.
358 STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
361 static ULONG GetHostVersion()
363 LIMITED_METHOD_CONTRACT;
364 _ASSERTE (m_Version != 0);
370 #if !defined(FEATURE_CORECLR) // simple hosting
372 public CorRuntimeHostBase, public ICorRuntimeHost, public CorThreadpool
373 , public CorGCHost, public CorConfiguration
374 , public CorValidator, public CorDebuggerInfo
375 , public CorExecutionManager
378 CorHost() {WRAPPER_NO_CONTRACT;}
380 // *** IUnknown methods ***
381 STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
382 STDMETHODIMP_(ULONG) AddRef(void)
385 STATIC_CONTRACT_SO_TOLERANT;
386 return CorRuntimeHostBase::AddRef();
388 STDMETHODIMP_(ULONG) Release(void);
391 // *** ICorRuntimeHost methods ***
392 // Returns an object for configuring the runtime prior to
393 // it starting. If the runtime has been initialized this
394 // routine returns an error. See ICorConfiguration.
395 STDMETHODIMP GetConfiguration(ICorConfiguration** pConfiguration);
398 // Starts the runtime. This is equivalent to CoInitializeCor();
399 STDMETHODIMP Start(void);
403 // Creates a domain in the runtime. The identity array is
404 // a pointer to an array TYPE containing IIdentity objects defining
405 // the security identity.
406 STDMETHODIMP CreateDomain(LPCWSTR pwzFriendlyName, // Optional
407 IUnknown* pIdentityArray, // Optional
408 IUnknown ** pAppDomain)
411 STATIC_CONTRACT_SO_TOLERANT;
412 return CorRuntimeHostBase::CreateDomain(pwzFriendlyName,pIdentityArray,pAppDomain);
415 // Returns the default domain.
416 STDMETHODIMP GetDefaultDomain(IUnknown ** pAppDomain)
419 STATIC_CONTRACT_SO_TOLERANT;
420 return CorRuntimeHostBase::GetDefaultDomain(pAppDomain);
423 // Enumerate currently existing domains.
424 STDMETHODIMP EnumDomains(HDOMAINENUM *hEnum)
427 STATIC_CONTRACT_SO_TOLERANT;
428 return CorRuntimeHostBase::EnumDomains(hEnum);
431 // Returns S_FALSE when there are no more domains. A domain
432 // is passed out only when S_OK is returned.
433 STDMETHODIMP NextDomain(HDOMAINENUM hEnum,
434 IUnknown** pAppDomain)
437 STATIC_CONTRACT_SO_TOLERANT;
438 return CorRuntimeHostBase::NextDomain(hEnum,pAppDomain);
441 // Close the enumeration releasing resources
442 STDMETHODIMP CloseEnum(HDOMAINENUM hEnum)
445 STATIC_CONTRACT_SO_TOLERANT;
446 return CorRuntimeHostBase::CloseEnum(hEnum);
449 STDMETHODIMP CreateDomainEx(LPCWSTR pwzFriendlyName,
450 IUnknown* pSetup, // Optional
451 IUnknown* pEvidence, // Optional
452 IUnknown ** pAppDomain)
455 STATIC_CONTRACT_SO_TOLERANT;
456 return CorRuntimeHostBase::CreateDomainEx(pwzFriendlyName,pSetup,pEvidence,pAppDomain);
459 // Create appdomain setup object that can be passed into CreateDomainEx
460 STDMETHODIMP CreateDomainSetup(IUnknown** pAppDomainSetup)
463 STATIC_CONTRACT_SO_TOLERANT;
464 return CorRuntimeHostBase::CreateDomainSetup(pAppDomainSetup);
467 // Create Evidence object that can be passed into CreateDomainEx
468 STDMETHODIMP CreateEvidence(IUnknown** pEvidence)
471 STATIC_CONTRACT_SO_TOLERANT;
472 return CorRuntimeHostBase::CreateEvidence(pEvidence);
475 // Unload a domain, releasing the reference will only release the
476 // the wrapper to the domain not unload the domain.
477 STDMETHODIMP UnloadDomain(IUnknown* pAppDomain)
480 STATIC_CONTRACT_SO_TOLERANT;
481 return CorRuntimeHostBase::UnloadDomain(pAppDomain);
484 // Returns the threads domain if there is one.
485 STDMETHODIMP CurrentDomain(IUnknown ** pAppDomain)
488 STATIC_CONTRACT_SO_TOLERANT;
489 return CorRuntimeHostBase::CurrentDomain(pAppDomain);
492 // TODO: Following 4 APIs should be move to CorHost for V1.
493 STDMETHODIMP CreateLogicalThreadState(); // Return code.
494 STDMETHODIMP DeleteLogicalThreadState(); // Return code.
495 STDMETHODIMP SwitchInLogicalThreadState( // Return code.
496 DWORD *pFiberCookie // [in] Cookie that indicates the fiber to use.
499 STDMETHODIMP SwitchOutLogicalThreadState( // Return code.
500 DWORD **pFiberCookie // [out] Cookie that indicates the fiber being switched out.
503 STDMETHODIMP LocksHeldByLogicalThread( // Return code.
504 DWORD *pCount // [out] Number of locks that the current thread holds.
508 STATIC_CONTRACT_SO_TOLERANT;
509 return CorRuntimeHostBase::LocksHeldByLogicalThread(pCount);
512 // Class factory hook-up.
513 static HRESULT CreateObject(REFIID riid, void **ppUnk);
515 STDMETHODIMP MapFile( // Return code.
516 HANDLE hFile, // [in] Handle for file
517 HMODULE *hMapAddress // [out] HINSTANCE for mapped file
521 STATIC_CONTRACT_SO_TOLERANT;
522 return CorRuntimeHostBase::MapFile(hFile,hMapAddress);
525 #endif // !defined(FEATURE_CORECLR)
527 class ConnectionNameTable;
528 typedef DPTR(class ConnectionNameTable) PTR_ConnectionNameTable;
532 // Defines the precedence (in increading oder) of the two symbol reading knobs
533 enum ESymbolReadingSetBy
535 eSymbolReadingSetByDefault,
536 eSymbolReadingSetByConfig, // EEConfig - config file, env var, etc.
537 eSymbolReadingSetByHost, // Hosting API - highest precedence
538 eSymbolReadingSetBy_COUNT
541 #ifdef FEATURE_INCLUDE_ALL_INTERFACES
542 // Hash table entry to keep track <connection, name> for SQL fiber support
543 typedef DPTR(struct ConnectionNameHashEntry) PTR_ConnectionNameHashEntry;
544 struct ConnectionNameHashEntry
547 CONNID m_dwConnectionId;
549 ICLRTask **m_ppCLRTaskArray;
554 class CCLRDebugManager : public ICLRDebugManager
557 CCLRDebugManager() {LIMITED_METHOD_CONTRACT;};
559 STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
560 STDMETHODIMP_(ULONG) AddRef(void)
562 LIMITED_METHOD_CONTRACT;
565 STDMETHODIMP_(ULONG) Release(void);
567 // ICLRTDebugManager's interface
568 STDMETHODIMP BeginConnection(
569 CONNID dwConnectionId,
570 __in_z wchar_t *szConnectionName);
571 STDMETHODIMP SetConnectionTasks(
574 ICLRTask **ppCLRTask);
575 STDMETHODIMP EndConnection(
576 CONNID dwConnectionId);
578 // Set ACL on shared section, events, and process
579 STDMETHODIMP SetDacl(PACL pacl);
581 // Returning the current ACL that CLR is using
582 STDMETHODIMP GetDacl(PACL *pacl);
584 STDMETHODIMP IsDebuggerAttached(BOOL *pbAttached);
586 // symbol reading policy - include file line info when getting a call stack etc.
587 STDMETHODIMP SetSymbolReadingPolicy(ESymbolReadingPolicy policy);
589 #ifdef DACCESS_COMPILE
590 // Expose iterators for DAC. Debugger can use this on attach to find existing Connections.
594 // ConnectionNameHashEntry * pConnection = FindFirst(&h);
595 // while(pConnection != NULL) {
596 // DoSomething(pConnection);
597 // pConnection = FindNext(&h);
599 static ConnectionNameHashEntry * FindFirst(HASHFIND * pHashfind);
600 static ConnectionNameHashEntry * FindNext(HASHFIND * pHashfind);
603 static void ProcessInit();
604 static void ProcessCleanup();
606 // Get the current symbol reading policy setting
607 static ESymbolReadingPolicy GetSymbolReadingPolicy()
609 return m_symbolReadingPolicy;
612 // Set the symbol reading policy if the setter has higher precendence than the current setting
613 static void SetSymbolReadingPolicy( ESymbolReadingPolicy policy, ESymbolReadingSetBy setBy );
616 static CrstStatic m_lockConnectionNameTable;
617 SPTR_DECL(ConnectionNameTable, m_pConnectionNameHash);
619 static ESymbolReadingPolicy m_symbolReadingPolicy;
620 static ESymbolReadingSetBy m_symbolReadingSetBy;
623 #endif // FEATURE_INCLUDE_ALL_INTERFACES
625 #if defined(FEATURE_INCLUDE_ALL_INTERFACES) || defined(FEATURE_WINDOWSPHONE)
626 class CCLRErrorReportingManager :
627 #ifdef FEATURE_WINDOWSPHONE
628 public ICLRErrorReportingManager2
630 public ICLRErrorReportingManager
631 #endif // FEATURE_WINDOWSPHONE
633 friend class ClrDataAccess;
634 friend struct _DacGlobals;
636 SVAL_DECL(ECustomDumpFlavor, g_ECustomDumpFlavor);
638 #ifdef FEATURE_WINDOWSPHONE
639 WCHAR* m_pApplicationId;
640 WCHAR* m_pInstanceId;
642 class BucketParamsCache
646 DWORD const m_cMaxParams;
648 BucketParamsCache(DWORD maxNumParams);
649 ~BucketParamsCache();
651 WCHAR const* GetAt(BucketParameterIndex index);
652 HRESULT SetAt(BucketParameterIndex index, WCHAR const* val);
655 BucketParamsCache* m_pBucketParamsCache;
657 HRESULT CopyToDataCache(WCHAR** pTarget, WCHAR const* pSource);
658 #endif // FEATURE_WINDOWSPHONE
661 CCLRErrorReportingManager();
662 ~CCLRErrorReportingManager();
664 STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
665 STDMETHODIMP_(ULONG) AddRef(void);
666 STDMETHODIMP_(ULONG) Release(void);
668 // ICLRErrorReportingManager APIs //
670 // Get Watson bucket parameters for "current" exception (on calling thread).
671 STDMETHODIMP GetBucketParametersForCurrentException(BucketParameters *pParams);
672 STDMETHODIMP BeginCustomDump( ECustomDumpFlavor dwFlavor,
674 CustomDumpItem items[],
676 STDMETHODIMP EndCustomDump();
678 #ifdef FEATURE_WINDOWSPHONE
679 // ICLRErrorReportingManager2 APIs //
681 STDMETHODIMP SetApplicationData(ApplicationDataKey key, WCHAR const* pValue);
682 STDMETHODIMP SetBucketParametersForUnhandledException(BucketParameters const* pBucketParams, DWORD* pCountParams);
686 // returns the application data for the specified key if available, else returns NULL.
687 WCHAR const* GetApplicationData(ApplicationDataKey key);
689 // returns bucket parameter override data if available, else returns NULL.
690 WCHAR const* GetBucketParamOverride(BucketParameterIndex bucketParamId);
691 #endif // FEATURE_WINDOWSPHONE
694 extern CCLRErrorReportingManager g_CLRErrorReportingManager;
695 #endif // defined(FEATURE_INCLUDE_ALL_INTERFACES) || defined(FEATURE_WINDOWSPHONE)
697 #ifdef FEATURE_IPCMAN
699 // consolidate the following class with DebuggerManager.
701 class CCLRSecurityAttributeManager
705 // Set ACL on shared section, events, and process
706 STDMETHODIMP SetDACL(PACL pacl);
708 // Returning the current ACL that CLR is using
709 STDMETHODIMP GetDACL(PACL *pacl);
711 static void ProcessInit();
712 static void ProcessCleanUp();
714 // retrieving Host security attribute setting. If host does not set it, default to
715 // our default policy.
716 static HRESULT GetHostSecurityAttributes(SECURITY_ATTRIBUTES **ppSA);
717 static void DestroyHostSecurityAttributes(SECURITY_ATTRIBUTES *pSA);
719 static CrstStatic m_hostSAMutex;
724 // Security attributes cached for the current process.
725 static SECURITY_ATTRIBUTES m_hostSA;
726 static SECURITY_DESCRIPTOR m_hostSD;
728 static HRESULT CopyACL(PACL pAclOriginal, PACL ppAclNew);
730 #endif // FEATURE_IPCMAN
733 public CorRuntimeHostBase
735 , public IPrivateManagedExceptionReporting /* This interface is for internal Watson testing only*/
736 #endif // FEATURE_PAL
737 #ifdef FEATURE_CORECLR
738 , public ICLRRuntimeHost2
740 , public CorThreadpool
742 , public CorConfiguration
743 , public CLRValidator
744 , public CorDebuggerInfo
745 , public ICLRRuntimeHost
746 #endif // FEATURE_CORECLR
747 #if defined(FEATURE_HOSTED_BINDER) && !defined(FEATURE_CORECLR)
748 , public ICLRPrivRuntime
750 , public CorExecutionManager
752 friend struct _DacGlobals;
757 // *** IUnknown methods ***
758 STDMETHODIMP QueryInterface(REFIID riid, void** ppv);
759 STDMETHODIMP_(ULONG) AddRef(void)
762 return CorRuntimeHostBase::AddRef();
764 STDMETHODIMP_(ULONG) Release(void);
767 // *** ICorRuntimeHost methods ***
768 #ifndef FEATURE_CORECLR
769 // Returns an object for configuring the runtime prior to
770 // it starting. If the runtime has been initialized this
771 // routine returns an error. See ICorConfiguration.
772 STDMETHODIMP GetConfiguration(ICorConfiguration** pConfiguration);
773 #endif // FEATURE_CORECLR
776 // defined in IPrivateManagedExceptionReporting interface for internal Watson testing only
777 STDMETHODIMP GetBucketParametersForCurrentException(BucketParameters *pParams);
778 #endif // FEATURE_PAL
780 // Starts the runtime. This is equivalent to CoInitializeCor().
781 STDMETHODIMP Start();
784 STDMETHODIMP ExecuteInAppDomain(DWORD dwAppDomainId,
785 FExecuteInAppDomainCallback pCallback,
788 STDMETHODIMP LocksHeldByLogicalThread( // Return code.
789 DWORD *pCount // [out] Number of locks that the current thread holds.
793 return CorRuntimeHostBase::LocksHeldByLogicalThread(pCount);
796 // Class factory hook-up.
797 static HRESULT CreateObject(REFIID riid, void **ppUnk);
799 STDMETHODIMP MapFile( // Return code.
800 HANDLE hFile, // [in] Handle for file
801 HMODULE *hMapAddress // [out] HINSTANCE for mapped file
805 return CorRuntimeHostBase::MapFile(hFile,hMapAddress);
808 STDMETHODIMP STDMETHODCALLTYPE SetHostControl(
809 IHostControl* pHostControl);
811 STDMETHODIMP STDMETHODCALLTYPE GetCLRControl(
812 ICLRControl** pCLRControl);
814 STDMETHODIMP UnloadAppDomain(DWORD dwDomainId, BOOL fWaitUntilDone);
816 STDMETHODIMP GetCurrentAppDomainId(DWORD *pdwAppDomainId);
818 STDMETHODIMP ExecuteApplication(LPCWSTR pwzAppFullName,
819 DWORD dwManifestPaths,
820 LPCWSTR *ppwzManifestPaths,
821 DWORD dwActivationData,
822 LPCWSTR *ppwzActivationData,
825 STDMETHODIMP ExecuteInDefaultAppDomain(LPCWSTR pwzAssemblyPath,
827 LPCWSTR pwzMethodName,
829 DWORD *pReturnValue);
831 #ifdef FEATURE_CORECLR
832 // *** ICLRRuntimeHost2 methods ***
833 STDMETHODIMP CreateAppDomainWithManager(
834 LPCWSTR wszFriendlyName,
835 DWORD dwSecurityFlags,
836 LPCWSTR wszAppDomainManagerAssemblyName,
837 LPCWSTR wszAppDomainManagerTypeName,
839 LPCWSTR* pPropertyNames,
840 LPCWSTR* pPropertyValues,
841 DWORD* pAppDomainID);
843 STDMETHODIMP CreateDelegate(
845 LPCWSTR wszAssemblyName,
846 LPCWSTR wszClassName,
847 LPCWSTR wszMethodName,
850 STDMETHODIMP Authenticate(ULONGLONG authKey);
852 STDMETHODIMP RegisterMacEHPort();
853 STDMETHODIMP SetStartupFlags(STARTUP_FLAGS flag);
854 STDMETHODIMP DllGetActivationFactory(
857 IActivationFactory ** factory);
859 STDMETHODIMP ExecuteAssembly(
861 LPCWSTR pwzAssemblyPath,
864 DWORD* pReturnValue);
866 #endif // !FEATURE_CORECLR
868 #if defined(FEATURE_HOSTED_BINDER) && !defined(FEATURE_CORECLR)
869 /**********************************************************************************
870 ** ICLRPrivRuntime Methods
871 **********************************************************************************/
872 STDMETHODIMP GetInterface(
877 STDMETHODIMP CreateAppDomain(
878 LPCWSTR pwzFriendlyName,
879 ICLRPrivBinder * pBinder,
880 LPDWORD pdwAppDomainId);
882 STDMETHODIMP CreateDelegate(
884 LPCWSTR wszAssemblyName,
885 LPCWSTR wszClassName,
886 LPCWSTR wszMethodName,
887 LPVOID * ppvDelegate);
889 STDMETHODIMP ExecuteMain(
890 ICLRPrivBinder * pBinder,
893 #endif // FEATURE_HOSTED_BINDER && !FEATURE_CORECLR
895 static IHostControl *GetHostControl ()
897 LIMITED_METHOD_CONTRACT;
899 #ifdef FEATURE_CORECLR
901 #else // FEATURE_CORECLR
902 return m_HostControl;
903 #endif // FEATURE_CORECLR
906 #ifdef FEATURE_INCLUDE_ALL_INTERFACES
907 static IHostMemoryManager *GetHostMemoryManager ()
909 LIMITED_METHOD_CONTRACT;
911 #ifdef FEATURE_CORECLR
913 #else // FEATURE_CORECLR
914 return m_HostMemoryManager;
915 #endif // FEATURE_CORECLR
918 static IHostMalloc *GetHostMalloc ()
920 LIMITED_METHOD_CONTRACT;
922 #ifdef FEATURE_CORECLR
924 #else // FEATURE_CORECLR
926 #endif // FEATURE_CORECLR
929 static IHostTaskManager *GetHostTaskManager ()
931 LIMITED_METHOD_CONTRACT;
933 #ifdef FEATURE_CORECLR
935 #else // FEATURE_CORECLR
936 return m_HostTaskManager;
937 #endif // FEATURE_CORECLR
940 static IHostThreadpoolManager *GetHostThreadpoolManager ()
942 LIMITED_METHOD_CONTRACT;
944 #ifdef FEATURE_CORECLR
946 #else // FEATURE_CORECLR
947 return m_HostThreadpoolManager;
948 #endif // FEATURE_CORECLR
951 static IHostIoCompletionManager *GetHostIoCompletionManager ()
953 LIMITED_METHOD_CONTRACT;
955 #ifdef FEATURE_CORECLR
957 #else // FEATURE_CORECLR
958 return m_HostIoCompletionManager;
959 #endif // FEATURE_CORECLR
962 static IHostSyncManager *GetHostSyncManager ()
964 LIMITED_METHOD_CONTRACT;
966 #ifdef FEATURE_CORECLR
968 #else // FEATURE_CORECLR
969 return m_HostSyncManager;
970 #endif // FEATURE_CORECLR
973 static IHostAssemblyManager *GetHostAssemblyManager()
975 LIMITED_METHOD_CONTRACT;
977 #ifdef FEATURE_CORECLR
979 #else // FEATURE_CORECLR
980 return m_HostAssemblyManager;
981 #endif // FEATURE_CORECLR
984 static IHostGCManager *GetHostGCManager()
986 LIMITED_METHOD_CONTRACT;
988 #ifdef FEATURE_CORECLR
990 #else // FEATURE_CORECLR
991 return m_HostGCManager;
992 #endif // FEATURE_CORECLR
995 static IHostSecurityManager *GetHostSecurityManager()
997 LIMITED_METHOD_CONTRACT;
999 #ifdef FEATURE_CORECLR
1001 #else // FEATURE_CORECLR
1002 return m_HostSecurityManager;
1003 #endif // FEATURE_CORECLR
1006 static IHostPolicyManager *GetHostPolicyManager ()
1008 LIMITED_METHOD_CONTRACT;
1010 #ifdef FEATURE_CORECLR
1012 #else // FEATURE_CORECLR
1013 return m_HostPolicyManager;
1014 #endif // FEATURE_CORECLR
1016 #endif // FEATURE_INCLUDE_ALL_INTERFACES
1018 #ifdef FEATURE_LEGACYNETCF_DBG_HOST_CONTROL
1019 static IHostNetCFDebugControlManager *GetHostNetCFDebugControlManager ()
1021 LIMITED_METHOD_CONTRACT;
1022 return m_HostNetCFDebugControlManager;
1026 static int GetHostOverlappedExtensionSize()
1028 LIMITED_METHOD_CONTRACT;
1030 #ifdef FEATURE_CORECLR
1032 #else // FEATURE_CORECLR
1033 _ASSERTE (m_HostOverlappedExtensionSize != -1);
1034 return m_HostOverlappedExtensionSize;
1035 #endif // FEATURE_CORECLR
1038 #ifdef FEATURE_INCLUDE_ALL_INTERFACES
1039 static ICLRAssemblyReferenceList *GetHostDomainNeutralAsms()
1041 LIMITED_METHOD_CONTRACT;
1043 #ifdef FEATURE_CORECLR
1045 #else // FEATURE_CORECLR
1046 return m_pHostDomainNeutralAsms;
1047 #endif // FEATURE_CORECLR
1049 #endif // FEATURE_INCLUDE_ALL_INTERFACES
1051 #ifndef FEATURE_CORECLR
1052 static HRESULT SetFlagsAndHostConfig(STARTUP_FLAGS dwStartupFlags, LPCWSTR pwzHostConfigFile, BOOL fFinalize);
1053 static LPCWSTR GetHostConfigFile();
1055 static void GetDefaultAppDomainProperties(StringArrayList **ppPropertyNames, StringArrayList **ppPropertyValues);
1056 #endif // !FEATURE_CORECLR
1058 static STARTUP_FLAGS GetStartupFlags();
1060 #ifndef FEATURE_CORECLR
1061 static HRESULT SetPropertiesForDefaultAppDomain(DWORD nProperties,
1062 __in_ecount(nProperties) LPCWSTR *pwszPropertyNames,
1063 __in_ecount(nProperties) LPCWSTR *pwszPropertyValues);
1065 static HRESULT SetAppDomainManagerType(LPCWSTR wszAppDomainManagerAssembly,
1066 LPCWSTR wszAppDomainManagerType,
1067 EInitializeNewDomainFlags dwInitializeDomainFlags);
1068 #endif // FEATURE_CORECLR
1070 static LPCWSTR GetAppDomainManagerAsm();
1072 static LPCWSTR GetAppDomainManagerType();
1074 static EInitializeNewDomainFlags GetAppDomainManagerInitializeNewDomainFlags();
1076 static BOOL HasAppDomainManagerInfo()
1078 LIMITED_METHOD_CONTRACT;
1079 return GetAppDomainManagerAsm() != NULL && GetAppDomainManagerType() != NULL;
1082 static BOOL HasStarted()
1084 return m_RefCount != 0;
1087 static BOOL IsLoadFromBlocked(); // LoadFrom, LoadFile and Load(byte[]) are blocked in certain hosting scenarios
1090 #ifdef FEATURE_CORECLR
1091 // This flag indicates if this instance was the first to load and start CoreCLR
1092 BOOL m_fFirstToLoadCLR;
1094 // This flag indicates if the host has authenticated with us or not
1095 BOOL m_fIsHostAuthenticated;
1097 #endif // FEATURE_CORECLR
1099 #if defined(FEATURE_CORECLR) || defined(FEATURE_HOSTED_BINDER)
1100 // Helpers for both ICLRRuntimeHost2 and ICLRPrivRuntime
1101 HRESULT _CreateAppDomain(
1102 LPCWSTR wszFriendlyName,
1104 LPCWSTR wszAppDomainManagerAssemblyName,
1105 LPCWSTR wszAppDomainManagerTypeName,
1107 LPCWSTR* pPropertyNames,
1108 LPCWSTR* pPropertyValues,
1109 #if defined(FEATURE_HOSTED_BINDER) && !defined(FEATURE_CORECLR)
1110 ICLRPrivBinder* pBinder,
1112 DWORD* pAppDomainID);
1114 HRESULT _CreateDelegate(
1116 LPCWSTR wszAssemblyName,
1117 LPCWSTR wszClassName,
1118 LPCWSTR wszMethodName,
1120 #endif // defined(FEATURE_CORECLR) || defined(FEATURE_HOSTED_BINDER)
1122 #ifdef FEATURE_HOSTED_BINDER
1123 // entrypoint helper to be wrapped in a filter to process unhandled exceptions
1124 VOID ExecuteMainInner(Assembly* pRootAssembly);
1125 #endif // FEATURE_HOSTED_BINDER
1127 static LONG m_RefCount;
1129 static IHostControl *m_HostControl;
1131 static LPCWSTR s_wszAppDomainManagerAsm;
1132 static LPCWSTR s_wszAppDomainManagerType;
1133 static EInitializeNewDomainFlags s_dwDomainManagerInitFlags;
1135 #if !defined(FEATURE_CORECLR)
1136 static StringArrayList s_defaultDomainPropertyNames;
1137 static StringArrayList s_defaultDomainPropertyValues;
1140 static IHostMemoryManager *m_HostMemoryManager;
1141 static IHostMalloc *m_HostMalloc;
1142 static IHostTaskManager *m_HostTaskManager;
1143 static IHostThreadpoolManager *m_HostThreadpoolManager;
1144 static IHostIoCompletionManager *m_HostIoCompletionManager;
1145 static IHostSyncManager *m_HostSyncManager;
1146 static IHostAssemblyManager *m_HostAssemblyManager;
1147 static IHostGCManager *m_HostGCManager;
1148 static IHostSecurityManager *m_HostSecurityManager;
1149 static IHostPolicyManager *m_HostPolicyManager;
1150 static int m_HostOverlappedExtensionSize;
1151 static ICLRAssemblyReferenceList *m_pHostDomainNeutralAsms;
1153 static WCHAR m_wzHostConfigFile[_MAX_PATH];
1155 static BOOL m_dwFlagsFinalized;
1156 static DangerousNonHostedSpinLock m_FlagsLock; // protects the flags and host config
1157 #endif // !defined(FEATURE_CORECLR)
1159 #ifdef FEATURE_LEGACYNETCF_DBG_HOST_CONTROL
1161 static IHostNetCFDebugControlManager *m_HostNetCFDebugControlManager;
1164 SVAL_DECL(STARTUP_FLAGS, m_dwStartupFlags);
1167 #ifdef FEATURE_INCLUDE_ALL_INTERFACES
1168 class CorHostProtectionManager : public ICLRHostProtectionManager
1169 #else // !FEATURE_INCLUDE_ALL_INTERFACES
1170 class CorHostProtectionManager
1171 #endif // FEATURE_INCLUDE_ALL_INTERFACES
1174 EApiCategories m_eProtectedCategories;
1175 bool m_fEagerSerializeGrantSet;
1179 CorHostProtectionManager();
1182 HRESULT STDMETHODCALLTYPE QueryInterface(
1185 ULONG STDMETHODCALLTYPE AddRef();
1186 ULONG STDMETHODCALLTYPE Release();
1188 // Interface methods
1189 virtual HRESULT STDMETHODCALLTYPE SetProtectedCategories(/* [in] */ EApiCategories eFullTrustOnlyResources);
1190 virtual HRESULT STDMETHODCALLTYPE SetEagerSerializeGrantSets();
1193 EApiCategories GetProtectedCategories();
1194 bool GetEagerSerializeGrantSets() const;
1199 #ifdef FEATURE_COMINTEROP
1201 HRESULT STDMETHODCALLTYPE DllGetActivationFactoryImpl(
1202 LPCWSTR wszAssemblyName,
1203 LPCWSTR wszTypeName,
1204 LPCWSTR wszCodeBase,
1205 IActivationFactory ** factory);
1207 #endif // defined(FEATURE_COMINTEROP)
1209 extern SIZE_T Host_SegmentSize;
1210 extern SIZE_T Host_MaxGen0Size;
1211 extern BOOL Host_fSegmentSizeSet;
1212 extern BOOL Host_fMaxGen0SizeSet;
1214 #define PARTIAL_TRUST_VISIBLE_ASSEMBLIES_PROPERTY W("PARTIAL_TRUST_VISIBLE_ASSEMBLIES")
1215 #endif // __CorHost__h__