Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Have one place for BundleInfo
Browse files Browse the repository at this point in the history
Store BundleInfo for the app-bundle in a global location,
rather than passing it around through initializers.

Also fix some spacing.
  • Loading branch information
swaroop-sridhar committed Sep 5, 2019
1 parent 9d873d6 commit bb6e54c
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 82 deletions.
9 changes: 4 additions & 5 deletions src/binder/assemblybinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include "assemblybinder.hpp"
#include "assemblyname.hpp"

#include "corbundle.h"
#include "assembly.hpp"
#include "applicationcontext.hpp"
#include "loadcontext.hpp"
Expand Down Expand Up @@ -422,15 +422,14 @@ namespace BINDER_SPACE
};

/* static */
HRESULT AssemblyBinder::Startup(bool isBundle)
HRESULT AssemblyBinder::Startup()
{
HRESULT hr = S_OK;

if (!BINDER_SPACE::fAssemblyBinderInitialized)
{

g_BinderVariables = new Variables();
IF_FAIL_GO(g_BinderVariables->Init(isBundle));
IF_FAIL_GO(g_BinderVariables->Init());

// Setup Debug log
BINDER_LOG_STARTUP();
Expand Down Expand Up @@ -1174,7 +1173,7 @@ namespace BINDER_SPACE
// Is assembly in the bundle?
// Single-file bundle contents take precedence over TPA.
// Bundled assemblies are treated similar to TPAs.
if (g_BinderVariables->fIsBundle)
if (BundleInfo::AppIsBundle())
{
SString candidates[] = { W(".dll"), W(".ni.dll") };

Expand Down
4 changes: 2 additions & 2 deletions src/binder/binderinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ using namespace BINDER_SPACE;
namespace BinderInterface
{

HRESULT Init(bool isBundle)
HRESULT Init()
{
HRESULT hr = S_OK;

EX_TRY
{
hr = AssemblyBinder::Startup(isBundle);
hr = AssemblyBinder::Startup();
}
EX_CATCH_HRESULT(hr);

Expand Down
10 changes: 5 additions & 5 deletions src/binder/coreclrbindercommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
#include "coreclrbindercommon.h"
#include "clrprivbindercoreclr.h"
#include "clrprivbinderutil.h"
#include "corbundle.h"

using namespace BINDER_SPACE;

//=============================================================================
// Init code
//-----------------------------------------------------------------------------
/* static */
HRESULT CCoreCLRBinderHelper::Init(bool isBundle)
HRESULT CCoreCLRBinderHelper::Init()
{
STANDARD_VM_CONTRACT;
HRESULT hr = S_OK;
EX_TRY
{
hr = AssemblyBinder::Startup(isBundle);
hr = AssemblyBinder::Startup();
}
EX_CATCH_HRESULT(hr);

Expand Down Expand Up @@ -126,8 +127,7 @@ HRESULT CCoreCLRBinderHelper::BindToSystemSatellite(SString &systemPa
ICLRPrivAssembly **ppSystemAssembly)
{
HRESULT hr = S_OK;
VALIDATE_ARG_RET(ppSystemAssembly != NULL &&
(SystemDomain::System()->DefaultDomain()->HasBundle() || !systemPath.IsEmpty()));
VALIDATE_ARG_RET(ppSystemAssembly != NULL && (BundleInfo::AppIsBundle() || !systemPath.IsEmpty()));

EX_TRY
{
Expand Down Expand Up @@ -162,7 +162,7 @@ HRESULT CCoreCLRBinderHelper::GetAssemblyFromImage(PEImage *pPEImage,
}
}
EX_CATCH_HRESULT(hr);

return hr;
}

Expand Down
2 changes: 1 addition & 1 deletion src/binder/inc/assemblybinder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace BINDER_SPACE
class AssemblyBinder
{
public:
static HRESULT Startup(bool isBundle);
static HRESULT Startup();

// See code:BINDER_SPACE::AssemblyBinder::GetAssembly for info on fNgenExplicitBind
// and fExplicitBindToNativeImage, and see code:CEECompileInfo::LoadAssemblyByPath
Expand Down
2 changes: 1 addition & 1 deletion src/binder/inc/binderinterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace BINDER_SPACE

namespace BinderInterface
{
HRESULT Init(bool isBundle);
HRESULT Init();

HRESULT SetupContext(/* in */ LPCWSTR wszApplicationBase,
/* in */ DWORD dwAppDomainId,
Expand Down
2 changes: 1 addition & 1 deletion src/binder/inc/coreclrbindercommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CLRPrivBinderCoreCLR;
class CCoreCLRBinderHelper
{
public:
static HRESULT Init(bool isBundle);
static HRESULT Init();

static HRESULT DefaultBinderSetupContext(DWORD dwAppDomainId,
CLRPrivBinderCoreCLR **ppTPABinder);
Expand Down
3 changes: 1 addition & 2 deletions src/binder/inc/variables.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace BINDER_SPACE
Variables();
~Variables();

HRESULT Init(bool isBundle);
HRESULT Init();

// ApplicationContext string constants
SString AppBaseURL;
Expand Down Expand Up @@ -57,7 +57,6 @@ namespace BINDER_SPACE
CRITSEC_COOKIE m_logCS;
HandleHolder m_hDebugLogFile;
#endif // BINDER_DEBUG_LOG
BOOL fIsBundle;
#endif
};

Expand Down
5 changes: 1 addition & 4 deletions src/binder/variables.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace BINDER_SPACE
// Nothing to do here
}

HRESULT Variables::Init(bool isBundle)
HRESULT Variables::Init()
{
HRESULT hr = S_OK;

Expand Down Expand Up @@ -126,9 +126,6 @@ namespace BINDER_SPACE
}
}
#endif // FEATURE_VERSIONING_LOG

// Single-file Bundle flag
fIsBundle = isBundle;
}
EX_CATCH_HRESULT(hr);

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/hosts/coreconsole/coreconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo

log << W("Starting ICLRRuntimeHost4") << Logger::endl;

hr = host->Start(nullptr);
hr = host->Start();
if (FAILED(hr)) {
log << W("Failed to start CoreCLR. ERRORCODE: ") << hr << Logger:: endl;
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/hosts/corerun/corerun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ bool TryRun(const int argc, const wchar_t* argv[], Logger &log, const bool verbo

log << W("Starting ICLRRuntimeHost4") << Logger::endl;

hr = host->Start(nullptr);
hr = host->Start();
if (FAILED(hr)) {
log << W("Failed to start CoreCLR. ERRORCODE: ") << Logger::hresult << hr << Logger:: endl;
return false;
Expand Down
8 changes: 6 additions & 2 deletions src/dlls/mscoree/unixinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,13 @@ int coreclr_initialize(
hr = host->SetStartupFlags(startupFlags);
IfFailRet(hr);

static BundleInfo bundleInfo(StringToUnicode(exePath), bundleProbe);
if (bundleProbe != nullptr)
{
static BundleInfo bundleInfo(StringToUnicode(exePath), bundleProbe);
BundleInfo::AppBundle = &bundleInfo;
}

hr = host->Start((bundleProbe != nullptr) ? &bundleInfo : nullptr);
hr = host->Start();
IfFailRet(hr);

hr = host->CreateAppDomainWithManager(
Expand Down
5 changes: 1 addition & 4 deletions src/inc/MSCOREE.IDL
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ interface IHostControl;
cpp_quote("struct ICLRControl;")
interface ICLRControl;

cpp_quote("class BundleInfo;")
interface BundleInfo;

// CLSID ComCallUnmarshal2
cpp_quote("EXTERN_GUID(CLSID_ComCallUnmarshalV4, 0x45fb4600,0xe6e8,0x4928,0xb2,0x5e,0x50,0x47,0x6f,0xf7,0x94,0x25);")

Expand Down Expand Up @@ -224,7 +221,7 @@ typedef enum
interface ICLRRuntimeHost : IUnknown
{
// Starts the runtime. This is equivalent to CoInitializeCor().
HRESULT Start(const BundleInfo *bundleInfo);
HRESULT Start();

// Terminates the runtime, This is equivalent CoUninitializeCor();
HRESULT Stop();
Expand Down
5 changes: 4 additions & 1 deletion src/inc/corbundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class BundleInfo
public:
BundleInfo(LPCWSTR bundlePath, bool(*probe)(LPCSTR, INT64*, INT64*));
bool Probe(LPCWSTR path, INT64* size, INT64* offset) const;
LPCWSTR Path() const;
LPCWSTR Path() const { LIMITED_METHOD_CONTRACT; return m_path; }

static BundleInfo* AppBundle; // The BundleInfo for the current app, initialized by coreclr_initialize.
static bool AppIsBundle() { LIMITED_METHOD_CONTRACT; return AppBundle != nullptr; }

private:

Expand Down
4 changes: 2 additions & 2 deletions src/inc/corhost.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CorRuntimeHostBase
STDMETHODIMP_(ULONG) AddRef(void);

// Starts the runtime. This is equivalent to CoInitializeCor()
STDMETHODIMP Start(const BundleInfo *bundleInfo);
STDMETHODIMP Start();

STDMETHODIMP MapFile( // Return code.
HANDLE hFile, // [in] Handle for file
Expand Down Expand Up @@ -134,7 +134,7 @@ class CorHost2 :
#endif // FEATURE_PAL

// Starts the runtime. This is equivalent to CoInitializeCor().
STDMETHODIMP Start(const BundleInfo *bundleInfo);
STDMETHODIMP Start();
STDMETHODIMP Stop();

STDMETHODIMP ExecuteInAppDomain(DWORD dwAppDomainId,
Expand Down
4 changes: 1 addition & 3 deletions src/pal/prebuilt/inc/mscoree.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ struct IHostControl;

struct ICLRControl;

class BundleInfo;

EXTERN_GUID(CLSID_ComCallUnmarshalV4, 0x45fb4600,0xe6e8,0x4928,0xb2,0x5e,0x50,0x47,0x6f,0xf7,0x94,0x25);
EXTERN_GUID(IID_ICLRRuntimeHost, 0x90F1A06C, 0x7712, 0x4762, 0x86, 0xB5, 0x7A, 0x5E, 0xBA, 0x6B, 0xDB, 0x02);
EXTERN_GUID(IID_ICLRRuntimeHost2, 0x712AB73F, 0x2C22, 0x4807, 0xAD, 0x7E, 0xF5, 0x01, 0xD7, 0xb7, 0x2C, 0x2D);
Expand Down Expand Up @@ -254,7 +252,7 @@ EXTERN_C const IID IID_ICLRRuntimeHost;
ICLRRuntimeHost : public IUnknown
{
public:
virtual HRESULT STDMETHODCALLTYPE Start(const BundleInfo *bundleInfo) = 0;
virtual HRESULT STDMETHODCALLTYPE Start() = 0;

virtual HRESULT STDMETHODCALLTYPE Stop( void) = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "comdelegate.h"
#include "siginfo.hpp"
#include "typekey.h"

#include "corbundle.h"
#include "caparser.h"
#include "ecall.h"
#include "finalizerthread.h"
Expand Down Expand Up @@ -1841,7 +1841,7 @@ void SystemDomain::Init()
// If we are running from a self-contained single-file bundle, the
// runtime is contained within the bundle.
// So, skip computing the systemDirectory, and leave it set to empty-string.
if (!pAppDomain->HasBundle())
if (!BundleInfo::AppIsBundle())
{
// Get the install directory so we can find mscorlib
hr = GetInternalSystemDirectory(NULL, &size);
Expand Down
4 changes: 0 additions & 4 deletions src/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2723,12 +2723,8 @@ class AppDomain : public BaseDomain
size_t m_MemoryPressure;

ArrayList m_NativeDllSearchDirectories;
const BundleInfo *m_BundleInfo;
bool m_ForceTrivialWaitOperations;

bool HasBundle() { return m_BundleInfo != nullptr; }
const BundleInfo* BundleInfo() { return m_BundleInfo; }

public:

#ifdef FEATURE_TYPEEQUIVALENCE
Expand Down
32 changes: 10 additions & 22 deletions src/vm/ceemain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ static int GetThreadUICultureId(__out LocaleIDValue* pLocale); // TODO: This sh
static HRESULT GetThreadUICultureNames(__inout StringArrayList* pCultureNames);
#endif // !CROSSGEN_COMPILE

HRESULT EEStartup(COINITIEE fFlags, const BundleInfo *bundleInfo);
HRESULT EEStartup(COINITIEE fFlags);


#ifndef CROSSGEN_COMPILE
Expand Down Expand Up @@ -270,22 +270,22 @@ static CLREvent * g_pEEShutDownEvent;

static DangerousNonHostedSpinLock g_EEStartupLock;

HRESULT InitializeEE(COINITIEE flags, const BundleInfo* bundleInfo)
HRESULT InitializeEE(COINITIEE flags)
{
WRAPPER_NO_CONTRACT;
#ifdef FEATURE_EVENT_TRACE
if (!g_fEEComActivatedStartup)
g_fEEOtherStartup = TRUE;
#endif // FEATURE_EVENT_TRACE
return EnsureEEStarted(flags, bundleInfo);
return EnsureEEStarted(flags);
}

// ---------------------------------------------------------------------------
// %%Function: EnsureEEStarted()
//
// Description: Ensure the CLR is started.
// ---------------------------------------------------------------------------
HRESULT EnsureEEStarted(COINITIEE flags, const BundleInfo *bundleInfo)
HRESULT EnsureEEStarted(COINITIEE flags)
{
CONTRACTL
{
Expand Down Expand Up @@ -339,7 +339,7 @@ HRESULT EnsureEEStarted(COINITIEE flags, const BundleInfo *bundleInfo)
{
g_dwStartupThreadId = GetCurrentThreadId();

EEStartup(flags, bundleInfo);
EEStartup(flags);
bStarted=g_fEEStarted;
hr = g_EEStartupStatus;

Expand Down Expand Up @@ -621,7 +621,7 @@ void EESocketCleanupHelper()
#endif // FEATURE_PAL
#endif // CROSSGEN_COMPILE

void EEStartupHelper(COINITIEE fFlags, const BundleInfo* bundleInfo)
void EEStartupHelper(COINITIEE fFlags)
{
CONTRACTL
{
Expand Down Expand Up @@ -739,7 +739,7 @@ void EEStartupHelper(COINITIEE fFlags, const BundleInfo* bundleInfo)

// Fusion
// Initialize the general Assembly Binder infrastructure
IfFailGoLog(CCoreCLRBinderHelper::Init(/*IsBundle?*/ bundleInfo != nullptr));
IfFailGoLog(CCoreCLRBinderHelper::Init());

if (g_pConfig != NULL)
{
Expand Down Expand Up @@ -859,11 +859,6 @@ void EEStartupHelper(COINITIEE fFlags, const BundleInfo* bundleInfo)
BaseDomain::Attach();
SystemDomain::Attach();

// Fill in the Bundle Info, if any. This step must be done before
// SystemDomain::Init() -- so that the location of corelib is available.

SystemDomain::System()->DefaultDomain()->m_BundleInfo = bundleInfo;

// Start up the EE intializing all the global variables
ECall::Init();

Expand Down Expand Up @@ -1125,21 +1120,14 @@ LONG FilterStartupException(PEXCEPTION_POINTERS p, PVOID pv)
// see code:EEStartup#TableOfContents for more on the runtime in general.
// see code:#EEShutdown for a analagous routine run during shutdown.
//

HRESULT EEStartup(COINITIEE fFlags, const BundleInfo* bundleInfo)
HRESULT EEStartup(COINITIEE fFlags)
{
// Cannot use normal contracts here because of the PAL_TRY.
STATIC_CONTRACT_NOTHROW;

_ASSERTE(!g_fEEStarted && !g_fEEInit && SUCCEEDED (g_EEStartupStatus));

struct EEStartupParams
{
COINITIEE Flags;
const BundleInfo* Info;
} eeParams = { fFlags, bundleInfo };

PAL_TRY(EEStartupParams*, params, &eeParams)
PAL_TRY(COINITIEE*, pfFlags, &fFlags)
{
#ifndef CROSSGEN_COMPILE
InitializeClrNotifications();
Expand All @@ -1149,7 +1137,7 @@ HRESULT EEStartup(COINITIEE fFlags, const BundleInfo* bundleInfo)
#endif
#endif // CROSSGEN_COMPILE

EEStartupHelper(params->Flags, params->Info);
EEStartupHelper(*pfFlags);
}
PAL_EXCEPT_FILTER (FilterStartupException)
{
Expand Down
Loading

0 comments on commit bb6e54c

Please sign in to comment.