SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DLAUNCHER_CONFIG_PATH=${LAUNCHER_CONFIG_PATH}")
ENDIF(DEFINED LAUNCHER_CONFIG_PATH)
-IF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH)
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DCORECLR_LAUNCHER_ASSEMBLY_PATH=${CORECLR_LAUNCHER_ASSEMBLY_PATH}")
-ENDIF(DEFINED CORECLR_LAUNCHER_ASSEMBLY_PATH)
-
IF(DEFINED DEVICE_API_DIR)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DDEVICE_API_DIR=${DEVICE_API_DIR}")
ENDIF(DEFINED DEVICE_API_DIR)
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DNATIVE_LIB_DIR=${NATIVE_LIB_DIR}")
ENDIF(DEFINED NATIVE_LIB_DIR)
-IF(USE_MANAGED_LAUNCHER STREQUAL "ENABLE")
- ADD_DEFINITIONS("-DUSE_MANAGED_LAUNCHER")
-ENDIF(USE_MANAGED_LAUNCHER)
-
OPTION(NOT_USE_FUNCTION "Remove build warning" OFF)
IF(NOT_USE_FUNCTION)
ADD_DEFINITIONS("-DNOT_USE_FUNCTION")
INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR})
INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR})
INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR})
-ENDIF(NOT DEFINED NO_TIZEN)
\ No newline at end of file
+ENDIF(NOT DEFINED NO_TIZEN)
APP_TYPE dotnet
DETECTION_METHOD TIMEOUT|DEMAND
TIMEOUT 5000
+ON_BOOT OFF
EXTRA_ARRAY preload
EXTRA_ARRAY_VAL /usr/lib/libappcore-efl.so.1
EXTRA_ARRAY_VAL /usr/lib/libappcore-common.so.1
#include <fstream>
#include <vector>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+
#include "utils.h"
#include "log.h"
#include "launcher.h"
pluginSetCoreclrInfo(nullptr),
pluginGetDllPath(nullptr),
pluginBeforeExecute(nullptr),
- pluginFinalize(nullptr)
+ pluginFinalize(nullptr),
+ fd(0)
{
#define __XSTR(x) #x
#define __STR(x) __XSTR(x)
__nativeLibDirectory = __STR(NATIVE_LIB_DIR);
#endif
-#ifdef USE_MANAGED_LAUNCHER
-#ifdef CORECLR_LAUNCHER_ASSEMBLY_PATH
- __launcherAssembly = __STR(CORECLR_LAUNCHER_ASSEMBLY_PATH);
-#endif
-#endif
-
#undef __STR
#undef __XSTR
// set Reference API directory
__refAPIDirectory = __deviceAPIDirectory + "/ref";
-#ifdef USE_MANAGED_LAUNCHER
- if (__launcherAssembly.empty()) {
- _ERR("Empty Launcher Assembly");
- return 1;
- } else {
- __launcherAssembly = absolutePath(__launcherAssembly);
- }
-#endif
-
std::string libCoreclr(concatPath(__runtimeDirectory, "libcoreclr.so"));
_DBG("libcoreclr : %s", libCoreclr.c_str());
if (!standalone && pluginPreload)
pluginPreload();
+ fd = open("/proc/self", O_DIRECTORY);
+ std::string path_tmp = std::string("/proc/self/fd/") + std::to_string(fd);
+
+ std::string appRoot = path_tmp;
+ std::string appBin = concatPath(appRoot, "bin");
+ std::string appLib = concatPath(appRoot, "lib");
+ std::string probePath = appBin + ":" + appLib;
+
+ std::string tpa;
+ std::vector<std::string> searchDirectories;
+ searchDirectories.push_back(__runtimeDirectory);
+ searchDirectories.push_back(__deviceAPIDirectory);
+ searchDirectories.push_back(__refAPIDirectory);
+
+ if (pluginGetDllPath) {
+ std::string pluginPath = pluginGetDllPath();
+ if (!pluginPath.empty()) {
+ searchDirectories.push_back(pluginPath);
+ }
+ }
+
+ assembliesInDirectory(searchDirectories, tpa);
+
+ std::string nativeLibPath;
+ nativeLibPath = appLib + ":" + appBin + ":" + __nativeLibDirectory;
+
+ std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid());
+ if (!initializeCoreClr(appName.c_str(), probePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) {
+ _ERR("Failed to initialize coreclr");
+ return 1;
+ }
+
return 0;
}
return true;
}
-int CoreRuntime::runManagedLauncher(const char* appId, const char* appBase, const char* tpaList)
-{
- if (fileNotExist(__launcherAssembly)) {
- _ERR("Launcher assembly is not exist in %s", __launcherAssembly.c_str());
- return 1;
- }
-
- if (!initializeCoreClr(appId, appBase, appBase, tpaList)) {
- _ERR("Failed to initialize coreclr");
- return 1;
- }
-
-#ifdef USE_MANAGED_LAUNCHER
- void *preparedFunctionDelegate;
- int st = createDelegate(__hostHandle, __domainId,
- "Tizen.Runtime",
- "Tizen.Runtime.Coreclr.AssemblyManager",
- "Prepared", &preparedFunctionDelegate);
- if (st < 0) {
- _ERR("Create delegate for Launch prepared function is fail (0x%08x)", st);
- return 1;
- }
- preparedFunction = reinterpret_cast<PreparedFunctionPtr>(preparedFunctionDelegate);
-
- if (preparedFunction != nullptr)
- preparedFunction();
-
- void *launchFunctionDelegate;
- st = createDelegate(__hostHandle, __domainId,
- "Tizen.Runtime",
- "Tizen.Runtime.Coreclr.AssemblyManager",
- "Launch", &launchFunctionDelegate);
- if (st < 0) {
- _ERR("Create delegate for Launch managed function is fail! (0x%08x)", st);
- return 1;
- }
- launchFunction = reinterpret_cast<LaunchFunctionPtr>(launchFunctionDelegate);
-#endif
- return 0;
-}
-
void CoreRuntime::dispose()
{
if (__hostHandle != nullptr) {
if (pluginSetAppInfo)
pluginSetAppInfo(appId, path);
- std::string tpa;
- std::string appRoot = root;
- std::string appBin = concatPath(appRoot, "bin");
- std::string appLib = concatPath(appRoot, "lib");
- std::string probePath = appBin + ":" + appLib + ":" + __nativeLibDirectory;
-
- std::vector<std::string> searchDirectories;
- searchDirectories.push_back(appBin);
- searchDirectories.push_back(appLib);
- if (pluginGetDllPath) {
- std::string pluginPath = pluginGetDllPath();
- if (!pluginPath.empty()) {
- probePath = probePath + ":" + pluginPath;
- searchDirectories.push_back(pluginPath);
- }
- }
- searchDirectories.push_back(__runtimeDirectory);
- searchDirectories.push_back(__deviceAPIDirectory);
- searchDirectories.push_back(__refAPIDirectory);
-#ifdef USE_MANAGED_LAUNCHER
- searchDirectories.push_back(baseName(__launcherAssembly));
-#endif
-
- assembliesInDirectory(searchDirectories, tpa);
+ int fd2 = open(root, O_DIRECTORY);
+ dup3(fd2, fd, O_CLOEXEC);
+ close(fd2);
if (pluginBeforeExecute)
pluginBeforeExecute();
_ERR("Failed to create logging thread");
}
-#ifdef USE_MANAGED_LAUNCHER
- runManagedLauncher(appId, probePath.c_str(), tpa.c_str());
-
- bool success = false;
- if (launchFunction != nullptr) {
- success = launchFunction(root, path, argc, argv);
- if (!success)
- _ERR("Failed to launch Application %s", path);
- return success ? 0 : 1;
- } else {
- _ERR("Failed to find launch function");
- return 1;
- }
-#else
- int st = initializeCoreClr(appId, probePath.c_str(), probePath.c_str(), tpa.c_str());
unsigned int ret = 0;
- st = executeAssembly(__hostHandle, __domainId, argc, (const char**)argv, path, &ret);
+ int 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;
-#endif
}
} // namespace dotnetcore
~CoreRuntime();
int initialize(bool standalone) override;
void dispose() override;
- int runManagedLauncher(const char* appId, const char* appBase, const char* tpaList) override;
int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) override;
private:
coreclr_create_delegate_ptr createDelegate;
std::string __deviceAPIDirectory;
std::string __runtimeDirectory;
- std::string __launcherAssembly;
std::string __nativeLibDirectory;
std::string __refAPIDirectory;
void* __coreclrLib;
plugin_get_dll_path_ptr pluginGetDllPath;
plugin_before_execute_ptr pluginBeforeExecute;
plugin_finalize_ptr pluginFinalize;
+ int fd;
};
} // dotnetcore
public:
virtual int initialize(bool standalone) = 0;
virtual void dispose() = 0;
- virtual int runManagedLauncher(const char* appId, const char* appBase, const char* tpaList) = 0;
virtual int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) = 0;
};
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.IO;
-using System.Linq;
-using System.Reflection;
-using System.Runtime.Loader;
-using System.Collections.Generic;
-
-namespace Tizen.Runtime.Coreclr
-{
- public class AssemblyLoader : AssemblyLoadContext
- {
- private const string NativeAssemblyInfix = ".ni";
- private const string DllAssemblySuffix = ".dll";
- private const string ExeAssemblySuffix = ".exe";
- private const string NativeDllAssemblySuffix = NativeAssemblyInfix + DllAssemblySuffix;
- private static readonly string[] Suffixes = new string[] { NativeDllAssemblySuffix, DllAssemblySuffix, ExeAssemblySuffix };
- private SortedSet<string> DllDirectoriesSet = new SortedSet<string>();
- private SortedSet<string> NativeDirectoriesSet = new SortedSet<string>();
- private HashSet<FileInfo> AssemblyCacheSet = new HashSet<FileInfo>();
-
- public AssemblyLoader()
- {
- AssemblyLoadContext.Default.Resolving += OnResolving;
- }
-
- public IEnumerable<string> DllDirectories
- {
- get { return DllDirectoriesSet; }
- }
-
- public IEnumerable<string> NativeDirectories
- {
- get { return NativeDirectoriesSet; }
- }
-
- public void AddSearchableDirectory(string directory)
- {
- if (Directory.Exists(directory))
- {
- DllDirectoriesSet.Add(directory);
- NativeDirectoriesSet.Add(directory);
-
- foreach (var file in Directory.GetFiles(directory))
- {
- var info = new FileInfo(file);
-
- if (Suffixes.Contains(info.Extension))
- {
- AssemblyCacheSet.Add(info);
- }
- }
- }
- }
-
- public void RemoveSearchableDirectory(string directory)
- {
- DllDirectoriesSet.Remove(directory);
- NativeDirectoriesSet.Remove(directory);
-
- AssemblyCacheSet.RemoveWhere(x => x.DirectoryName == directory);
- }
-
- public Assembly LoadFromPath(string path)
- {
- if (string.Compare(path, path.Length - NativeDllAssemblySuffix.Length, NativeAssemblyInfix, 0, NativeAssemblyInfix.Length, StringComparison.OrdinalIgnoreCase) == 0)
- {
- return LoadFromNativeImagePath(path, null);
- }
- else
- {
- return LoadFromAssemblyPath(path);
- }
- }
-
- protected override Assembly Load(AssemblyName assemblyName)
- {
- return Resolve(assemblyName);
- }
-
- protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
- {
- IntPtr native = base.LoadUnmanagedDll(unmanagedDllName);
- if (native == IntPtr.Zero)
- {
- foreach (string dir in NativeDirectories)
- {
- FileInfo f = new FileInfo(Path.Combine(dir, unmanagedDllName));
- if (File.Exists(f.FullName))
- {
- native = LoadUnmanagedDllFromPath(f.FullName);
- break;
- }
- }
- }
-
- return native;
- }
-
- private Assembly Resolve(AssemblyName assemblyName)
- {
- foreach (string suffix in Suffixes)
- {
- var info = AssemblyCacheSet.FirstOrDefault(x => x.Name == assemblyName.Name + suffix);
-
- if (info != null)
- {
- return LoadFromPath(info.FullName);
- }
- }
-
- return null;
- }
-
- private Assembly OnResolving(AssemblyLoadContext context, AssemblyName assemblyName)
- {
- return Resolve(assemblyName);
- }
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.IO;
-using System.Reflection;
-using System.Runtime.Loader;
-using System.Linq;
-using System.Runtime.InteropServices;
-
-namespace Tizen.Runtime.Coreclr
-{
- public static class AssemblyManager
- {
- public static AssemblyLoader CurrentAssemblyLoaderContext
- {
- get;
- private set;
- }
-
- public static bool Launch(
- [In] string rootPath,
- [In] string path,
- [In] int argc,
- [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)]
- [In] string[] argv)
- {
- ALog.Debug($"Application Launch path : {path}");
- try
- {
- DirectoryInfo binDir = new DirectoryInfo(Path.Combine(rootPath, "bin"));
- DirectoryInfo libDir = new DirectoryInfo(Path.Combine(rootPath, "lib"));
- if (Directory.Exists(binDir.FullName))
- {
- CurrentAssemblyLoaderContext.AddSearchableDirectory(binDir.FullName);
- }
-
- if (Directory.Exists(libDir.FullName))
- {
- CurrentAssemblyLoaderContext.AddSearchableDirectory(libDir.FullName);
- }
-
- Execute(path, argv);
- }
- catch (Exception e)
- {
- ALog.Debug("Exception in Launch()");
- PrintException(e);
- return false;
- }
-
- return true;
- }
-
- public static void Prepared()
- {
- try
- {
- if (!Initialize())
- {
- ALog.Debug($"Failed to Initialized");
- }
- }
- catch (Exception e)
- {
- ALog.Debug("Exception at Preparing");
- PrintException(e);
- }
- }
-
- public static void UnhandledExceptionHandler(object sender, object args)
- {
- TypeInfo unhandledExceptionEventArgsType =
- Type.GetType("UnhandledExceptionEventArgs").GetTypeInfo();
-
- PropertyInfo exception = unhandledExceptionEventArgsType.GetProperty("ExceptionObject");
- Exception e = (Exception)exception.GetValue(args);
-
- PrintException(e);
- }
-
- public static bool Initialize()
- {
- try
- {
- // Set UnhandledException handler with reflection
- // we must replace this to no reflection method after AppDomain is comming in used net standard
- TypeInfo appdomainType = Type.GetType("System.AppDomain").GetTypeInfo();
- PropertyInfo currentDomain = appdomainType.GetProperty("CurrentDomain",
- BindingFlags.Public | BindingFlags.Static);
- EventInfo unhandledException = appdomainType.GetDeclaredEvent("UnhandledException");
- object appDomain = currentDomain.GetValue(null, null);
- MethodInfo handlerInfo = typeof(AssemblyManager).GetTypeInfo().GetDeclaredMethod("UnhandledExceptionHandler");
- Delegate handler = handlerInfo.CreateDelegate(unhandledException.EventHandlerType);
- var addMethod = unhandledException.GetAddMethod(true);
- addMethod.Invoke(appDomain, new[] {handler});
- }
- catch (Exception e)
- {
- ALog.Debug("Exception on set handler for unhandled exception");
- PrintException(e);
- }
-
- try
- {
- CurrentAssemblyLoaderContext = new AssemblyLoader();
- }
- catch (Exception e)
- {
- ALog.Debug("Exception on Initialized");
- PrintException(e);
- return false;
- }
-
- return true;
- }
-
- public static void Execute(string dllPath, string[] argv)
- {
- try
- {
- FileInfo f = new FileInfo(dllPath);
- if (File.Exists(f.FullName))
- {
- Assembly asm = CurrentAssemblyLoaderContext.LoadFromPath(f.FullName);
-
- if (asm == null)
- {
- throw new FileNotFoundException($"{f.FullName} is not found");
- }
-
- if (asm.EntryPoint == null)
- {
- throw new ArgumentException($"{f.FullName} did not have EntryPoint");
- }
-
- asm.EntryPoint.Invoke(null, new object[] {argv});
- }
- else
- {
- ALog.Debug($"Requested file does not exist: {dllPath}");
- }
- }
- catch (Exception e)
- {
- ALog.Debug("Exception on Execute");
- PrintException(e);
- }
- }
-
- private static void PrintException(Exception exception)
- {
- while (exception != null)
- {
- ALog.Debug(exception.ToString());
- exception = exception.InnerException;
- }
- }
-
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.IO;
-using System.Runtime.InteropServices;
-using System.Runtime.CompilerServices;
-
-namespace Tizen.Runtime
-{
- internal static class ALog
- {
- const string Library = "libdlog.so.0";
- const string Tag = "DOTNET_LAUNCHER";
-
- internal enum LogPriority
- {
- DLOG_UNKNOWN = 0,
- DLOG_DEFAULT,
- DLOG_VERBOSE,
- DLOG_DEBUG,
- DLOG_INFO,
- DLOG_WARN,
- DLOG_ERROR,
- DLOG_FATAL,
- DLOG_SILENT,
- DLOG_PRIO_MAX,
- }
-
- public static void Debug(string message,
- [CallerFilePath] string file = "",
- [CallerMemberName] string function = "",
- [CallerLineNumber] int line = 0)
- {
- Print(LogPriority.DLOG_DEBUG, Tag, message, file, function, line);
- }
-
- public static void Info(string message,
- [CallerFilePath] string file = "",
- [CallerMemberName] string function = "",
- [CallerLineNumber] int line = 0)
- {
- Print(LogPriority.DLOG_INFO, Tag, message, file, function, line);
- }
-
- public static void Error(string message,
- [CallerFilePath] string file = "",
- [CallerMemberName] string function = "",
- [CallerLineNumber] int line = 0)
- {
- Print(LogPriority.DLOG_ERROR, Tag, message, file, function, line);
- }
-
- [DllImportAttribute(Library, EntryPoint = "dlog_print")]
- internal static extern int Print(LogPriority priority, string tag, string format, string file, string function, int line, string msg);
-
- private static void Print(LogPriority priority, string tag, string message, string file, string function, int line)
- {
- FileInfo fileInfo = new FileInfo(file);
- Print(priority, tag, "%s: %s(%d) > %s", fileInfo.Name, function, line, message);
- }
-
- }
-}
+++ /dev/null
-<Project Sdk="Microsoft.NET.Sdk">
-
- <PropertyGroup>
- <TargetFramework>netstandard1.6</TargetFramework>
- </PropertyGroup>
-
- <ItemGroup>
- <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
- </ItemGroup>
-
-</Project>
\ No newline at end of file
%prep
%setup -q
-%define use_managed_launcher 0
-%if %{use_managed_launcher}
- %define USE_MANAGED_LAUNCHER ENABLE
-%endif
-
%build
%if 0%{?asan_enabled}
-DDEVICE_API_DIR=%{_device_api_dir} \
-DRUNTIME_DIR=%{_runtime_dir} \
-DCROSSGEN_PATH=%{_device_api_dir}/crossgen \
-%if %{use_managed_launcher}
- -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.dll \
-%endif
-DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \
-DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \
-DVERSION=%{version} \
- -DUSE_MANAGED_LAUNCHER=%{?USE_MANAGED_LAUNCHER:%USE_MANAGED_LAUNCHER} \
-DNATIVE_LIB_DIR=%{_native_lib_dir} \
NativeLauncher
make %{?jobs:-j%jobs} VERBOSE=1
-%dotnet_build Tizen.Runtime
-
%install
rm -rf %{buildroot}
%make_install
-%if %{use_managed_launcher}
-install -p -m 644 Tizen.Runtime/bin/*/*/Tizen.Runtime.dll %{buildroot}%{_bindir}
-%endif
mkdir -p %{buildroot}%{_native_lib_dir}
ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so
%{_bindir}/nitool
#%{_install_plugin_dir}/libui-application.so
%{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so
-%if %{use_managed_launcher}
-%{_bindir}/Tizen.Runtime.dll
-%endif
%{_bindir}/dotnet-launcher