From: pius.lee Date: Thu, 20 Oct 2016 11:40:09 +0000 (+0900) Subject: Now --standalone mode don't use managed launcher X-Git-Tag: accepted/tizen/mobile/20161215.072340~14 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0a0ecc4a37e4504cd8eb5c6b1681acb47086678e;p=platform%2Fcore%2Fdotnet%2Flauncher.git 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 --- 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 searchDirectories = { - RuntimeDirectory, DeviceAPIDirectory, launcherDir + std::vector 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 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