Skip to content

Commit

Permalink
Remove codebase argument from AssemblyNative::Load (dotnet#1697)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung authored and jkotas committed Jan 14, 2020
1 parent 270ff58 commit 1c2264c
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,13 @@ internal static RuntimeAssembly InternalLoadAssemblyName(AssemblyName assemblyRe
assemblyRef.ProcessorArchitecture = ProcessorArchitecture.None;
}

string? codeBase = VerifyCodeBase(assemblyRef.CodeBase);
Debug.Assert(assemblyRef.CodeBase == null);

return nLoad(assemblyRef, codeBase, null, ref stackMark, true, assemblyLoadContext);
return nLoad(assemblyRef, null, ref stackMark, true, assemblyLoadContext);
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern RuntimeAssembly nLoad(AssemblyName fileName,
string? codeBase,
RuntimeAssembly? assemblyContext,
ref StackCrawlMark stackMark,
bool throwOnFileNotFound,
Expand Down Expand Up @@ -456,34 +455,6 @@ public override string ImageRuntimeVersion

public override long HostContext => 0;

private static string? VerifyCodeBase(string? codebase)
{
if (codebase == null)
return null;

int len = codebase.Length;
if (len == 0)
return null;


int j = codebase.IndexOf(':');
// Check to see if the url has a prefix
if ((j != -1) &&
(j + 2 < len) &&
((codebase[j + 1] == '/') || (codebase[j + 1] == '\\')) &&
((codebase[j + 2] == '/') || (codebase[j + 2] == '\\')))
return codebase;
#if PLATFORM_WINDOWS
else if ((len > 2) && (codebase[0] == '\\') && (codebase[1] == '\\'))
return "file://" + codebase;
else
return "file:///" + Path.GetFullPath(codebase);
#else
else
return "file://" + Path.GetFullPath(codebase);
#endif // PLATFORM_WINDOWS
}

[DllImport(RuntimeHelpers.QCall, CharSet = CharSet.Unicode)]
private static extern void GetVersion(QCallAssembly assembly,
out int majVer,
Expand Down Expand Up @@ -589,7 +560,7 @@ public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? vers
// This stack crawl mark is never used because the requesting assembly is explicitly specified,
// so the value could be anything.
StackCrawlMark unused = default;
RuntimeAssembly? retAssembly = nLoad(an, null, this, ref unused, throwOnFileNotFound);
RuntimeAssembly? retAssembly = nLoad(an, this, ref unused, throwOnFileNotFound);

if (retAssembly == this)
{
Expand Down
11 changes: 2 additions & 9 deletions src/coreclr/src/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
#include "../binder/inc/bindertracing.h"
#include "../binder/inc/clrprivbindercoreclr.h"

FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAFE,
StringObject* codeBaseUNSAFE,
FCIMPL5(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAFE,
AssemblyBaseObject* requestingAssemblyUNSAFE,
StackCrawlMark* stackMark,
CLR_BOOL fThrowOnFileNotFound,
Expand All @@ -43,14 +42,12 @@ FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAF
struct _gc
{
ASSEMBLYNAMEREF assemblyName;
STRINGREF codeBase;
ASSEMBLYREF requestingAssembly;
ASSEMBLYREF rv;
ASSEMBLYLOADCONTEXTREF assemblyLoadContext;
} gc;

gc.assemblyName = (ASSEMBLYNAMEREF) assemblyNameUNSAFE;
gc.codeBase = (STRINGREF) codeBaseUNSAFE;
gc.requestingAssembly = (ASSEMBLYREF) requestingAssemblyUNSAFE;
gc.rv = NULL;
gc.assemblyLoadContext = (ASSEMBLYLOADCONTEXTREF) assemblyLoadContextUNSAFE;
Expand All @@ -69,8 +66,7 @@ FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAF

if(gc.assemblyName->GetSimpleName() == NULL)
{
if (gc.codeBase == NULL)
COMPlusThrow(kArgumentException, W("Format_StringZeroLength"));
COMPlusThrow(kArgumentException, W("Format_StringZeroLength"));
}
else
{
Expand Down Expand Up @@ -101,9 +97,6 @@ FCIMPL6(Object*, AssemblyNative::Load, AssemblyNameBaseObject* assemblyNameUNSAF
EEFileLoadException::Throw(&spec, COR_E_NOTSUPPORTED);
}

if (gc.codeBase != NULL)
spec.SetCodeBase(pStackingAllocator, &gc.codeBase);

if (pParentAssembly != NULL)
spec.SetParentAssembly(pParentAssembly);

Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/src/vm/assemblynative.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ class AssemblyNative
static
void QCALLTYPE GetExecutingAssembly(QCall::StackCrawlMarkHandle stackMark, QCall::ObjectHandleOnStack retAssembly);

static FCDECL6(Object*, Load, AssemblyNameBaseObject* assemblyNameUNSAFE,
StringObject* codeBaseUNSAFE,
static FCDECL5(Object*, Load, AssemblyNameBaseObject* assemblyNameUNSAFE,
AssemblyBaseObject* requestingAssemblyUNSAFE,
StackCrawlMark* stackMark,
CLR_BOOL fThrowOnFileNotFound,
Expand Down
26 changes: 0 additions & 26 deletions src/coreclr/src/vm/assemblyspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,32 +624,6 @@ void AssemblySpec::AssemblyNameInit(ASSEMBLYNAMEREF* pAsmName, PEImage* pImageIn
GCPROTECT_END();
}

// This uses thread storage to allocate space. Please use Checkpoint and release it.
void AssemblySpec::SetCodeBase(StackingAllocator* alloc, STRINGREF *pCodeBase)
{
CONTRACTL
{
INSTANCE_CHECK;
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
PRECONDITION(CheckPointer(pCodeBase));
INJECT_FAULT(COMPlusThrowOM(););
}
CONTRACTL_END;

// Codebase
if (pCodeBase != NULL && *pCodeBase != NULL) {
WCHAR* pString;
int iString;
(*pCodeBase)->RefInterpretGetStringValuesDangerousForGC(&pString, &iString);

DWORD dwCodeBase = (DWORD) iString+1;
m_wszCodeBase = new (alloc) WCHAR[dwCodeBase];
memcpy((void*)m_wszCodeBase, pString, dwCodeBase * sizeof(WCHAR));
}
}

#endif // CROSSGEN_COMPILE

// Check if the supplied assembly's public key matches up with the one in the Spec, if any
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/src/vm/assemblyspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ class AssemblySpec : public BaseAssemblySpec
WRAPPER_NO_CONTRACT;
BaseAssemblySpec::SetCodeBase(szCodeBase);
}
void SetCodeBase(StackingAllocator* alloc, STRINGREF *pCodeBase);

void SetParentAssembly(DomainAssembly *pAssembly)
{
Expand Down

0 comments on commit 1c2264c

Please sign in to comment.