Switch P/Invokes into libcoreclr for the PAL to QCalls (#25055)
authorJeremy Koritzinsky <jekoritz@microsoft.com>
Tue, 11 Jun 2019 04:33:00 +0000 (21:33 -0700)
committerGitHub <noreply@github.com>
Tue, 11 Jun 2019 04:33:00 +0000 (21:33 -0700)
* Switch PInvokes into libcoreclr to QCalls

* Register QCalls in runtime. Remove pal exports from libcoreclr

* Alphabetize new ecalllist.h entries

* Remove W suffixes from native side of QCall

* Interop signatures are in nested classes (which doesn't show up here) in the root namespace. So we don't want to pass a namespace in here

* Convert the interop test in R2R to use a local native library instead of calling into the CoreCLR PAL via DllImport.

src/System.Private.CoreLib/src/Interop/Unix/Interop.Libraries.cs
src/dlls/mscoree/mscorwks_unixexports.src
src/vm/ecalllist.h
tests/src/readytorun/CMakeLists.txt [new file with mode: 0644]
tests/src/readytorun/tests/CMakeLists.txt [new file with mode: 0644]
tests/src/readytorun/tests/main.cs
tests/src/readytorun/tests/mainv1.csproj
tests/src/readytorun/tests/mainv2.csproj
tests/src/readytorun/tests/native.cpp [new file with mode: 0644]
tests/src/readytorun/tests/test.cs

index da7cbf2..2e54ff8 100644 (file)
@@ -2,14 +2,16 @@
 // The .NET Foundation licenses this file to you under the MIT license.
 // See the LICENSE file in the project root for more information.
 
+using System.Runtime.CompilerServices;
+
 internal static partial class Interop
 {
     internal static partial class Libraries
     {
-        internal const string Kernel32 = "libcoreclr";
-        internal const string User32   = "libcoreclr";
-        internal const string Ole32    = "libcoreclr";
-        internal const string OleAut32 = "libcoreclr";
-        internal const string Advapi32 = "libcoreclr";
+        internal const string Kernel32 = JitHelpers.QCall;
+        internal const string User32   = JitHelpers.QCall;
+        internal const string Ole32    = JitHelpers.QCall;
+        internal const string OleAut32 = JitHelpers.QCall;
+        internal const string Advapi32 = JitHelpers.QCall;
     }
 }
index 6ba08c9..98db67b 100644 (file)
@@ -19,42 +19,3 @@ PAL_UnregisterModule
 CoreDllMain
 DllMain
 GetCLRRuntimeHost
-
-; Win32 API and other PAL functions used by the System.Private.CoreLib
-CloseHandle
-CoTaskMemAlloc
-CoTaskMemRealloc
-CoTaskMemFree
-CreateEventW
-CreateEventExW
-CreateMutexW
-CreateMutexExW
-CreateSemaphoreW
-CreateSemaphoreExW
-FormatMessageW
-FreeEnvironmentStringsW
-GetCurrentProcessId
-GetCurrentThreadId
-GetEnvironmentStringsW
-GetEnvironmentVariableW
-GetStdHandle
-GetSystemInfo
-LocalAlloc
-LocalReAlloc
-LocalFree
-OpenEventW
-OpenMutexW
-OpenSemaphoreW
-OutputDebugStringW
-QueryPerformanceCounter  
-QueryPerformanceFrequency
-ReleaseMutex
-ReleaseSemaphore
-ResetEvent
-SetEnvironmentVariableW
-SetEvent
-SysAllocStringByteLen
-SysAllocStringLen
-SysFreeString
-SysStringLen
-WriteFile
index b63d216..3b9d6b1 100644 (file)
@@ -1140,6 +1140,54 @@ FCFuncStart(gWeakReferenceOfTFuncs)
     FCFuncElement("IsTrackResurrection", WeakReferenceOfTNative::IsTrackResurrection)
 FCFuncEnd()
 
+#ifdef FEATURE_PAL
+FCFuncStart(gPalKernel32Funcs)
+    QCFuncElement("CloseHandle", CloseHandle)
+    QCFuncElement("CreateEvent", CreateEventW)
+    QCFuncElement("CreateEventEx", CreateEventExW)
+    QCFuncElement("CreateMutex", CreateMutexW)
+    QCFuncElement("CreateMutexEx", CreateMutexExW)
+    QCFuncElement("CreateSemaphore", CreateSemaphoreW)
+    QCFuncElement("CreateSemaphoreEx", CreateSemaphoreExW)
+    QCFuncElement("FormatMessage", FormatMessageW)
+    QCFuncElement("FreeEnvironmentStrings", FreeEnvironmentStringsW)
+    QCFuncElement("GetCurrentProcessId", GetCurrentProcessId)
+    QCFuncElement("GetCurrentThreadId", GetCurrentThreadId)
+    QCFuncElement("GetEnvironmentStrings", GetEnvironmentStringsW)
+    QCFuncElement("GetEnvironmentVariable", GetEnvironmentVariableW)
+    QCFuncElement("GetStdHandle", GetStdHandle)
+    QCFuncElement("GetSystemInfo", GetSystemInfo)
+    QCFuncElement("LocalAlloc", LocalAlloc)
+    QCFuncElement("LocalReAlloc", LocalReAlloc)
+    QCFuncElement("LocalFree", LocalFree)
+    QCFuncElement("OpenEvent", OpenEventW)
+    QCFuncElement("OpenMutex", OpenMutexW)
+    QCFuncElement("OpenSemaphore", OpenSemaphoreW)
+    QCFuncElement("OutputDebugString", OutputDebugStringW)
+    QCFuncElement("QueryPerformanceCounter", QueryPerformanceCounter)
+    QCFuncElement("QueryPerformanceFrequency", QueryPerformanceFrequency)
+    QCFuncElement("ReleaseMutex", ReleaseMutex)
+    QCFuncElement("ReleaseSemaphore", ReleaseSemaphore)
+    QCFuncElement("ResetEvent", ResetEvent)
+    QCFuncElement("SetEnvironmentVariable", SetEnvironmentVariableW)
+    QCFuncElement("SetEvent", SetEvent)
+    QCFuncElement("WriteFile", WriteFile)
+FCFuncEnd()
+
+FCFuncStart(gPalOle32Funcs)
+    QCFuncElement("CoTaskMemAlloc", CoTaskMemAlloc)
+    QCFuncElement("CoTaskMemRealloc", CoTaskMemRealloc)
+    QCFuncElement("CoTaskMemFree", CoTaskMemFree)
+FCFuncEnd()
+
+FCFuncStart(gPalOleAut32Funcs)
+    QCFuncElement("SysAllocStringByteLen", SysAllocStringByteLen)
+    QCFuncElement("SysAllocStringLen", SysAllocStringLen)
+    QCFuncElement("SysFreeString", SysFreeString)
+    QCFuncElement("SysStringLen", SysStringLen)
+FCFuncEnd()
+#endif
+
 #ifdef FEATURE_COMINTEROP
 
 //
@@ -1215,6 +1263,9 @@ FCClassElement("IReflect", "System.Reflection", gStdMngIReflectFuncs)
 FCClassElement("InterfaceMarshaler", "System.StubHelpers", gInterfaceMarshalerFuncs)
 #endif
 FCClassElement("Interlocked", "System.Threading", gInterlockedFuncs)
+#if FEATURE_PAL
+FCClassElement("Kernel32", "", gPalKernel32Funcs)
+#endif
 FCClassElement("LoaderAllocatorScout", "System.Reflection", gLoaderAllocatorFuncs)
 FCClassElement("Marshal", "System.Runtime.InteropServices", gInteropMarshalFuncs)
 FCClassElement("Math", "System", gMathFuncs)
@@ -1241,6 +1292,10 @@ FCClassElement("Object", "System", gObjectFuncs)
 #ifdef FEATURE_COMINTEROP
 FCClassElement("ObjectMarshaler", "System.StubHelpers", gObjectMarshalerFuncs)
 #endif
+#ifdef FEATURE_PAL
+FCClassElement("Ole32", "", gPalOle32Funcs)
+FCClassElement("OleAut32", "", gPalOleAut32Funcs)
+#endif
 FCClassElement("OverlappedData", "System.Threading", gOverlappedFuncs)
 
 
diff --git a/tests/src/readytorun/CMakeLists.txt b/tests/src/readytorun/CMakeLists.txt
new file mode 100644 (file)
index 0000000..88c0516
--- /dev/null
@@ -0,0 +1 @@
+add_subdirectory(tests)
diff --git a/tests/src/readytorun/tests/CMakeLists.txt b/tests/src/readytorun/tests/CMakeLists.txt
new file mode 100644 (file)
index 0000000..19c217f
--- /dev/null
@@ -0,0 +1,6 @@
+include_directories( ${INC_PLATFORM_DIR} )
+set(SOURCES native.cpp)
+
+add_library(nativelibrary SHARED ${SOURCES})
+
+install(TARGETS nativelibrary DESTINATION bin)
index bcadc37..d8abe28 100644 (file)
@@ -123,15 +123,7 @@ class Program
 
     static void TestInterop()
     {
-        // Verify both intra-module and inter-module PInvoke interop
-        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
-        {
-            MyClass.GetTickCount();
-        }
-        else
-        {
-            MyClass.GetCurrentThreadId();
-        }
+        MyClass.NativeMethod();
 
         MyClass.TestInterop();
     }
index 5a58658..4219444 100644 (file)
@@ -28,6 +28,7 @@
     <ProjectReference Include="testv1\test.csproj">
        <Project>{F74F55A1-DFCF-4C7C-B462-E96E1D0BB667}</Project>
     </ProjectReference>
+    <ProjectReference Include="CMakeLists.txt" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="main.cs" />
index f775294..985f7ca 100644 (file)
@@ -26,6 +26,7 @@
   <ItemGroup>
     <ProjectReference Include="fieldgetter.ilproj" />
     <ProjectReference Include="testv1\test.csproj" />
+    <ProjectReference Include="CMakeLists.txt" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="main.cs" />
diff --git a/tests/src/readytorun/tests/native.cpp b/tests/src/readytorun/tests/native.cpp
new file mode 100644 (file)
index 0000000..cf02957
--- /dev/null
@@ -0,0 +1,6 @@
+#include <platformdefines.h>
+
+extern "C" int DLL_EXPORT NativeMethod()
+{
+    return 100;
+}
index 508b369..585c30e 100644 (file)
@@ -147,22 +147,12 @@ public class MyClass : IMyInterface
 #endif
    }
 
-   [DllImport("api-ms-win-core-sysinfo-l1-1-0.dll")]
-   public extern static int GetTickCount();
-
-   [DllImport("libcoreclr")]
-   public extern static int GetCurrentThreadId();
+   [DllImport("nativelibrary")]
+   public extern static int NativeMethod();
 
    static public void TestInterop()
    {
-        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
-        {
-            GetTickCount();
-        }
-        else
-        {
-            GetCurrentThreadId();
-        }
+        NativeMethod();
    }
 
 #if V2