Skip to content

Commit 0a33e18

Browse files
Revert "Refactor external_assembly_probe to be separate from single-file bu…" (#113746)
This reverts commit 035ee5c. Co-authored-by: Andy Gocke <[email protected]>
1 parent 4dcbbe4 commit 0a33e18

21 files changed

+141
-264
lines changed

Diff for: src/coreclr/binder/assemblybindercommon.cpp

+28-25
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ extern HRESULT RuntimeInvokeHostAssemblyResolver(INT_PTR pManagedAssemblyLoadCon
3737

3838
STDAPI BinderAcquirePEImage(LPCTSTR szAssemblyPath,
3939
PEImage** ppPEImage,
40-
ProbeExtensionResult probeExtensionResult);
40+
BundleFileLocation bundleFileLocation);
4141

4242
namespace BINDER_SPACE
4343
{
@@ -271,8 +271,8 @@ namespace BINDER_SPACE
271271
StackSString sCoreLibName(CoreLibName_IL_W);
272272
StackSString sCoreLib;
273273
BinderTracing::PathSource pathSource = BinderTracing::PathSource::Bundle;
274-
ProbeExtensionResult probeExtensionResult = AssemblyProbeExtension::Probe(sCoreLibName, /*pathIsBundleRelative */ true);
275-
if (!probeExtensionResult.IsValid())
274+
BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(sCoreLibName, /*pathIsBundleRelative */ true);
275+
if (!bundleFileLocation.IsValid())
276276
{
277277
pathSource = BinderTracing::PathSource::ApplicationAssemblies;
278278
}
@@ -282,7 +282,7 @@ namespace BINDER_SPACE
282282
hr = AssemblyBinderCommon::GetAssembly(sCoreLib,
283283
TRUE /* fIsInTPA */,
284284
&pSystemAssembly,
285-
probeExtensionResult);
285+
bundleFileLocation);
286286

287287
BinderTracing::PathProbed(sCoreLib, pathSource, hr);
288288

@@ -322,7 +322,7 @@ namespace BINDER_SPACE
322322
hr = AssemblyBinderCommon::GetAssembly(sCoreLib,
323323
TRUE /* fIsInTPA */,
324324
&pSystemAssembly,
325-
probeExtensionResult);
325+
bundleFileLocation);
326326

327327
BinderTracing::PathProbed(sCoreLib, BinderTracing::PathSource::ApplicationAssemblies, hr);
328328
}
@@ -367,8 +367,8 @@ namespace BINDER_SPACE
367367
StackSString sCoreLibSatellite;
368368

369369
BinderTracing::PathSource pathSource = BinderTracing::PathSource::Bundle;
370-
ProbeExtensionResult probeExtensionResult = AssemblyProbeExtension::Probe(relativePath, /*pathIsBundleRelative */ true);
371-
if (!probeExtensionResult.IsValid())
370+
BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(relativePath, /*pathIsBundleRelative */ true);
371+
if (!bundleFileLocation.IsValid())
372372
{
373373
sCoreLibSatellite.Set(systemDirectory);
374374
pathSource = BinderTracing::PathSource::ApplicationAssemblies;
@@ -379,7 +379,7 @@ namespace BINDER_SPACE
379379
IF_FAIL_GO(AssemblyBinderCommon::GetAssembly(sCoreLibSatellite,
380380
TRUE /* fIsInTPA */,
381381
&pSystemAssembly,
382-
probeExtensionResult));
382+
bundleFileLocation));
383383
BinderTracing::PathProbed(sCoreLibSatellite, pathSource, hr);
384384

385385
*ppSystemAssembly = pSystemAssembly.Extract();
@@ -590,15 +590,15 @@ namespace BINDER_SPACE
590590

591591
namespace
592592
{
593-
HRESULT BindSatelliteResourceByProbeExtension(
593+
HRESULT BindSatelliteResourceFromBundle(
594594
AssemblyName* pRequestedAssemblyName,
595595
SString &relativePath,
596596
BindResult* pBindResult)
597597
{
598598
HRESULT hr = S_OK;
599599

600-
ProbeExtensionResult probeExtensionResult = AssemblyProbeExtension::Probe(relativePath, /* pathIsBundleRelative */ true);
601-
if (!probeExtensionResult.IsValid())
600+
BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(relativePath, /* pathIsBundleRelative */ true);
601+
if (!bundleFileLocation.IsValid())
602602
{
603603
return hr;
604604
}
@@ -607,7 +607,7 @@ namespace BINDER_SPACE
607607
hr = AssemblyBinderCommon::GetAssembly(relativePath,
608608
FALSE /* fIsInTPA */,
609609
&pAssembly,
610-
probeExtensionResult);
610+
bundleFileLocation);
611611

612612
BinderTracing::PathProbed(relativePath, BinderTracing::PathSource::Bundle, hr);
613613

@@ -692,7 +692,7 @@ namespace BINDER_SPACE
692692
BindResult* pBindResult)
693693
{
694694
// Satellite resource probing strategy is to look:
695-
// * First via probe extensions (single-file bundle, external data)
695+
// * First within the single-file bundle
696696
// * Then under each of the Platform Resource Roots
697697
// * Then under each of the App Paths.
698698
//
@@ -712,7 +712,7 @@ namespace BINDER_SPACE
712712
CombinePath(fileName, simpleNameRef, fileName);
713713
fileName.Append(W(".dll"));
714714

715-
hr = BindSatelliteResourceByProbeExtension(pRequestedAssemblyName, fileName, pBindResult);
715+
hr = BindSatelliteResourceFromBundle(pRequestedAssemblyName, fileName, pBindResult);
716716

717717
if (pBindResult->HaveResult() || FAILED(hr))
718718
{
@@ -841,9 +841,12 @@ namespace BINDER_SPACE
841841
ReleaseHolder<Assembly> pTPAAssembly;
842842
const SString& simpleName = pRequestedAssemblyName->GetSimpleName();
843843

844-
// Probing extensions (single-file, external probe) take precedence over TPA.
845-
// For single-file, bundled assemblies should only be in the bundle manifest, not in the TPA.
846-
if (AssemblyProbeExtension::IsEnabled())
844+
// Is assembly in the bundle?
845+
// Single-file bundle contents take precedence over TPA.
846+
// The list of bundled assemblies is contained in the bundle manifest, and NOT in the TPA.
847+
// Therefore the bundle is first probed using the assembly's simple name.
848+
// If found, the assembly is loaded from the bundle.
849+
if (Bundle::AppIsBundle())
847850
{
848851
// Search Assembly.ni.dll, then Assembly.dll
849852
// The Assembly.ni.dll paths are rare, and intended for supporting managed C++ R2R assemblies.
@@ -855,16 +858,16 @@ namespace BINDER_SPACE
855858
SString assemblyFileName(simpleName);
856859
assemblyFileName.Append(candidates[i]);
857860

858-
ProbeExtensionResult probeExtensionResult = AssemblyProbeExtension::Probe(assemblyFileName, /* pathIsBundleRelative */ true);
859-
if (probeExtensionResult.IsValid())
860-
{
861-
SString assemblyFilePath(Bundle::AppIsBundle() ? Bundle::AppBundle->BasePath() : SString::Empty());
862-
assemblyFilePath.Append(assemblyFileName);
861+
SString assemblyFilePath(Bundle::AppBundle->BasePath());
862+
assemblyFilePath.Append(assemblyFileName);
863863

864+
BundleFileLocation bundleFileLocation = Bundle::ProbeAppBundle(assemblyFileName, /* pathIsBundleRelative */ true);
865+
if (bundleFileLocation.IsValid())
866+
{
864867
hr = GetAssembly(assemblyFilePath,
865868
TRUE, // fIsInTPA
866869
&pTPAAssembly,
867-
probeExtensionResult);
870+
bundleFileLocation);
868871

869872
BinderTracing::PathProbed(assemblyFilePath, BinderTracing::PathSource::Bundle, hr);
870873

@@ -993,7 +996,7 @@ namespace BINDER_SPACE
993996
HRESULT AssemblyBinderCommon::GetAssembly(SString &assemblyPath,
994997
BOOL fIsInTPA,
995998
Assembly **ppAssembly,
996-
ProbeExtensionResult probeExtensionResult)
999+
BundleFileLocation bundleFileLocation)
9971000
{
9981001
HRESULT hr = S_OK;
9991002

@@ -1009,7 +1012,7 @@ namespace BINDER_SPACE
10091012
{
10101013
LPCTSTR szAssemblyPath = const_cast<LPCTSTR>(assemblyPath.GetUnicode());
10111014

1012-
hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, probeExtensionResult);
1015+
hr = BinderAcquirePEImage(szAssemblyPath, &pPEImage, bundleFileLocation);
10131016
IF_FAIL_GO(hr);
10141017
}
10151018

Diff for: src/coreclr/binder/inc/assembly.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "customassemblybinder.h"
2626
#endif // !defined(DACCESS_COMPILE)
2727

28+
#include "bundle.h"
2829
#include <assemblybinderutil.h>
2930

3031
namespace BINDER_SPACE

Diff for: src/coreclr/binder/inc/assemblybindercommon.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#include "bindertypes.hpp"
1818
#include "bindresult.hpp"
19-
#include <assemblyprobeextension.h>
19+
#include "bundle.h"
2020

2121
class AssemblyBinder;
2222
class DefaultAssemblyBinder;
@@ -28,7 +28,7 @@ namespace BINDER_SPACE
2828
class AssemblyBinderCommon
2929
{
3030
public:
31-
static HRESULT BindAssembly(/* in */ AssemblyBinder *pBinder,
31+
static HRESULT BindAssembly(/* in */ AssemblyBinder *pBinder,
3232
/* in */ AssemblyName *pAssemblyName,
3333
/* in */ bool excludeAppPaths,
3434
/* out */ Assembly **ppAssembly);
@@ -44,7 +44,7 @@ namespace BINDER_SPACE
4444
static HRESULT GetAssembly(/* in */ SString &assemblyPath,
4545
/* in */ BOOL fIsInTPA,
4646
/* out */ Assembly **ppAssembly,
47-
/* in */ ProbeExtensionResult probeExtensionResult = ProbeExtensionResult::Invalid());
47+
/* in */ BundleFileLocation bundleFileLocation = BundleFileLocation::Invalid());
4848

4949
#if !defined(DACCESS_COMPILE)
5050
static HRESULT BindUsingHostAssemblyResolver (/* in */ INT_PTR pManagedAssemblyLoadContextToBindWithin,

Diff for: src/coreclr/dlls/mscoree/exports.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,12 @@ int coreclr_initialize(
288288
hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host);
289289
IfFailRet(hr);
290290

291-
if (bundleProbe != nullptr)
291+
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
292+
293+
ExternalAssemblyProbeFn* externalAssemblyProbe = hostContract != nullptr ? hostContract->external_assembly_probe : nullptr;
294+
if (bundleProbe != nullptr || externalAssemblyProbe != nullptr)
292295
{
293-
static Bundle bundle(exePath, bundleProbe);
296+
static Bundle bundle(exePath, bundleProbe, externalAssemblyProbe);
294297
Bundle::AppBundle = &bundle;
295298
}
296299

@@ -306,7 +309,6 @@ int coreclr_initialize(
306309
hr = host->Start();
307310
IfFailRet(hr);
308311

309-
ConstWStringHolder appDomainFriendlyNameW = StringToUnicode(appDomainFriendlyName);
310312
hr = host->CreateAppDomainWithManager(
311313
appDomainFriendlyNameW,
312314
0,

Diff for: src/coreclr/inc/assemblyprobeextension.h

-68
This file was deleted.

Diff for: src/coreclr/inc/bundle.h

+8-5
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,31 @@ class Bundle;
1818
struct BundleFileLocation
1919
{
2020
INT64 Size;
21+
void* DataStart;
2122
INT64 Offset;
22-
INT64 UncompressedSize;
23+
INT64 UncompresedSize;
2324

2425
BundleFileLocation()
2526
{
2627
LIMITED_METHOD_CONTRACT;
2728

2829
Size = 0;
30+
DataStart = nullptr;
2931
Offset = 0;
30-
UncompressedSize = 0;
32+
UncompresedSize = 0;
3133
}
3234

3335
static BundleFileLocation Invalid() { LIMITED_METHOD_CONTRACT; return BundleFileLocation(); }
3436

3537
const SString &Path() const;
3638

37-
bool IsValid() const { LIMITED_METHOD_CONTRACT; return Offset != 0; }
39+
bool IsValid() const { LIMITED_METHOD_CONTRACT; return DataStart != nullptr || Offset != 0; }
3840
};
3941

4042
class Bundle
4143
{
4244
public:
43-
Bundle(LPCSTR bundlePath, BundleProbeFn *probe);
45+
Bundle(LPCSTR bundlePath, BundleProbeFn *probe, ExternalAssemblyProbeFn* externalAssemblyProbe = nullptr);
4446
BundleFileLocation Probe(const SString& path, bool pathIsBundleRelative = false) const;
4547

4648
const SString &Path() const { LIMITED_METHOD_CONTRACT; return m_path; }
@@ -51,8 +53,9 @@ class Bundle
5153
static BundleFileLocation ProbeAppBundle(const SString& path, bool pathIsBundleRelative = false);
5254

5355
private:
54-
SString m_path; // The path to single-file executable
56+
SString m_path; // The path to single-file executable or package name/id on Android
5557
BundleProbeFn *m_probe;
58+
ExternalAssemblyProbeFn *m_externalAssemblyProbe;
5659

5760
SString m_basePath; // The prefix to denote a path within the bundle
5861
COUNT_T m_basePathLength;

Diff for: src/coreclr/inc/hostinformation.h

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ class HostInformation
1111
public:
1212
static void SetContract(_In_ host_runtime_contract* hostContract);
1313
static bool GetProperty(_In_z_ const char* name, SString& value);
14-
15-
static bool HasExternalProbe();
16-
static bool ExternalAssemblyProbe(_In_ const SString& path, _Out_ void** data, _Out_ int64_t* size);
1714
};
1815

1916
#endif // _HOSTINFORMATION_H_

Diff for: src/coreclr/vm/CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ set(VM_SOURCES_WKS
293293
${VM_SOURCES_DAC_AND_WKS_COMMON}
294294
appdomainnative.cpp
295295
assemblynative.cpp
296-
assemblyprobeextension.cpp
297296
assemblyspec.cpp
298297
baseassemblyspec.cpp
299298
${RUNTIME_DIR}/CachedInterfaceDispatch.cpp
@@ -391,7 +390,6 @@ set(VM_HEADERS_WKS
391390
../inc/jithelpers.h
392391
appdomainnative.hpp
393392
assemblynative.hpp
394-
../inc/assemblyprobeextension.h
395393
assemblyspec.hpp
396394
assemblyspecbase.h
397395
baseassemblyspec.h

Diff for: src/coreclr/vm/assemblynative.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ extern "C" void QCALLTYPE AssemblyNative_LoadFromPath(INT_PTR ptrNativeAssemblyB
191191

192192
if (pwzILPath != NULL)
193193
{
194-
pILImage = PEImage::OpenImage(pwzILPath);
194+
pILImage = PEImage::OpenImage(pwzILPath,
195+
MDInternalImport_Default,
196+
BundleFileLocation::Invalid());
195197

196198
// Need to verify that this is a valid CLR assembly.
197199
if (!pILImage->CheckILFormat())

0 commit comments

Comments
 (0)