diff --git a/src/binder/assemblybinder.cpp b/src/binder/assemblybinder.cpp index 895aecfa91ef..89a26c2a78a4 100644 --- a/src/binder/assemblybinder.cpp +++ b/src/binder/assemblybinder.cpp @@ -1407,21 +1407,21 @@ namespace BINDER_SPACE } /* static */ - HRESULT AssemblyBinder::GetAssembly(SString &assemblyPath, - BOOL fIsInGAC, + HRESULT AssemblyBinder::GetAssembly(SString &assemblyPath, + BOOL fIsInGAC, // When binding to the native image, should we // assume assemblyPath explicitly specifies that // NI? (If not, infer the path to the NI // implicitly.) - BOOL fExplicitBindToNativeImage, + BOOL fExplicitBindToNativeImage, - Assembly **ppAssembly, + Assembly **ppAssembly, // If assemblyPath refers to a native image without metadata, // szMDAssemblyPath gives the alternative file to get metadata. - LPCTSTR szMDAssemblyPath, - BundleLoc bundleLoc) + LPCTSTR szMDAssemblyPath, + BundleFileLocation bundleFileLocation) { HRESULT hr = S_OK; @@ -1445,7 +1445,7 @@ namespace BINDER_SPACE LPCTSTR szAssemblyPath = const_cast(assemblyPath.GetUnicode()); BINDER_LOG_ENTER(W("BinderAcquirePEImage")); - hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, &pNativePEImage, fExplicitBindToNativeImage, bundleLoc); + hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, &pNativePEImage, fExplicitBindToNativeImage, bundleFileLocation); BINDER_LOG_LEAVE_HR(W("BinderAcquirePEImage"), hr); IF_FAIL_GO(hr); @@ -1462,7 +1462,7 @@ namespace BINDER_SPACE BinderReleasePEImage(pNativePEImage); BINDER_LOG_ENTER(W("BinderAcquirePEImageIL")); - hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, &pNativePEImage, false, bundleLoc); + hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, &pNativePEImage, false, bundleFileLocation); BINDER_LOG_LEAVE_HR(W("BinderAcquirePEImageIL"), hr); IF_FAIL_GO(hr); } @@ -1492,7 +1492,7 @@ namespace BINDER_SPACE else { BINDER_LOG_ENTER(W("BinderAcquirePEImage")); - hr = BinderAcquirePEImage(szMDAssemblyPath, &pPEImage, NULL, FALSE, bundleLoc); + hr = BinderAcquirePEImage(szMDAssemblyPath, &pPEImage, NULL, FALSE, bundleFileLocation); BINDER_LOG_LEAVE_HR(W("BinderAcquirePEImage"), hr); IF_FAIL_GO(hr); diff --git a/src/binder/inc/assembly.hpp b/src/binder/inc/assembly.hpp index cfba9a5744f8..0b4283dd22e5 100644 --- a/src/binder/inc/assembly.hpp +++ b/src/binder/inc/assembly.hpp @@ -28,11 +28,11 @@ #endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) #include "bundle.h" -STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath, - PEImage **ppPEImage, - PEImage **ppNativeImage, - BOOL fExplicitBindToNativeImage, - BundleLoc bundleLoc); +STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath, + PEImage **ppPEImage, + PEImage **ppNativeImage, + BOOL fExplicitBindToNativeImage, + BundleFileLocation bundleFileLocation); STDAPI BinderAcquireImport(PEImage *pPEImage, IMDInternalImport **pIMetaDataAssemblyImport, diff --git a/src/binder/inc/assemblybinder.hpp b/src/binder/inc/assemblybinder.hpp index be9896a41186..6ec72e6a9f43 100644 --- a/src/binder/inc/assemblybinder.hpp +++ b/src/binder/inc/assemblybinder.hpp @@ -63,12 +63,12 @@ namespace BINDER_SPACE /* in */ PEImage *pNativePEImage, /* out */ Assembly **ppAssembly); - static HRESULT GetAssembly(/* in */ SString &assemblyPath, - /* in */ BOOL fIsInGAC, - /* in */ BOOL fExplicitBindToNativeImage, - /* out */ Assembly **ppAssembly, - /* in */ LPCTSTR szMDAssemblyPath = NULL, - /* in */ BundleLoc bundleLoc = BundleLoc::Invalid()); + static HRESULT GetAssembly(/* in */ SString &assemblyPath, + /* in */ BOOL fIsInGAC, + /* in */ BOOL fExplicitBindToNativeImage, + /* out */ Assembly **ppAssembly, + /* in */ LPCTSTR szMDAssemblyPath = NULL, + /* in */ BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid()); #if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE) static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin, diff --git a/src/dlls/mscoree/unixinterface.cpp b/src/dlls/mscoree/unixinterface.cpp index b6831fe55397..c15fb5e316fb 100644 --- a/src/dlls/mscoree/unixinterface.cpp +++ b/src/dlls/mscoree/unixinterface.cpp @@ -119,7 +119,8 @@ static void ConvertConfigPropertiesToUnicode( const char** propertyValues, int propertyCount, LPCWSTR** propertyKeysWRef, - LPCWSTR** propertyValuesWRef) + LPCWSTR** propertyValuesWRef, + BundleProbe** bundleProbe) { LPCWSTR* propertyKeysW = new (nothrow) LPCWSTR[propertyCount]; ASSERTE_ALL_BUILDS(propertyKeysW != nullptr); @@ -129,8 +130,20 @@ static void ConvertConfigPropertiesToUnicode( for (int propertyIndex = 0; propertyIndex < propertyCount; ++propertyIndex) { + if (strcmp(propertyKeys[propertyIndex], "BUNDLE_PROBE") == 0) + { + // If this application is a single-file bundle, the bundle-probe callback + // is passed in as the value of "BUNDLE_PROBE" property (masquarading as char *). + // Therefore obtain the value; don't convert it to Unicode. + + *bundleProbe = (BundleProbe *)propertyValues[propertyIndex]; + propertyKeysW[propertyIndex] = W("BUNDLE_PROBE"); + propertyValuesW[propertyIndex] = W(""); + continue; + } + propertyKeysW[propertyIndex] = StringToUnicode(propertyKeys[propertyIndex]); - propertyValuesW[propertyIndex] = propertyValues[propertyIndex] != nullptr ? StringToUnicode(propertyValues[propertyIndex]) : nullptr; + propertyValuesW[propertyIndex] = StringToUnicode(propertyValues[propertyIndex]); } *propertyKeysWRef = propertyKeysW; @@ -192,34 +205,24 @@ int coreclr_initialize( hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host); IfFailRet(hr); - // If this application is a single-file bundle, the bundle-probe callback - // is passed in as the value of "BUNDLE_PROBE" property (masquarading as char *). - // Therefore obtain the value before converting property keys/values to unicode. - for (int i = 0; i < propertyCount; i++) - { - if (strcmp(propertyKeys[i], "BUNDLE_PROBE") == 0) - { - BundleProbe* bundleProbe = (BundleProbe*)propertyValues[i]; - - if (bundleProbe != nullptr) - { - static Bundle bundle(StringToUnicode(exePath), bundleProbe); - Bundle::AppBundle = &bundle; - } - break; - } - } - ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName); LPCWSTR* propertyKeysW; LPCWSTR* propertyValuesW; + BundleProbe* bundleProbe = nullptr; ConvertConfigPropertiesToUnicode( propertyKeys, propertyValues, propertyCount, &propertyKeysW, - &propertyValuesW); + &propertyValuesW, + &bundleProbe); + + if (bundleProbe != nullptr) + { + static Bundle bundle(StringToUnicode(exePath), bundleProbe); + Bundle::AppBundle = &bundle; + } // This will take ownership of propertyKeysWTemp and propertyValuesWTemp Configuration::InitializeConfigurationKnobs(propertyCount, propertyKeysW, propertyValuesW); diff --git a/src/inc/bundle.h b/src/inc/bundle.h index 1ed8cd1d5b10..4380d49d3dff 100644 --- a/src/inc/bundle.h +++ b/src/inc/bundle.h @@ -15,12 +15,12 @@ class Bundle; -struct BundleLoc +struct BundleFileLocation { INT64 Size; INT64 Offset; - BundleLoc() + BundleFileLocation() { LIMITED_METHOD_CONTRACT; @@ -28,7 +28,7 @@ struct BundleLoc Offset = 0; } - static BundleLoc Invalid() { LIMITED_METHOD_CONTRACT; return BundleLoc(); } + static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); } LPCWSTR Path() const; @@ -41,14 +41,14 @@ class Bundle { public: Bundle(LPCWSTR bundlePath, BundleProbe *probe); - BundleLoc Probe(LPCWSTR path, bool pathIsBundleRelative = false) const; + BundleFileLocation Probe(LPCWSTR path, bool pathIsBundleRelative = false) const; LPCWSTR Path() const { LIMITED_METHOD_CONTRACT; return m_path; } LPCWSTR BasePath() const { LIMITED_METHOD_CONTRACT; return m_basePath; } static Bundle* AppBundle; // The BundleInfo for the current app, initialized by coreclr_initialize. static bool AppIsBundle() { LIMITED_METHOD_CONTRACT; return AppBundle != nullptr; } - static BundleLoc ProbeAppBundle(LPCWSTR path, bool pathIsBundleRelative = false); + static BundleFileLocation ProbeAppBundle(LPCWSTR path, bool pathIsBundleRelative = false); private: diff --git a/src/vm/bundle.cpp b/src/vm/bundle.cpp index 8ded6b0ec8d7..b8aff7ededd8 100644 --- a/src/vm/bundle.cpp +++ b/src/vm/bundle.cpp @@ -31,14 +31,14 @@ static LPCSTR UnicodeToUtf8(LPCWSTR str) return result; } -LPCWSTR BundleLoc::Path() const +LPCWSTR BundleFileLocation::Path() const { LIMITED_METHOD_CONTRACT; // Currently, there is only one bundle -- the bundle for the main App. // Therefore, obtain the path from the global AppBundle. // If there is more than one bundle in one application (ex: single file plugins) - // the BundlePath may be stored in the BundleLoc structure. + // the BundlePath may be stored in the BundleFileLocation structure. _ASSERTE(IsValid()); _ASSERTE(Bundle::AppBundle != nullptr); @@ -74,14 +74,14 @@ Bundle::Bundle(LPCWSTR bundlePath, BundleProbe *probe) _ASSERTE(pos != nullptr); size_t baseLen = pos - bundlePath + 1; // Include DIRECTORY_SEPARATOR_CHAR_W in m_basePath - m_basePath.Set(bundlePath, baseLen); + m_basePath.Set(bundlePath, (COUNT_T)baseLen); } -BundleLoc Bundle::Probe(LPCWSTR path, bool pathIsBundleRelative) const +BundleFileLocation Bundle::Probe(LPCWSTR path, bool pathIsBundleRelative) const { STANDARD_VM_CONTRACT; - BundleLoc loc; + BundleFileLocation loc; // Skip over m_base_path, if any. // TODO: Normalize paths @@ -106,10 +106,10 @@ BundleLoc Bundle::Probe(LPCWSTR path, bool pathIsBundleRelative) const return loc; } -BundleLoc Bundle::ProbeAppBundle(LPCWSTR path, bool pathIsBundleRelative) +BundleFileLocation Bundle::ProbeAppBundle(LPCWSTR path, bool pathIsBundleRelative) { STANDARD_VM_CONTRACT; - return AppIsBundle() ? AppBundle->Probe(path, pathIsBundleRelative) : BundleLoc::Invalid(); + return AppIsBundle() ? AppBundle->Probe(path, pathIsBundleRelative) : BundleFileLocation::Invalid(); } diff --git a/src/vm/coreassemblyspec.cpp b/src/vm/coreassemblyspec.cpp index d71deb3fcb57..4095841e0e73 100644 --- a/src/vm/coreassemblyspec.cpp +++ b/src/vm/coreassemblyspec.cpp @@ -197,11 +197,11 @@ VOID AssemblySpec::Bind(AppDomain *pAppDomain, } -STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, - PEImage **ppPEImage, - PEImage **ppNativeImage, - BOOL fExplicitBindToNativeImage, - BundleLoc bundleLoc) +STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, + PEImage **ppPEImage, + PEImage **ppNativeImage, + BOOL fExplicitBindToNativeImage, + BundleFileLocation bundleFileLocation) { HRESULT hr = S_OK; @@ -218,7 +218,7 @@ STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, // fExplicitBindToNativeImage is set on Phone when we bind to a list of native images and have no IL on device for an assembly if (fExplicitBindToNativeImage) { - pNativeImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_TrustedNativeImage, bundleLoc); + pNativeImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_TrustedNativeImage, bundleFileLocation); // Make sure that the IL image can be opened if the native image is not available. hr=pNativeImage->TryOpenFile(); @@ -230,7 +230,7 @@ STDAPI BinderAcquirePEImage(LPCWSTR wszAssemblyPath, else #endif { - pImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_Default, bundleLoc); + pImage = PEImage::OpenImage(wszAssemblyPath, MDInternalImport_Default, bundleFileLocation); // Make sure that the IL image can be opened if the native image is not available. hr=pImage->TryOpenFile(); diff --git a/src/vm/peimage.h b/src/vm/peimage.h index 09a6d7b0bbe3..eaa711eee2cf 100644 --- a/src/vm/peimage.h +++ b/src/vm/peimage.h @@ -102,7 +102,7 @@ class PEImage static PTR_PEImage OpenImage( LPCWSTR pPath, MDInternalImportFlags flags = MDInternalImport_Default, - BundleLoc bundleLoc = BundleLoc::Invalid()); + BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid()); // clones the image with new flags (this is pretty much about cached / noncached difference) void Clone(MDInternalImportFlags flags, PTR_PEImage* ppImage) @@ -242,7 +242,7 @@ class PEImage // Private routines // ------------------------------------------------------------ - void Init(LPCWSTR pPath, BundleLoc bundleLoc); + void Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation); void Init(IStream* pStream, UINT64 uStreamAsmId, DWORD dwModuleId, BOOL resourceFile); @@ -278,9 +278,9 @@ class PEImage SString m_path; LONG m_refCount; - BundleLoc m_bundleLoc; // If this image is located within a single-file bundle, - // the location within the bundle. If m_bundleLoc is vaild, - // it takes precedence over m_path for loading. + BundleFileLocation m_bundleFileLocation; // If this image is located within a single-file bundle, + // the location within the bundle. If m_bundleFileLocation is vaild, + // it takes precedence over m_path for loading. // This variable will have the data of module name. // It is only used by DAC to remap fusion loaded modules back to diff --git a/src/vm/peimage.inl b/src/vm/peimage.inl index 7326d08efe67..cabd4222c533 100644 --- a/src/vm/peimage.inl +++ b/src/vm/peimage.inl @@ -37,20 +37,20 @@ inline const SString PEImage::GetPathToLoad() { LIMITED_METHOD_DAC_CONTRACT; - return m_bundleLoc.IsValid() ? (SString)m_bundleLoc.Path() : m_path; + return m_bundleFileLocation.IsValid() ? (SString)m_bundleFileLocation.Path() : m_path; } inline INT64 PEImage::GetOffset() const { LIMITED_METHOD_CONTRACT; - return m_bundleLoc.Offset; + return m_bundleFileLocation.Offset; } inline INT64 PEImage::GetSize() const { LIMITED_METHOD_CONTRACT; - return m_bundleLoc.Size; + return m_bundleFileLocation.Size; } inline void PEImage::SetModuleFileNameHintForDAC() @@ -439,7 +439,7 @@ inline CHECK PEImage::CheckFormat() CHECK_OK; } -inline void PEImage::Init(LPCWSTR pPath, BundleLoc bundleLoc) +inline void PEImage::Init(LPCWSTR pPath, BundleFileLocation bundleFileLocation) { CONTRACTL { @@ -451,7 +451,7 @@ inline void PEImage::Init(LPCWSTR pPath, BundleLoc bundleLoc) m_path = pPath; m_path.Normalize(); - m_bundleLoc = bundleLoc; + m_bundleFileLocation = bundleFileLocation; SetModuleFileNameHintForDAC(); } #ifndef DACCESS_COMPILE @@ -483,14 +483,14 @@ inline PTR_PEImage PEImage::FindByPath(LPCWSTR pPath) } /* static */ -inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */, BundleLoc bundleLoc) +inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags /* = MDInternalImport_Default */, BundleFileLocation bundleFileLocation) { BOOL fUseCache = !((flags & MDInternalImport_NoCache) == MDInternalImport_NoCache); if (!fUseCache) { PEImageHolder pImage(new PEImage); - pImage->Init(pPath, bundleLoc); + pImage->Init(pPath, bundleFileLocation); return dac_cast(pImage.Extract()); } @@ -511,7 +511,7 @@ inline PTR_PEImage PEImage::OpenImage(LPCWSTR pPath, MDInternalImportFlags flags if (flags & MDInternalImport_TrustedNativeImage) pImage->SetIsTrustedNativeImage(); #endif - pImage->Init(pPath, bundleLoc); + pImage->Init(pPath, bundleFileLocation); pImage->AddToHashMap(); return dac_cast(pImage.Extract());