diff --git a/eng/native.wasm.targets b/eng/native.wasm.targets
index 8f5d59d25c05a0..790aa1a711c65b 100644
--- a/eng/native.wasm.targets
+++ b/eng/native.wasm.targets
@@ -22,7 +22,10 @@
-
+
+
+
+
diff --git a/src/coreclr/CMakeLists.txt b/src/coreclr/CMakeLists.txt
index 1c8c544b3879a9..4061bf8f294e4d 100644
--- a/src/coreclr/CMakeLists.txt
+++ b/src/coreclr/CMakeLists.txt
@@ -79,8 +79,7 @@ endif()
if(NOT CLR_CROSS_COMPONENTS_BUILD)
set(STATIC_LIBS_ONLY 1)
if(CLR_CMAKE_TARGET_BROWSER)
- # WASM-TODO set GEN_PINVOKE to 1 once we generate them. static entrypoint.c prevents C linker from trimming, when IL trimming trims PInvokes
- set(GEN_PINVOKE 0)
+ set(GEN_PINVOKE 1)
set(BUILD_LIBS_NATIVE_BROWSER 1)
set(STATIC_LIB_DESTINATION ${CMAKE_BINARY_DIR}/libs-native)
set(CORERUN_LIBS_ONLY 1)
diff --git a/src/coreclr/hosts/corerun/CMakeLists.txt b/src/coreclr/hosts/corerun/CMakeLists.txt
index 53f647085db21a..37f92d61e71ef4 100644
--- a/src/coreclr/hosts/corerun/CMakeLists.txt
+++ b/src/coreclr/hosts/corerun/CMakeLists.txt
@@ -52,8 +52,14 @@ else()
target_include_directories(corerun PRIVATE ./wasm/)
target_link_libraries(corerun PRIVATE
coreclr_static
+ System.IO.Compression.Native-Static
System.Native-Static
System.Native.TimeZoneData.Invariant)
+
+ # additional requirements for System.IO.Compression.Native
+ include(${CLR_SRC_NATIVE_DIR}/libs/System.IO.Compression.Native/extra_libs.cmake)
+ append_extra_compression_libs(NATIVE_LIBS)
+
# linker options for NodeJs, link in JavaScript helper, access to local filesystem
if (CLR_CMAKE_TARGET_BROWSER)
target_link_libraries(corerun PRIVATE
diff --git a/src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp b/src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp
index 26cc0d7a426806..a568275ddd97ee 100644
--- a/src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp
+++ b/src/coreclr/hosts/corerun/wasm/pinvoke_override.cpp
@@ -2,28 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
#include
-
-#define _In_z_
-#define _In_
+#include
#include "pinvokeoverride.h"
-extern "C" const void* SystemResolveDllImport(const char* name);
-
-// pinvoke_override:
-// Check if given function belongs to one of statically linked libraries and return a pointer if found.
-static const void* pinvoke_override(const char* library_name, const char* entry_point_name)
-{
- // This function is only called with the library name specified for a p/invoke, not any variations.
- // It must handle exact matches to the names specified. See Interop.Libraries.cs for each platform.
- if (strcmp(library_name, "libSystem.Native") == 0)
- {
- return SystemResolveDllImport(entry_point_name);
- }
-
- return nullptr;
-}
+const void* callhelpers_pinvoke_override(const char* library_name, const char* entry_point_name);
void add_pinvoke_override()
{
- PInvokeOverride::SetPInvokeOverride(pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration);
+ PInvokeOverride::SetPInvokeOverride(callhelpers_pinvoke_override, PInvokeOverride::Source::RuntimeConfiguration);
}
diff --git a/src/coreclr/vm/CMakeLists.txt b/src/coreclr/vm/CMakeLists.txt
index 4966617f6afe23..982ea2ba74831b 100644
--- a/src/coreclr/vm/CMakeLists.txt
+++ b/src/coreclr/vm/CMakeLists.txt
@@ -947,6 +947,11 @@ elseif(CLR_CMAKE_TARGET_ARCH_WASM)
exceptionhandling.cpp
gcinfodecoder.cpp
)
+ if (GEN_PINVOKE)
+ list(APPEND VM_SOURCES_WKS_ARCH
+ ${ARCH_SOURCES_DIR}/callhelpers-pinvoke.cpp
+ )
+ endif(GEN_PINVOKE)
endif()
set(VM_SOURCES_DAC_ARCH
diff --git a/src/coreclr/vm/pinvokeoverride.cpp b/src/coreclr/vm/pinvokeoverride.cpp
index d8f1d0972a3994..74901214e85685 100644
--- a/src/coreclr/vm/pinvokeoverride.cpp
+++ b/src/coreclr/vm/pinvokeoverride.cpp
@@ -27,10 +27,12 @@ namespace
// here we handle PInvokes whose implementation is always statically linked (even in .so/.dll case)
static const void* DefaultResolveDllImport(const char* libraryName, const char* entrypointName)
{
+#ifndef TARGET_WASM
if (strcmp(libraryName, GLOBALIZATION_DLL_NAME) == 0)
{
return GlobalizationResolveDllImport(entrypointName);
}
+#endif // TARGET_WASM
return nullptr;
}
diff --git a/src/coreclr/vm/wasm/callhelpers-pinvoke.cpp b/src/coreclr/vm/wasm/callhelpers-pinvoke.cpp
new file mode 100644
index 00000000000000..f8729546cf95b9
--- /dev/null
+++ b/src/coreclr/vm/wasm/callhelpers-pinvoke.cpp
@@ -0,0 +1,334 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+//
+
+//
+// GENERATED FILE, DON'T EDIT
+// Generated by coreclr callhelpers generator
+//
+
+#include
+#include
+
+extern "C" {
+ uint32_t CompressionNative_Crc32 (uint32_t, void *, int32_t);
+ int32_t CompressionNative_Deflate (void *, int32_t);
+ int32_t CompressionNative_DeflateEnd (void *);
+ int32_t CompressionNative_DeflateInit2_ (void *, int32_t, int32_t, int32_t, int32_t, int32_t);
+ int32_t CompressionNative_Inflate (void *, int32_t);
+ int32_t CompressionNative_InflateEnd (void *);
+ int32_t CompressionNative_InflateInit2_ (void *, int32_t);
+ int32_t CompressionNative_InflateReset2_ (void *, int32_t);
+ void GlobalizationNative_ChangeCase (void *, int32_t, void *, int32_t, int32_t);
+ void GlobalizationNative_ChangeCaseInvariant (void *, int32_t, void *, int32_t, int32_t);
+ void GlobalizationNative_ChangeCaseTurkish (void *, int32_t, void *, int32_t, int32_t);
+ void GlobalizationNative_CloseSortHandle (void *);
+ int32_t GlobalizationNative_CompareString (void *, void *, int32_t, void *, int32_t, int32_t);
+ int32_t GlobalizationNative_EndsWith (void *, void *, int32_t, void *, int32_t, int32_t, void *);
+ int32_t GlobalizationNative_EnumCalendarInfo (void *, void *, uint32_t, int32_t, void *);
+ int32_t GlobalizationNative_GetCalendarInfo (void *, uint32_t, int32_t, void *, int32_t);
+ int32_t GlobalizationNative_GetCalendars (void *, void *, int32_t);
+ int32_t GlobalizationNative_GetDefaultLocaleName (void *, int32_t);
+ int32_t GlobalizationNative_GetICUVersion ();
+ int32_t GlobalizationNative_GetJapaneseEraStartDate (int32_t, void *, void *, void *);
+ int32_t GlobalizationNative_GetLatestJapaneseEra ();
+ int32_t GlobalizationNative_GetLocaleInfoGroupingSizes (void *, uint32_t, void *, void *);
+ int32_t GlobalizationNative_GetLocaleInfoInt (void *, uint32_t, void *);
+ int32_t GlobalizationNative_GetLocaleInfoString (void *, uint32_t, void *, int32_t, void *);
+ int32_t GlobalizationNative_GetLocaleName (void *, void *, int32_t);
+ int32_t GlobalizationNative_GetLocaleTimeFormat (void *, int32_t, void *, int32_t);
+ int32_t GlobalizationNative_GetLocales (void *, int32_t);
+ int32_t GlobalizationNative_GetSortHandle (void *, void *);
+ int32_t GlobalizationNative_GetSortKey (void *, void *, int32_t, void *, int32_t, int32_t);
+ int32_t GlobalizationNative_GetSortVersion (void *);
+ int32_t GlobalizationNative_IndexOf (void *, void *, int32_t, void *, int32_t, int32_t, void *);
+ void GlobalizationNative_InitICUFunctions (void *, void *, void *, void *);
+ void GlobalizationNative_InitOrdinalCasingPage (int32_t, void *);
+ int32_t GlobalizationNative_IsNormalized (int32_t, void *, int32_t);
+ int32_t GlobalizationNative_IsPredefinedLocale (void *);
+ int32_t GlobalizationNative_LastIndexOf (void *, void *, int32_t, void *, int32_t, int32_t, void *);
+ int32_t GlobalizationNative_LoadICU ();
+ int32_t GlobalizationNative_NormalizeString (int32_t, void *, int32_t, void *, int32_t);
+ int32_t GlobalizationNative_StartsWith (void *, void *, int32_t, void *, int32_t, int32_t, void *);
+ int32_t GlobalizationNative_ToAscii (uint32_t, void *, int32_t, void *, int32_t);
+ int32_t GlobalizationNative_ToUnicode (uint32_t, void *, int32_t, void *, int32_t);
+ void * SystemJS_GetLocaleInfo (void *, int32_t, void *, int32_t, void *, int32_t, void *);
+ int32_t SystemNative_Access (void *, int32_t);
+ void * SystemNative_AlignedAlloc (void *, void *);
+ void SystemNative_AlignedFree (void *);
+ void * SystemNative_AlignedRealloc (void *, void *, void *);
+ void * SystemNative_Calloc (void *, void *);
+ int32_t SystemNative_CanGetHiddenFlag ();
+ int32_t SystemNative_ChDir (void *);
+ int32_t SystemNative_ChMod (void *, int32_t);
+ int32_t SystemNative_Close (void *);
+ int32_t SystemNative_CloseDir (void *);
+ int32_t SystemNative_ConvertErrorPalToPlatform (int32_t);
+ int32_t SystemNative_ConvertErrorPlatformToPal (int32_t);
+ int32_t SystemNative_CopyFile (void *, void *, int64_t);
+ void * SystemNative_Dup (void *);
+ int32_t SystemNative_FAllocate (void *, int64_t, int64_t);
+ int32_t SystemNative_FChMod (void *, int32_t);
+ int32_t SystemNative_FChflags (void *, uint32_t);
+ int32_t SystemNative_FLock (void *, int32_t);
+ int32_t SystemNative_FStat (void *, void *);
+ int32_t SystemNative_FSync (void *);
+ int32_t SystemNative_FTruncate (void *, int64_t);
+ int32_t SystemNative_FUTimens (void *, void *);
+ int32_t SystemNative_FcntlSetFD (void *, int32_t);
+ void SystemNative_Free (void *);
+ void SystemNative_FreeLibrary (void *);
+ int32_t SystemNative_GetAddressFamily (void *, int32_t, void *);
+ double SystemNative_GetCpuUtilization (void *);
+ int32_t SystemNative_GetCryptographicallySecureRandomBytes (void *, int32_t);
+ void * SystemNative_GetCwd (void *, int32_t);
+ void * SystemNative_GetDefaultSearchOrderPseudoHandle ();
+ int32_t SystemNative_GetErrNo ();
+ uint32_t SystemNative_GetFileSystemType (void *);
+ int32_t SystemNative_GetIPv4Address (void *, int32_t, void *);
+ int32_t SystemNative_GetIPv6Address (void *, int32_t, void *, int32_t, void *);
+ void * SystemNative_GetLoadLibraryError ();
+ int64_t SystemNative_GetLowResolutionTimestamp ();
+ void SystemNative_GetNonCryptographicallySecureRandomBytes (void *, int32_t);
+ int32_t SystemNative_GetPort (void *, int32_t, void *);
+ void * SystemNative_GetProcAddress (void *, void *);
+ int32_t SystemNative_GetSocketAddressSizes (void *, void *, void *, void *);
+ int64_t SystemNative_GetSystemTimeAsTicks ();
+ void * SystemNative_GetTimeZoneData (void *, void *);
+ int64_t SystemNative_GetTimestamp ();
+ int32_t SystemNative_IsMemfdSupported ();
+ int32_t SystemNative_LChflags (void *, uint32_t);
+ int32_t SystemNative_LChflagsCanSetHiddenFlag ();
+ int64_t SystemNative_LSeek (void *, int64_t, int32_t);
+ int32_t SystemNative_LStat (void *, void *);
+ int32_t SystemNative_Link (void *, void *);
+ void * SystemNative_LoadLibrary (void *);
+ int32_t SystemNative_LockFileRegion (void *, int64_t, int64_t, int32_t);
+ void SystemNative_Log (void *, int32_t);
+ void SystemNative_LogError (void *, int32_t);
+ void SystemNative_LowLevelMonitor_Acquire (void *);
+ void * SystemNative_LowLevelMonitor_Create ();
+ void SystemNative_LowLevelMonitor_Destroy (void *);
+ void SystemNative_LowLevelMonitor_Release (void *);
+ void SystemNative_LowLevelMonitor_Signal_Release (void *);
+ int32_t SystemNative_LowLevelMonitor_TimedWait (void *, int32_t);
+ void SystemNative_LowLevelMonitor_Wait (void *);
+ int32_t SystemNative_MAdvise (void *, uint64_t, int32_t);
+ void * SystemNative_MMap (void *, uint64_t, int32_t, int32_t, void *, int64_t);
+ int32_t SystemNative_MSync (void *, uint64_t, int32_t);
+ int32_t SystemNative_MUnmap (void *, uint64_t);
+ void * SystemNative_Malloc (void *);
+ void * SystemNative_MemfdCreate (void *, int32_t);
+ int32_t SystemNative_MkDir (void *, int32_t);
+ void * SystemNative_MkdTemp (void *);
+ void * SystemNative_MksTemps (void *, int32_t);
+ void * SystemNative_Open (void *, int32_t, int32_t);
+ void * SystemNative_OpenDir (void *);
+ int32_t SystemNative_PRead (void *, void *, int32_t, int64_t);
+ int64_t SystemNative_PReadV (void *, void *, int32_t, int64_t);
+ int32_t SystemNative_PWrite (void *, void *, int32_t, int64_t);
+ int64_t SystemNative_PWriteV (void *, void *, int32_t, int64_t);
+ int32_t SystemNative_PosixFAdvise (void *, int64_t, int64_t, int32_t);
+ int32_t SystemNative_Read (void *, void *, int32_t);
+ int32_t SystemNative_ReadDir (void *, void *);
+ int32_t SystemNative_ReadLink (void *, void *, int32_t);
+ void * SystemNative_Realloc (void *, void *);
+ int32_t SystemNative_Rename (void *, void *);
+ int32_t SystemNative_RmDir (void *);
+ int32_t SystemNative_SchedGetCpu ();
+ int32_t SystemNative_SetAddressFamily (void *, int32_t, int32_t);
+ void SystemNative_SetErrNo (int32_t);
+ int32_t SystemNative_SetIPv4Address (void *, int32_t, uint32_t);
+ int32_t SystemNative_SetIPv6Address (void *, int32_t, void *, int32_t, uint32_t);
+ int32_t SystemNative_SetPort (void *, int32_t, uint32_t);
+ void * SystemNative_ShmOpen (void *, int32_t, int32_t);
+ int32_t SystemNative_ShmUnlink (void *);
+ int32_t SystemNative_Stat (void *, void *);
+ void * SystemNative_StrErrorR (int32_t, void *, int32_t);
+ int32_t SystemNative_SymLink (void *, void *);
+ int64_t SystemNative_SysConf (int32_t);
+ void SystemNative_SysLog (int32_t, void *, void *);
+ int32_t SystemNative_UTimensat (void *, void *);
+ int32_t SystemNative_Unlink (void *);
+ int32_t SystemNative_Write (void *, void *, int32_t);
+} // extern "C"
+
+static const Entry s_libSystem_Globalization_Native [] = {
+ DllImportEntry(GlobalizationNative_ChangeCase) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_ChangeCaseInvariant) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_ChangeCaseTurkish) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_CloseSortHandle) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_CompareString) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_EndsWith) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_EnumCalendarInfo) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetCalendarInfo) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetCalendars) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetDefaultLocaleName) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetICUVersion) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetJapaneseEraStartDate) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLatestJapaneseEra) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocaleInfoGroupingSizes) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocaleInfoInt) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocaleInfoString) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocaleName) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocaleTimeFormat) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetLocales) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetSortHandle) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetSortKey) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_GetSortVersion) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_IndexOf) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_InitICUFunctions) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_InitOrdinalCasingPage) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_IsNormalized) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_IsPredefinedLocale) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_LastIndexOf) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_LoadICU) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_NormalizeString) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_StartsWith) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_ToAscii) // System.Private.CoreLib
+ DllImportEntry(GlobalizationNative_ToUnicode) // System.Private.CoreLib
+};
+
+static const Entry s_libSystem_IO_Compression_Native [] = {
+ DllImportEntry(CompressionNative_Crc32) // System.IO.Compression
+ DllImportEntry(CompressionNative_Deflate) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_DeflateEnd) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_DeflateInit2_) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_Inflate) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_InflateEnd) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_InflateInit2_) // System.IO.Compression, System.Net.WebSockets
+ DllImportEntry(CompressionNative_InflateReset2_) // System.IO.Compression
+};
+
+static const Entry s_libSystem_Native [] = {
+ DllImportEntry(SystemNative_Access) // System.Private.CoreLib
+ DllImportEntry(SystemNative_AlignedAlloc) // System.Private.CoreLib
+ DllImportEntry(SystemNative_AlignedFree) // System.Private.CoreLib
+ DllImportEntry(SystemNative_AlignedRealloc) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Calloc) // System.Private.CoreLib
+ DllImportEntry(SystemNative_CanGetHiddenFlag) // System.Private.CoreLib
+ DllImportEntry(SystemNative_ChDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_ChMod) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Close) // System.Private.CoreLib
+ DllImportEntry(SystemNative_CloseDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_ConvertErrorPalToPlatform) // System.Console, System.IO.Compression.ZipFile, System.IO.MemoryMappedFiles, System.Net.Primitives, System.Private.CoreLib
+ DllImportEntry(SystemNative_ConvertErrorPlatformToPal) // System.Console, System.IO.Compression.ZipFile, System.IO.MemoryMappedFiles, System.Net.Primitives, System.Private.CoreLib
+ DllImportEntry(SystemNative_CopyFile) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Dup) // System.Console
+ DllImportEntry(SystemNative_FAllocate) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FChMod) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FChflags) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FLock) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FStat) // System.IO.Compression.ZipFile, System.IO.MemoryMappedFiles, System.Private.CoreLib
+ DllImportEntry(SystemNative_FSync) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FTruncate) // System.IO.MemoryMappedFiles, System.Private.CoreLib
+ DllImportEntry(SystemNative_FUTimens) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FcntlSetFD) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_Free) // System.Private.CoreLib
+ DllImportEntry(SystemNative_FreeLibrary) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetAddressFamily) // System.Net.Primitives
+ DllImportEntry(SystemNative_GetCpuUtilization) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetCryptographicallySecureRandomBytes) // System.Private.CoreLib, System.Security.Cryptography
+ DllImportEntry(SystemNative_GetCwd) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetDefaultSearchOrderPseudoHandle) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetErrNo) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetFileSystemType) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetIPv4Address) // System.Net.Primitives
+ DllImportEntry(SystemNative_GetIPv6Address) // System.Net.Primitives
+ DllImportEntry(SystemNative_GetLoadLibraryError) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetLowResolutionTimestamp) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetNonCryptographicallySecureRandomBytes) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetPort) // System.Net.Primitives
+ DllImportEntry(SystemNative_GetProcAddress) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetSocketAddressSizes) // System.Net.Primitives
+ DllImportEntry(SystemNative_GetSystemTimeAsTicks) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetTimeZoneData) // System.Private.CoreLib
+ DllImportEntry(SystemNative_GetTimestamp) // System.Private.CoreLib
+ DllImportEntry(SystemNative_IsMemfdSupported) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_LChflags) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LChflagsCanSetHiddenFlag) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LSeek) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LStat) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Link) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LoadLibrary) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LockFileRegion) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Log) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LogError) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Acquire) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Create) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Destroy) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Release) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Signal_Release) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_TimedWait) // System.Private.CoreLib
+ DllImportEntry(SystemNative_LowLevelMonitor_Wait) // System.Private.CoreLib
+ DllImportEntry(SystemNative_MAdvise) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_MMap) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_MSync) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_MUnmap) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_Malloc) // System.Private.CoreLib
+ DllImportEntry(SystemNative_MemfdCreate) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_MkDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_MkdTemp) // System.Private.CoreLib
+ DllImportEntry(SystemNative_MksTemps) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Open) // System.Private.CoreLib
+ DllImportEntry(SystemNative_OpenDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_PRead) // System.Private.CoreLib
+ DllImportEntry(SystemNative_PReadV) // System.Private.CoreLib
+ DllImportEntry(SystemNative_PWrite) // System.Private.CoreLib
+ DllImportEntry(SystemNative_PWriteV) // System.Private.CoreLib
+ DllImportEntry(SystemNative_PosixFAdvise) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Read) // System.Private.CoreLib
+ DllImportEntry(SystemNative_ReadDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_ReadLink) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Realloc) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Rename) // System.Private.CoreLib
+ DllImportEntry(SystemNative_RmDir) // System.Private.CoreLib
+ DllImportEntry(SystemNative_SchedGetCpu) // System.Private.CoreLib
+ DllImportEntry(SystemNative_SetAddressFamily) // System.Net.Primitives
+ DllImportEntry(SystemNative_SetErrNo) // System.Private.CoreLib
+ DllImportEntry(SystemNative_SetIPv4Address) // System.Net.Primitives
+ DllImportEntry(SystemNative_SetIPv6Address) // System.Net.Primitives
+ DllImportEntry(SystemNative_SetPort) // System.Net.Primitives
+ DllImportEntry(SystemNative_ShmOpen) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_ShmUnlink) // System.IO.MemoryMappedFiles
+ DllImportEntry(SystemNative_Stat) // System.IO.Compression.ZipFile, System.Private.CoreLib
+ DllImportEntry(SystemNative_StrErrorR) // System.Console, System.IO.Compression.ZipFile, System.IO.MemoryMappedFiles, System.Net.Primitives, System.Private.CoreLib
+ DllImportEntry(SystemNative_SymLink) // System.Private.CoreLib
+ DllImportEntry(SystemNative_SysConf) // System.IO.MemoryMappedFiles, System.Private.CoreLib
+ DllImportEntry(SystemNative_SysLog) // System.Private.CoreLib
+ DllImportEntry(SystemNative_UTimensat) // System.Private.CoreLib
+ DllImportEntry(SystemNative_Unlink) // System.IO.MemoryMappedFiles, System.Private.CoreLib
+ DllImportEntry(SystemNative_Write) // System.Console, System.Private.CoreLib
+};
+
+static const Entry s_libSystem_Native_Browser [] = {
+ DllImportEntry(SystemJS_GetLocaleInfo) // System.Private.CoreLib
+};
+
+typedef struct PInvokeTable {
+ const char* LibraryName;
+ const Entry* Entries;
+ size_t EntryCount;
+} PInvokeTable;
+
+static PInvokeTable s_PInvokeTables[] = {
+ {"libSystem.Globalization.Native", s_libSystem_Globalization_Native, 33},
+ {"libSystem.IO.Compression.Native", s_libSystem_IO_Compression_Native, 8},
+ {"libSystem.Native", s_libSystem_Native, 98},
+ {"libSystem.Native.Browser", s_libSystem_Native_Browser, 1}
+};
+const size_t s_PInvokeTablesCount = sizeof(s_PInvokeTables) / sizeof(s_PInvokeTables[0]);
+
+const void* callhelpers_pinvoke_override(const char* library_name, const char* entry_point_name)
+{
+ for (size_t i = 0; i < s_PInvokeTablesCount; i++)
+ {
+ if (strcmp(library_name, s_PInvokeTables[i].LibraryName) == 0)
+ {
+ LOG((LF_INTEROP, LL_INFO1000, "Wasm callhelpers PInvoke override for: lib: %s, entry: %s \n", library_name, entry_point_name));
+ return minipal_resolve_dllimport(s_PInvokeTables[i].Entries, s_PInvokeTables[i].EntryCount, entry_point_name);
+ }
+ }
+
+ return nullptr;
+}
diff --git a/src/coreclr/vm/wasm/callhelpers-reverse.cpp b/src/coreclr/vm/wasm/callhelpers-reverse.cpp
index 6848825ca1c65f..f2c84f5c89f3cb 100644
--- a/src/coreclr/vm/wasm/callhelpers-reverse.cpp
+++ b/src/coreclr/vm/wasm/callhelpers-reverse.cpp
@@ -4,7 +4,7 @@
//
// GENERATED FILE, DON'T EDIT
-// Generated by coreclr InterpToNativeGenerator
+// Generated by coreclr callhelpers generator
//
#include
@@ -339,26 +339,20 @@ static int32_t Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComA
extern const ReverseThunkMapEntry g_ReverseThunks[] =
{
- { 2644319183, 3863938719, { &MD_System_Private_CoreLib_System_GC__RegisterNoGCRegionCallback_g__Callback_7C_72_0_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_GC__RegisterNoGCRegionCallback_g__Callback_7C_72_0_I32_RetVoid } } /* alternate key source: g__Callback|72_0#1:System.Private.CoreLib:System:GC */,
- { 2644321986, 1336557534, { &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid } } /* alternate key source: BackgroundJobHandler#0:System.Private.CoreLib:System.Threading:ThreadPool */,
- { 3685902048, 2901966433, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_BindAssemblyExports_I32_RetVoid } } /* alternate key source: BindAssemblyExports#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 3685901981, 2601830388, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallDelegate_I32_RetVoid } } /* alternate key source: CallDelegate#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 3685902049, 433365813, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallJSExport_I32_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CallJSExport_I32_I32_RetVoid } } /* alternate key source: CallJSExport#2:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 3685902050, 3113228365, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_CompleteTask_I32_RetVoid } } /* alternate key source: CompleteTask#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 2644319190, 3378852959, { &MD_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid, (void*)&Call_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid } } /* alternate key source: ConfigCallback#5:System.Private.CoreLib:System:GC */,
- { 2644325552, 1196551088, { &MD_System_Private_CoreLib_System_Globalization_CalendarData_EnumCalendarInfoCallback_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Globalization_CalendarData_EnumCalendarInfoCallback_I32_I32_RetVoid } } /* alternate key source: EnumCalendarInfoCallback#2:System.Private.CoreLib:System.Globalization:CalendarData */,
- { 2644360829, 2613312799, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_GetClassFactoryForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_GetClassFactoryForTypeInternal_I32_RetI32 } } /* alternate key source: GetClassFactoryForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */,
- { 2644361095, 993231473, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: GetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
- { 3685902051, 1081971317, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_GetManagedStackTrace_I32_RetVoid } } /* alternate key source: GetManagedStackTrace#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 2644361096, 3422156547, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssembly#3:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
- { 2644361099, 542185314, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssemblyAndGetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
- { 2644361094, 3765950975, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssemblyBytes#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
- { 2644339600, 343912841, { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32 } } /* alternate key source: NewExternalTypeEntry#2:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary */,
- { 2644339601, 3327247096, { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewProxyTypeEntry_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewProxyTypeEntry_I32_I32_RetI32 } } /* alternate key source: NewProxyTypeEntry#2:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary */,
- { 2644360826, 4239234100, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32 } } /* alternate key source: RegisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */,
- { 3685901980, 1403522766, { &MD_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_I32_RetVoid, (void*)&Call_System_Runtime_InteropServices_JavaScript_System_Runtime_InteropServices_JavaScript_JavaScriptExports_ReleaseJSOwnedObjectByGCHandle_I32_RetVoid } } /* alternate key source: ReleaseJSOwnedObjectByGCHandle#1:System.Runtime.InteropServices.JavaScript:System.Runtime.InteropServices.JavaScript:JavaScriptExports */,
- { 2644321657, 167179540, { &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid } } /* alternate key source: TimerHandler#0:System.Private.CoreLib:System.Threading:TimerQueue */,
- { 2644360827, 2150642223, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32 } } /* alternate key source: UnregisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */
+ { 2644319180, 3863938719, { &MD_System_Private_CoreLib_System_GC__RegisterNoGCRegionCallback_g__Callback_7C_72_0_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_GC__RegisterNoGCRegionCallback_g__Callback_7C_72_0_I32_RetVoid } } /* alternate key source: g__Callback|72_0#1:System.Private.CoreLib:System:GC */,
+ { 2644321552, 1336557534, { &MD_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_ThreadPool_BackgroundJobHandler_Void_RetVoid } } /* alternate key source: BackgroundJobHandler#0:System.Private.CoreLib:System.Threading:ThreadPool */,
+ { 2644319191, 3378852959, { &MD_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid, (void*)&Call_System_Private_CoreLib_System_GC_ConfigCallback_I32_I32_I32_I32_I64_RetVoid } } /* alternate key source: ConfigCallback#5:System.Private.CoreLib:System:GC */,
+ { 2644325221, 1196551088, { &MD_System_Private_CoreLib_System_Globalization_CalendarData_EnumCalendarInfoCallback_I32_I32_RetVoid, (void*)&Call_System_Private_CoreLib_System_Globalization_CalendarData_EnumCalendarInfoCallback_I32_I32_RetVoid } } /* alternate key source: EnumCalendarInfoCallback#2:System.Private.CoreLib:System.Globalization:CalendarData */,
+ { 2644360531, 2613312799, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_GetClassFactoryForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_GetClassFactoryForTypeInternal_I32_RetI32 } } /* alternate key source: GetClassFactoryForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */,
+ { 2644360541, 993231473, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_GetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: GetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
+ { 2644360542, 3422156547, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssembly_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssembly#3:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
+ { 2644360545, 542185314, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyAndGetFunctionPointer_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssemblyAndGetFunctionPointer#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
+ { 2644360540, 3765950975, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComponentActivator_LoadAssemblyBytes_I32_I32_I32_I32_I32_I32_RetI32 } } /* alternate key source: LoadAssemblyBytes#6:System.Private.CoreLib:Internal.Runtime.InteropServices:ComponentActivator */,
+ { 2644339381, 343912841, { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewExternalTypeEntry_I32_I32_RetI32 } } /* alternate key source: NewExternalTypeEntry#2:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary */,
+ { 2644339378, 3327247096, { &MD_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewProxyTypeEntry_I32_I32_RetI32, (void*)&Call_System_Private_CoreLib_System_Runtime_InteropServices_TypeMapLazyDictionary_NewProxyTypeEntry_I32_I32_RetI32 } } /* alternate key source: NewProxyTypeEntry#2:System.Private.CoreLib:System.Runtime.InteropServices:TypeMapLazyDictionary */,
+ { 2644360528, 4239234100, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_RegisterClassForTypeInternal_I32_RetI32 } } /* alternate key source: RegisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */,
+ { 2644321735, 167179540, { &MD_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid, (void*)&Call_System_Private_CoreLib_System_Threading_TimerQueue_TimerHandler_Void_RetVoid } } /* alternate key source: TimerHandler#0:System.Private.CoreLib:System.Threading:TimerQueue */,
+ { 2644360529, 2150642223, { &MD_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32, (void*)&Call_System_Private_CoreLib_Internal_Runtime_InteropServices_ComActivator_UnregisterClassForTypeInternal_I32_RetI32 } } /* alternate key source: UnregisterClassForTypeInternal#1:System.Private.CoreLib:Internal.Runtime.InteropServices:ComActivator */
};
const size_t g_ReverseThunksCount = sizeof(g_ReverseThunks) / sizeof(g_ReverseThunks[0]);
diff --git a/src/native/corehost/browserhost/CMakeLists.txt b/src/native/corehost/browserhost/CMakeLists.txt
index bbf88764ae9e12..95137e02461c56 100644
--- a/src/native/corehost/browserhost/CMakeLists.txt
+++ b/src/native/corehost/browserhost/CMakeLists.txt
@@ -40,6 +40,7 @@ set(HEADERS
)
add_compile_definitions(FEATURE_APPHOST)
+add_definitions(-DGEN_PINVOKE=1)
add_definitions(-DFEATURE_APPHOST=1)
add_definitions(-DFEATURE_STATIC_HOST=1)
diff --git a/src/native/corehost/browserhost/browserhost.cpp b/src/native/corehost/browserhost/browserhost.cpp
index 78ce28e62ec153..f16ebfafa9f8e4 100644
--- a/src/native/corehost/browserhost/browserhost.cpp
+++ b/src/native/corehost/browserhost/browserhost.cpp
@@ -44,11 +44,13 @@ extern "C"
pal::hresult_t coreclr_set_error_writer(
coreclr_error_writer_callback_fn error_writer);
+#if !GEN_PINVOKE
const void* SystemResolveDllImport(const char* name);
const void* SystemJSResolveDllImport(const char* name);
const void* SystemJSInteropResolveDllImport(const char* name);
const void* GlobalizationResolveDllImport(const char* name);
const void* CompressionResolveDllImport(const char* name);
+#endif // not GEN_PINVOKE
bool BrowserHost_ExternalAssemblyProbe(const char* pathPtr, /*out*/ void **outDataStartPtr, /*out*/ int64_t* outSize);
}
@@ -62,6 +64,9 @@ static void log_error_info(const char* line)
std::fprintf(stderr, "log error: %s\n", line);
}
+#if GEN_PINVOKE
+const void* callhelpers_pinvoke_override(const char* library_name, const char* entry_point_name);
+#else
static const void* pinvoke_override(const char* library_name, const char* entry_point_name)
{
if (strcmp(library_name, "libSystem.Native") == 0)
@@ -88,12 +93,17 @@ static const void* pinvoke_override(const char* library_name, const char* entry_
return nullptr;
}
+#endif // GEN_PINVOKE
static host_runtime_contract host_contract = { sizeof(host_runtime_contract), nullptr };
extern "C" void* BrowserHost_CreateHostContract(void)
{
+#if GEN_PINVOKE
+ host_contract.pinvoke_override = &callhelpers_pinvoke_override;
+#else
host_contract.pinvoke_override = &pinvoke_override;
+#endif // GEN_PINVOKE
host_contract.external_assembly_probe = &BrowserHost_ExternalAssemblyProbe;
return &host_contract;
}
diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt
index f048d8a777136a..305cf2f2742024 100644
--- a/src/native/libs/CMakeLists.txt
+++ b/src/native/libs/CMakeLists.txt
@@ -19,6 +19,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON)
if (CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI)
set(STATIC_LIBS_ONLY 1)
set(GEN_SHARED_LIB 0)
+ add_definitions(-DGEN_PINVOKE=${GEN_PINVOKE})
if (NOT STATIC_LIB_DESTINATION)
if (BUILD_LIBS_NATIVE_BROWSER)
set(STATIC_LIB_DESTINATION ${CMAKE_BINARY_DIR}/lib)
@@ -113,9 +114,7 @@ else ()
add_subdirectory(System.Globalization.Native)
endif ()
-if (NOT CORERUN_LIBS_ONLY)
- add_subdirectory(System.IO.Compression.Native)
-endif ()
+add_subdirectory(System.IO.Compression.Native)
# Only when Browser for CoreCLR
if (CLR_CMAKE_TARGET_BROWSER AND BUILD_LIBS_NATIVE_BROWSER)
diff --git a/src/native/libs/System.Native.Browser/CMakeLists.txt b/src/native/libs/System.Native.Browser/CMakeLists.txt
index 054ff74dd4cd25..909e70230b212b 100644
--- a/src/native/libs/System.Native.Browser/CMakeLists.txt
+++ b/src/native/libs/System.Native.Browser/CMakeLists.txt
@@ -1,16 +1,13 @@
project(System.Native.Browser C)
-set(BROWSER_SOURCES)
-
-if (NOT GEN_PINVOKE)
- set (BROWSER_SOURCES ${BROWSER_SOURCES} entrypoints.c)
-endif()
+set(BROWSER_SOURCES ${BROWSER_SOURCES} entrypoints.c)
add_library(System.Native.Browser-Static
STATIC
${BROWSER_SOURCES}
)
set_target_properties(System.Native.Browser-Static PROPERTIES OUTPUT_NAME System.Native.Browser CLEAN_DIRECT_OUTPUT 1)
+
install(TARGETS System.Native.Browser-Static DESTINATION ${STATIC_LIB_DESTINATION} COMPONENT libs)
if (NOT CORERUN_LIBS_ONLY)
install(TARGETS System.Native.Browser-Static DESTINATION sharedFramework COMPONENT runtime)
diff --git a/src/native/libs/System.Native.Browser/entrypoints.c b/src/native/libs/System.Native.Browser/entrypoints.c
index 17ca2e9361e503..2880f365b54fa6 100644
--- a/src/native/libs/System.Native.Browser/entrypoints.c
+++ b/src/native/libs/System.Native.Browser/entrypoints.c
@@ -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.
+#if !GEN_PINVOKE
#include
#include
@@ -30,3 +31,4 @@ EXTERN_C const void* SystemJSResolveDllImport(const char* name)
{
return minipal_resolve_dllimport(s_browserNative, ARRAY_SIZE(s_browserNative), name);
}
+#endif // not GEN_PINVOKE
diff --git a/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/CMakeLists.txt b/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/CMakeLists.txt
index 271ef54b649cb8..a773d53bdf8b88 100644
--- a/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/CMakeLists.txt
+++ b/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/CMakeLists.txt
@@ -1,10 +1,6 @@
project(System.Runtime.InteropServices.JavaScript.Native C)
-set(BROWSER_INTEROP_SOURCES)
-
-if (NOT GEN_PINVOKE)
- set (BROWSER_INTEROP_SOURCES ${BROWSER_INTEROP_SOURCES} entrypoints.c)
-endif()
+set (BROWSER_INTEROP_SOURCES ${BROWSER_INTEROP_SOURCES} entrypoints.c)
add_library(System.Runtime.InteropServices.JavaScript.Native-Static
STATIC
diff --git a/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/entrypoints.c b/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/entrypoints.c
index dc41cc1b5bada8..ef2d6cf38d5731 100644
--- a/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/entrypoints.c
+++ b/src/native/libs/System.Runtime.InteropServices.JavaScript.Native/entrypoints.c
@@ -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.
+#if !GEN_PINVOKE
#include
#include
@@ -32,3 +33,4 @@ EXTERN_C const void* SystemJSInteropResolveDllImport(const char* name)
{
return minipal_resolve_dllimport(s_browserNative, ARRAY_SIZE(s_browserNative), name);
}
+#endif // not GEN_PINVOKE
diff --git a/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj b/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
index 531896e2b51308..adfc8de1918f66 100644
--- a/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
+++ b/src/tasks/WasmAppBuilder/WasmAppBuilder.csproj
@@ -46,16 +46,17 @@
+
-
diff --git a/src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs b/src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs
index 41588db3d57149..33f529a98a9753 100644
--- a/src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs
+++ b/src/tasks/WasmAppBuilder/coreclr/ManagedToNativeGenerator.cs
@@ -29,6 +29,9 @@ public class ManagedToNativeGenerator : Task
[Required, NotNull]
public string? PInvokeOutputPath { get; set; }
+ [Required, NotNull]
+ public string? ReversePInvokeOutputPath { get; set; }
+
[Required, NotNull]
public string? InterpToNativeOutputPath { get; set; }
public string? CacheFilePath { get; set; }
@@ -122,7 +125,7 @@ private void ExecuteInternal(LogAdapter log)
}
IEnumerable cookies = Enumerable.Concat(
- pinvoke.Generate(PInvokeModules, PInvokeOutputPath),
+ pinvoke.Generate(PInvokeModules, PInvokeOutputPath, ReversePInvokeOutputPath),
Enumerable.Concat(icall.Generate(IcallOutputPath),
missingCookies));
diff --git a/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs b/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs
index b360c69d70b3e5..7e2fdca26f32c5 100644
--- a/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs
+++ b/src/tasks/WasmAppBuilder/coreclr/PInvokeTableGenerator.cs
@@ -39,24 +39,33 @@ public void ScanAssembly(Assembly asm)
_pinvokeCollector.CollectPInvokes(pinvokes, callbacks, signatures, type);
}
- public IEnumerable Generate(string[] pinvokeModules, string outputPath)
+ public IEnumerable Generate(string[] pinvokeModules, string outputPathPInvoke, string outputPathReversePInvoke)
{
var modules = new SortedDictionary(StringComparer.Ordinal);
foreach (var module in pinvokeModules)
modules[module] = module;
- using TempFileName tmpFileName = new();
- using (var w = new JoinedStringStreamWriter(tmpFileName.Path, false))
+ using TempFileName tmpFileNamePInvoke = new();
+ using (var w = new JoinedStringStreamWriter(tmpFileNamePInvoke.Path, false))
+ {
+ EmitPInvokeTable(w, modules, pinvokes);
+ }
+
+ using TempFileName tmpFileNameReversePInvoke = new();
+ using (var w = new JoinedStringStreamWriter(tmpFileNameReversePInvoke.Path, false))
{
- // WASM-TODO: the generator is WIP, so we disable pinvoke table generation
- // EmitPInvokeTable(w, modules, pinvokes);
EmitNativeToInterp(w, callbacks);
}
- if (Utils.CopyIfDifferent(tmpFileName.Path, outputPath, useHash: false))
- Log.LogMessage(MessageImportance.Low, $"Generating pinvoke table to '{outputPath}'.");
+ if (Utils.CopyIfDifferent(tmpFileNamePInvoke.Path, outputPathPInvoke, useHash: false))
+ Log.LogMessage(MessageImportance.Low, $"Generating pinvoke table to '{outputPathPInvoke}'.");
+ else
+ Log.LogMessage(MessageImportance.Low, $"PInvoke table in {outputPathPInvoke} is unchanged.");
+
+ if (Utils.CopyIfDifferent(tmpFileNameReversePInvoke.Path, outputPathReversePInvoke, useHash: false))
+ Log.LogMessage(MessageImportance.Low, $"Generating pinvoke reverse table to '{outputPathReversePInvoke}'.");
else
- Log.LogMessage(MessageImportance.Low, $"PInvoke table in {outputPath} is unchanged.");
+ Log.LogMessage(MessageImportance.Low, $"PInvoke reverse table in {outputPathReversePInvoke} is unchanged.");
return signatures;
}
@@ -72,25 +81,37 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary m
// are called.
if (pinvoke.WasmLinkage)
{
- // WasmLinkage means we needs to import the module
+ // WasmLinkage means we need to import the module
modules.Add(pinvoke.Module, pinvoke.Module);
Log.LogMessage(MessageImportance.Low, $"Adding module {pinvoke.Module} for WasmImportLinkage");
}
- else if (pinvoke.Module == "*" || pinvoke.Module == "__Internal")
+ else if (pinvoke.Module == "*")
{
- // Special case for __Internal and * modules to indicate static linking without specifying the module
+ // Special case for * module to indicate static linking without specifying the module
modules.Add(pinvoke.Module, pinvoke.Module);
Log.LogMessage(MessageImportance.Low, $"Adding module {pinvoke.Module} for static linking");
}
- else
+ else if (pinvoke.Module != "QCall")
{
- Log.Warning("WASM0066", $"PInvoke module '{pinvoke.Module}' for method '{pinvoke.Method.DeclaringType}::{pinvoke.Method.Name}' is not in the list of allowed modules. It is also not special treated module.");
+ Log.Warning("WASM0066", $"PInvoke module '{pinvoke.Module}' for method '{pinvoke.Method.DeclaringType}::{pinvoke.Method.Name}' is not in the list of allowed modules. It is also not a specially treated module.");
}
}
w.WriteLine(
- $"""
- // GENERATED FILE, DO NOT MODIFY (PInvokeTableGenerator.cs)
+ $$"""
+ // Licensed to the .NET Foundation under one or more agreements.
+ // The .NET Foundation licenses this file to you under the MIT license.
+ //
+
+ //
+ // GENERATED FILE, DON'T EDIT
+ // Generated by coreclr callhelpers generator
+ //
+
+ #include
+ #include
+
+ extern "C" {
""");
var pinvokesGroupedByEntryPoint = pinvokes
@@ -129,6 +150,12 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary m
}
}
+ w.Write(
+ $$"""
+ } // extern "C"
+
+ """);
+
var moduleImports = new Dictionary>();
foreach (var module in modules.Keys)
{
@@ -137,16 +164,15 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary m
.Where(l => l.Module == module && !l.Skip)
.OrderBy(l => l.EntryPoint, StringComparer.Ordinal)
.GroupBy(d => d.EntryPoint, StringComparer.Ordinal)
- .Select(l => $"{{\"{EscapeLiteral(l.Key)}\", {CEntryPoint(l.First())}}}, // {ListRefs(l)}{w.NewLine} ")
+ .Select(l => $" DllImportEntry({CEntryPoint(l.First())}) // {ListRefs(l)}{w.NewLine}")
.ToList();
moduleImports[module] = imports;
w.Write(
$$"""
- static PinvokeImport {{_fixupSymbolName(module)}}_imports [] = {
- {{string.Join("", imports)}}{NULL, NULL}
- };
+ static const Entry s_{{_fixupSymbolName(module)}} [] = {
+ {{string.Join("", imports)}}};
""");
}
@@ -154,9 +180,30 @@ private void EmitPInvokeTable(StreamWriter w, SortedDictionary m
w.Write(
$$"""
- static PinvokeTable pinvoke_tables[] = {
- {{modules.Keys.Join($",{w.NewLine} ", m => $"{{\"{EscapeLiteral(m)}\", {_fixupSymbolName(m)}_imports, {moduleImports[m].Count}}}")}}
+ typedef struct PInvokeTable {
+ const char* LibraryName;
+ const Entry* Entries;
+ size_t EntryCount;
+ } PInvokeTable;
+
+ static PInvokeTable s_PInvokeTables[] = {
+ {{modules.Keys.Join($",{w.NewLine} ", m => $"{{\"{EscapeLiteral(m)}\", s_{_fixupSymbolName(m)}, {moduleImports[m].Count}}}")}}
};
+ const size_t s_PInvokeTablesCount = sizeof(s_PInvokeTables) / sizeof(s_PInvokeTables[0]);
+
+ const void* callhelpers_pinvoke_override(const char* library_name, const char* entry_point_name)
+ {
+ for (size_t i = 0; i < s_PInvokeTablesCount; i++)
+ {
+ if (strcmp(library_name, s_PInvokeTables[i].LibraryName) == 0)
+ {
+ LOG((LF_INTEROP, LL_INFO1000, "Wasm callhelpers PInvoke override for: lib: %s, entry: %s \n", library_name, entry_point_name));
+ return minipal_resolve_dllimport(s_PInvokeTables[i].Entries, s_PInvokeTables[i].EntryCount, entry_point_name);
+ }
+ }
+
+ return nullptr;
+ }
""");
@@ -281,11 +328,12 @@ private static bool TryIsMethodGetParametersSupported(MethodInfo method, [NotNul
realParameterTypes.Insert(0, "void *");
}
- return
- $$"""
- {{(pinvoke.WasmLinkage ? $"__attribute__((import_module(\"{EscapeLiteral(pinvoke.Module)}\"),import_name(\"{EscapeLiteral(pinvoke.EntryPoint)}\")))" : "")}}
- {{(pinvoke.WasmLinkage ? "extern " : "")}}{{MapType(realReturnType)}} {{CEntryPoint(pinvoke)}} ({{string.Join(", ", realParameterTypes)}});
- """;
+ var importAttributes = pinvoke.WasmLinkage
+ ? $"__attribute__((import_module(\"{EscapeLiteral(pinvoke.Module)}\"),import_name(\"{EscapeLiteral(pinvoke.EntryPoint)}\"))) "
+ : "";
+ var externKeyword = pinvoke.WasmLinkage ? "extern " : "";
+
+ return $" {importAttributes}{externKeyword}{MapType(realReturnType)} {CEntryPoint(pinvoke)} ({string.Join(", ", realParameterTypes)});";
}
private static string EscapeLiteral(string? input)
@@ -349,7 +397,7 @@ private void EmitNativeToInterp(StreamWriter w, List callbacks)
//
// GENERATED FILE, DON'T EDIT
- // Generated by coreclr InterpToNativeGenerator
+ // Generated by coreclr callhelpers generator
//
#include