Skip to content

Fix embedded coreclr detection in corhost.cpp #80294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 6, 2023
Merged
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
7 changes: 1 addition & 6 deletions src/coreclr/dlls/mscoree/exports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <utilcode.h>
#include <corhost.h>
#include <configuration.h>
#include "../../vm/ceemain.h"
#ifdef FEATURE_GDBJIT
#include "../../vm/gdbjithelpers.h"
#endif // FEATURE_GDBJIT
Expand All @@ -27,12 +28,6 @@
// Holder for const wide strings
typedef NewArrayHolder<const WCHAR> ConstWStringHolder;

// Specifies whether coreclr is embedded or standalone
extern bool g_coreclr_embedded;

// Specifies whether hostpolicy is embedded in executable or standalone
extern bool g_hostpolicy_embedded;

// Holder for array of wide strings
class ConstWStringArrayHolder : public NewArrayHolder<LPCWSTR>
{
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/vm/ceemain.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,10 @@ INT32 GetLatchedExitCode (void);
// Stronger than IsGCHeapInitialized
BOOL IsGarbageCollectorFullyInitialized();

// Specifies whether coreclr is embedded or standalone
extern bool g_coreclr_embedded;

// Specifies whether hostpolicy is embedded in executable or standalone
extern bool g_hostpolicy_embedded;

#endif
33 changes: 18 additions & 15 deletions src/coreclr/vm/corhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,23 +630,26 @@ HRESULT CorHost2::CreateAppDomainWithManager(
sAppPaths));
}

#if defined(TARGET_UNIX) && !defined(CORECLR_EMBEDDED)
// Check if the current code is executing in the single file host or in libcoreclr.so. The libSystem.Native is linked
// into the single file host, so we need to check only when this code is in libcoreclr.so.
// Preload the libSystem.Native.so/dylib to detect possible problems with loading it early
EX_TRY
{
NativeLibrary::LoadLibraryByName(W("libSystem.Native"), SystemDomain::SystemAssembly(), FALSE, 0, TRUE);
}
EX_HOOK
#if defined(TARGET_UNIX)
if (!g_coreclr_embedded)
{
Exception *ex = GET_EXCEPTION();
SString err;
ex->GetMessage(err);
LogErrorToHost("Error message: %s", err.GetUTF8());
// Check if the current code is executing in the single file host or in libcoreclr.so. The libSystem.Native is linked
// into the single file host, so we need to check only when this code is in libcoreclr.so.
// Preload the libSystem.Native.so/dylib to detect possible problems with loading it early
EX_TRY
{
NativeLibrary::LoadLibraryByName(W("libSystem.Native"), SystemDomain::SystemAssembly(), FALSE, 0, TRUE);
}
EX_HOOK
{
Exception *ex = GET_EXCEPTION();
SString err;
ex->GetMessage(err);
LogErrorToHost("Error message: %s", err.GetUTF8());
}
EX_END_HOOK;
}
EX_END_HOOK;
#endif // TARGET_UNIX && !CORECLR_EMBEDDED
#endif // TARGET_UNIX

*pAppDomainID=DefaultADID;

Expand Down