summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpius.lee <pius.lee@samsung.com>2016-10-20 20:40:09 +0900
committerpius.lee <pius.lee@samsung.com>2016-10-20 20:40:09 +0900
commit0a0ecc4a37e4504cd8eb5c6b1681acb47086678e (patch)
tree351a297d880b92a0aa60ee34b33e89d56cfa2147
parent080a106fc01e98133ef456f26a9e09e7da9217fc (diff)
downloadlauncher-0a0ecc4a37e4504cd8eb5c6b1681acb47086678e.tar.gz
launcher-0a0ecc4a37e4504cd8eb5c6b1681acb47086678e.tar.bz2
launcher-0a0ecc4a37e4504cd8eb5c6b1681acb47086678e.zip
Now --standalone mode don't use managed launcher
Launched assembly start on native directly on standalone mode. It does not use assembly launcher. Change-Id: I64536ed0bf48a7a9254f51189b53d219b8e4777b
-rw-r--r--NativeLauncher/src/dotnet/dotnet_launcher.cc96
-rw-r--r--NativeLauncher/src/dotnet/dotnet_launcher.h1
-rw-r--r--NativeLauncher/src/main.cc5
-rw-r--r--NativeLauncher/src/mono/mono_launcher.cc83
-rw-r--r--NativeLauncher/src/mono/mono_launcher.h4
5 files changed, 118 insertions, 71 deletions
diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.cc b/NativeLauncher/src/dotnet/dotnet_launcher.cc
index d9879ba..ce880a9 100644
--- a/NativeLauncher/src/dotnet/dotnet_launcher.cc
+++ b/NativeLauncher/src/dotnet/dotnet_launcher.cc
@@ -127,31 +127,14 @@ int CoreRuntime::Initialize(bool standalone)
return 0;
}
-int CoreRuntime::RunManagedLauncher()
+bool CoreRuntime::InitializeCoreClr(const char* assembly_probe_paths, const char* pinvoke_probe_paths)
{
- void* hostHandle;
- unsigned int domainId;
-
- if (FileNotExist(LauncherAssembly))
- {
- _ERR("Launcher assembly is not exist in %s", LauncherAssembly.c_str());
- return 1;
- }
-
- std::string launcherDir = Basename(LauncherAssembly);
- std::vector<std::string> searchDirectories = {
- RuntimeDirectory, DeviceAPIDirectory, launcherDir
+ std::vector<std::string> platformDirectories = {
+ RuntimeDirectory, DeviceAPIDirectory
};
std::string trusted_assemblies;
- AssembliesInDirectory(searchDirectories, trusted_assemblies);
- std::string trusted_directories = JoinStrings(searchDirectories, ":");
-
- _DBG("coreclr_dir : %s", RuntimeDirectory.c_str());
- _DBG("tpa_dirs : %s", trusted_directories.c_str());
- _DBG("native_so_search_dir : %s", trusted_directories.c_str());
- _DBG("launcher_assembly : %s", LauncherAssembly.c_str());
- _DBG("launcher_dir : %s", launcherDir.c_str());
+ AssembliesInDirectory(platformDirectories, trusted_assemblies);
const char *propertyKeys[] =
{
@@ -165,31 +148,16 @@ int CoreRuntime::RunManagedLauncher()
const char *propertyValues[] =
{
trusted_assemblies.c_str(),
- launcherDir.c_str(),
- launcherDir.c_str(),
- trusted_directories.c_str(),
+ assembly_probe_paths,
+ assembly_probe_paths,
+ pinvoke_probe_paths,
"UseLatestBehaviorWhenTFMNotSpecified"
};
-
- //_DBG("trusted platform assemblies : %s", propertyValues[0]);
- _DBG("app_path : %s", propertyValues[1]);
- _DBG("app_ni_path : %s", propertyValues[2]);
- _DBG("native dll search path : %s", propertyValues[3]);
- _DBG("app domain compat switch : %s", propertyValues[4]);
-
- _DBG("before InitializeClr");
- _DBG("this addr : %x", this);
- _DBG("coreclr_initialize : %x", InitializeClr);
std::string selfPath = ReadSelfPath();
- _DBG("self path : %s", selfPath.c_str());
-
- _DBG("libcoreclr addr : %x", coreclrLib);
-
int st = InitializeClr(
selfPath.c_str(),
- //LauncherAssembly.c_str(),
"dotnet-launcher",
sizeof(propertyKeys) / sizeof(propertyKeys[0]),
propertyKeys,
@@ -200,13 +168,41 @@ int CoreRuntime::RunManagedLauncher()
if (st < 0)
{
_ERR("initialize core clr fail! (0x%08x)", st);
- return 1;
+ return false;
}
_DBG("Initialize core clr success");
+ return true;
+}
+
+int CoreRuntime::RunManagedLauncher()
+{
+ if (FileNotExist(LauncherAssembly))
+ {
+ _ERR("Launcher assembly is not exist in %s", LauncherAssembly.c_str());
+ return 1;
+ }
+
+ std::string launcherDir = Basename(LauncherAssembly);
+ std::vector<std::string> searchDirectories = {
+ RuntimeDirectory, DeviceAPIDirectory
+ };
+
+ std::string trusted_directories = JoinStrings(searchDirectories, ":");
+
+ _DBG("coreclr_dir : %s", RuntimeDirectory.c_str());
+ _DBG("native_so_search_dir : %s", trusted_directories.c_str());
+ _DBG("launcher_assembly : %s", LauncherAssembly.c_str());
+ _DBG("launcher_dir : %s", launcherDir.c_str());
+
+ if (!InitializeCoreClr(launcherDir.c_str(), launcherDir.c_str()))
+ {
+ _ERR("Failed to initialize coreclr");
+ return 1;
+ }
void *preparedFunctionDelegate;
- st = CreateDelegate(hostHandle, domainId,
+ int st = CreateDelegate(hostHandle, domainId,
"Tizen.Runtime.Coreclr",
"Tizen.Runtime.Coreclr.AssemblyManager",
"Prepared", &preparedFunctionDelegate);
@@ -279,8 +275,24 @@ int CoreRuntime::Launch(const char* root, const char* path, int argc, char* argv
{
_ERR("Failed to launch Application %s", path);
}
+ return success ? 0 : 1;
+ }
+ else
+ {
+ std::string appRoot = root;
+ std::string appBin = ConcatPath(appRoot, "bin");
+ std::string appLib = ConcatPath(appRoot, "lib");
+ std::string probePath = appBin + ":" + appLib;
+
+ int st = InitializeCoreClr(probePath.c_str(), probePath.c_str());
+ unsigned int ret = 0;
+ st = ExecuteAssembly(hostHandle, domainId, argc, (const char**)argv, path, &ret);
+ if (st < 0)
+ {
+ _ERR("Failed to Execute Assembly %s (0x%08x)", path, st);
+ }
+ return ret;
}
- return success ? 0 : 1;
}
} // namespace dotnetcore
diff --git a/NativeLauncher/src/dotnet/dotnet_launcher.h b/NativeLauncher/src/dotnet/dotnet_launcher.h
index 92567f6..fa72e11 100644
--- a/NativeLauncher/src/dotnet/dotnet_launcher.h
+++ b/NativeLauncher/src/dotnet/dotnet_launcher.h
@@ -50,6 +50,7 @@ class CoreRuntime : public tizen::runtime::LauncherInterface
int Launch(const char* root, const char* path, int argc, char* argv[]) override;
private:
+ bool InitializeCoreClr(const char* assembly_probe_paths, const char* pinvoke_probe_paths);
coreclr_initialize_ptr InitializeClr;
coreclr_execute_assembly_ptr ExecuteAssembly;
coreclr_shutdown_ptr Shutdown;
diff --git a/NativeLauncher/src/main.cc b/NativeLauncher/src/main.cc
index 9f43bfc..18085b7 100644
--- a/NativeLauncher/src/main.cc
+++ b/NativeLauncher/src/main.cc
@@ -103,11 +103,6 @@ int main(int argc, char *argv[])
_ERR("Failed to initialize");
return 1;
}
- if (runtime->RunManagedLauncher() != 0)
- {
- _ERR("Failed to run managed launcher");
- return 1;
- }
int args_len = vargs.size();
char** args = &vargs[0];
diff --git a/NativeLauncher/src/mono/mono_launcher.cc b/NativeLauncher/src/mono/mono_launcher.cc
index fff1104..8636447 100644
--- a/NativeLauncher/src/mono/mono_launcher.cc
+++ b/NativeLauncher/src/mono/mono_launcher.cc
@@ -10,10 +10,13 @@ namespace tizen {
namespace runtime {
namespace mono {
+static const char* DOMAIN_NAME = "tizen_mono_domain";
static const char* LIBMONO = "/usr/lib/libmono-2.0.so.1";
MonoRuntime::MonoRuntime() :
- monolib(nullptr)
+ monolib(nullptr),
+ domain(nullptr),
+ launch(nullptr)
{
#define __XSTR(x) #x
@@ -83,6 +86,8 @@ int MonoRuntime::Initialize(bool standalone)
MONOLIB_RETURN_IF_NOSYM(mono_get_string_class_ptr, GetStringClass, "mono_get_string_class");
MONOLIB_RETURN_IF_NOSYM(mono_array_new_ptr, ArrayNew, "mono_array_new");
MONOLIB_RETURN_IF_NOSYM(mono_array_addr_with_size_ptr, ArrayAddrWithSize, "mono_array_addr_with_size");
+ MONOLIB_RETURN_IF_NOSYM(mono_jit_cleanup_ptr, DomainCleanup, "mono_jit_cleanup");
+ MONOLIB_RETURN_IF_NOSYM(mono_jit_exec_ptr, AssemblyExec, "mono_jit_exec");
#undef MONOLIB_RETURN_IF_NOSYM
@@ -93,6 +98,10 @@ int MonoRuntime::Initialize(bool standalone)
void MonoRuntime::Dispose()
{
+ if (domain != nullptr)
+ {
+ DomainCleanup(domain);
+ }
if (monolib != nullptr && dlclose(monolib) != 0)
{
_ERR("libmono close failed");
@@ -119,7 +128,7 @@ int MonoRuntime::RunManagedLauncher()
*/
SetAssembliesPath(deviceAPIDirectory.c_str());
- domain = JitInit("tizen_mono_domain");
+ domain = JitInit(DOMAIN_NAME);
if (domain == nullptr)
{
_ERR("Failed to init mono jit");
@@ -179,31 +188,57 @@ int MonoRuntime::RunManagedLauncher()
int MonoRuntime::Launch(const char* root, const char* path, int argc, char* argv[])
{
- MonoString *rootMonoString = NewString(domain, root);
- MonoString *pathMonoString = NewString(domain, path);
- MonoArray *argvMonoArray = ArrayNew(domain, GetStringClass(), argc);
- for (int i=0; i<argc; i++)
+ if (domain == nullptr)
{
- MonoString *arg = NewString(domain, argv[i]);
- ArraySet(argvMonoArray, MonoString*, i, arg);
+ domain = JitInit(DOMAIN_NAME);
+ if (domain == nullptr)
+ {
+ _ERR("Failed to init mono jit");
+ return 1;
+ }
}
-
- void **args = new void*[argc+2];
- args[0] = rootMonoString;
- args[1] = pathMonoString;
- args[2] = &argc;
- args[3] = argvMonoArray;
-
- MonoObject* exception = nullptr;
- RuntimeInvoke(launch, nullptr, args, &exception);
- if (exception != nullptr)
+ if (launch != nullptr)
{
- MonoString * exceptionMsg = ObjectToString(exception, nullptr);
- char* cstringMsg = StringToUtf8(exceptionMsg);
- _ERR("Failed to invoke launch method in runtime");
- _ERR("%s", cstringMsg);
- free(cstringMsg);
- return 1;
+ MonoString *rootMonoString = NewString(domain, root);
+ MonoString *pathMonoString = NewString(domain, path);
+ MonoArray *argvMonoArray = ArrayNew(domain, GetStringClass(), argc);
+ for (int i=0; i<argc; i++)
+ {
+ MonoString *arg = NewString(domain, argv[i]);
+ ArraySet(argvMonoArray, MonoString*, i, arg);
+ }
+
+ void **args = new void*[argc+2];
+ args[0] = rootMonoString;
+ args[1] = pathMonoString;
+ args[2] = &argc;
+ args[3] = argvMonoArray;
+
+ MonoObject* exception = nullptr;
+ RuntimeInvoke(launch, nullptr, args, &exception);
+ if (exception != nullptr)
+ {
+ MonoString * exceptionMsg = ObjectToString(exception, nullptr);
+ char* cstringMsg = StringToUtf8(exceptionMsg);
+ _ERR("Failed to invoke launch method in runtime");
+ _ERR("%s", cstringMsg);
+ free(cstringMsg);
+ return 1;
+ }
+ }
+ else
+ {
+ std::string appBin = ConcatPath(root, "bin");
+ std::string appLib = ConcatPath(root, "lib");
+ std::string probePath = deviceAPIDirectory + ":" + appBin + ":" + appLib;
+ SetAssembliesPath(probePath.c_str());
+ MonoAssembly* app = DomainAssemblyOpen(domain, path);
+ if (app == nullptr)
+ {
+ _ERR("Failed to open assembly : %s", path);
+ return 1;
+ }
+ int ret = AssemblyExec(domain, app, argc, argv);
}
return 0;
}
diff --git a/NativeLauncher/src/mono/mono_launcher.h b/NativeLauncher/src/mono/mono_launcher.h
index 8aa5a4b..d705d9e 100644
--- a/NativeLauncher/src/mono/mono_launcher.h
+++ b/NativeLauncher/src/mono/mono_launcher.h
@@ -27,6 +27,8 @@ extern "C"
typedef MonoClass* (*mono_get_string_class_ptr) ();
typedef MonoArray* (*mono_array_new_ptr) (MonoDomain *, MonoClass *, uintptr_t);
typedef char* (*mono_array_addr_with_size_ptr) (MonoArray *, int, uintptr_t);
+ typedef void (*mono_jit_cleanup_ptr) (MonoDomain *domain);
+ typedef int (*mono_jit_exec_ptr) (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[]);
}
namespace tizen {
@@ -59,6 +61,8 @@ class MonoRuntime : public tizen::runtime::LauncherInterface
mono_get_string_class_ptr GetStringClass;
mono_array_new_ptr ArrayNew;
mono_array_addr_with_size_ptr ArrayAddrWithSize;
+ mono_jit_cleanup_ptr DomainCleanup;
+ mono_jit_exec_ptr AssemblyExec;
MonoDomain* domain;
MonoAssembly* launcherAssembly;