Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1c0b32b
from prototype
VSadov Nov 12, 2020
4adfaa6
fix OSX
VSadov Nov 12, 2020
0facc65
fix for Android
VSadov Nov 16, 2020
a2ab07c
treat "libSystem.Globalization.Native" as QCall in mono too (for now).
VSadov Nov 17, 2020
2b2f800
fix for wasm
VSadov Nov 19, 2020
8c4e514
current
VSadov Nov 20, 2020
6e584b4
remove no longer needed hacks
VSadov Nov 20, 2020
ba71464
Undo confusing changes for now
VSadov Nov 20, 2020
4563d69
fix pedantic errors on GCC
VSadov Nov 20, 2020
51281d6
delete gPalGlobalizationNative
VSadov Nov 21, 2020
25369f4
pass overrider from the host
VSadov Nov 21, 2020
e6fca93
default override
VSadov Nov 21, 2020
c11612f
default PInvoke override runs after optional host-provided overrider.
VSadov Nov 23, 2020
d3f4abe
Some PR feedback (mostly related to code, not the CMake stuff).
VSadov Nov 25, 2020
79453c7
more coding PR feedback
VSadov Dec 1, 2020
becda0e
Deleted "libraries-native" folder.
VSadov Dec 1, 2020
932b5fe
unifying tryrun.cmake into 1 common file
VSadov Dec 2, 2020
3f5cea9
factor out adding lib-specific dependencies into one place (per nativ…
VSadov Dec 3, 2020
8d2b6b9
cleanup: entirely remove tryrun.cmake propagation in eng, gen-buildsy…
VSadov Dec 3, 2020
9b7476f
remove "clrcompression.dll" and "libSystem.IO.Compression.Native.dyli…
VSadov Dec 3, 2020
8a02254
mono: refactor Globalization lookup into `default_resolve_dllimport`.
VSadov Dec 3, 2020
f22e9fd
set FEATURE_DISTRO_AGNOSTIC_SSL according to __PortableBuild
VSadov Dec 3, 2020
e539a1a
CORECLR_CALLING_CONVENTION for the host callback types
VSadov Dec 3, 2020
06dad00
revert change in pal_gssapi.h
VSadov Dec 3, 2020
ac026ba
keep the #include "pal_config.h"
VSadov Dec 4, 2020
eb62c4a
refactor common parts of entrypoints.c into entrypoints.h
VSadov Dec 4, 2020
2f45a47
rename OverrideEntry --> DllImportEntry
VSadov Dec 4, 2020
7b2bdef
extra libs as CMake functions
VSadov Dec 4, 2020
7ab3211
use macros instead of functions in extra_libs.cmake
VSadov Dec 4, 2020
7bf0a63
mono formatting style in src/mono/mono/metadata/native-library.c
VSadov Dec 4, 2020
d3a15fa
mono: Remaining stylistic nits.
VSadov Dec 4, 2020
6c55b68
do not set DFEATURE_DISTRO_AGNOSTIC_SSL on iOS, Android, tvOS
VSadov Dec 7, 2020
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
Prev Previous commit
Next Next commit
current
  • Loading branch information
VSadov committed Dec 5, 2020
commit 8c4e51485eb72d484a6b208481bf1ef830b3620c
12 changes: 12 additions & 0 deletions src/coreclr/src/dlls/mscoree/unixinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
#include "../../vm/gdbjithelpers.h"
#endif // FEATURE_GDBJIT
#include "bundle.h"
#include "pinvokeoverride.h"

// TODO: WIP, this is for testing, will remove later.
#include "pinvokeoverrideimpl.h"

#define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS(__FILE__, (expr))

Expand Down Expand Up @@ -211,6 +215,14 @@ int coreclr_initialize(

g_hostpolicy_embedded = hostPolicyEmbedded;

// TODO: WIP, fetch this from args similar to Bundle/bundleProbe
//
// if (overider != nullptr)
// {
// PInvokeOverride::SetPInvokeOverride(overrider);
// }
PInvokeOverride::SetPInvokeOverride(SuperHost::ResolveDllImport);

ReleaseHolder<ICLRRuntimeHost4> host;

hr = CorHost2::CreateObject(IID_ICLRRuntimeHost4, (void**)&host);
Expand Down
26 changes: 26 additions & 0 deletions src/coreclr/src/inc/pinvokeoverride.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/*****************************************************************************
** **
** pinvokeoverride.h - PInvoke binding override **
** **
*****************************************************************************/

#ifndef _PINVOKEOVERRIDE_H_
#define _PINVOKEOVERRIDE_H_

typedef const void* (__stdcall PInvokeOverrideFn)(const char* libraryName, const char* entrypointName);

class PInvokeOverride
{
private:
static PInvokeOverrideFn* s_overrideImpl;

public:
static void SetPInvokeOverride(PInvokeOverrideFn* overrideImpl);
static const void* TryGetMethodImpl(const char* libraryName, const char* entrypointName);
};

#endif // _PINVOKEOVERRIDE_H_
// EOF =======================================================================
12 changes: 12 additions & 0 deletions src/coreclr/src/inc/pinvokeoverrideimpl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

//
// REVIEW: THE IMPLEMENTATION FOR THE OVERRIDER WILL BE MOVED TO HOST
//

namespace SuperHost
{
const void* ResolveDllImport(const char* libraryName, const char* entrypointName);
}
2 changes: 2 additions & 0 deletions src/coreclr/src/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ set(VM_SOURCES_DAC_AND_WKS_COMMON
perfmap.cpp
perfinfo.cpp
pgo.cpp
pinvokeoverride.cpp
pinvokeoverrideimpl.cpp
precode.cpp
prestub.cpp
profilerdiagnosticprotocolhelper.cpp
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/src/vm/corelib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,6 @@ const USHORT c_nCoreLibFieldDescriptions = NumItems(c_rgCoreLibFieldDescriptions
// ECalls
//

// ECalls defined by libraries-native shims
EXTERN_C const LPVOID gPalGlobalizationNative[];
EXTERN_C const LPVOID gEmbedded_Brotli[];
EXTERN_C const LPVOID gEmbedded_zlib[];

// When compiling crossgen, we only need the target version of the ecall tables
#if !defined(CROSSGEN_COMPILE) || defined(CROSSGEN_CORELIB)

Expand Down
16 changes: 11 additions & 5 deletions src/coreclr/src/vm/dllimport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "strongnameholders.h"
#include "ecall.h"
#include "fieldmarshaler.h"
#include "pinvokeoverride.h"

#include <formattype.h>
#include "../md/compiler/custattr.h"
Expand Down Expand Up @@ -4230,11 +4231,7 @@ void NDirect::PopulateNDirectMethodDesc(NDirectMethodDesc* pNMD, PInvokeStaticSi
if (callConv == pmCallConvThiscall)
ndirectflags |= NDirectMethodDesc::kThisCall;

if ((pNMD->GetLoaderModule()->IsSystem() && (strcmp(szLibName, "QCall") == 0)) ||
(szLibName != NULL &&
(strcmp(szLibName, "libSystem.Globalization.Native") == 0 ||
strcmp(szLibName, "libSystem.IO.Compression.Native") == 0 ||
strcmp(szLibName, "clrcompression") == 0)))
if (pNMD->GetLoaderModule()->IsSystem() && (strcmp(szLibName, "QCall") == 0))
{
ndirectflags |= NDirectMethodDesc::kIsQCall;
}
Expand Down Expand Up @@ -6512,6 +6509,15 @@ VOID NDirect::NDirectLink(NDirectMethodDesc *pMD)
// Loading unmanaged dlls can trigger dllmains which certainly count as code execution!
pMD->EnsureActive();

{
LPVOID pvTarget = (LPVOID)PInvokeOverride::TryGetMethodImpl(pMD->GetLibNameRaw(), pMD->GetEntrypointName());
if (pvTarget != NULL)
{
pMD->SetNDirectTarget(pvTarget);
return;
}
}

LoadLibErrorTracker errorTracker;

BOOL fSuccess = FALSE;
Expand Down
10 changes: 0 additions & 10 deletions src/coreclr/src/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -1116,9 +1116,6 @@ FCClassElement("AssemblyExtensions", "System.Reflection.Metadata", gAssemblyExte
FCClassElement("AssemblyLoadContext", "System.Runtime.Loader", gAssemblyLoadContextFuncs)

FCClassElement("AssemblyName", "System.Reflection", gAssemblyNameFuncs)
#ifndef CROSSGEN_COMPILE
FCClassElement("Brotli", "", gEmbedded_Brotli)
#endif
FCClassElement("Buffer", "System", gBufferFuncs)
FCClassElement("CLRConfig", "System", gClrConfig)
FCClassElement("CastHelpers", "System.Runtime.CompilerServices", gCastHelpers)
Expand All @@ -1142,9 +1139,6 @@ FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs)
FCClassElement("GC", "System", gGCInterfaceFuncs)
FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs)
FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs)
#ifndef CROSSGEN_COMPILE
FCClassElement("Globalization", "", gPalGlobalizationNative)
#endif
#ifdef FEATURE_COMINTEROP
FCClassElement("IEnumerable", "System.Collections", gStdMngIEnumerableFuncs)
FCClassElement("IEnumerator", "System.Collections", gStdMngIEnumeratorFuncs)
Expand Down Expand Up @@ -1227,10 +1221,6 @@ FCClassElement("X86Base", "System.Runtime.Intrinsics.X86", gX86BaseFuncs)
FCClassElement("XplatEventLogger", "System.Diagnostics.Tracing", gEventLogger)
#endif //defined(FEATURE_EVENTSOURCE_XPLAT)

#ifndef CROSSGEN_COMPILE
FCClassElement("zlib", "", gEmbedded_zlib)
#endif

#undef FCFuncElement
#undef FCFuncElementSig
#undef FCIntrinsic
Expand Down
24 changes: 24 additions & 0 deletions src/coreclr/src/vm/pinvokeoverride.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//*****************************************************************************
// pinvokeoverride.cpp
//
// Helpers to implement PInvoke overriding
//
//*****************************************************************************

#include "pinvokeoverride.h"

PInvokeOverrideFn* PInvokeOverride::s_overrideImpl = nullptr;

void PInvokeOverride::SetPInvokeOverride(PInvokeOverrideFn* overrideImpl)
{
s_overrideImpl = overrideImpl;
}

const void* PInvokeOverride::TryGetMethodImpl(const char* libraryName, const char* entrypointName)
{
return s_overrideImpl ?
s_overrideImpl(libraryName, entrypointName) :
nullptr;
}
32 changes: 32 additions & 0 deletions src/coreclr/src/vm/pinvokeoverrideimpl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//

//
// REVIEW: THE IMPLEMENTATION FOR THE OVERRIDER WILL BE MOVED TO HOST
//

#include "common.h"
#include "pinvokeoverrideimpl.h"

extern "C" const void* GlobalizationResolveDllImport(const char* name);
extern "C" const void* CompressionResolveDllImport(const char* name);

const void* SuperHost::ResolveDllImport(const char* libraryName, const char* entrypointName)
{
if (strcmp(libraryName, "libSystem.Globalization.Native") == 0)
{
return GlobalizationResolveDllImport(entrypointName);
}

#if defined(_WIN32)
if (strcmp(libraryName, "clrcompression") == 0)
#else
if (strcmp(libraryName, "libSystem.IO.Compression.Native") == 0)
#endif
{
return CompressionResolveDllImport(entrypointName);
}

return nullptr;
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

#include <string.h>
#include <stdint.h>

// Include System.IO.Compression.Native headers
Expand All @@ -10,33 +11,47 @@
#include "../brotli/include/brotli/port.h"
#include "../brotli/include/brotli/types.h"

#define FCFuncStart(name) EXTERN_C const void* name[]; const void* name[] = {
#define FCFuncEnd() (void*)0x01 /* FCFuncFlag_EndOfArray */ };
#ifndef lengthof
#define lengthof(rg) (sizeof(rg)/sizeof(rg[0]))
#endif

#define QCFuncElement(name,impl) \
(void*)0x8 /* FCFuncFlag_QCall */, (void*)(impl), (void*)name,
typedef struct
{
const char* name;
const void* method;
} Entry;

FCFuncStart(gEmbedded_Brotli)
QCFuncElement("BrotliDecoderCreateInstance", BrotliDecoderCreateInstance)
QCFuncElement("BrotliDecoderDecompress", BrotliDecoderDecompress)
QCFuncElement("BrotliDecoderDecompressStream", BrotliDecoderDecompressStream)
QCFuncElement("BrotliDecoderDestroyInstance", BrotliDecoderDestroyInstance)
QCFuncElement("BrotliDecoderIsFinished", BrotliDecoderIsFinished)
QCFuncElement("BrotliEncoderCompress", BrotliEncoderCompress)
QCFuncElement("BrotliEncoderCompressStream", BrotliEncoderCompressStream)
QCFuncElement("BrotliEncoderCreateInstance", BrotliEncoderCreateInstance)
QCFuncElement("BrotliEncoderDestroyInstance", BrotliEncoderDestroyInstance)
QCFuncElement("BrotliEncoderHasMoreOutput", BrotliEncoderHasMoreOutput)
QCFuncElement("BrotliEncoderSetParameter", BrotliEncoderSetParameter)
FCFuncEnd()
static Entry s_compressionNative[] =
{
{"BrotliDecoderCreateInstance", BrotliDecoderCreateInstance},
{"BrotliDecoderDecompress", BrotliDecoderDecompress},
{"BrotliDecoderDecompressStream", BrotliDecoderDecompressStream},
{"BrotliDecoderDestroyInstance", BrotliDecoderDestroyInstance},
{"BrotliDecoderIsFinished", BrotliDecoderIsFinished},
{"BrotliEncoderCompress", BrotliEncoderCompress},
{"BrotliEncoderCompressStream", BrotliEncoderCompressStream},
{"BrotliEncoderCreateInstance", BrotliEncoderCreateInstance},
{"BrotliEncoderDestroyInstance", BrotliEncoderDestroyInstance},
{"BrotliEncoderHasMoreOutput", BrotliEncoderHasMoreOutput},
{"BrotliEncoderSetParameter", BrotliEncoderSetParameter},
{"CompressionNative_Crc32", CompressionNative_Crc32},
{"CompressionNative_Deflate", CompressionNative_Deflate},
{"CompressionNative_DeflateEnd", CompressionNative_DeflateEnd},
{"CompressionNative_DeflateInit2_", CompressionNative_DeflateInit2_},
{"CompressionNative_Inflate", CompressionNative_Inflate},
{"CompressionNative_InflateEnd", CompressionNative_InflateEnd},
{"CompressionNative_InflateInit2_", CompressionNative_InflateInit2_},
};

FCFuncStart(gEmbedded_zlib)
QCFuncElement("crc32", CompressionNative_Crc32)
QCFuncElement("Deflate", CompressionNative_Deflate)
QCFuncElement("DeflateEnd", CompressionNative_DeflateEnd)
QCFuncElement("DeflateInit2_", CompressionNative_DeflateInit2_)
QCFuncElement("Inflate", CompressionNative_Inflate)
QCFuncElement("InflateEnd", CompressionNative_InflateEnd)
QCFuncElement("InflateInit2_", CompressionNative_InflateInit2_)
FCFuncEnd()
extern const void* CompressionResolveDllImport(const char* name)
{
for (int i = 0; i < lengthof(s_compressionNative); i++)
{
if (strcmp(name, s_compressionNative[i].name) == 0)
{
return s_compressionNative[i].method;
}
}

return NULL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

#include <stdint.h>
#include <string.h>

typedef uint16_t UChar;

Expand Down Expand Up @@ -60,3 +61,64 @@ FCFuncStart(gPalGlobalizationNative)
QCFuncElement("ToAscii", GlobalizationNative_ToAscii)
QCFuncElement("ToUnicode", GlobalizationNative_ToUnicode)
FCFuncEnd()

#ifndef lengthof
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to extract these into a common header shared by all the System.* libraries instead of repeating the definitions of the macro and struct in each one. And maybe the lookup code too, creating a common function with (Entry*, count, name) arguments.

#define lengthof(rg) (sizeof(rg)/sizeof(rg[0]))
#endif

typedef struct
{
const char* name;
const void* method;
} Entry;

static Entry s_globalizationNative[] =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't linker-friendly. IT will keep every globalization function alive even if the IL Linker eliminates them all.

The data should be in a separate file from the lookup algorithm so that (for example) the WASM toolchain can supply a trimmed version of this table.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work ok with the linker as long as you are careful to not reference this mapping table. I agree that it is fragile.

Consideration of linker friendliness was why these were in separate location (src/coreclr/src/libraries-native) originally. #37670 folded the mapping table into the implementation.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, are we linker-friendly here or need changes?

{
{"GlobalizationNative_ChangeCase", GlobalizationNative_ChangeCase},
{"GlobalizationNative_ChangeCaseInvariant", GlobalizationNative_ChangeCaseInvariant},
{"GlobalizationNative_ChangeCaseTurkish", GlobalizationNative_ChangeCaseTurkish},
{"GlobalizationNative_CloseSortHandle", GlobalizationNative_CloseSortHandle},
{"GlobalizationNative_CompareString", GlobalizationNative_CompareString},
{"GlobalizationNative_EndsWith", GlobalizationNative_EndsWith},
{"GlobalizationNative_EnumCalendarInfo", GlobalizationNative_EnumCalendarInfo},
{"GlobalizationNative_GetCalendarInfo", GlobalizationNative_GetCalendarInfo},
{"GlobalizationNative_GetCalendars", GlobalizationNative_GetCalendars},
{"GlobalizationNative_GetDefaultLocaleName", GlobalizationNative_GetDefaultLocaleName},
{"GlobalizationNative_GetICUVersion", GlobalizationNative_GetICUVersion},
{"GlobalizationNative_GetJapaneseEraStartDate", GlobalizationNative_GetJapaneseEraStartDate},
{"GlobalizationNative_GetLatestJapaneseEra", GlobalizationNative_GetLatestJapaneseEra},
{"GlobalizationNative_GetLocaleInfoGroupingSizes", GlobalizationNative_GetLocaleInfoGroupingSizes},
{"GlobalizationNative_GetLocaleInfoInt", GlobalizationNative_GetLocaleInfoInt},
{"GlobalizationNative_GetLocaleInfoString", GlobalizationNative_GetLocaleInfoString},
{"GlobalizationNative_GetLocaleName", GlobalizationNative_GetLocaleName},
{"GlobalizationNative_GetLocales", GlobalizationNative_GetLocales},
{"GlobalizationNative_GetLocaleTimeFormat", GlobalizationNative_GetLocaleTimeFormat},
{"GlobalizationNative_GetSortHandle", GlobalizationNative_GetSortHandle},
{"GlobalizationNative_GetSortKey", GlobalizationNative_GetSortKey},
{"GlobalizationNative_GetSortVersion", GlobalizationNative_GetSortVersion},
{"GlobalizationNative_GetTimeZoneDisplayName", GlobalizationNative_GetTimeZoneDisplayName},
{"GlobalizationNative_IndexOf", GlobalizationNative_IndexOf},
{"GlobalizationNative_InitICUFunctions", GlobalizationNative_InitICUFunctions},
{"GlobalizationNative_InitOrdinalCasingPage", GlobalizationNative_InitOrdinalCasingPage},
{"GlobalizationNative_IsNormalized", GlobalizationNative_IsNormalized},
{"GlobalizationNative_IsPredefinedLocale", GlobalizationNative_IsPredefinedLocale},
{"GlobalizationNative_LastIndexOf", GlobalizationNative_LastIndexOf},
{"GlobalizationNative_LoadICU", GlobalizationNative_LoadICU},
{"GlobalizationNative_NormalizeString", GlobalizationNative_NormalizeString},
{"GlobalizationNative_StartsWith", GlobalizationNative_StartsWith},
{"GlobalizationNative_ToAscii", GlobalizationNative_ToAscii},
{"GlobalizationNative_ToUnicode", GlobalizationNative_ToUnicode},
};

extern "C" const void* GlobalizationResolveDllImport(const char* name)
{
for (int i = 0; i < lengthof(s_globalizationNative); i++)
{
if (strcmp(name, s_globalizationNative[i].name) == 0)
{
return s_globalizationNative[i].method;
}
}

return NULL;
}