Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
137 changes: 95 additions & 42 deletions src/coreclr/binder/applicationcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "utils.hpp"
#include "ex.h"
#include "clr/fs/path.h"
#include "hostinformation.h"
using namespace clr::fs;

namespace BINDER_SPACE
Expand Down Expand Up @@ -102,69 +103,80 @@ namespace BINDER_SPACE
{
SString fileName;
SString simpleName;
bool isNativeImage = false;
HRESULT pathResult = S_OK;
IF_FAIL_GO(pathResult = GetNextTPAPath(sTrustedPlatformAssemblies, i, /*dllOnly*/ false, fileName, simpleName, isNativeImage));
IF_FAIL_GO(pathResult = GetNextTPAPath(sTrustedPlatformAssemblies, i, /*dllOnly*/ false, fileName, simpleName));
if (pathResult == S_FALSE)
{
break;
}

const SimpleNameToFileNameMapEntry *pExistingEntry = m_pTrustedPlatformAssemblyMap->LookupPtr(simpleName.GetUnicode());
IF_FAIL_GO(hr = AddAssemblyMapEntry(simpleName, fileName));
}

if (pExistingEntry != nullptr)
{
//
// We want to store only the first entry matching a simple name we encounter.
// The exception is if we first store an IL reference and later in the string
// we encounter a native image. Since we don't touch IL in the presence of
// native images, we replace the IL entry with the NI.
//
if ((pExistingEntry->m_wszILFileName != nullptr && !isNativeImage) ||
(pExistingEntry->m_wszNIFileName != nullptr && isNativeImage))
{
continue;
}
}
//
// Parse PlatformResourceRoots
//
sPlatformResourceRoots.Normalize();
for (SString::Iterator i = sPlatformResourceRoots.Begin(); i != sPlatformResourceRoots.End(); )
{
SString pathName;
HRESULT pathResult = S_OK;

LPWSTR wszSimpleName = nullptr;
if (pExistingEntry == nullptr)
{
wszSimpleName = new WCHAR[simpleName.GetCount() + 1];
if (wszSimpleName == nullptr)
{
GO_WITH_HRESULT(E_OUTOFMEMORY);
}
wcscpy_s(wszSimpleName, simpleName.GetCount() + 1, simpleName.GetUnicode());
}
else
IF_FAIL_GO(pathResult = GetNextPath(sPlatformResourceRoots, i, pathName));
if (pathResult == S_FALSE)
{
wszSimpleName = pExistingEntry->m_wszSimpleName;
break;
}

LPWSTR wszFileName = new WCHAR[fileName.GetCount() + 1];
if (wszFileName == nullptr)
if (Path::IsRelative(pathName))
{
GO_WITH_HRESULT(E_OUTOFMEMORY);
GO_WITH_HRESULT(E_INVALIDARG);
}
wcscpy_s(wszFileName, fileName.GetCount() + 1, fileName.GetUnicode());

SimpleNameToFileNameMapEntry mapEntry;
mapEntry.m_wszSimpleName = wszSimpleName;
if (isNativeImage)
m_platformResourceRoots.Append(pathName);
}

//
// Parse AppPaths
//
sAppPaths.Normalize();
for (SString::Iterator i = sAppPaths.Begin(); i != sAppPaths.End(); )
{
SString pathName;
HRESULT pathResult = S_OK;

IF_FAIL_GO(pathResult = GetNextPath(sAppPaths, i, pathName));
if (pathResult == S_FALSE)
{
mapEntry.m_wszNIFileName = wszFileName;
mapEntry.m_wszILFileName = pExistingEntry == nullptr ? nullptr : pExistingEntry->m_wszILFileName;
break;
}
else

if (Path::IsRelative(pathName))
{
mapEntry.m_wszILFileName = wszFileName;
mapEntry.m_wszNIFileName = pExistingEntry == nullptr ? nullptr : pExistingEntry->m_wszNIFileName;
GO_WITH_HRESULT(E_INVALIDARG);
}

m_pTrustedPlatformAssemblyMap->AddOrReplace(mapEntry);
m_appPaths.Append(pathName);
}

Exit:
return hr;
}

HRESULT ApplicationContext::SetupBindingPaths(SString &sPlatformResourceRoots,
SString &sAppPaths,
BOOL fAcquireLock)
{
HRESULT hr = S_OK;

CRITSEC_Holder contextLock(fAcquireLock ? GetCriticalSectionCookie() : NULL);
if (m_pTrustedPlatformAssemblyMap != nullptr)
{
GO_WITH_HRESULT(S_OK);
}

m_pTrustedPlatformAssemblyMap = HostInformation::Instance().GetHostAssemblyNames();

//
// Parse PlatformResourceRoots
//
Expand Down Expand Up @@ -219,4 +231,45 @@ namespace BINDER_SPACE
{
return m_pTrustedPlatformAssemblyMap != nullptr;
}

HRESULT ApplicationContext::AddAssemblyMapEntry(SString& simpleName, SString& fileName)
{
HRESULT hr = S_OK;
const SimpleNameToFileNameMapEntry *pExistingEntry = m_pTrustedPlatformAssemblyMap->LookupPtr(simpleName.GetUnicode());

LPWSTR wszSimpleName = nullptr;
if (pExistingEntry == nullptr)
{
wszSimpleName = new WCHAR[simpleName.GetCount() + 1];
if (wszSimpleName == nullptr)
{
return E_OUTOFMEMORY;
}
wcscpy_s(wszSimpleName, simpleName.GetCount() + 1, simpleName.GetUnicode());
}
else
{
wszSimpleName = pExistingEntry->m_wszSimpleName;
}

LPWSTR wszFileName = nullptr;

if (fileName.GetCount() > 0)
{
wszFileName = new WCHAR[fileName.GetCount() + 1];
if (wszFileName == nullptr)
{
return E_OUTOFMEMORY;
}
wcscpy_s(wszFileName, fileName.GetCount() + 1, fileName.GetUnicode());
}

SimpleNameToFileNameMapEntry mapEntry;
mapEntry.m_wszSimpleName = wszSimpleName;
mapEntry.m_wszILFileName = wszFileName;

m_pTrustedPlatformAssemblyMap->AddOrReplace(mapEntry);

return hr;
}
};
30 changes: 14 additions & 16 deletions src/coreclr/binder/assemblybindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "bindertracing.h"
#include "bindresult.inl"
#include "failurecache.hpp"
#include "hostinformation.h"
#include "utils.hpp"
#include "stringarraylist.h"
#include "configuration.h"
Expand Down Expand Up @@ -298,9 +299,8 @@ namespace BINDER_SPACE
{
SString fileName;
SString simpleName;
bool isNativeImage = false;
HRESULT pathResult = S_OK;
IF_FAIL_GO(pathResult = GetNextTPAPath(sTrustedPlatformAssemblies, i, /*dllOnly*/ true, fileName, simpleName, isNativeImage));
IF_FAIL_GO(pathResult = GetNextTPAPath(sTrustedPlatformAssemblies, i, /*dllOnly*/ true, fileName, simpleName));
if (pathResult == S_FALSE)
{
break;
Expand Down Expand Up @@ -893,25 +893,23 @@ namespace BINDER_SPACE
const SimpleNameToFileNameMapEntry *pTpaEntry = tpaMap->LookupPtr(simpleName.GetUnicode());
if (pTpaEntry != nullptr)
{
if (pTpaEntry->m_wszNIFileName != nullptr)
{
SString fileName(pTpaEntry->m_wszNIFileName);
SString fileName;

hr = GetAssembly(fileName,
TRUE, // fIsInTPA
&pTPAAssembly);
BinderTracing::PathProbed(fileName, BinderTracing::PathSource::ApplicationAssemblies, hr);
// If supported, go ask the host to resolve the path to the assembly
if (pTpaEntry->m_wszILFileName == nullptr)
{
_ASSERTE(pTpaEntry->m_wszSimpleName != nullptr);
HostInformation::Instance().ResolveHostAssemblyPath(simpleName, fileName);
}
else
{
_ASSERTE(pTpaEntry->m_wszILFileName != nullptr);
SString fileName(pTpaEntry->m_wszILFileName);

hr = GetAssembly(fileName,
TRUE, // fIsInTPA
&pTPAAssembly);
BinderTracing::PathProbed(fileName, BinderTracing::PathSource::ApplicationAssemblies, hr);
fileName.Set(pTpaEntry->m_wszILFileName);
}

hr = GetAssembly(fileName,
TRUE, // fIsInTPA
&pTPAAssembly);
BinderTracing::PathProbed(fileName, BinderTracing::PathSource::ApplicationAssemblies, hr);

pBindResult->SetAttemptResult(hr, pTPAAssembly);

Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/binder/defaultassemblybinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,19 @@ HRESULT DefaultAssemblyBinder::SetupBindingPaths(SString &sTrustedPlatformAssem
return hr;
}

HRESULT DefaultAssemblyBinder::SetupBindingPaths(SString &sPlatformResourceRoots,
SString &sAppPaths)
{
HRESULT hr = S_OK;

EX_TRY
{
hr = GetAppContext()->SetupBindingPaths(sPlatformResourceRoots, sAppPaths, TRUE /* fAcquireLock */);
}
EX_CATCH_HRESULT(hr);
return hr;
}

HRESULT DefaultAssemblyBinder::BindToSystem(BINDER_SPACE::Assembly** ppSystemAssembly)
{
HRESULT hr = S_OK;
Expand Down
66 changes: 8 additions & 58 deletions src/coreclr/binder/inc/applicationcontext.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,10 @@
#include "bindertypes.hpp"
#include "failurecache.hpp"
#include "stringarraylist.h"
#include "simplefilenamemap.h"

namespace BINDER_SPACE
{
//=============================================================================================
// Data structures for Simple Name -> File Name hash

// Entry in SHash table that maps namespace to list of files
struct SimpleNameToFileNameMapEntry
{
LPWSTR m_wszSimpleName;
LPWSTR m_wszILFileName;
LPWSTR m_wszNIFileName;
};

// SHash traits for Namespace -> FileNameList hash
class SimpleNameToFileNameMapTraits : public NoRemoveSHashTraits< DefaultSHashTraits< SimpleNameToFileNameMapEntry > >
{
public:
typedef PCWSTR key_t;
static const SimpleNameToFileNameMapEntry Null() { SimpleNameToFileNameMapEntry e; e.m_wszSimpleName = nullptr; return e; }
static bool IsNull(const SimpleNameToFileNameMapEntry & e) { return e.m_wszSimpleName == nullptr; }
static key_t GetKey(const SimpleNameToFileNameMapEntry & e)
{
key_t key;
key = e.m_wszSimpleName;
return key;
}
static count_t Hash(const key_t &str)
{
SString ssKey(SString::Literal, str);
return ssKey.HashCaseInsensitive();
}
static BOOL Equals(const key_t &lhs, const key_t &rhs) { LIMITED_METHOD_CONTRACT; return (SString::_wcsicmp(lhs, rhs) == 0); }

void OnDestructPerEntryCleanupAction(const SimpleNameToFileNameMapEntry & e)
{
if (e.m_wszILFileName == nullptr && e.m_wszNIFileName == nullptr)
{
// Don't delete simple name here since it's a filename only entry and will be cleaned up
// by the SimpleName -> FileName entry which reuses the same filename pointer.
return;
}

if (e.m_wszSimpleName != nullptr)
{
delete [] e.m_wszSimpleName;
}
if (e.m_wszILFileName != nullptr)
{
delete [] e.m_wszILFileName;
}
if (e.m_wszNIFileName != nullptr)
{
delete [] e.m_wszNIFileName;
}
}
static const bool s_DestructPerEntryCleanupAction = true;
};

typedef SHash<SimpleNameToFileNameMapTraits> SimpleNameToFileNameMap;

class AssemblyHashTraits;
typedef SHash<AssemblyHashTraits> ExecutionContext;

Expand All @@ -95,6 +38,10 @@ namespace BINDER_SPACE
/* in */ SString &sPlatformResourceRoots,
/* in */ SString &sAppPaths,
/* in */ BOOL fAcquireLock);

HRESULT SetupBindingPaths(/* in */ SString &sPlatformResourceRoots,
/* in */ SString &sAppPaths,
/* in */ BOOL fAcquireLock);

// Getters/Setter
inline ExecutionContext *GetExecutionContext();
Expand All @@ -111,6 +58,9 @@ namespace BINDER_SPACE
inline LONG GetVersion();
inline void IncrementVersion();

private:
HRESULT AddAssemblyMapEntry(SString& simpleName, SString& fileName);

private:
Volatile<LONG> m_cVersion;
SString m_applicationName;
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/binder/inc/defaultassemblybinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class DefaultAssemblyBinder final : public AssemblyBinder
HRESULT SetupBindingPaths(SString &sTrustedPlatformAssemblies,
SString &sPlatformResourceRoots,
SString &sAppPaths);

HRESULT SetupBindingPaths(SString &PlatformResourceRoots,
SString &AppPaths);

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

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/binder/inc/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace BINDER_SPACE
BOOL IsFileNotFound(HRESULT hr);

HRESULT GetNextPath(const SString& paths, SString::CIterator& startPos, SString& outPath);
HRESULT GetNextTPAPath(const SString& paths, SString::CIterator& startPos, bool dllOnly, SString& outPath, SString& simpleName, bool& isNativeImage);
HRESULT GetNextTPAPath(const SString& paths, SString::CIterator& startPos, bool dllOnly, SString& outPath, SString& simpleName);
};

#endif
Loading