diff options
author | Aaron Robinson <arobins@microsoft.com> | 2019-04-09 15:07:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-09 15:07:34 -0700 |
commit | a6b0eef9d4a61e3ef5c3879a5016931f8ca0cf99 (patch) | |
tree | fc4ab7c05721f8dcfb667cd522737f2c1cd8f12f /src/coreclr | |
parent | 5608b4ff0f81b99a5d436dec1e23b393503a4e07 (diff) | |
download | coreclr-a6b0eef9d4a61e3ef5c3879a5016931f8ca0cf99.tar.gz coreclr-a6b0eef9d4a61e3ef5c3879a5016931f8ca0cf99.tar.bz2 coreclr-a6b0eef9d4a61e3ef5c3879a5016931f8ca0cf99.zip |
Alter CCW wrapping semantics (#23709)
* Update CCW semantics to not unwrap when a managed COM server was activated
from a managed COM client. This is a functional change from .NET Framework.
* Add support for CoreShim to "attach" to the existing CLR instance when
running from a CoreRun scenario.
* Add testing for NET COM client activating a NET COM server
Diffstat (limited to 'src/coreclr')
-rw-r--r-- | src/coreclr/hosts/corerun/corerun.cpp | 36 | ||||
-rw-r--r-- | src/coreclr/hosts/coreshim/CoreShim.cpp | 18 | ||||
-rw-r--r-- | src/coreclr/hosts/coreshim/CoreShim.h | 1 |
3 files changed, 54 insertions, 1 deletions
diff --git a/src/coreclr/hosts/corerun/corerun.cpp b/src/coreclr/hosts/corerun/corerun.cpp index 42aa3009ea..e1864c81f7 100644 --- a/src/coreclr/hosts/corerun/corerun.cpp +++ b/src/coreclr/hosts/corerun/corerun.cpp @@ -423,6 +423,41 @@ private: ULONG_PTR _actCookie; }; +class ClrInstanceDetails +{ + static void * _currentClrInstance; + static unsigned int _currentAppDomainId; + +public: // static + static HRESULT GetDetails(void **clrInstance, unsigned int *appDomainId) + { + *clrInstance = _currentClrInstance; + *appDomainId = _currentAppDomainId; + return S_OK; + } + +public: + ClrInstanceDetails(void *clrInstance, unsigned int appDomainId) + { + _currentClrInstance = clrInstance; + _currentAppDomainId = appDomainId; + } + + ~ClrInstanceDetails() + { + _currentClrInstance = nullptr; + _currentAppDomainId = 0; + } +}; + +void * ClrInstanceDetails::_currentClrInstance; +unsigned int ClrInstanceDetails::_currentAppDomainId; + +extern "C" __declspec(dllexport) HRESULT __cdecl GetCurrentClrDetails(void **clrInstance, unsigned int *appDomainId) +{ + return ClrInstanceDetails::GetDetails(clrInstance, appDomainId); +} + bool TryLoadHostPolicy(StackSString& hostPolicyPath) { const WCHAR *hostpolicyName = W("hostpolicy.dll"); @@ -666,6 +701,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo { ActivationContext cxt{ log, managedAssemblyFullName.GetUnicode() }; + ClrInstanceDetails current{ host, domainId }; hr = host->ExecuteAssembly(domainId, managedAssemblyFullName, argc - 1, (argc - 1) ? &(argv[1]) : NULL, &exitCode); if (FAILED(hr)) diff --git a/src/coreclr/hosts/coreshim/CoreShim.cpp b/src/coreclr/hosts/coreshim/CoreShim.cpp index 7a5c3a1d1c..238e40fb87 100644 --- a/src/coreclr/hosts/coreshim/CoreShim.cpp +++ b/src/coreclr/hosts/coreshim/CoreShim.cpp @@ -334,6 +334,7 @@ HRESULT coreclr::CreateTpaList(_Inout_ std::string &tpaList, _In_opt_z_ const WC coreclr::coreclr(_Inout_ AutoModule hmod) : _hmod{ std::move(hmod) } + , _attached{ false } , _clrInst{ nullptr } , _appDomainId{ std::numeric_limits<uint32_t>::max() } { @@ -349,7 +350,7 @@ coreclr::coreclr(_Inout_ AutoModule hmod) coreclr::~coreclr() { - if (_clrInst != nullptr) + if (_clrInst != nullptr && !_attached) { HRESULT hr = _shutdown(_clrInst, _appDomainId); assert(SUCCEEDED(hr)); @@ -370,6 +371,21 @@ HRESULT coreclr::Initialize( appDomainName = "CoreShim"; HRESULT hr; + + // Check if this is hosted scenario - launched via CoreRun.exe + HMODULE mod = ::GetModuleHandleW(W("CoreRun.exe")); + if (mod != NULL) + { + using GetCurrentClrDetailsFunc = HRESULT(*)(void **clrInstance, unsigned int *appDomainId); + auto getCurrentClrDetails = (GetCurrentClrDetailsFunc)::GetProcAddress(mod, "GetCurrentClrDetails"); + RETURN_IF_FAILED(getCurrentClrDetails(&_clrInst, &_appDomainId)); + if (_clrInst != nullptr) + { + _attached = true; + return S_OK; + } + } + try { const std::wstring exePathW = GetExePath(); diff --git a/src/coreclr/hosts/coreshim/CoreShim.h b/src/coreclr/hosts/coreshim/CoreShim.h index d4c8b0aa6b..5875b457bc 100644 --- a/src/coreclr/hosts/coreshim/CoreShim.h +++ b/src/coreclr/hosts/coreshim/CoreShim.h @@ -174,6 +174,7 @@ public: private: AutoModule _hmod; + bool _attached; void *_clrInst; uint32_t _appDomainId; |