summaryrefslogtreecommitdiff
path: root/src/dlls/mscoree/unixinterface.cpp
diff options
context:
space:
mode:
authorMatt Ellis <matell@microsoft.com>2015-03-02 22:48:35 -0800
committerMatt Ellis <matell@microsoft.com>2015-03-10 22:09:56 -0700
commit1bf04d443bea95493d2a549d9b5e7b4d3d421812 (patch)
tree864dd83d47f893b6000e56616e87d9003b33f4aa /src/dlls/mscoree/unixinterface.cpp
parent6d1715d68d8ca1f921534897828242bbcc4f00b6 (diff)
downloadcoreclr-1bf04d443bea95493d2a549d9b5e7b4d3d421812.tar.gz
coreclr-1bf04d443bea95493d2a549d9b5e7b4d3d421812.tar.bz2
coreclr-1bf04d443bea95493d2a549d9b5e7b4d3d421812.zip
Add custom entry point support.
Hosts like ASP.net don't want to call ExecuteAssembly, because their entry point is library, not a managed exe. However, forcing cross platform hosts to actually call CreateAppDomainWithManager and CreateDelegate themselves requires a bunch of tedious code, since these hosts don't have access to mscoree.h and the PAL. This change adds the ability to specificy an assembly, type and method which can be used as a custom entrypoint. The signiture of the managed entry point needs to be `static int E(int, char**)`.
Diffstat (limited to 'src/dlls/mscoree/unixinterface.cpp')
-rw-r--r--src/dlls/mscoree/unixinterface.cpp41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/dlls/mscoree/unixinterface.cpp b/src/dlls/mscoree/unixinterface.cpp
index 169b0aab13..265e99539e 100644
--- a/src/dlls/mscoree/unixinterface.cpp
+++ b/src/dlls/mscoree/unixinterface.cpp
@@ -16,6 +16,11 @@
#include <utilcode.h>
#include <corhost.h>
+typedef int (STDMETHODCALLTYPE *HostMain)(
+ const int argc,
+ const wchar_t** argv
+ );
+
#define ASSERTE_ALL_BUILDS(expr) _ASSERTE_ALL_BUILDS(__FILE__, (expr))
// Holder for const wide strings
@@ -94,7 +99,10 @@ static LPCWSTR* StringArrayToUnicode(int argc, LPCSTR* argv)
// propertyValues - Values of properties of the app domain
// argc - Number of arguments passed to the executed assembly
// argv - Array of arguments passed to the executed assembly
-// managedAssemblyPath - Path of the managed assembly to execute
+// managedAssemblyPath - Path of the managed assembly to execute (or NULL if using a custom entrypoint).
+// enntyPointAssemblyName - Name of the assembly which holds the custom entry point (or NULL to use managedAssemblyPath).
+// entryPointTypeName - Name of the type which holds the custom entry point (or NULL to use managedAssemblyPath).
+// entryPointMethodName - Name of the method which is the custom entry point (or NULL to use managedAssemblyPath).
// exitCode - Exit code returned by the executed assembly
//
// Returns:
@@ -111,6 +119,9 @@ HRESULT ExecuteAssembly(
int argc,
LPCSTR* argv,
LPCSTR managedAssemblyPath,
+ LPCSTR entryPointAssemblyName,
+ LPCSTR entryPointTypeName,
+ LPCSTR entryPointMethodName,
DWORD* exitCode)
{
*exitCode = 0;
@@ -177,11 +188,33 @@ HRESULT ExecuteAssembly(
ConstWStringArrayHolder argvW;
argvW.Set(StringArrayToUnicode(argc, argv), argc);
- ConstWStringHolder managedAssemblyPathW = StringToUnicode(managedAssemblyPath);
+ if (entryPointAssemblyName == NULL || entryPointTypeName == NULL || entryPointMethodName == NULL)
+ {
+ ConstWStringHolder managedAssemblyPathW = StringToUnicode(managedAssemblyPath);
- hr = host->ExecuteAssembly(domainId, managedAssemblyPathW, argc, argvW, exitCode);
- IfFailRet(hr);
+ hr = host->ExecuteAssembly(domainId, managedAssemblyPathW, argc, argvW, exitCode);
+ IfFailRet(hr);
+ }
+ else
+ {
+ ConstWStringHolder entryPointAssemblyNameW = StringToUnicode(entryPointAssemblyName);
+ ConstWStringHolder entryPointTypeNameW = StringToUnicode(entryPointTypeName);
+ ConstWStringHolder entryPointMethodNameW = StringToUnicode(entryPointMethodName);
+
+ HostMain pHostMain;
+
+ hr = host->CreateDelegate(
+ domainId,
+ entryPointAssemblyNameW,
+ entryPointTypeNameW,
+ entryPointMethodNameW,
+ (INT_PTR*)&pHostMain);
+
+ IfFailRet(hr);
+ *exitCode = pHostMain(argc, argvW);
+ }
+
hr = host->UnloadAppDomain(domainId,
true); // Wait until done
IfFailRet(hr);