Add header file for the hosting API
authorJan Vorlicek <janvorli@microsoft.com>
Wed, 23 Mar 2016 17:01:31 +0000 (18:01 +0100)
committerJan Vorlicek <janvorli@microsoft.com>
Wed, 6 Apr 2016 10:40:53 +0000 (12:40 +0200)
Add the header file and also modify coreruncommon.cpp to use it.

Commit migrated from https://github.com/dotnet/coreclr/commit/a9abb7b987b648cac9ab3d16ddd6ecc4e960177a

src/coreclr/CMakeLists.txt
src/coreclr/src/ToolBox/SOS/lldbplugin/CMakeLists.txt
src/coreclr/src/coreclr/CMakeLists.txt
src/coreclr/src/coreclr/hosts/CMakeLists.txt
src/coreclr/src/coreclr/hosts/inc/coreclrhost.h [new file with mode: 0644]
src/coreclr/src/coreclr/hosts/unixcoreruncommon/coreruncommon.cpp

index ba328f4..07a45de 100644 (file)
@@ -659,16 +659,10 @@ endif()
 if(CLR_CMAKE_PLATFORM_UNIX)
   add_subdirectory(src/ToolBox/SOS/lldbplugin)
   add_subdirectory(src/pal)
-  add_subdirectory(src/coreclr/hosts/unixcoreruncommon)
-  add_subdirectory(src/coreclr/hosts/unixcorerun)
-  add_subdirectory(src/coreclr/hosts/unixcoreconsole)
+  add_subdirectory(src/coreclr/hosts)
   add_subdirectory(src/ildasm/unixcoreclrloader)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
-if(CLR_CMAKE_PLATFORM_DARWIN)
-  add_subdirectory(src/coreclr/hosts/osxbundlerun)
-endif(CLR_CMAKE_PLATFORM_DARWIN)
-
 # Add this subdir. We install the headers for the jit.
 add_subdirectory(src/pal/prebuilt/inc)
 
index 438ae33..875d740 100644 (file)
@@ -67,6 +67,7 @@ include_directories(inc)
 include_directories("${LLDB_H}")
 include_directories(${CLR_DIR}/src/debug/inc)
 include_directories(${CLR_DIR}/src/inc)
+include_directories(${CLR_DIR}/src/coreclr/hosts/inc)
 include_directories(${CLR_DIR}/src/coreclr/hosts/unixcoreruncommon)
 
 set(SOURCES
@@ -93,4 +94,4 @@ if (CLR_CMAKE_PLATFORM_UNIX)
 endif()
 
 # add the install targets
-install_clr(sosplugin)
\ No newline at end of file
+install_clr(sosplugin)
index e40df6c..c1bed7b 100644 (file)
@@ -1,5 +1,6 @@
 # Add the Merge flag here is needed. Not needed for RyuJIT if building as a DLL.
 add_definitions(-DFEATURE_MERGE_JIT_AND_ENGINE)
-
-add_subdirectory(hosts)
+if(WIN32)
+  add_subdirectory(hosts)
+endif(WIN32)
 
index cc990ad..bb425b9 100644 (file)
@@ -1,3 +1,13 @@
-add_subdirectory(corerun)
-add_subdirectory(coreconsole)
+include_directories(inc)
 
+if(WIN32)
+  add_subdirectory(corerun)
+  add_subdirectory(coreconsole)
+else(WIN32)
+  add_subdirectory(unixcoreruncommon)
+  add_subdirectory(unixcorerun)
+  add_subdirectory(unixcoreconsole)
+  if(CLR_CMAKE_PLATFORM_DARWIN)
+    add_subdirectory(osxbundlerun)
+  endif(CLR_CMAKE_PLATFORM_DARWIN)
+endif(WIN32)
diff --git a/src/coreclr/src/coreclr/hosts/inc/coreclrhost.h b/src/coreclr/src/coreclr/hosts/inc/coreclrhost.h
new file mode 100644 (file)
index 0000000..f0d7952
--- /dev/null
@@ -0,0 +1,50 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+//
+// APIs for hosting CoreCLR
+//
+
+#ifndef __CORECLR_HOST_H__
+#define __CORECLR_HOST_H__
+
+// For each hosting API, we define a function prototype and a function pointer
+// The prototype is useful for implicit linking against the dynamic coreclr
+// library and the pointer for explicit dynamic loading (dlopen, LoadLibrary)
+#define CORECLR_HOSTING_API(function, ...) \
+    extern "C" int function(__VA_ARGS__); \
+    typedef int (*function##_ptr)(__VA_ARGS__)
+    
+CORECLR_HOSTING_API(coreclr_initialize,
+            const char* exePath,
+            const char* appDomainFriendlyName,
+            int propertyCount,
+            const char** propertyKeys,
+            const char** propertyValues,
+            void** hostHandle,
+            unsigned int* domainId);
+
+CORECLR_HOSTING_API(coreclr_shutdown,
+            void* hostHandle,
+            unsigned int domainId);
+
+CORECLR_HOSTING_API(coreclr_create_delegate,
+            void* hostHandle,
+            unsigned int domainId,
+            const char* entryPointAssemblyName,
+            const char* entryPointTypeName,
+            const char* entryPointMethodName,
+            void** delegate);
+
+CORECLR_HOSTING_API(coreclr_execute_assembly,
+            void* hostHandle,
+            unsigned int domainId,
+            int argc,
+            const char** argv,
+            const char* managedAssemblyPath,
+            unsigned int* exitCode);
+
+#undef CORECLR_HOSTING_API
+                      
+#endif // __CORECLR_HOST_H__
index bc795fd..6a2ee48 100644 (file)
@@ -16,6 +16,7 @@
 #include <string.h>
 #include <sys/stat.h>
 #include "coreruncommon.h"
+#include "coreclrhost.h"
 #include <unistd.h>
 
 #define SUCCEEDED(Status) ((Status) >= 0)
@@ -29,30 +30,6 @@ static const char* serverGcVar = "CORECLR_SERVER_GC";
 // used in the same way as serverGcVar. Concurrent GC is on by default.
 static const char* concurrentGcVar = "CORECLR_CONCURRENT_GC";
 
-// Prototype of the coreclr_initialize function from the libcoreclr.so
-typedef int (*InitializeCoreCLRFunction)(
-            const char* exePath,
-            const char* appDomainFriendlyName,
-            int propertyCount,
-            const char** propertyKeys,
-            const char** propertyValues,
-            void** hostHandle,
-            unsigned int* domainId);
-
-// Prototype of the coreclr_shutdown function from the libcoreclr.so
-typedef int (*ShutdownCoreCLRFunction)(
-            void* hostHandle,
-            unsigned int domainId);
-
-// Prototype of the coreclr_execute_assembly function from the libcoreclr.so
-typedef int (*ExecuteAssemblyFunction)(
-            void* hostHandle,
-            unsigned int domainId,
-            int argc,
-            const char** argv,
-            const char* managedAssemblyPath,
-            unsigned int* exitCode);
-
 #if defined(__linux__)
 #define symlinkEntrypointExecutable "/proc/self/exe"
 #elif !defined(__APPLE__)
@@ -306,9 +283,9 @@ int ExecuteManagedAssembly(
     void* coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL);
     if (coreclrLib != nullptr)
     {
-        InitializeCoreCLRFunction initializeCoreCLR = (InitializeCoreCLRFunction)dlsym(coreclrLib, "coreclr_initialize");
-        ExecuteAssemblyFunction executeAssembly = (ExecuteAssemblyFunction)dlsym(coreclrLib, "coreclr_execute_assembly");
-        ShutdownCoreCLRFunction shutdownCoreCLR = (ShutdownCoreCLRFunction)dlsym(coreclrLib, "coreclr_shutdown");
+        coreclr_initialize_ptr initializeCoreCLR = (coreclr_initialize_ptr)dlsym(coreclrLib, "coreclr_initialize");
+        coreclr_execute_assembly_ptr executeAssembly = (coreclr_execute_assembly_ptr)dlsym(coreclrLib, "coreclr_execute_assembly");
+        coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(coreclrLib, "coreclr_shutdown");
 
         if (initializeCoreCLR == nullptr)
         {