Skip to content

Commit

Permalink
Delete AssemblySpec::m_wszCodeBase (#68186)
Browse files Browse the repository at this point in the history
* Delete AssemblySpec::m_wszCodeBase

This was only used for assembly loading using hosting APIs that can be short-circuited to load directly without going through AssemblySpec

* Delete unnecessary ownedFlags argument
  • Loading branch information
jkotas authored Apr 19, 2022
1 parent 3ab4120 commit eb9dd67
Show file tree
Hide file tree
Showing 24 changed files with 66 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@ internal AssemblyName(string? name,
byte[]? publicKeyToken,
Version? version,
CultureInfo? cultureInfo,
AssemblyHashAlgorithm hashAlgorithm,
AssemblyVersionCompatibility versionCompatibility,
string? codeBase,
AssemblyNameFlags flags)
: this()
{
_name = name;
_publicKey = publicKey;
_publicKeyToken = publicKeyToken;
_version = version;
_cultureInfo = cultureInfo;
_hashAlgorithm = hashAlgorithm;
_versionCompatibility = versionCompatibility;
_codeBase = codeBase;
_flags = flags;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,16 @@ public override AssemblyName GetName(bool copiedName)
null, // public key token
GetVersion(),
GetLocale(),
GetHashAlgorithm(),
AssemblyVersionCompatibility.SameMachine,
codeBase,
GetFlags() | AssemblyNameFlags.PublicKey);

#pragma warning disable IL3000 // System.Reflection.AssemblyName.CodeBase' always returns an empty string for assemblies embedded in a single-file app.
an.CodeBase = codeBase;
#pragma warning restore IL3000

#pragma warning disable SYSLIB0037 // AssemblyName.HashAlgorithm is obsolete
an.HashAlgorithm = GetHashAlgorithm();
#pragma warning restore SYSLIB0037

Module manifestModule = ManifestModule;
if (manifestModule.MDStreamVersion > 0x10000)
{
Expand Down
132 changes: 7 additions & 125 deletions src/coreclr/binder/assemblybindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,53 +107,6 @@ namespace BINDER_SPACE
return true;
}

const WCHAR* s_httpURLPrefix = W("http://");
HRESULT URLToFullPath(PathString &assemblyPath)
{
HRESULT hr = S_OK;

SString::Iterator pos = assemblyPath.Begin();
if (assemblyPath.MatchCaseInsensitive(pos, s_httpURLPrefix))
{
// HTTP downloads are unsupported
hr = FUSION_E_CODE_DOWNLOAD_DISABLED;
}
else
{
SString fullAssemblyPath;
WCHAR *pwzFullAssemblyPath = fullAssemblyPath.OpenUnicodeBuffer(MAX_LONGPATH);
DWORD dwCCFullAssemblyPath = MAX_LONGPATH + 1; // SString allocates extra byte for null.

MutateUrlToPath(assemblyPath);

dwCCFullAssemblyPath = WszGetFullPathName(assemblyPath.GetUnicode(),
dwCCFullAssemblyPath,
pwzFullAssemblyPath,
NULL);
if (dwCCFullAssemblyPath > MAX_LONGPATH)
{
fullAssemblyPath.CloseBuffer();
pwzFullAssemblyPath = fullAssemblyPath.OpenUnicodeBuffer(dwCCFullAssemblyPath - 1);
dwCCFullAssemblyPath = WszGetFullPathName(assemblyPath.GetUnicode(),
dwCCFullAssemblyPath,
pwzFullAssemblyPath,
NULL);
}
fullAssemblyPath.CloseBuffer(dwCCFullAssemblyPath);

if (dwCCFullAssemblyPath == 0)
{
hr = HRESULT_FROM_GetLastError();
}
else
{
assemblyPath.Set(fullAssemblyPath);
}
}

return hr;
}

HRESULT CreateImageAssembly(PEImage *pPEImage,
BindResult *pBindResult)
{
Expand Down Expand Up @@ -238,7 +191,6 @@ namespace BINDER_SPACE

HRESULT AssemblyBinderCommon::BindAssembly(/* in */ AssemblyBinder *pBinder,
/* in */ AssemblyName *pAssemblyName,
/* in */ LPCWSTR szCodeBase,
/* in */ bool excludeAppPaths,
/* out */ Assembly **ppAssembly)
{
Expand All @@ -255,28 +207,13 @@ namespace BINDER_SPACE
// Lock the binding application context
CRITSEC_Holder contextLock(pApplicationContext->GetCriticalSectionCookie());

if (szCodeBase == NULL)
{
_ASSERTE(pAssemblyName != NULL);
IF_FAIL_GO(BindByName(pApplicationContext,
pAssemblyName,
false, // skipFailureCaching
false, // skipVersionCompatibilityCheck
excludeAppPaths,
&bindResult));
}
else
{
PathString assemblyPath(szCodeBase);

// Convert URL to full path and block HTTP downloads
IF_FAIL_GO(URLToFullPath(assemblyPath));

IF_FAIL_GO(BindWhereRef(pApplicationContext,
assemblyPath,
excludeAppPaths,
&bindResult));
}
_ASSERTE(pAssemblyName != NULL);
IF_FAIL_GO(BindByName(pApplicationContext,
pAssemblyName,
false, // skipFailureCaching
false, // skipVersionCompatibilityCheck
excludeAppPaths,
&bindResult));

// Remember the post-bind version
kContextVersion = pApplicationContext->GetVersion();
Expand Down Expand Up @@ -526,61 +463,6 @@ namespace BINDER_SPACE
return hr;
}

/* static */
HRESULT AssemblyBinderCommon::BindWhereRef(ApplicationContext *pApplicationContext,
PathString &assemblyPath,
bool excludeAppPaths,
BindResult *pBindResult)
{
HRESULT hr = S_OK;

ReleaseHolder<Assembly> pAssembly;
BindResult lockedBindResult;

// Look for already cached binding failure
hr = pApplicationContext->GetFailureCache()->Lookup(assemblyPath);
if (FAILED(hr))
{
goto LogExit;
}

// If we return this assembly, then it is guaranteed to be not in GAC
// Design decision. For now, keep the V2 model of Fusion being oblivious of the strong name.
// Security team did not see any security concern with interpreting the version information.
IF_FAIL_GO(GetAssembly(assemblyPath,
FALSE /* fIsInTPA */,
&pAssembly,
Bundle::ProbeAppBundle(assemblyPath)));

AssemblyName *pAssemblyName;
pAssemblyName = pAssembly->GetAssemblyName();

IF_FAIL_GO(BindLocked(pApplicationContext,
pAssemblyName,
false, // skipVersionCompatibilityCheck
excludeAppPaths,
&lockedBindResult));
if (lockedBindResult.HaveResult())
{
pBindResult->SetResult(&lockedBindResult);
GO_WITH_HRESULT(S_OK);
}

hr = S_OK;
pBindResult->SetResult(pAssembly);

Exit:

if (FAILED(hr))
{
// Always cache binding failures
hr = pApplicationContext->AddToFailureCache(assemblyPath, hr);
}

LogExit:
return hr;
}

/* static */
HRESULT AssemblyBinderCommon::BindLocked(ApplicationContext *pApplicationContext,
AssemblyName *pAssemblyName,
Expand Down
3 changes: 0 additions & 3 deletions src/coreclr/binder/bindertracing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ namespace
AssemblySpec *spec = request.AssemblySpec;
_ASSERTE(spec != nullptr);

if (request.AssemblyPath.IsEmpty())
request.AssemblyPath = spec->GetCodeBase();

if (spec->GetName() != nullptr)
spec->GetDisplayName(ASM_DISPLAYF_VERSION | ASM_DISPLAYF_CULTURE | ASM_DISPLAYF_PUBLIC_KEY_TOKEN, request.AssemblyName);

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/binder/customassemblybinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ HRESULT CustomAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNam
// Do we have the assembly already loaded in the context of the current binder?
hr = AssemblyBinderCommon::BindAssembly(this,
pAssemblyName,
NULL, // szCodeBase
false, //excludeAppPaths,
ppCoreCLRFoundAssembly);
if (!FAILED(hr))
Expand Down
27 changes: 0 additions & 27 deletions src/coreclr/binder/defaultassemblybinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ HRESULT DefaultAssemblyBinder::BindAssemblyByNameWorker(BINDER_SPACE::AssemblyNa

hr = AssemblyBinderCommon::BindAssembly(this,
pAssemblyName,
NULL, // szCodeBase
excludeAppPaths,
ppCoreCLRFoundAssembly);
if (!FAILED(hr))
Expand Down Expand Up @@ -187,32 +186,6 @@ HRESULT DefaultAssemblyBinder::SetupBindingPaths(SString &sTrustedPlatformAssem
return hr;
}

HRESULT DefaultAssemblyBinder::Bind(LPCWSTR wszCodeBase,
BINDER_SPACE::Assembly **ppAssembly)
{
HRESULT hr = S_OK;
VALIDATE_ARG_RET(wszCodeBase != NULL && ppAssembly != NULL);

EX_TRY
{
ReleaseHolder<BINDER_SPACE::Assembly> pAsm;
hr = AssemblyBinderCommon::BindAssembly(this,
NULL, // pAssemblyName
wszCodeBase,
false, // excludeAppPaths
&pAsm);
if(SUCCEEDED(hr))
{
_ASSERTE(pAsm != NULL);
pAsm->SetBinder(this);
*ppAssembly = pAsm.Extract();
}
}
EX_CATCH_HRESULT(hr);

return hr;
}

HRESULT DefaultAssemblyBinder::BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly)
{
HRESULT hr = S_OK;
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/binder/inc/assemblybindercommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace BINDER_SPACE
public:
static HRESULT BindAssembly(/* in */ AssemblyBinder *pBinder,
/* in */ AssemblyName *pAssemblyName,
/* in */ LPCWSTR szCodeBase,
/* in */ bool excludeAppPaths,
/* out */ Assembly **ppAssembly);

Expand Down Expand Up @@ -75,11 +74,6 @@ namespace BINDER_SPACE
/* in */ bool excludeAppPaths,
/* out */ BindResult *pBindResult);

static HRESULT BindWhereRef(/* in */ ApplicationContext *pApplicationContext,
/* in */ PathString &assemblyPath,
/* in */ bool excludeAppPaths,
/* out */ BindResult *pBindResult);

static HRESULT BindLocked(/* in */ ApplicationContext *pApplicationContext,
/* in */ AssemblyName *pAssemblyName,
/* in */ bool skipVersionCompatibilityCheck,
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/binder/inc/defaultassemblybinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ class DefaultAssemblyBinder final : public AssemblyBinder
SString &sPlatformResourceRoots,
SString &sAppPaths);

HRESULT Bind(LPCWSTR wszCodeBase, BINDER_SPACE::Assembly **ppAssembly);

HRESULT BindToSystem(BINDER_SPACE::Assembly **ppSystemAssembly);

private:
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/binder/inc/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

namespace BINDER_SPACE
{
void MutateUrlToPath(SString &urlOrPath);

// It is safe to use either A or B as CombinedPath.
void CombinePath(const SString &pathA,
const SString &pathB,
Expand Down
42 changes: 0 additions & 42 deletions src/coreclr/binder/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,48 +32,6 @@ namespace BINDER_SPACE
}
}

void MutateUrlToPath(SString &urlOrPath)
{
const SString fileUrlPrefix(SString::Literal, W("file://"));
SString::Iterator i = urlOrPath.Begin();

if (urlOrPath.MatchCaseInsensitive(i, fileUrlPrefix))
{
urlOrPath.Delete(i, fileUrlPrefix.GetCount());

i = urlOrPath.Begin() + 1;
if (i[0] == W(':'))
{
// CLR erroneously passes in file:// prepended to file paths,
// so we can't tell the difference between UNC and local file.
goto Exit;
}

i = urlOrPath.Begin();
#if !defined(TARGET_UNIX)
if (i[0] == W('/'))
{
// Disk path file:///
urlOrPath.Delete(i, 1);
}
else if (i[0] != W('\\'))
{
// UNC Path, re-insert "//" if not the wrong file://\\...
urlOrPath.Insert(i, W("//"));
}
#else
// Unix doesn't have a distinction between local and network path
_ASSERTE(i[0] == W('\\') || i[0] == W('/'));
#endif
}

Exit:
while (urlOrPath.Find(i, W('/')))
{
urlOrPath.Replace(i, W('\\'));
}
}

void CombinePath(const SString &pathA,
const SString &pathB,
SString &combinedPath)
Expand Down
19 changes: 4 additions & 15 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2380,22 +2380,11 @@ ClrDataAccess::GetFailedAssemblyLocation(CLRDATA_ADDRESS assembly, unsigned int
SOSDacEnter();
FailedAssembly* pAssembly = PTR_FailedAssembly(TO_TADDR(assembly));

// Turn from bytes to wide characters
if (!pAssembly->location.IsEmpty())
{
if (!pAssembly->location.DacGetUnicode(count, location, pNeeded))
{
hr = E_FAIL;
}
}
else
{
if (pNeeded)
*pNeeded = 1;
if (pNeeded)
*pNeeded = 1;

if (location)
location[0] = 0;
}
if (location)
location[0] = 0;

SOSDacLeave();
return hr;
Expand Down
Loading

0 comments on commit eb9dd67

Please sign in to comment.