From ac9910576fe5fe1795b9ca98d431a8347ddb7c11 Mon Sep 17 00:00:00 2001 From: JongHeon Choi Date: Wed, 19 Apr 2017 13:23:11 +0900 Subject: [PATCH] Modify tizen coding style Change-Id: I454c5c4296d9ab3e18d0ea40db0ca1061de67668 --- NativeLauncher/inc/utils.h | 30 +- NativeLauncher/installer-plugin/common.cc | 505 +++++----- NativeLauncher/installer-plugin/common.h | 16 +- NativeLauncher/installer-plugin/nitool.cc | 145 ++- .../pkgmgr_parser_plugin_interface.h | 24 +- .../installer-plugin/prefer_dotnet_aot_plugin.cc | 60 +- NativeLauncher/installer-plugin/ui-application.cc | 133 ++- NativeLauncher/launcher/dotnet/dotnet_launcher.cc | 450 ++++----- NativeLauncher/launcher/dotnet/dotnet_launcher.h | 99 +- NativeLauncher/launcher/dotnet/scd_launcher.cc | 1015 +++++++++----------- NativeLauncher/launcher/launcher.cc | 301 +++--- NativeLauncher/launcher/launcher.h | 35 +- NativeLauncher/launcher/main.cc | 187 ++-- NativeLauncher/util/utils.cc | 457 ++++----- README.md | 2 +- .../AssemblyLoader.cs | 43 +- .../AssemblyManager.cs | 67 +- Tizen.Runtime/{Tizen.Runtime => }/Log.cs | 77 +- Tizen.Runtime/Tizen.Runtime.Coreclr.csproj | 90 -- Tizen.Runtime/Tizen.Runtime.Coreclr.project.json | 10 - Tizen.Runtime/Tizen.Runtime.csproj | 11 + Tizen.Runtime/Tizen.Runtime.snk | Bin 599 -> 0 bytes .../Tizen.Runtime/DefaultConfigAttribute.cs | 35 - packaging/dotnet-launcher.spec | 12 +- test_build_on_desktop.sh | 23 - 25 files changed, 1674 insertions(+), 2153 deletions(-) mode change 100755 => 100644 NativeLauncher/inc/utils.h mode change 100755 => 100644 NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc rename Tizen.Runtime/{Tizen.Runtime.Coreclr => CoreClr}/AssemblyLoader.cs (69%) mode change 100755 => 100644 rename Tizen.Runtime/{Tizen.Runtime.Coreclr => CoreClr}/AssemblyManager.cs (81%) rename Tizen.Runtime/{Tizen.Runtime => }/Log.cs (56%) delete mode 100644 Tizen.Runtime/Tizen.Runtime.Coreclr.csproj delete mode 100644 Tizen.Runtime/Tizen.Runtime.Coreclr.project.json create mode 100644 Tizen.Runtime/Tizen.Runtime.csproj delete mode 100644 Tizen.Runtime/Tizen.Runtime.snk delete mode 100644 Tizen.Runtime/Tizen.Runtime/DefaultConfigAttribute.cs delete mode 100755 test_build_on_desktop.sh diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h old mode 100755 new mode 100644 index 59774cb..034b7f3 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -26,21 +26,21 @@ #define PATH_SEPARATOR '/' #endif -bool ICompare(const std::string& a, const std::string& b); -bool ICompare(const std::string& a, int a_offset, const std::string& b, int b_offset, int length); -bool IsManagedAssembly(const std::string& filename); -bool IsNativeImage(const std::string& filename); -std::string ReadSelfPath (); -std::string ConcatPath (const std::string& path1, const std::string& path2); -void AppendPath (std::string& path1, const std::string& path2); -std::string AbsolutePath (const std::string& path); -std::string Basename (const std::string& path); -bool EndWithIgnoreCase (const std::string& str1, const std::string& str2, std::string& filename); -void AssembliesInDirectory(const std::vector& directories, std::string& tpaList); +bool iCompare(const std::string& a, const std::string& b); +bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length); +bool isManagedAssembly(const std::string& fileName); +bool isNativeImage(const std::string& fileName); +std::string readSelfPath(); +std::string concatPath(const std::string& path1, const std::string& path2); +void appendPath(std::string& path1, const std::string& path2); +std::string absolutePath(const std::string& path); +std::string baseName(const std::string& path); +bool endWithIgnoreCase(const std::string& str1, const std::string& str2, std::string& fileName); +void assembliesInDirectory(const std::vector& directories, std::string& tpaList); -bool FileNotExist(const std::string& path); -std::string JoinStrings(const std::vector& strings, const char* const delimeter); +bool fileNotExist(const std::string& path); +std::string joinStrings(const std::vector& strings, const char* const delimeter); typedef std::function FileReader; -void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth); -#endif // __UTILS_H__ +void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth); +#endif /* __UTILS_H__ */ diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index 6473dc8..e53cff3 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -55,319 +55,266 @@ #define __XSTR(x) #x #define __STR(x) __XSTR(x) -static const char* DeviceAPIDir = __STR(DEVICE_API_DIR); -static const char* RuntimeDir = __STR(RUNTIME_DIR); -static const char* CrossgenPath = __STR(CROSSGEN_PATH); -static const char* JITPath = __STR(RUNTIME_DIR)"/libclrjit.so"; +static const char* __DEVICE_API_DIR = __STR(DEVICE_API_DIR); +static const char* __RUNTIME_DIR = __STR(RUNTIME_DIR); +static const char* __CROSSGEN_PATH = __STR(CROSSGEN_PATH); +static const char* __JIT_PATH = __STR(RUNTIME_DIR)"/libclrjit.so"; #undef __STR #undef __XSTR -static void crossgen(const char* dll_path, const char* app_path); -static void smack_(const char* dll_path, const char* label); +static void crossgen(const char* dllPath, const char* appPath); +static void smack_(const char* dllPath, const char* label); -std::string Replace(std::string &str, const std::string& from, const std::string& to) +std::string replace(std::string &str, const std::string& from, const std::string& to) { - size_t start_pos = 0; - while((start_pos = str.find(from, start_pos)) != std::string::npos) - { - str.replace(start_pos, from.length(), to); - start_pos += to.length(); - } - return str; + size_t startPos = 0; + while ((startPos = str.find(from, startPos)) != std::string::npos) { + str.replace(startPos, from.length(), to); + startPos += to.length(); + } + return str; } -void create_ni_platform() +void createNiPlatform() { - std::string corlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.dll"); - std::string nicorlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.ni.dll"); + std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); + std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); - if (FileNotExist(nicorlib)) - { - crossgen(corlib.c_str(), nullptr); - smack_(nicorlib.c_str(), "_"); - } + if (fileNotExist(niCoreLib)) { + crossgen(coreLib.c_str(), nullptr); + smack_(niCoreLib.c_str(), "_"); + } - const char* platform_dirs[] = {RuntimeDir, DeviceAPIDir, "/usr/bin"}; - const char* ignores[] = {corlib.c_str()}; + const char* platformDirs[] = {__RUNTIME_DIR, __DEVICE_API_DIR, "/usr/bin"}; + const char* ignores[] = {coreLib.c_str()}; - create_ni_under_dirs(platform_dirs, 3, ignores, 1, [](const char* ni){ - smack_(ni, "_"); - }); + createNiUnderDirs(platformDirs, 3, ignores, 1, [](const char* ni) { + smack_(ni, "_"); + }); } -void create_ni_select(const char* dll_path) +void createNiSelect(const char* dllPath) { - std::string corlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.dll"); - std::string nicorlib = ConcatPath(RuntimeDir, "System.Private.CoreLib.ni.dll"); - - if (FileNotExist(nicorlib)) - { - crossgen(corlib.c_str(), nullptr); - smack_(nicorlib.c_str(), "_"); - } - - if (!FileNotExist(dll_path)) - { - std::string str_path = dll_path; - std::string ni_path = Replace(str_path, std::string(".dll"), std::string(".ni.dll")); - if (FileNotExist(ni_path)) - crossgen(dll_path, nullptr); - else - printf("Already [%s] file is exist\n", ni_path.c_str()); - smack_(ni_path.c_str(), "_"); - } + std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); + std::string niCoreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.ni.dll"); + + if (fileNotExist(niCoreLib)) { + crossgen(coreLib.c_str(), nullptr); + smack_(niCoreLib.c_str(), "_"); + } + + if (!fileNotExist(dllPath)) { + std::string strPath = dllPath; + std::string niPath = replace(strPath, std::string(".dll"), std::string(".ni.dll")); + if (fileNotExist(niPath)) + crossgen(dllPath, nullptr); + else + printf("Already [%s] file is exist\n", niPath.c_str()); + smack_(niPath.c_str(), "_"); + } } -static void smack_(const char* dll_path, const char* label) +static void smack_(const char* dllPath, const char* label) { - static const char* CHKSMACK = "/usr/bin/chsmack"; - pid_t pid = fork(); - if (pid == -1) - { - return; - } - - if (pid > 0) - { - int status; - waitpid(pid, &status, 0); - if (WIFEXITED(status)) - { - return; - } - } - else - { - const char* args[] = { - CHKSMACK, - "-a", label, - dll_path, - nullptr - }; - execv(CHKSMACK, const_cast(args)); - - exit(0); - } + static const char* chsmack = "/usr/bin/chsmack"; + pid_t pid = fork(); + if (pid == -1) + return; + + if (pid > 0) { + int status; + waitpid(pid, &status, 0); + if (WIFEXITED(status)) + return; + } else { + const char* args[] = { + chsmack, + "-a", label, + dllPath, + nullptr + }; + execv(chsmack, const_cast(args)); + + exit(0); + } } -static void crossgen(const char* dll_path, const char* app_path) +static void crossgen(const char* dllPath, const char* appPath) { - //pid_t parent = getpid(); - pid_t pid = fork(); - if (pid == -1) - { - return; - } - - if (pid > 0) - { - int status; - waitpid(pid, &status, 0); - if (WIFEXITED(status)) - { - return; - } - } - else - { - // search dlls in the application directory first, to use application dlls - // instead of system dlls when proceeding NI - std::vector tpaDir; - if (app_path != NULL) - { - std::string path(app_path); - std::string::size_type prev_pos = 0, pos = 0; - while((pos = path.find(':', pos)) != std::string::npos) - { - std::string substring(path.substr(prev_pos, pos - prev_pos)); - tpaDir.push_back(substring); - prev_pos = ++pos; - } - std::string substring(path.substr(prev_pos, pos - prev_pos)); - tpaDir.push_back(substring); - } - tpaDir.push_back(RuntimeDir); - tpaDir.push_back(DeviceAPIDir); - - std::string tpa; - AssembliesInDirectory(tpaDir, tpa); - - std::vector argv = - { - CrossgenPath, - "/Trusted_Platform_Assemblies", tpa.c_str(), - "/JITPath", JITPath, - "/FragileNonVersionable" - }; - if (app_path != nullptr) - { - argv.push_back("/App_Paths"); - argv.push_back(app_path); - } - argv.push_back(dll_path); - argv.push_back(nullptr); - - /* - for (const char* arg : argv) - { - printf("%s ", arg); - } - printf("\n"); - */ - printf("+ %s\n", dll_path); - - execv(CrossgenPath, const_cast(argv.data())); - exit(0); - } + //pid_t parent = getpid(); + pid_t pid = fork(); + if (pid == -1) + return; + + if (pid > 0) { + int status; + waitpid(pid, &status, 0); + if (WIFEXITED(status)) + return; + } else { + // search dlls in the application directory first, to use application dlls + // instead of system dlls when proceeding NI + std::vector tpaDir; + if (appPath != NULL) { + std::string path(appPath); + std::string::size_type prevPos = 0, pos = 0; + while ((pos = path.find(':', pos)) != std::string::npos) { + std::string substring(path.substr(prevPos, pos - prevPos)); + tpaDir.push_back(substring); + prevPos = ++pos; + } + std::string substring(path.substr(prevPos, pos - prevPos)); + tpaDir.push_back(substring); + } + tpaDir.push_back(__RUNTIME_DIR); + tpaDir.push_back(__DEVICE_API_DIR); + + std::string tpa; + assembliesInDirectory(tpaDir, tpa); + + std::vector argv = { + __CROSSGEN_PATH, + "/Trusted_Platform_Assemblies", tpa.c_str(), + "/__JIT_PATH", __JIT_PATH, + "/FragileNonVersionable" + }; + if (appPath != nullptr) { + argv.push_back("/App_Paths"); + argv.push_back(appPath); + } + argv.push_back(dllPath); + argv.push_back(nullptr); + + printf("+ %s\n", dllPath); + + execv(__CROSSGEN_PATH, const_cast(argv.data())); + exit(0); + } } -static int get_root_path(const char *pkgid, std::string& root_path) +static int getRootPath(const char *pkgId, std::string& rootPath) { - int ret = 0; - char *path = 0; - - uid_t uid = 0; - - if (pkgmgr_installer_info_get_target_uid(&uid) < 0) - { - _ERR("Failed to get UID"); - return -1; - } - - _INFO("user id is %d", uid); - - pkgmgrinfo_pkginfo_h handle; - if (uid == 0) - { - ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &handle); - if (ret != PMINFO_R_OK) - return -1; - } - else - { - ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - if (ret != PMINFO_R_OK) - return -1; - } - - ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path); - if (ret != PMINFO_R_OK) { - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - return -1; - } - root_path = path; - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - - return 0; + int ret = 0; + char *path = 0; + + uid_t uid = 0; + + if (pkgmgr_installer_info_get_target_uid(&uid) < 0) { + _ERR("Failed to get UID"); + return -1; + } + + _INFO("user id is %d", uid); + + pkgmgrinfo_pkginfo_h handle; + if (uid == 0) { + ret = pkgmgrinfo_pkginfo_get_pkginfo(pkgId, &handle); + if (ret != PMINFO_R_OK) + return -1; + } else { + ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId, uid, &handle); + if (ret != PMINFO_R_OK) + return -1; + } + + ret = pkgmgrinfo_pkginfo_get_root_path(handle, &path); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + return -1; + } + rootPath = path; + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + + return 0; } -static bool NIExist(const std::string& path, std::string& ni) +static bool niExist(const std::string& path, std::string& ni) { - static const char* possible_exts[] = { - ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL", - ".ni.exe", ".NI.exe", ".NI.EXE", ".ni.EXE" - }; - std::string fname = path.substr(0, path.size() - 4); - - struct stat sb; - - for (const char* ext : possible_exts) - { - std::string f = fname + ext; - if (stat(f.c_str(), &sb) == 0) - { - ni = f; - return true; - } - } - - return false; + static const char* possibleExts[] = { + ".ni.dll", ".NI.dll", ".NI.DLL", ".ni.DLL", + ".ni.exe", ".NI.exe", ".NI.EXE", ".ni.EXE" + }; + std::string fName = path.substr(0, path.size() - 4); + + struct stat sb; + + for (const char* ext : possibleExts) { + std::string f = fName + ext; + if (stat(f.c_str(), &sb) == 0) { + ni = f; + return true; + } + } + + return false; } -void create_ni_under_dirs(const char* root_paths[], int count, const char* ignores[], int igcount, after_create cb) +void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb) { - std::string app_paths; - for (int i=0; i -typedef std::function after_create; -void create_ni_under_dirs(const char* root_paths[], int count, const char* ignores[], int igcount, after_create cb); -void create_ni_under_dirs(const char* root_paths[], int count, after_create cb); -void create_ni_under_dirs(const char* root_paths[], int count); -int create_ni_under_pkg_root(const char* pkg_name); -void create_ni_platform(); -void create_ni_select(const char* dll_path); +typedef std::function afterCreate; +void createNiUnderDirs(const char* rootPaths[], int count, const char* ignores[], int igcount, afterCreate cb); +void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb); +void createNiUnderDirs(const char* rootPaths[], int count); +int createNiUnderPkgRoot(const char* pkgName); +void createNiPlatform(); +void createNiSelect(const char* dllPath); -#endif // __INSTALLER_PLUGIN_COMMON_H__ +#endif /* __INSTALLER_PLUGIN_COMMON_H__ */ diff --git a/NativeLauncher/installer-plugin/nitool.cc b/NativeLauncher/installer-plugin/nitool.cc index b60bd8b..c34a696 100644 --- a/NativeLauncher/installer-plugin/nitool.cc +++ b/NativeLauncher/installer-plugin/nitool.cc @@ -22,103 +22,84 @@ #include #include -std::vector get_cmd_args(char** begin, char** end) +std::vector getCmdArgs(char** begin, char** end) { - std::vector list; - for (char** itr = begin+1; itr != end; itr++) - { - if (strncmp(*itr, "--", 2) != 0) - list.push_back(*itr); - } - return list; + std::vector list; + for (char** itr = begin+1; itr != end; itr++) { + if (strncmp(*itr, "--", 2) != 0) + list.push_back(*itr); + } + return list; } -bool cmd_option_exists(char** begin, char** end, const std::string& option) +bool cmdOptionExists(char** begin, char** end, const std::string& option) { - return std::find(begin, end, option) != end; + return std::find(begin, end, option) != end; } static void help(const char *argv0) { - const char* helpdesc = - "Usage: %s [args] \n" - " --help - Display this screen\n" - " --system - Create NI under System DLLs\n" - " --dll - Create NI for DLL\n" - " --pkg - Create NI for package\n" - "\n" - "Example:\n" - "Create native image for dlls and exes under platform directories\n" - "%s --system\n" - "Create native image for dll\n" - "%s --dll /usr/bin/Tizen.Runtime.Coreclr.dll\n" - "Create native image under the package's bin and lib directory\n" - "%s --pkg org.tizen.FormsGallery\n\n"; - printf(helpdesc, argv0, argv0, argv0, argv0); + const char* helpDesc = + "Usage: %s [args] \n" + " --help - Display this screen\n" + " --system - Create NI under System DLLs\n" + " --dll - Create NI for DLL\n" + " --pkg - Create NI for package\n" + "\n" + "Example:\n" + "Create native image for dlls and exes under platform directories\n" + "%s --system\n" + "Create native image for dll\n" + "%s --dll /usr/bin/Tizen.Runtime.dll\n" + "Create native image under the package's bin and lib directory\n" + "%s --pkg org.tizen.FormsGallery\n\n"; + printf(helpDesc, argv0, argv0, argv0, argv0); } int main(int argc, char* argv[]) { - bool pkg_mode = false; - bool dll_mode = false; + bool pkgMode = false; + bool dllMode = false; - if (cmd_option_exists(argv, argv+argc, "--help")) - { - help(argv[0]); - return 0; - } - else if (cmd_option_exists(argv, argv+argc, "--system")) - { - create_ni_platform(); - return 0; - } - else if (cmd_option_exists(argv, argv+argc, "--dll")) - { - dll_mode = true; - } - else if (cmd_option_exists(argv, argv+argc, "--pkg")) - { - pkg_mode = true; - } - else { - help(argv[0]); - return 1; - } + if (cmdOptionExists(argv, argv+argc, "--help")) { + help(argv[0]); + return 0; + } else if (cmdOptionExists(argv, argv+argc, "--system")) { + createNiPlatform(); + return 0; + } else if (cmdOptionExists(argv, argv+argc, "--dll")) { + dllMode = true; + } else if (cmdOptionExists(argv, argv+argc, "--pkg")) { + pkgMode = true; + } else { + help(argv[0]); + return 1; + } - std::vector args = get_cmd_args(argv, argv+argc); + std::vector args = getCmdArgs(argv, argv+argc); - if (args.size() < 1) - { - if (pkg_mode) - fprintf(stderr, "Package name is missed\n"); - else if (dll_mode) - fprintf(stderr, "DLL path is missed\n"); - help(argv[0]); - return 1; - } + if (args.size() < 1) { + if (pkgMode) + fprintf(stderr, "Package name is missed\n"); + else if (dllMode) + fprintf(stderr, "DLL path is missed\n"); + help(argv[0]); + return 1; + } - if (pkg_mode) - { - for (const char* pkg : args) - { - if (create_ni_under_pkg_root(pkg) != 0) - { - fprintf(stderr, "Failed to get root path from [%s]\n", pkg); - return 1; - } - } - } - else if (dll_mode) - { - for (const char* dll : args) - { - create_ni_select(dll); - } - } - else - { - create_ni_under_dirs(args.data(), args.size()); - } + if (pkgMode) { + for (const char* pkg : args) { + if (createNiUnderPkgRoot(pkg) != 0) { + fprintf(stderr, "Failed to get root path from [%s]\n", pkg); + return 1; + } + } + } else if (dllMode) { + for (const char* dll : args) + createNiSelect(dll); + } else { + createNiUnderDirs(args.data(), args.size()); + } - return 0; + return 0; } diff --git a/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h index fc4354c..883eb6c 100644 --- a/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h +++ b/NativeLauncher/installer-plugin/pkgmgr_parser_plugin_interface.h @@ -19,19 +19,19 @@ extern "C" { - typedef struct _xmlDoc xmlDoc; - typedef xmlDoc* xmlDocPtr; - int PKGMGR_PARSER_PLUGIN_PRE_INSTALL (const char *pkgid); - int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE (const char *pkgid); - int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL (const char *pkgid); + typedef struct _xmlDoc xmlDoc; + typedef xmlDoc* xmlDocPtr; + int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId); + int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId); + int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId); - int PKGMGR_PARSER_PLUGIN_INSTALL (xmlDocPtr doc, const char* pkgid); - int PKGMGR_PARSER_PLUGIN_UPGRADE (xmlDocPtr doc, const char* pkgid); - int PKGMGR_PARSER_PLUGIN_UNINSTALL (xmlDocPtr doc, const char* pkgid); + int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId); + int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId); + int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId); - int PKGMGR_PARSER_PLUGIN_POST_INSTALL (const char *pkgid); - int PKGMGR_PARSER_PLUGIN_POST_UPGRADE (const char *pkgid); - int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL (const char *pkgid); + int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId); + int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId); + int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId); } -#endif // __PKGMGR_PARSER_PLUGIN_INTERFACE__ +#endif /* __PKGMGR_PARSER_PLUGIN_INTERFACE__ */ diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc old mode 100755 new mode 100644 index a9c940b..83a018e --- a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc +++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc @@ -29,45 +29,39 @@ #include typedef struct Metadata { - const char *key; - const char *value; + const char *key; + const char *value; } Metadata; -const std::string VALUE_TRUE = "true"; +const std::string valueType = "true"; const std::string mdKey = "http://tizen.org/metadata/prefer_dotnet_aot"; -extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL (const char *pkgid, const char *appid, GList *list) +extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list) { - GList *tag = NULL; - bool mdValue = false; - Metadata *mdInfo = NULL; - tag = g_list_first(list); - while (tag) - { - mdInfo = (Metadata*)tag->data; - if(mdInfo->key == mdKey && mdInfo->value == VALUE_TRUE) - { - _DBG("Prefer dotnet application AOT set TRUE"); - mdValue = true; - } - tag = g_list_next(tag); - } + GList *tag = NULL; + bool mdValue = false; + Metadata *mdInfo = NULL; + tag = g_list_first(list); + while (tag) { + mdInfo = (Metadata*)tag->data; + if (mdInfo->key == mdKey && mdInfo->value == valueType) { + _DBG("Prefer dotnet application AOT set TRUE"); + mdValue = true; + } + tag = g_list_next(tag); + } - if (mdValue) - { - if (create_ni_under_pkg_root(pkgid) != 0) - { - _ERR("Failed to get root path from [%s]", pkgid); - return -1; - } - else - { - _DBG("Complete make application to native image"); - } - } - return 0; + if (mdValue) { + if (createNiUnderPkgRoot(pkgId) != 0) { + _ERR("Failed to get root path from [%s]", pkgId); + return -1; + } else { + _DBG("Complete make application to native image"); + } + } + return 0; } -extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE (const char *pkgid, const char *appid, GList *list) +extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE(const char *pkgId, const char *appId, GList *list) { - return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list); + return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgId, appId, list); } diff --git a/NativeLauncher/installer-plugin/ui-application.cc b/NativeLauncher/installer-plugin/ui-application.cc index f731888..e626265 100644 --- a/NativeLauncher/installer-plugin/ui-application.cc +++ b/NativeLauncher/installer-plugin/ui-application.cc @@ -35,78 +35,69 @@ * */ -extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL (const char *pkgid) +extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId) { - _INFO("pkg : %s", pkgid); - - uid_t uid = 0; - - if (pkgmgr_installer_info_get_target_uid(&uid) < 0) - { - _ERR("Failed to get UID"); - return 0; - } - - pkgmgrinfo_pkginfo_h handle; - int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid, uid, &handle); - if (ret != PMINFO_R_OK) - { - _ERR("Failed to get pkg info"); - return 0; - } - - _INFO("success to get pkg info"); - - bool dotnet_exist = false; - - auto dotnet_app_counter = [] (pkgmgrinfo_appinfo_h handle, void *user_data) -> int - { - char* appid = nullptr; - char* type = nullptr; - bool* dotnet = static_cast(user_data); - - if (pkgmgrinfo_appinfo_get_appid(handle, &appid) != PMINFO_R_OK) - { - _ERR("Failed to get app id"); - return 0; - } - - _INFO("App id : %s", appid); - - if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) - { - _ERR("Failed to get app type : %s", appid); - return 0; - } - - _INFO("App type : %s", type); - - if (strcmp(type, "dotnet") == 0) - { - *dotnet = true; - } - - return 0; - }; - - if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, dotnet_app_counter, &dotnet_exist, uid) != PMINFO_R_OK) - { - _ERR("Failed to get list of app in pkg : %s", pkgid); - return -1; - } - - _INFO("Finish to get pkg list"); - - pkgmgrinfo_pkginfo_destroy_pkginfo(handle); - if (dotnet_exist) - { - _INFO("dotnet app is exist"); - return create_ni_under_pkg_root(pkgid) == 0 ? 0 : -1; - } - - return 0; + _INFO("pkg : %s", pkgId); + + uid_t uid = 0; + + if (pkgmgr_installer_info_get_target_uid(&uid) < 0) { + _ERR("Failed to get UID"); + return 0; + } + + pkgmgrinfo_pkginfo_h handle; + int ret = pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgId, uid, &handle); + if (ret != PMINFO_R_OK) { + _ERR("Failed to get pkg info"); + return 0; + } + + _INFO("success to get pkg info"); + + bool dotnetExist = false; + + auto dotnetAppCounter = [] (pkgmgrinfo_appinfo_h handle, void *userData) -> int { + char* appId = nullptr; + char* type = nullptr; + bool* dotnet = static_cast(userData); + + if (pkgmgrinfo_appinfo_get_appid(handle, &appId) != PMINFO_R_OK) { + _ERR("Failed to get app id"); + return 0; + } + + _INFO("App id : %s", appId); + + if (pkgmgrinfo_appinfo_get_apptype(handle, &type) != PMINFO_R_OK) { + _ERR("Failed to get app type : %s", appId); + return 0; + } + + _INFO("App type : %s", type); + + if (strcmp(type, "dotnet") == 0) + *dotnet = true; + + return 0; + }; + + if (pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, dotnetAppCounter, &dotnetExist, uid) != PMINFO_R_OK) { + _ERR("Failed to get list of app in pkg : %s", pkgId); + return -1; + } + + _INFO("Finish to get pkg list"); + + pkgmgrinfo_pkginfo_destroy_pkginfo(handle); + if (dotnetExist) { + _INFO("dotnet app is exist"); + return createNiUnderPkgRoot(pkgId) == 0 ? 0 : -1; + } + + return 0; } -extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE (const char *pkgid) +extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId) { - return PKGMGR_PARSER_PLUGIN_POST_INSTALL(pkgid); + return PKGMGR_PARSER_PLUGIN_POST_INSTALL(pkgId); } diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc index b3ad787..d3df80e 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc @@ -31,311 +31,275 @@ namespace runtime { namespace dotnetcore { CoreRuntime::CoreRuntime() : - InitializeClr(nullptr), - ExecuteAssembly(nullptr), - Shutdown(nullptr), - CreateDelegate(nullptr), - coreclrLib(nullptr), - hostHandle(nullptr), - domainId(-1), - PreparedFunction(nullptr), - LaunchFunction(nullptr) + initializeClr(nullptr), + executeAssembly(nullptr), + shutdown(nullptr), + createDelegate(nullptr), + __coreclrLib(nullptr), + __hostHandle(nullptr), + __domainId(-1), + preparedFunction(nullptr), + launchFunction(nullptr) { #define __XSTR(x) #x #define __STR(x) __XSTR(x) #ifdef DEVICE_API_DIR - DeviceAPIDirectory = __STR(DEVICE_API_DIR); + __deviceAPIDirectory = __STR(DEVICE_API_DIR); #endif #ifdef RUNTIME_DIR - RuntimeDirectory = __STR(RUNTIME_DIR); + __runtimeDirectory = __STR(RUNTIME_DIR); #endif #ifdef NATIVE_LIB_DIR - NativeLibDirectory = __STR(NATIVE_LIB_DIR); + __nativeLibDirectory = __STR(NATIVE_LIB_DIR); #endif #ifdef USE_MANAGED_LAUNCHER #ifdef CORECLR_LAUNCHER_ASSEMBLY_PATH - LauncherAssembly = __STR(CORECLR_LAUNCHER_ASSEMBLY_PATH); + __launcherAssembly = __STR(CORECLR_LAUNCHER_ASSEMBLY_PATH); #endif #endif #undef __STR #undef __XSTR - _DBG("Constructor called!!"); + _DBG("Constructor called!!"); } CoreRuntime::~CoreRuntime() { - Dispose(); + dispose(); } -int CoreRuntime::Initialize(bool standalone) +int CoreRuntime::initialize(bool standalone) { - if (standalone) - { - const char *_deviceapi_directory = getenv("DeviceAPIDirectory"); - const char *_runtime_directory = getenv("RuntimeDirectory"); - if (_deviceapi_directory != nullptr) - DeviceAPIDirectory = _deviceapi_directory; - if (_runtime_directory != nullptr) - RuntimeDirectory = _runtime_directory; + if (standalone) { + const char *deviceApiDirectory = getenv("__deviceAPIDirectory"); + const char *runtimeDirectory = getenv("__runtimeDirectory"); + if (deviceApiDirectory != nullptr) + __deviceAPIDirectory = deviceApiDirectory; + if (runtimeDirectory != nullptr) + __runtimeDirectory = runtimeDirectory; #ifdef USE_MANAGED_LAUNCHER - const char *_launcher_assembly = getenv("LauncherAssembly"); - if (_launcher_assembly != nullptr) - LauncherAssembly = _launcher_assembly; + const char *launcherAssembly = getenv("__launcherAssembly"); + if (launcherAssembly != nullptr) + __launcherAssembly = launcherAssembly; #endif - } - - if (DeviceAPIDirectory.empty()) - { - _ERR("Empty Device API Directory"); - return 1; - } - else - { - DeviceAPIDirectory = AbsolutePath(DeviceAPIDirectory); - } - - if (RuntimeDirectory.empty()) - { - _ERR("Empty Runtime Directory"); - return 1; - } - else - { - RuntimeDirectory = AbsolutePath(RuntimeDirectory); - } + } + + if (__deviceAPIDirectory.empty()) { + _ERR("Empty Device API Directory"); + return 1; + } else { + __deviceAPIDirectory = absolutePath(__deviceAPIDirectory); + } + + if (__runtimeDirectory.empty()) { + _ERR("Empty Runtime Directory"); + return 1; + } else { + __runtimeDirectory = absolutePath(__runtimeDirectory); + } #ifdef USE_MANAGED_LAUNCHER - if (LauncherAssembly.empty()) - { - _ERR("Empty Launcher Assembly"); - return 1; - } - else - { - LauncherAssembly = AbsolutePath(LauncherAssembly); - } + if (__launcherAssembly.empty()) { + _ERR("Empty Launcher Assembly"); + return 1; + } else { + __launcherAssembly = absolutePath(__launcherAssembly); + } #endif - std::string libcoreclr(ConcatPath(RuntimeDirectory, "libcoreclr.so")); + std::string libCoreclr(concatPath(__runtimeDirectory, "libcoreclr.so")); - _DBG("libcoreclr : %s", libcoreclr.c_str()); + _DBG("libcoreclr : %s", libCoreclr.c_str()); - coreclrLib = dlopen(libcoreclr.c_str(), RTLD_NOW | RTLD_LOCAL); - if (coreclrLib == nullptr) - { - char *err = dlerror(); - _ERR("dlopen failed to open libcoreclr.so with error %s", err); - return 1; - } + __coreclrLib = dlopen(libCoreclr.c_str(), RTLD_NOW | RTLD_LOCAL); + if (__coreclrLib == nullptr) { + char *err = dlerror(); + _ERR("dlopen failed to open libcoreclr.so with error %s", err); + return 1; + } #define CORELIB_RETURN_IF_NOSYM(type, variable, name) \ - do { variable = (type)dlsym(coreclrLib, name); \ - if (variable == nullptr) { \ - _ERR(name " is not found in the libcoreclr.so"); \ - return 1; \ - }} while(0) - - CORELIB_RETURN_IF_NOSYM(coreclr_initialize_ptr, InitializeClr, "coreclr_initialize"); - CORELIB_RETURN_IF_NOSYM(coreclr_execute_assembly_ptr, ExecuteAssembly, "coreclr_execute_assembly"); - CORELIB_RETURN_IF_NOSYM(coreclr_shutdown_ptr, Shutdown, "coreclr_shutdown"); - CORELIB_RETURN_IF_NOSYM(coreclr_create_delegate_ptr, CreateDelegate, "coreclr_create_delegate"); + do { \ + variable = (type)dlsym(__coreclrLib, name); \ + if (variable == nullptr) { \ + _ERR(name " is not found in the libcoreclr.so"); \ + return 1; \ + } \ + } while (0) + + CORELIB_RETURN_IF_NOSYM(coreclr_initialize_ptr, initializeClr, "coreclr_initialize"); + CORELIB_RETURN_IF_NOSYM(coreclr_execute_assembly_ptr, executeAssembly, "coreclr_execute_assembly"); + CORELIB_RETURN_IF_NOSYM(coreclr_shutdown_ptr, shutdown, "coreclr_shutdown"); + CORELIB_RETURN_IF_NOSYM(coreclr_create_delegate_ptr, createDelegate, "coreclr_create_delegate"); #undef CORELIB_RETURN_IF_NOSYM - _DBG("libcoreclr dlopen and dlsym success"); - - _DBG("this addr : %x", this); - _DBG("coreclr_initialize : %x", InitializeClr); + _DBG("libcoreclr dlopen and dlsym success"); + _DBG("this addr : %x", this); + _DBG("coreclr_initialize : %x", initializeClr); - return 0; + return 0; } -bool CoreRuntime::InitializeCoreClr(const char* app_id, - const char* assembly_probe_paths, - const char* pinvoke_probe_paths, - const char* tpa_list) +bool CoreRuntime::initializeCoreClr(const char* appId, + const char* assemblyProbePaths, + const char* pinvokeProbePaths, + const char* tpaList) { - const char *propertyKeys[] = - { - "TRUSTED_PLATFORM_ASSEMBLIES", - "APP_PATHS", - "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", - "AppDomainCompatSwitch" - }; - - const char *propertyValues[] = - { - tpa_list, - assembly_probe_paths, - assembly_probe_paths, - pinvoke_probe_paths, - "UseLatestBehaviorWhenTFMNotSpecified" - }; - - std::string selfPath = ReadSelfPath(); - - int st = InitializeClr( - selfPath.c_str(), - app_id, - sizeof(propertyKeys) / sizeof(propertyKeys[0]), - propertyKeys, - propertyValues, - &hostHandle, - &domainId); - - if (st < 0) - { - _ERR("initialize core clr fail! (0x%08x)", st); - return false; - } - - _DBG("Initialize core clr success"); - return true; + const char *propertyKeys[] = { + "TRUSTED_PLATFORM_ASSEMBLIES", + "APP_PATHS", + "APP_NI_PATHS", + "NATIVE_DLL_SEARCH_DIRECTORIES", + "AppDomainCompatSwitch" + }; + + const char *propertyValues[] = { + tpaList, + assemblyProbePaths, + assemblyProbePaths, + pinvokeProbePaths, + "UseLatestBehaviorWhenTFMNotSpecified" + }; + + std::string selfPath = readSelfPath(); + + int st = initializeClr(selfPath.c_str(), + appId, + sizeof(propertyKeys) / sizeof(propertyKeys[0]), + propertyKeys, + propertyValues, + &__hostHandle, + &__domainId); + + if (st < 0) { + _ERR("initialize core clr fail! (0x%08x)", st); + return false; + } + + _DBG("Initialize core clr success"); + return true; } -int CoreRuntime::RunManagedLauncher(const char* app_id, const char* app_base, const char* tpa_list) +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(app_id, app_base, app_base, tpa_list)) - { - _ERR("Failed to initialize coreclr"); - return 1; - } + 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.Coreclr", - "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(preparedFunctionDelegate); - - if(PreparedFunction != nullptr) - { - PreparedFunction(); - } - - void *launchFunctionDelegate; - st = CreateDelegate(hostHandle, domainId, - "Tizen.Runtime.Coreclr", - "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(launchFunctionDelegate); + 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(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(launchFunctionDelegate); #endif - return 0; + return 0; } -void CoreRuntime::Dispose() +void CoreRuntime::dispose() { - if (hostHandle != nullptr) - { - int st = Shutdown(hostHandle, domainId); - if (st < 0) - { - _ERR("shutdown core clr fail! (0x%08x)", st); - } - } - - if (dlclose(coreclrLib) != 0) - { - _ERR("libcoreclr.so close failed"); - } - coreclrLib = nullptr; - - _DBG("Dotnet runtime disposed"); + if (__hostHandle != nullptr) { + int st = shutdown(__hostHandle, __domainId); + if (st < 0) + _ERR("shutdown core clr fail! (0x%08x)", st); + } + + if (dlclose(__coreclrLib) != 0) + _ERR("libcoreclr.so close failed"); + + __coreclrLib = nullptr; + + _DBG("Dotnet runtime disposed"); } -int CoreRuntime::Launch(const char* app_id, const char* root, const char* path, int argc, char* argv[]) +int CoreRuntime::launch(const char* appId, const char* root, const char* path, int argc, char* argv[]) { - if (path == nullptr) - { - _ERR("executable path is null"); - return 1; - } - - if (FileNotExist(path)) - { - _ERR("File not exist : %s", path); - return 1; - } - - 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 searchDirectories; - searchDirectories.push_back(appBin); - searchDirectories.push_back(appLib); - searchDirectories.push_back(RuntimeDirectory); - searchDirectories.push_back(DeviceAPIDirectory); + if (path == nullptr) { + _ERR("executable path is null"); + return 1; + } + + if (fileNotExist(path)) { + _ERR("File not exist : %s", path); + return 1; + } + + 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 searchDirectories; + searchDirectories.push_back(appBin); + searchDirectories.push_back(appLib); + searchDirectories.push_back(__runtimeDirectory); + searchDirectories.push_back(__deviceAPIDirectory); #ifdef USE_MANAGED_LAUNCHER - searchDirectories.push_back(Basename(LauncherAssembly)); + searchDirectories.push_back(baseName(__launcherAssembly)); #endif - AssembliesInDirectory(searchDirectories, tpa); + assembliesInDirectory(searchDirectories, tpa); #ifdef USE_MANAGED_LAUNCHER - RunManagedLauncher(app_id, probePath.c_str(), tpa.c_str()); - - bool success = false; - if (LaunchFunction != nullptr) - { - std::string cpppath(path); - - if (IsManagedAssembly(cpppath) && !IsNativeImage(cpppath)) - { - size_t extindex = cpppath.size() - 4; - cpppath = cpppath.substr(0, extindex) + ".ni" + cpppath.substr(extindex, 4); - if (!FileNotExist(cpppath)) - { - path = cpppath.c_str(); - } - } - - 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; - } + runManagedLauncher(appId, probePath.c_str(), tpa.c_str()); + + bool success = false; + if (launchFunction != nullptr) { + std::string cppPath(path); + + if (isManagedAssembly(cppPath) && !isNativeImage(cppPath)) { + size_t extindex = cppPath.size() - 4; + cppPath = cppPath.substr(0, extindex) + ".ni" + cppPath.substr(extindex, 4); + if (!fileNotExist(cppPath)) + path = cppPath.c_str(); + } + + 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(app_id, probePath.c_str(), probePath.c_str(), tpa.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; + 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); + if (st < 0) + _ERR("Failed to Execute Assembly %s (0x%08x)", path, st); + return ret; #endif } diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h index 27d1298..fb44a47 100644 --- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h +++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h @@ -14,38 +14,41 @@ * limitations under the License. */ +#ifndef __DOTNET_LAUNCHER_H__ +#define __DOTNET_LAUNCHER_H__ + #include "launcher.h" extern "C" { - typedef int (*coreclr_initialize_ptr)( - const char* exePath, - const char* appDomainFriendlyName, - int propertyCount, - const char** propertyKeys, - const char** propertyValues, - void** hostHandle, - unsigned int* domainId); + typedef int (*coreclr_initialize_ptr)( + const char* exePath, + const char* appDomainFriendlyName, + int propertyCount, + const char** propertyKeys, + const char** propertyValues, + void** hostHandle, + unsigned int* domainId); - typedef int (*coreclr_execute_assembly_ptr)( - void* hostHandle, - unsigned int domainId, - int argc, - const char** argv, - const char* managedAssemblyPath, - unsigned int* exitCode); + typedef int (*coreclr_execute_assembly_ptr)( + void* hostHandle, + unsigned int domainId, + int argc, + const char** argv, + const char* managedAssemblyPath, + unsigned int* exitCode); - typedef int (*coreclr_shutdown_ptr)( - void* hostHandle, - unsigned int domainId); + typedef int (*coreclr_shutdown_ptr)( + void* hostHandle, + unsigned int domainId); - typedef int (*coreclr_create_delegate_ptr)( - void* hostHandle, - unsigned int domainId, - const char* entryPointAssemblyName, - const char* entryPointTypeName, - const char* entryPointMethodName, - void** delegate); + typedef int (*coreclr_create_delegate_ptr)( + void* hostHandle, + unsigned int domainId, + const char* entryPointAssemblyName, + const char* entryPointTypeName, + const char* entryPointMethodName, + void** delegate); } namespace tizen { @@ -57,31 +60,33 @@ typedef bool (*LaunchFunctionPtr)(const char* root, const char* path, int argc, class CoreRuntime : public tizen::runtime::LauncherInterface { - public: - CoreRuntime(); - ~CoreRuntime(); - int Initialize(bool standalone) override; - void Dispose() override; - int RunManagedLauncher(const char* app_id, const char* app_base, const char* tpa_list) override; - int Launch(const char* app_id, const char* root, const char* path, int argc, char* argv[]) override; + public: + CoreRuntime(); + ~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: - bool InitializeCoreClr(const char* app_id, const char* assembly_probe_paths, const char* pinvoke_probe_paths, const char* tpa); - coreclr_initialize_ptr InitializeClr; - coreclr_execute_assembly_ptr ExecuteAssembly; - coreclr_shutdown_ptr Shutdown; - coreclr_create_delegate_ptr CreateDelegate; - std::string DeviceAPIDirectory; - std::string RuntimeDirectory; - std::string LauncherAssembly; - std::string NativeLibDirectory; - void* coreclrLib; - void* hostHandle; - unsigned int domainId; - PreparedFunctionPtr PreparedFunction; - LaunchFunctionPtr LaunchFunction; + private: + bool initializeCoreClr(const char* appId, const char* assemblyProbePaths, const char* pinvokeProbePaths, const char* tpaList); + coreclr_initialize_ptr initializeClr; + coreclr_execute_assembly_ptr executeAssembly; + coreclr_shutdown_ptr shutdown; + coreclr_create_delegate_ptr createDelegate; + std::string __deviceAPIDirectory; + std::string __runtimeDirectory; + std::string __launcherAssembly; + std::string __nativeLibDirectory; + void* __coreclrLib; + void* __hostHandle; + unsigned int __domainId; + PreparedFunctionPtr preparedFunction; + LaunchFunctionPtr launchFunction; }; } // dotnetcore } // namespace runtime } // namespace tizen + +#endif /* __DOTNET_LAUNCHER_H__ */ \ No newline at end of file diff --git a/NativeLauncher/launcher/dotnet/scd_launcher.cc b/NativeLauncher/launcher/dotnet/scd_launcher.cc index 138d9f4..029e93c 100644 --- a/NativeLauncher/launcher/dotnet/scd_launcher.cc +++ b/NativeLauncher/launcher/dotnet/scd_launcher.cc @@ -50,42 +50,37 @@ using namespace std; bool isDebugMode = false; -char *coreclr_gdbjit[PATH_MAX]; -char *root_path; +char *coreclrGdbjit[PATH_MAX]; +char *rootPath; bool service_app_create(void *data) { - // Todo: add your code here. - return true; + // Todo: add your code here. + return true; } void service_app_terminate(void *data) { - // Todo: add your code here. + // Todo: add your code here. - return; + return; } -void service_app_control(app_control_h app_control, void *data) +void service_app_control(app_control_h appControl, void *data) { - // Get _DEBUG_ value - char* buf[82]; - int ret = app_control_get_extra_data(app_control, "_SCD_DEBUG_", buf); - - if (ret == APP_CONTROL_ERROR_NONE) - { - if(strcmp(*buf, "1") == 0) - { - isDebugMode = true; - } - } - if (isDebugMode) - { - ret = app_control_get_extra_data(app_control, "_SCD_CORECLR_GDBJIT_", coreclr_gdbjit); - } - - service_app_exit(); - return; + // Get _DEBUG_ value + char* buf[82]; + int ret = app_control_get_extra_data(appControl, "_SCD_DEBUG_", buf); + + if (ret == APP_CONTROL_ERROR_NONE) + if (strcmp(*buf, "1") == 0) + isDebugMode = true; + + if (isDebugMode) + ret = app_control_get_extra_data(appControl, "_SCD_CORECLR_GDBJIT_", coreclrGdbjit); + + service_app_exit(); + return; } @@ -96,568 +91,490 @@ void service_app_control(app_control_h app_control, void *data) #ifndef SUCCEEDED #define SUCCEEDED(Status) ((Status) >= 0) -#endif // !SUCCEEDED +#endif // !SUCCEEDED -static const char * const coreClrDll = "libcoreclr.so"; +static const char * const __CORECLR_DLL = "libcoreclr.so"; // Name of the environment variable controlling server GC. // If set to 1, server GC is enabled on startup. If 0, server GC is // disabled. Server GC is off by default. -static const char* serverGcVar = "CORECLR_SERVER_GC"; +static const char* __SERVER_GC_VAR = "CORECLR_SERVER_GC"; #define symlinkEntrypointExecutable "/proc/self/exe" -bool GetEntrypointExecutableAbsolutePath(std::string& entrypointExecutable) +bool getEntrypointExecutableabsolutePath(std::string& entrypointExecutable) { - bool result = false; - - entrypointExecutable.clear(); - - // Get path to the executable for the current process using - // platform specific means. - - // On Linux, fetch the entry point EXE absolute path, inclusive of filename. - char exe[PATH_MAX]; - ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1); - if (res != -1) - { - exe[res] = '\0'; - entrypointExecutable.assign(exe); - result = true; - } - else - { - result = false; - } - - return result; + bool result = false; + + entrypointExecutable.clear(); + + // Get path to the executable for the current process using + // platform specific means. + + // On Linux, fetch the entry point EXE absolute path, inclusive of filename. + char exe[PATH_MAX]; + ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1); + if (res != -1) { + exe[res] = '\0'; + entrypointExecutable.assign(exe); + result = true; + } else { + result = false; + } + + return result; } -bool GetAbsolutePath(const char* path, std::string& absolutePath) +bool getabsolutePath(const char* path, std::string& absolutePath) { - bool result = false; + bool result = false; - char realPath[PATH_MAX]; - if (realpath(path, realPath) != nullptr && realPath[0] != '\0') - { - absolutePath.assign(realPath); - // realpath should return canonicalized path without the trailing slash - assert(absolutePath.back() != '/'); + char realPath[PATH_MAX]; + if (realpath(path, realPath) != nullptr && realPath[0] != '\0') { + absolutePath.assign(realPath); + // realpath should return canonicalized path without the trailing slash + assert(absolutePath.back() != '/'); - result = true; - } + result = true; + } - return result; + return result; } -bool GetDirectory(const char* absolutePath, std::string& directory) +bool getDirectory(const char* absolutePath, std::string& directory) { - directory.assign(absolutePath); - size_t lastSlash = directory.rfind('/'); - if (lastSlash != std::string::npos) - { - directory.erase(lastSlash); - return true; - } - - return false; + directory.assign(absolutePath); + size_t lastSlash = directory.rfind('/'); + if (lastSlash != std::string::npos) { + directory.erase(lastSlash); + return true; + } + + return false; } -bool GetClrFilesAbsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath) +bool getClrFilesabsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath) { - std::string clrFilesRelativePath; - const char* clrFilesPathLocal = clrFilesPath; - if (clrFilesPathLocal == nullptr) - { - // There was no CLR files path specified, use the folder of the corerun/coreconsole - if (!GetDirectory(currentExePath, clrFilesRelativePath)) - { - perror("Failed to get directory from argv[0]"); - return false; - } - - clrFilesPathLocal = clrFilesRelativePath.c_str(); - - // TODO: consider using an env variable (if defined) as a fall-back. - // The windows version of the corerun uses core_root env variable - } - - if (!GetAbsolutePath(clrFilesPathLocal, clrFilesAbsolutePath)) - { - perror("Failed to convert CLR files path to absolute path"); - return false; - } - - return true; + std::string clrFilesRelativePath; + const char* clrFilesPathLocal = clrFilesPath; + if (clrFilesPathLocal == nullptr) { + // There was no CLR files path specified, use the folder of the corerun/coreconsole + if (!getDirectory(currentExePath, clrFilesRelativePath)) { + perror("Failed to get directory from argv[0]"); + return false; + } + + clrFilesPathLocal = clrFilesRelativePath.c_str(); + + // TODO: consider using an env variable (if defined) as a fall-back. + // The windows version of the corerun uses core_root env variable + } + + if (!getabsolutePath(clrFilesPathLocal, clrFilesAbsolutePath)) { + perror("Failed to convert CLR files path to absolute path"); + return false; + } + + return true; } -void AddFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList) +void addFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList) { - const char * const tpaExtensions[] = { - ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir - ".dll", - ".ni.exe", - ".exe", - }; - - DIR* dir = opendir(directory); - if (dir == nullptr) - { - return; - } - - std::set addedAssemblies; - - // Walk the directory for each extension separately so that we first get files with .ni.dll extension, - // then files with .dll extension, etc. - for (unsigned int extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++) - { - const char* ext = tpaExtensions[extIndex]; - int extLength = strlen(ext); - - struct dirent* entry; - - // For all entries in the directory - while ((entry = readdir(dir)) != nullptr) - { - // We are interested in files only - switch (entry->d_type) - { - case DT_REG: - break; - - // Handle symlinks and file systems that do not support d_type - case DT_LNK: - case DT_UNKNOWN: - { - std::string fullFilename; - - fullFilename.append(directory); - fullFilename.append("/"); - fullFilename.append(entry->d_name); - - struct stat sb; - if (stat(fullFilename.c_str(), &sb) == -1) - { - continue; - } - - if (!S_ISREG(sb.st_mode)) - { - continue; - } - } - break; - - default: - continue; - } - - std::string filename(entry->d_name); - - // Check if the extension matches the one we are looking for - int extPos = filename.length() - extLength; - if ((extPos <= 0) || (filename.compare(extPos, extLength, ext) != 0)) - { - continue; - } - - std::string filenameWithoutExt(filename.substr(0, extPos)); - - // Make sure if we have an assembly with multiple extensions present, - // we insert only one version of it. - if (addedAssemblies.find(filenameWithoutExt) == addedAssemblies.end()) - { - addedAssemblies.insert(filenameWithoutExt); - - tpaList.append(directory); - tpaList.append("/"); - tpaList.append(filename); - tpaList.append(":"); - } - } - - // Rewind the directory stream to be able to iterate over it for the next extension - rewinddir(dir); - } - - closedir(dir); + const char * const tpaExtensions[] = { + ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir + ".dll", + ".ni.exe", + ".exe", + }; + + DIR* dir = opendir(directory); + if (dir == nullptr) + return; + + std::set addedAssemblies; + + // Walk the directory for each extension separately so that we first get files with .ni.dll extension, + // then files with .dll extension, etc. + for (unsigned int extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++) { + const char* ext = tpaExtensions[extIndex]; + int extLength = strlen(ext); + + struct dirent* entry; + + // For all entries in the directory + while ((entry = readdir(dir)) != nullptr) { + // We are interested in files only + switch (entry->d_type) { + case DT_REG: + break; + + // Handle symlinks and file systems that do not support d_type + case DT_LNK: + case DT_UNKNOWN: + { + std::string fullFileName; + + fullFileName.append(directory); + fullFileName.append("/"); + fullFileName.append(entry->d_name); + + struct stat sb; + if (stat(fullFileName.c_str(), &sb) == -1) + continue; + + if (!S_ISREG(sb.st_mode)) + continue; + } + break; + + default: + continue; + } + + std::string fileName(entry->d_name); + + // Check if the extension matches the one we are looking for + int extPos = fileName.length() - extLength; + if ((extPos <= 0) || (fileName.compare(extPos, extLength, ext) != 0)) + continue; + + std::string fileNameWithoutExt(fileName.substr(0, extPos)); + + // Make sure if we have an assembly with multiple extensions present, + // we insert only one version of it. + if (addedAssemblies.find(fileNameWithoutExt) == addedAssemblies.end()) { + addedAssemblies.insert(fileNameWithoutExt); + + tpaList.append(directory); + tpaList.append("/"); + tpaList.append(fileName); + tpaList.append(":"); + } + } + + // Rewind the directory stream to be able to iterate over it for the next extension + rewinddir(dir); + } + + closedir(dir); } -int ExecuteManagedAssembly(const char* currentExeAbsolutePath, - const char* clrFilesAbsolutePath, - const char* managedAssemblyAbsolutePath, - int managedAssemblyArgc, - const char** managedAssemblyArgv) +int executeManagedAssembly(const char* currentExeAbsolutePath, + const char* clrFilesAbsolutePath, + const char* managedAssemblyAbsolutePath, + int managedAssemblyArgc, + const char** managedAssemblyArgv) { - // Indicates failure - int exitCode = -1; + // Indicates failure + int exitCode = -1; #ifdef _ARM_ - // libunwind library is used to unwind stack frame, but libunwind for ARM - // does not support ARM vfpv3/NEON registers in DWARF format correctly. - // Therefore let's disable stack unwinding using DWARF information - // See https://github.com/dotnet/coreclr/issues/6698 - // - // libunwind use following methods to unwind stack frame. - // UNW_ARM_METHOD_ALL 0xFF - // UNW_ARM_METHOD_DWARF 0x01 - // UNW_ARM_METHOD_FRAME 0x02 - // UNW_ARM_METHOD_EXIDX 0x04 - putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); -#endif // _ARM_ - - std::string coreClrDllPath(clrFilesAbsolutePath); - coreClrDllPath.append("/"); - coreClrDllPath.append(coreClrDll); - - if (coreClrDllPath.length() >= PATH_MAX) - { - fprintf(stderr, "Absolute path to libcoreclr.so too long\n"); - return -1; - } - - // Get just the path component of the managed assembly path - std::string appPath; - GetDirectory(managedAssemblyAbsolutePath, appPath); - - std::string tpaList; - // Construct native search directory paths - std::string nativeDllSearchDirs(appPath); - char *coreLibraries = getenv("CORE_LIBRARIES"); - if (coreLibraries) - { - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(coreLibraries); - if (std::strcmp(coreLibraries, clrFilesAbsolutePath) != 0) - { - AddFilesFromDirectoryToTpaList(coreLibraries, tpaList); - } - } - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(clrFilesAbsolutePath); - - AddFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList); - - void* coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL); - if (coreclrLib != nullptr) - { - 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) - { - fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n"); - } - else if (executeAssembly == nullptr) - { - fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n"); - } - else if (shutdownCoreCLR == nullptr) - { - fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); - } - else - { - // Check whether we are enabling server GC (off by default) - const char* useServerGc = std::getenv(serverGcVar); - if (useServerGc == nullptr) - { - useServerGc = "0"; - } - - // CoreCLR expects strings "true" and "false" instead of "1" and "0". - useServerGc = std::strcmp(useServerGc, "1") == 0 ? "true" : "false"; - - // Allowed property names: - // APPBASE - // - The base path of the application from which the exe and other assemblies will be loaded - // - // TRUSTED_PLATFORM_ASSEMBLIES - // - The list of complete paths to each of the fully trusted assemblies - // - // APP_PATHS - // - The list of paths which will be probed by the assembly loader - // - // APP_NI_PATHS - // - The list of additional paths that the assembly loader will probe for ngen images - // - // NATIVE_DLL_SEARCH_DIRECTORIES - // - The list of paths that will be probed for native DLLs called by PInvoke - // - const char *propertyKeys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES", - "APP_PATHS", - "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", - "System.GC.Server", - }; - const char *propertyValues[] = { - // TRUSTED_PLATFORM_ASSEMBLIES - tpaList.c_str(), - // APP_PATHS - appPath.c_str(), - // APP_NI_PATHS - appPath.c_str(), - // NATIVE_DLL_SEARCH_DIRECTORIES - nativeDllSearchDirs.c_str(), - // System.GC.Server - useServerGc, - }; - - void* hostHandle; - unsigned int domainId; - - int st = initializeCoreCLR(currentExeAbsolutePath, - "unixcorerun", - sizeof(propertyKeys) / sizeof(propertyKeys[0]), - propertyKeys, - propertyValues, - &hostHandle, - &domainId); - - if (!SUCCEEDED(st)) - { - fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st); - exitCode = -1; - } - else - { - st = executeAssembly(hostHandle, - domainId, - managedAssemblyArgc, - managedAssemblyArgv, - managedAssemblyAbsolutePath, - (unsigned int*)&exitCode); - - if (!SUCCEEDED(st)) - { - fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st); - exitCode = -1; - } - - st = shutdownCoreCLR(hostHandle, domainId); - if (!SUCCEEDED(st)) - { - fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); - exitCode = -1; - } - } - } - - if (dlclose(coreclrLib) != 0) - { - fprintf(stderr, "Warning - dlclose failed\n"); - } - } - else - { - const char* error = dlerror(); - fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error); - } - - return exitCode; + // libunwind library is used to unwind stack frame, but libunwind for ARM + // does not support ARM vfpv3/NEON registers in DWARF format correctly. + // Therefore let's disable stack unwinding using DWARF information + // See https://github.com/dotnet/coreclr/issues/6698 + // + // libunwind use following methods to unwind stack frame. + // UNW_ARM_METHOD_ALL 0xFF + // UNW_ARM_METHOD_DWARF 0x01 + // UNW_ARM_METHOD_FRAME 0x02 + // UNW_ARM_METHOD_EXIDX 0x04 + putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); +#endif // _ARM_ + + std::string coreClrDllPath(clrFilesAbsolutePath); + coreClrDllPath.append("/"); + coreClrDllPath.append(__CORECLR_DLL); + + if (coreClrDllPath.length() >= PATH_MAX) { + fprintf(stderr, "Absolute path to libcoreclr.so too long\n"); + return -1; + } + + // Get just the path component of the managed assembly path + std::string appPath; + getDirectory(managedAssemblyAbsolutePath, appPath); + + std::string tpaList; + // Construct native search directory paths + std::string nativeDllSearchDirs(appPath); + char *coreLibraries = getenv("CORE_LIBRARIES"); + if (coreLibraries) { + nativeDllSearchDirs.append(":"); + nativeDllSearchDirs.append(coreLibraries); + if (std::strcmp(coreLibraries, clrFilesAbsolutePath) != 0) + addFilesFromDirectoryToTpaList(coreLibraries, tpaList); + } + nativeDllSearchDirs.append(":"); + nativeDllSearchDirs.append(clrFilesAbsolutePath); + + addFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList); + + void* __coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL); + if (__coreclrLib != nullptr) { + 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) { + fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n"); + } else if (executeAssembly == nullptr) { + fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n"); + } else if (shutdownCoreCLR == nullptr) { + fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); + } else { + // Check whether we are enabling server GC (off by default) + const char* useServerGc = std::getenv(__SERVER_GC_VAR); + if (useServerGc == nullptr) + useServerGc = "0"; + + // CoreCLR expects strings "true" and "false" instead of "1" and "0". + useServerGc = std::strcmp(useServerGc, "1") == 0 ? "true" : "false"; + + // Allowed property names: + // APPBASE + // - The base path of the application from which the exe and other assemblies will be loaded + // + // TRUSTED_PLATFORM_ASSEMBLIES + // - The list of complete paths to each of the fully trusted assemblies + // + // APP_PATHS + // - The list of paths which will be probed by the assembly loader + // + // APP_NI_PATHS + // - The list of additional paths that the assembly loader will probe for ngen images + // + // NATIVE_DLL_SEARCH_DIRECTORIES + // - The list of paths that will be probed for native DLLs called by PInvoke + // + const char *propertyKeys[] = { + "TRUSTED_PLATFORM_ASSEMBLIES", + "APP_PATHS", + "APP_NI_PATHS", + "NATIVE_DLL_SEARCH_DIRECTORIES", + "System.GC.Server", + }; + const char *propertyValues[] = { + // TRUSTED_PLATFORM_ASSEMBLIES + tpaList.c_str(), + // APP_PATHS + appPath.c_str(), + // APP_NI_PATHS + appPath.c_str(), + // NATIVE_DLL_SEARCH_DIRECTORIES + nativeDllSearchDirs.c_str(), + // System.GC.Server + useServerGc, + }; + + void* hostHandle; + unsigned int domainId; + + int st = initializeCoreCLR(currentExeAbsolutePath, + "unixcorerun", + sizeof(propertyKeys) / sizeof(propertyKeys[0]), + propertyKeys, + propertyValues, + &hostHandle, + &domainId); + + if (!SUCCEEDED(st)) { + fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st); + exitCode = -1; + } else { + st = executeAssembly(hostHandle, + domainId, + managedAssemblyArgc, + managedAssemblyArgv, + managedAssemblyAbsolutePath, + (unsigned int*)&exitCode); + + if (!SUCCEEDED(st)) { + fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st); + exitCode = -1; + } + + st = shutdownCoreCLR(hostHandle, domainId); + if (!SUCCEEDED(st)) { + fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); + exitCode = -1; + } + } + } + + if (dlclose(__coreclrLib) != 0) { + fprintf(stderr, "Warning - dlclose failed\n"); + } + } else { + const char* error = dlerror(); + fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error); + } + + return exitCode; } // Display the help text -void DisplayUsage() +void displayUsage() { - fprintf(stderr, - "Runs executables on CoreCLR\n\n" - "Usage: [OPTIONS] [ARGUMENTS]\n" - "Runs .dll on CoreCLR.\n\n" - "Options:\n" - "-_c path to libcoreclr.so and the managed CLR assemblies.\n" - "-_h show this help message. \n"); + fprintf(stderr, + "Runs executables on CoreCLR\n\n" + "Usage: [OPTIONS] [ARGUMENTS]\n" + "Runs .dll on CoreCLR.\n\n" + "Options:\n" + "-_c path to libcoreclr.so and the managed CLR assemblies.\n" + "-_h show this help message. \n"); } // Parse the command line arguments -bool ParseArguments( - const int argc, - const char* argv[], - const char** clrFilesPath, - int* managedAssemblyArgc, - const char*** managedAssemblyArgv) +bool parseArguments(const int argc, + const char* argv[], + const char** clrFilesPath, + int* managedAssemblyArgc, + const char*** managedAssemblyArgv) { - bool success = true; - - *clrFilesPath = nullptr; - *managedAssemblyArgv = nullptr; - *managedAssemblyArgc = 0; - - for (int i = 1; i < argc; i++) - { - // Check for options. Options to the Unix coreconsole are prefixed with '-_' to match the convention - // used in the Windows version of coreconsole. - if (strncmp(argv[i], "-_", 2) == 0) - { - // Path to the libcoreclr.so and the managed CLR assemblies - if (strcmp(argv[i], "-_c") == 0) - { - i++; - if (i < argc) - { - *clrFilesPath = argv[i]; - } - else - { - fprintf(stderr, "Option %s: missing path\n", argv[i - 1]); - success = false; - break; - } - } - else if (strcmp(argv[i], "-_h") == 0) - { - DisplayUsage(); - success = false; - break; - } - else - { - fprintf(stderr, "Unknown option %s\n", argv[i]); - success = false; - break; - } - } - else - { - // We treat everything starting from the first non-option argument as arguments - // to the managed assembly. - *managedAssemblyArgc = argc - i; - if (*managedAssemblyArgc != 0) - { - *managedAssemblyArgv = &argv[i]; - } - - break; - } - } - - return success; + bool success = true; + + *clrFilesPath = nullptr; + *managedAssemblyArgv = nullptr; + *managedAssemblyArgc = 0; + + for (int i = 1; i < argc; i++) { + // Check for options. Options to the Unix coreconsole are prefixed with '-_' to match the convention + // used in the Windows version of coreconsole. + if (strncmp(argv[i], "-_", 2) == 0) { + // Path to the libcoreclr.so and the managed CLR assemblies + if (strcmp(argv[i], "-_c") == 0) { + i++; + if (i < argc) { + *clrFilesPath = argv[i]; + } else { + fprintf(stderr, "Option %s: missing path\n", argv[i - 1]); + success = false; + break; + } + } else if (strcmp(argv[i], "-_h") == 0) { + displayUsage(); + success = false; + break; + } else { + fprintf(stderr, "Unknown option %s\n", argv[i]); + success = false; + break; + } + } else { + // We treat everything starting from the first non-option argument as arguments + // to the managed assembly. + *managedAssemblyArgc = argc - i; + if (*managedAssemblyArgc != 0) + *managedAssemblyArgv = &argv[i]; + + break; + } + } + + return success; } int main(const int argc, const char* argv[]) { - /// service_app_begin - char *root_path = getenv("AUL_ROOT_PATH"); - char *second_pass = getenv("SECONDPASS"); - - // This routine check whether _SCD_DEBUG_ flag is set(1) or not. - // In second pass, this routine is skipped. - if (second_pass == NULL) - { - // run service_app routine to extract _SCD_DEBUG_ - char ad[50] = {0,}; - service_app_lifecycle_callback_s event_callback; - event_callback.create = service_app_create; - event_callback.terminate = service_app_terminate; - event_callback.app_control = service_app_control; - // FIXME: casting of argv is safe ? - service_app_main(argc, (char**)argv, &event_callback, ad); - - char buf[PATH_MAX]; - vector vargs; - int status = 0; - - if (isDebugMode) - { - dlog_print(DLOG_INFO,"dotnet","debugmode on\n"); - setenv("CORECLR_GDBJIT", *coreclr_gdbjit, 1); - - string cur_path(getenv("PATH")); - string new_path("/home/owner/share/tmp/sdk_tools/lldb/bin:"); - new_path.append(cur_path); - setenv("PATH", new_path.c_str(), 1); - - vargs.push_back("/home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server"); - vargs.push_back("g"); - vargs.push_back("--platform=host"); - vargs.push_back("*:1234"); - vargs.push_back("--"); - } - snprintf(buf, sizeof(buf), "%s/bin/%s", root_path, basename(root_path)); - vargs.push_back(buf); - - // Pass app argument to lldb-server as it is - for (int i=1; i vargs; + int status = 0; + + if (isDebugMode) { + dlog_print(DLOG_INFO, "dotnet", "debugmode on\n"); + setenv("CORECLR_GDBJIT", *coreclrGdbjit, 1); + + string curPath(getenv("PATH")); + string newPath("/home/owner/share/tmp/sdk_tools/lldb/bin:"); + newPath.append(curPath); + setenv("PATH", newPath.c_str(), 1); + + vargs.push_back("/home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server"); + vargs.push_back("g"); + vargs.push_back("--platform=host"); + vargs.push_back("*:1234"); + vargs.push_back("--"); + } + snprintf(buf, sizeof(buf), "%s/bin/%s", rootPath, basename(rootPath)); + vargs.push_back(buf); + + // Pass app argument to lldb-server as it is + for (int i = 1; i < argc; i++) + vargs.push_back(argv[i]); + + const char** newArgs = &vargs[0]; + setenv("SECONDPASS", "1", 1); + status = execvp(newArgs[0], (char *const *)newArgs); + if (status == -1) + dlog_print(DLOG_ERROR, "dotnet", "execvp error"); + dlog_print(DLOG_INFO, "dotnet", "something wrong errno: %d\n", errno); + } + /// service_app_end + + // Make sure we have a full path for argv[0]. + std::string argv0AbsolutePath; + std::string entryPointExecutablePath; + + if (!getEntrypointExecutableabsolutePath(entryPointExecutablePath)) { + perror("Could not get full path to current executable"); + return -1; + } + + if (!getabsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath)) { + perror("Could not normalize full path to current executable"); + return -1; + } + + // We will try to load the managed assembly with the same name as this executable + // but with the .dll extension. + std::string programPath(argv0AbsolutePath); + programPath.append(".dll"); + const char* managedAssemblyAbsolutePath = programPath.c_str(); + + // Check if the specified managed assembly file exists + struct stat sb; + if (stat(managedAssemblyAbsolutePath, &sb) == -1) { + perror("Managed assembly not found"); + return -1; + } + + // Verify that the managed assembly path points to a file + if (!S_ISREG(sb.st_mode)) { + fprintf(stderr, "The specified managed assembly is not a file\n"); + return -1; + } + + const char* clrFilesPath; + const char** managedAssemblyArgv; + int managedAssemblyArgc; + if (!parseArguments(argc, argv, &clrFilesPath, &managedAssemblyArgc, &managedAssemblyArgv)) + return -1; + + std::string clrFilesAbsolutePath; + if (!getClrFilesabsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) + return -1; + + int exitCode = executeManagedAssembly(argv0AbsolutePath.c_str(), + clrFilesAbsolutePath.c_str(), + managedAssemblyAbsolutePath, + managedAssemblyArgc, + managedAssemblyArgv); + + return exitCode; } diff --git a/NativeLauncher/launcher/launcher.cc b/NativeLauncher/launcher/launcher.cc index d36f61f..91ccb02 100644 --- a/NativeLauncher/launcher/launcher.cc +++ b/NativeLauncher/launcher/launcher.cc @@ -35,10 +35,9 @@ namespace tizen { namespace runtime { -struct FdHandler -{ - Ecore_Fd_Handler *handler; - loader_receiver_cb receiver; +struct FdHandler { + Ecore_Fd_Handler *handler; + loader_receiver_cb receiver; }; static int __argc; @@ -47,192 +46,170 @@ static Evas_Object *__win; class LaunchpadAdapterImpl : public LaunchpadAdapter { - public: - LaunchpadAdapterImpl() : - callbacks(), - adapter(), - launcher(nullptr), - isLaunched(false) - { } - void LoaderMain(int argc, char* argv[]) override; - - std::map Handlers; - - private: - AppInfo appinfo; - loader_lifecycle_callback_s callbacks; - loader_adapter_s adapter; - LauncherInterface* launcher; - bool isLaunched; - std::string launchPath; + public: + LaunchpadAdapterImpl() : + callbacks(), + adapter(), + launcher(nullptr), + __isLaunched(false) + { } + void loaderMain(int argc, char* argv[]) override; + + std::map handlers; + + private: + AppInfo appInfo; + loader_lifecycle_callback_s callbacks; + loader_adapter_s adapter; + LauncherInterface* launcher; + bool __isLaunched; + std::string __launchPath; }; LaunchpadAdapterImpl LaunchpadImpl; LaunchpadAdapter& Launchpad = LaunchpadImpl; #define WITH_SELF(data) \ - LaunchpadAdapterImpl* self = static_cast(data); \ - if (self == nullptr) \ - { \ - _ERR("No LaunchpadImplData"); \ - } else + LaunchpadAdapterImpl* self = static_cast(data); \ + if (self == nullptr) \ + _ERR("No LaunchpadImplData"); \ + else -static Eina_Bool Fd_Handler(void *data, Ecore_Fd_Handler* handler) +static Eina_Bool fdHandler(void *data, Ecore_Fd_Handler* handler) { - WITH_SELF(data) - { - int fd = ecore_main_fd_handler_fd_get(handler); - if (fd == -1) - { - _ERR("Failed to get the Ecore FD"); - exit(-1); - } - - if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) - { - if (self->Handlers.find(fd) != self->Handlers.end()) - { - self->Handlers[fd].receiver(fd); - } - } - else if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) - { - _ERR("Ecore FD Handler Have Error"); - close(fd); - exit(-1); - } - } - - return ECORE_CALLBACK_CANCEL; + WITH_SELF(data) { + int fd = ecore_main_fd_handler_fd_get(handler); + if (fd == -1) { + _ERR("Failed to get the Ecore FD"); + exit(-1); + } + + if (ecore_main_fd_handler_active_get(handler, ECORE_FD_READ)) { + if (self->handlers.find(fd) != self->handlers.end()) + self->handlers[fd].receiver(fd); + } else if (ecore_main_fd_handler_active_get(handler, ECORE_FD_ERROR)) { + _ERR("Ecore FD Handler Have Error"); + close(fd); + exit(-1); + } + } + + return ECORE_CALLBACK_CANCEL; } -static void Fd_Add(void *data, int fd, loader_receiver_cb receiver) +static void fdAdd(void *data, int fd, loader_receiver_cb receiver) { - Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, - static_cast(ECORE_FD_READ | ECORE_FD_ERROR), - Fd_Handler, data, nullptr, nullptr); - if (handler == nullptr) - { - _ERR("Failed to add a FD handler to ecore main loop"); - close(fd); - exit(-1); - } - WITH_SELF(data) - { - self->Handlers[fd] = {handler, receiver}; - } + Ecore_Fd_Handler* handler = ecore_main_fd_handler_add(fd, + static_cast(ECORE_FD_READ | ECORE_FD_ERROR), + fdHandler, data, nullptr, nullptr); + if (handler == nullptr) { + _ERR("Failed to add a FD handler to ecore main loop"); + close(fd); + exit(-1); + } WITH_SELF(data) { + self->handlers[fd] = {handler, receiver}; + } } -static void Fd_Remove(void *data, int fd) +static void fdRemove(void *data, int fd) { - WITH_SELF(data) - { - if (self->Handlers.find(fd) != self->Handlers.end()) - { - Ecore_Fd_Handler* handler = self->Handlers[fd].handler; - ecore_main_fd_handler_del(handler); - self->Handlers.erase(fd); - } - } + WITH_SELF(data) { + if (self->handlers.find(fd) != self->handlers.end()) { + Ecore_Fd_Handler* handler = self->handlers[fd].handler; + ecore_main_fd_handler_del(handler); + self->handlers.erase(fd); + } + } } - -static void PreloadLibsAndWindow(bundle *extra, int type, void *user_data) +static void preloadLibsAndWindow(bundle *extra, int type, void *userData) { - int elm_init_cnt = 0; - const char **so_array; - int len = 0; - int i; - void *handle = NULL; + int elmInitCnt = 0; + const char **soArray; + int len = 0; + int i; + void *handle = NULL; - // Preload native libraries - if (extra == NULL) { - _DBG("No extra data"); - return; - } + // Preload native libraries + if (extra == NULL) { + _DBG("No extra data"); + return; + } - so_array = bundle_get_str_array(extra, "preload", &len); + soArray = bundle_get_str_array(extra, "preload", &len); - if (!so_array) - return; + if (!soArray) + return; - for (i = 0; i < len; i++) { - handle = dlopen(so_array[i], RTLD_NOW); - _DBG("preload %s# - handle : %x", so_array[i], handle); - } + for (i = 0; i < len; i++) { + handle = dlopen(soArray[i], RTLD_NOW); + _DBG("preload %s# - handle : %x", soArray[i], handle); + } - // Precreate window - elm_init_cnt = elm_init(__argc, __argv); - _DBG("[candidate] elm init, returned: %d", elm_init_cnt); + // Precreate window + elmInitCnt = elm_init(__argc, __argv); + _DBG("[candidate] elm init, returned: %d", elmInitCnt); - elm_config_accel_preference_set("hw"); + elm_config_accel_preference_set("hw"); - __win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC); - if (__win == NULL) { - _DBG("[candidate] elm_win_add() failed"); - return; - } + __win = elm_win_add(NULL, "package_name", ELM_WIN_BASIC); + if (__win == NULL) { + _DBG("[candidate] elm_win_add() failed"); + return; + } - elm_win_precreated_object_set(__win); + elm_win_precreated_object_set(__win); } -void LaunchpadAdapterImpl::LoaderMain(int argc, char* argv[]) +void LaunchpadAdapterImpl::loaderMain(int argc, char* argv[]) { - __argc = argc; - __argv = argv; - callbacks.create = [](bundle *extra, int type, void *user_data) - { - ecore_init(); - PreloadLibsAndWindow(extra, type, user_data); - WITH_SELF(user_data) - { - if (self->OnCreate != nullptr) - self->OnCreate(); - } - }; - callbacks.launch = [](int argc, char** argv, const char* app_path, - const char* appid, const char* pkgid, - const char* pkg_type, void* user_data) -> int - { - WITH_SELF(user_data) - { - self->appinfo.root = std::string(aul_get_app_root_path()); - self->appinfo.path = app_path; - self->appinfo.id = appid; - self->appinfo.pkg = pkgid; - self->appinfo.type = pkg_type; - if (self->OnLaunch != nullptr) - self->OnLaunch(self->appinfo, argc, argv); - } - - return 0; - }; - callbacks.terminate = [](int argc, char **argv, void* user_data) -> int - { - _DBG("Terminate!!"); - WITH_SELF(user_data) - { - if (self->OnTerminate != nullptr) - self->OnTerminate(self->appinfo, argc, argv); - } - return 0; - }; - - adapter.loop_begin = [](void *data) - { - ecore_main_loop_begin(); - }; - - adapter.loop_quit = [](void *data) - { - ecore_main_loop_quit(); - }; - adapter.add_fd = Fd_Add; - adapter.remove_fd = Fd_Remove; - - _DBG("launchpad_loader_main is start"); - int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this); - _DBG("launchpad_loader_main is finished with [%d]", r); + __argc = argc; + __argv = argv; + callbacks.create = [](bundle *extra, int type, void *userData) { + ecore_init(); + preloadLibsAndWindow(extra, type, userData); + WITH_SELF(userData) { + if (self->onCreate != nullptr) + self->onCreate(); + } + }; + callbacks.launch = [](int argc, char** argv, const char* appPath, + const char* appId, const char* pkgId, + const char* pkgType, void* userData) -> int { + WITH_SELF(userData) { + self->appInfo.root = std::string(aul_get_app_root_path()); + self->appInfo.path = appPath; + self->appInfo.id = appId; + self->appInfo.pkg = pkgId; + self->appInfo.type = pkgType; + if (self->onLaunch != nullptr) + self->onLaunch(self->appInfo, argc, argv); + } + + return 0; + }; + callbacks.terminate = [](int argc, char **argv, void* userData) -> int { + _DBG("Terminate!!"); + WITH_SELF(userData) { + if (self->onTerminate != nullptr) + self->onTerminate(self->appInfo, argc, argv); + } + return 0; + }; + + adapter.loop_begin = [](void *data) { + ecore_main_loop_begin(); + }; + + adapter.loop_quit = [](void *data) { + ecore_main_loop_quit(); + }; + adapter.add_fd = fdAdd; + adapter.remove_fd = fdRemove; + + _DBG("launchpad_loader_main is start"); + int r = launchpad_loader_main(argc, argv, &(this->callbacks), &(this->adapter), this); + _DBG("launchpad_loader_main is finished with [%d]", r); } #undef WITH_SELF diff --git a/NativeLauncher/launcher/launcher.h b/NativeLauncher/launcher/launcher.h index 66c3aaa..41ed2ac 100644 --- a/NativeLauncher/launcher/launcher.h +++ b/NativeLauncher/launcher/launcher.h @@ -25,29 +25,28 @@ namespace runtime { class LauncherInterface { - public: - virtual int Initialize(bool standalone) = 0; - virtual void Dispose() = 0; - virtual int RunManagedLauncher(const char* app_id, const char* app_base, const char* tpa_list) = 0; - virtual int Launch(const char* app_id, const char* root, const char* path, int argc, char* argv[]) = 0; + 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; }; -struct AppInfo -{ - std::string root; - std::string path; - std::string id; - std::string pkg; - std::string type; +struct AppInfo { + std::string root; + std::string path; + std::string id; + std::string pkg; + std::string type; }; class LaunchpadAdapter { - public: - virtual void LoaderMain(int argc, char* argv[]) = 0; - std::function OnCreate = nullptr; - std::function OnLaunch = nullptr; - std::function OnTerminate = nullptr; + public: + virtual void loaderMain(int argc, char* argv[]) = 0; + std::function onCreate = nullptr; + std::function onLaunch = nullptr; + std::function onTerminate = nullptr; }; extern LaunchpadAdapter& Launchpad; @@ -55,4 +54,4 @@ extern LaunchpadAdapter& Launchpad; } // namespace runtime } // namespace tizen -#endif // __LAUNCHER_INTERFACE_H__ +#endif /* __LAUNCHER_INTERFACE_H__ */ diff --git a/NativeLauncher/launcher/main.cc b/NativeLauncher/launcher/main.cc index a25eaae..5754589 100644 --- a/NativeLauncher/launcher/main.cc +++ b/NativeLauncher/launcher/main.cc @@ -40,110 +40,85 @@ static std::string StandaloneOption("--standalone"); int main(int argc, char *argv[]) { - int i; - bool standalone = false; - const char* standalonePath = nullptr; - - std::vector vargs; - - // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter - for (i=1; i argc-1) - { - fprintf(stderr, "Assembly path must be after \"--standalone\" option\n"); - return 1; - } - i++; - standalonePath = argv[i]; - } - else - { - vargs.push_back(argv[i]); - } - } - - using tizen::runtime::LauncherInterface; - using tizen::runtime::Launchpad; - using tizen::runtime::AppInfo; - std::unique_ptr runtime; - - using tizen::runtime::dotnetcore::CoreRuntime; - std::unique_ptr coreRuntime(new CoreRuntime()); - runtime = std::move(coreRuntime); - - if (standalone) - { - _DBG("##### Run it standalone #########"); - const char* appid = getenv("AUL_APPID"); - _DBG("AUL_APPID : %s", appid); - std::string approot; - if (appid != nullptr) - { - const char* approot_path = aul_get_app_root_path(); - if (approot_path != nullptr) - { - approot = std::string(approot_path); - } - } - if (approot.empty()) - { - approot = Basename(standalonePath); - } - if (runtime->Initialize(true) != 0) - { - _ERR("Failed to initialize"); - return 1; - } - - int args_len = vargs.size(); - char** args = &vargs[0]; - if (runtime->Launch(appid, approot.c_str(), standalonePath, args_len, args)) - { - _ERR("Failed to launch"); - return 0; - } - } - else - { - Launchpad.OnCreate = [&runtime]() - { - if (runtime->Initialize(false) != 0) - { - _ERR("Failed to initialized"); - } - else - { - _DBG("Success to initialized"); - } - }; - - Launchpad.OnTerminate = [&runtime](const AppInfo& info, int argc, char** argv) - { - _DBG("terminated with app path : %s", info.path.c_str()); - _DBG("appid : %s", info.id.c_str()); - _DBG("pkg : %s", info.pkg.c_str()); - _DBG("type : %s", info.type.c_str()); - - // The launchpad pass the name of exe file to the first argument. - // For the C# spec, we have to skip this first argument. - - if (runtime->Launch(info.id.c_str(), info.root.c_str(), info.path.c_str(), argc-1, argv+1)) - { - _ERR("Failed to launch"); - } - }; - Launchpad.LoaderMain(argc, argv); - } - - return 0; + int i; + bool standalone = false; + const char* standalonePath = nullptr; + + std::vector vargs; + + // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter + for (i = 1; i argc-1) { + fprintf(stderr, "Assembly path must be after \"--standalone\" option\n"); + return 1; + } + i++; + standalonePath = argv[i]; + } else { + vargs.push_back(argv[i]); + } + } + + using tizen::runtime::LauncherInterface; + using tizen::runtime::Launchpad; + using tizen::runtime::AppInfo; + std::unique_ptr runtime; + + using tizen::runtime::dotnetcore::CoreRuntime; + std::unique_ptr coreRuntime(new CoreRuntime()); + runtime = std::move(coreRuntime); + + if (standalone) { + _DBG("##### Run it standalone #########"); + const char* appId = getenv("AUL_APPID"); + _DBG("AUL_APPID : %s", appId); + std::string appRoot; + if (appId != nullptr) { + const char* appRootPath = aul_get_app_root_path(); + if (appRootPath != nullptr) + appRoot = std::string(appRootPath); + } + if (appRoot.empty()) + appRoot = baseName(standalonePath); + if (runtime->initialize(true) != 0) { + _ERR("Failed to initialize"); + return 1; + } + + int argsLen = vargs.size(); + char** args = &vargs[0]; + if (runtime->launch(appId, appRoot.c_str(), standalonePath, argsLen, args)) { + _ERR("Failed to launch"); + return 0; + } + } else { + Launchpad.onCreate = [&runtime]() { + if (runtime->initialize(false) != 0) + _ERR("Failed to initialized"); + else + _DBG("Success to initialized"); + }; + + Launchpad.onTerminate = [&runtime](const AppInfo& appInfo, int argc, char** argv) { + _DBG("terminated with app path : %s", appInfo.path.c_str()); + _DBG("appId : %s", appInfo.id.c_str()); + _DBG("pkg : %s", appInfo.pkg.c_str()); + _DBG("type : %s", appInfo.type.c_str()); + + // The launchpad pass the name of exe file to the first argument. + // For the C# spec, we have to skip this first argument. + + if (runtime->launch(appInfo.id.c_str(), appInfo.root.c_str(), appInfo.path.c_str(), argc-1, argv+1)) + _ERR("Failed to launch"); + }; + Launchpad.loaderMain(argc, argv); + } + + return 0; } diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc index 1019db4..d5cf5d3 100644 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -31,315 +31,264 @@ #include "utils.h" -bool ICompare(const std::string& a, const std::string& b) +bool iCompare(const std::string& a, const std::string& b) { - return a.length() == b.length() && - std::equal(b.begin(), b.end(), a.begin(), - [](unsigned char a, unsigned char b) - { return std::tolower(a) == std::tolower(b); }); + return a.length() == b.length() && + std::equal(b.begin(), b.end(), a.begin(), + [](unsigned char a, unsigned char b) + { return std::tolower(a) == std::tolower(b); }); } -bool ICompare(const std::string& a, int a_offset, const std::string& b, int b_offset, int length) +bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length) { - return static_cast(a.length()) - length >= a_offset && - static_cast(b.length()) - length >= b_offset && - std::equal(b.begin() + b_offset, b.begin() + b_offset + length, a.begin() + a_offset, - [](unsigned char a, unsigned char b) - { return std::tolower(a) == std::tolower(b); }); + return static_cast(a.length()) - length >= aOffset && + static_cast(b.length()) - length >= bOffset && + std::equal(b.begin() + bOffset, b.begin() + bOffset + length, a.begin() + aOffset, + [](unsigned char a, unsigned char b) + { return std::tolower(a) == std::tolower(b); }); } -bool IsManagedAssembly(const std::string& filename) +bool isManagedAssembly(const std::string& fileName) { - return ICompare(filename, filename.size()-4, ".dll", 0, 4) || - ICompare(filename, filename.size()-4, ".exe", 0, 4); + return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) || + iCompare(fileName, fileName.size()-4, ".exe", 0, 4); } -bool IsNativeImage(const std::string& filename) +bool isNativeImage(const std::string& fileName) { - return ICompare(filename, filename.size()-7, ".ni", 0, 3); + return iCompare(fileName, fileName.size()-7, ".ni", 0, 3); } -std::string ReadSelfPath() +std::string readSelfPath() { - char buff[PATH_MAX]; - ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1); - if (len != -1) { - buff[len] = '\0'; - return std::string(buff); - } - - return ""; + char buff[PATH_MAX]; + ssize_t len = ::readlink("/proc/self/exe", buff, sizeof(buff)-1); + if (len != -1) { + buff[len] = '\0'; + return std::string(buff); + } + + return ""; } -std::string ConcatPath(const std::string& path1, const std::string& path2) +std::string concatPath(const std::string& path1, const std::string& path2) { - std::string path(path1); - if (path.back() == PATH_SEPARATOR) - { - path.append(path2); - } - else - { - path += PATH_SEPARATOR; - path.append(path2); - } - - return path; + std::string path(path1); + if (path.back() == PATH_SEPARATOR) { + path.append(path2); + } else { + path += PATH_SEPARATOR; + path.append(path2); + } + + return path; } -void AppendPath(std::string& path1, const std::string& path2) +void appendPath(std::string& path1, const std::string& path2) { - if (path1.back() == PATH_SEPARATOR) - { - path1.append(path2); - } - else - { - path1 += PATH_SEPARATOR; - path1.append(path2); - } + if (path1.back() == PATH_SEPARATOR) { + path1.append(path2); + } else { + path1 += PATH_SEPARATOR; + path1.append(path2); + } } -std::string AbsolutePath(const std::string& path) +std::string absolutePath(const std::string& path) { - std::string absPath; + std::string absPath; + char realPath[PATH_MAX]; + if (realpath(path.c_str(), realPath) != nullptr && realPath[0] != '\0') + absPath.assign(realPath); - char realPath[PATH_MAX]; - if (realpath(path.c_str(), realPath) != nullptr && realPath[0] != '\0') - { - absPath.assign(realPath); - } - - return absPath; + return absPath; } -std::string Basename(const std::string& path) +std::string baseName(const std::string& path) { - auto pos = path.find_last_of(PATH_SEPARATOR); - if (pos != std::string::npos) - { - return path.substr(0, pos); - } - else - { - return std::string("."); - } - return path; + auto pos = path.find_last_of(PATH_SEPARATOR); + if (pos != std::string::npos) + return path.substr(0, pos); + else + return std::string("."); + return path; } -bool EndWithIgnoreCase(const std::string& str1, const std::string& str2, std::string& filename) +bool endWithIgnoreCase(const std::string& str1, const std::string& str2, std::string& fileName) { - std::string::size_type len1 = str1.length(); - std::string::size_type len2 = str2.length(); - if (len2 > len1) return false; - - int i = 0; - bool result = std::all_of(str1.cend() - len2, str1.end(), - [&i, &str2] (char x) { - return std::tolower(x) == std::tolower(str2[i++]); - }); - if (result) - { - filename = str1.substr(0, len1 - len2); - } - return result; + std::string::size_type len1 = str1.length(); + std::string::size_type len2 = str2.length(); + if (len2 > len1) + return false; + + int i = 0; + bool result = std::all_of(str1.cend() - len2, str1.end(), + [&i, &str2] (char x) { + return std::tolower(x) == std::tolower(str2[i++]); + }); + if (result) + fileName = str1.substr(0, len1 - len2); + + return result; } -bool FileNotExist(const std::string& path) +bool fileNotExist(const std::string& path) { - struct stat sb; - return stat(path.c_str(), &sb) != 0; + struct stat sb; + return stat(path.c_str(), &sb) != 0; } #ifdef NOT_USE_FUNCTION -static bool ExtCheckAndGetFileNameIfExist(const std::string& dir, const std::string& ext, struct dirent* entry, std::string& filename) +static bool extCheckAndGetFileNameIfExist(const std::string& dir, const std::string& ext, struct dirent* entry, std::string& fileName) { - std::string fname(entry->d_name); - if (fname.length() < ext.length() || - fname.compare(fname.length() - ext.length(), ext.length(), ext) != 0) - { - return false; - } - std::string fullname = ConcatPath(dir, entry->d_name); - switch (entry->d_type) - { - case DT_REG: break; - case DT_LNK: - case DT_UNKNOWN: - if (FileNotExist(fullname)) - { - return false; - } - default: - return false; - } - - filename = fullname; - - return true; + std::string fName(entry->d_name); + if (fName.length() < ext.length() || + fHame.compare(fName.length() - ext.length(), ext.length(), ext) != 0) { + return false; + + std::string fullName = concatPath(dir, entry->d_name); + switch (entry->d_type) { + case DT_REG: break; + case DT_LNK: + case DT_UNKNOWN: + if (fileNotExist(fullName)) + return false; + default: + return false; + } + + fileName = fullName; + + return true; } #endif -std::string StripNIDLL(const std::string& path) +std::string stripNiDLL(const std::string& path) { - std::string npath(path); - if (path.size() < 5) return npath; - if (!strncasecmp(path.c_str() + path.size() - 4, ".dll", 4)) - { - npath = path.substr(0, path.size()-4); - }else if (!strncasecmp(path.c_str() + path.size() - 4, ".exe", 4)) - { - npath = path.substr(0, path.size()-4); - } - if (!strncasecmp(npath.c_str() + npath.size() - 3, ".ni", 3)) - { - return npath.substr(0, npath.size()-3); - } - return npath; + std::string niPath(path); + if (path.size() < 5) return niPath; + if (!strncasecmp(path.c_str() + path.size() - 4, ".dll", 4)) + niPath = path.substr(0, path.size()-4); + else if (!strncasecmp(path.c_str() + path.size() - 4, ".exe", 4)) + niPath = path.substr(0, path.size()-4); + + if (!strncasecmp(niPath.c_str() + niPath.size() - 3, ".ni", 3)) + return niPath.substr(0, niPath.size()-3); + + return niPath; } -std::string JoinStrings(const std::vector& strings, const char* const delimeter) +std::string joinStrings(const std::vector& strings, const char* const delimeter) { - switch (strings.size()) - { - case 0: - return ""; - case 1: - return strings[0]; - default: - std::ostringstream os; - std::copy(strings.begin(), strings.end()-1, std::ostream_iterator(os, delimeter)); - os << *strings.rbegin(); - return os.str(); - } + switch (strings.size()) { + case 0: + return ""; + case 1: + return strings[0]; + default: + std::ostringstream os; + std::copy(strings.begin(), strings.end()-1, std::ostream_iterator(os, delimeter)); + os << *strings.rbegin(); + return os.str(); + } } -struct AssemblyFile -{ - std::string noext; - std::string ext; +struct AssemblyFile { + std::string noExt; + std::string ext; }; bool operator == (const AssemblyFile& lhs, const AssemblyFile& rhs) { - return lhs.noext == rhs.noext && lhs.ext == rhs.ext; + return lhs.noExt == rhs.noExt && lhs.ext == rhs.ext; } -namespace std -{ - template<> - struct hash - { - std::size_t operator () (const AssemblyFile& f) const - { - const std::size_t h1 = std::hash{}(f.noext); - const std::size_t h2 = std::hash{}(f.ext); - - return h1 ^ (h2 << 1); - } - }; +namespace std { + template<> + struct hash { + std::size_t operator () (const AssemblyFile& f) const { + const std::size_t h1 = std::hash{}(f.noExt); + const std::size_t h2 = std::hash{}(f.ext); + + return h1 ^ (h2 << 1); + } + }; } -void AssembliesInDirectory(const std::vector& directories, std::string& tpaList) +void assembliesInDirectory(const std::vector& directories, std::string& tpaList) { - std::map assemblyList; - std::map tmpList; - - auto reader = [&assemblyList, &tmpList] (const char* path, const char* name) - { - std::string _path(path); - if (IsManagedAssembly(_path)) - { - std::string dll_name = StripNIDLL(name); - std::pair::iterator, bool> ret; - ret = tmpList.insert(std::pair(dll_name, _path)); - if (ret.second == false) - { - if (IsNativeImage(_path)) - { - tmpList[dll_name] = _path; - } - } - } - }; - - for (auto directory : directories) - { - ScanFilesInDir(directory.c_str(), reader, 1); - // merge scaned dll list to tpa list. - // if the dll is already exist in the list, that is skipped. - assemblyList.insert(tmpList.begin(), tmpList.end()); - } - - std::map::iterator it; - for (it = assemblyList.begin(); it != assemblyList.end(); it++) - { - tpaList += it->second + ':'; - } - if (tpaList.back() == ':') - { - tpaList.pop_back(); - } + std::map assemblyList; + std::map tmpList; + + auto reader = [&assemblyList, &tmpList] (const char* path, const char* name) { + std::string pathStr(path); + if (isManagedAssembly(pathStr)) { + std::string dllName = stripNiDLL(name); + std::pair::iterator, bool> ret; + ret = tmpList.insert(std::pair(dllName, pathStr)); + if (ret.second == false) { + if (isNativeImage(pathStr)) + tmpList[dllName] = pathStr; + } + } + }; + + for (auto directory : directories) { + scanFilesInDir(directory.c_str(), reader, 1); + // merge scaned dll list to tpa list. + // if the dll is already exist in the list, that is skipped. + assemblyList.insert(tmpList.begin(), tmpList.end()); + } + + std::map::iterator it; + for (it = assemblyList.begin(); it != assemblyList.end(); it++) + tpaList += it->second + ':'; + + if (tpaList.back() == ':') + tpaList.pop_back(); } -void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth) +void scanFilesInDir(const char* directory, FileReader reader, unsigned int depth) { - DIR *dir; - struct dirent* entry; - bool isDir; - - dir = opendir(directory); - - if (dir == nullptr) - { - //_ERR("Can not open directory : %s", directory); - return; - } - - std::vector innerDirectories; - - while ((entry = readdir(dir)) != nullptr) - { - isDir = false; - std::string path = ConcatPath(directory, entry->d_name); - switch (entry->d_type) - { - case DT_REG: break; - case DT_DIR: - isDir = true; - break; - case DT_LNK: - case DT_UNKNOWN: - struct stat sb; - if (stat(path.c_str(), &sb) == -1) - { - continue; - } - - if (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode)) - { - break; - } - default: - continue; - } - if (!isDir) - { - reader(path.c_str(), entry->d_name); - } - else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) - { - innerDirectories.push_back(path); - } - } - - if (depth != 0) - { - for (auto& d : innerDirectories) - { - ScanFilesInDir(d.c_str(), reader, depth-1); - } - } - - closedir(dir); + DIR *dir; + struct dirent* entry; + bool isDir; + + dir = opendir(directory); + + if (dir == nullptr) + return; + + std::vector innerDirectories; + + while ((entry = readdir(dir)) != nullptr) { + isDir = false; + std::string path = concatPath(directory, entry->d_name); + switch (entry->d_type) { + case DT_REG: break; + case DT_DIR: + isDir = true; + break; + case DT_LNK: + case DT_UNKNOWN: + struct stat sb; + if (stat(path.c_str(), &sb) == -1) + continue; + + if (S_ISREG(sb.st_mode) || S_ISDIR(sb.st_mode)) + break; + default: + continue; + } + if (!isDir) + reader(path.c_str(), entry->d_name); + else if (depth > 1 && strcmp(entry->d_name, ".") && strcmp(entry->d_name, "..")) + innerDirectories.push_back(path); + } + + if (depth != 0) + for (auto& d : innerDirectories) + scanFilesInDir(d.c_str(), reader, depth-1); + + closedir(dir); } \ No newline at end of file diff --git a/README.md b/README.md index b0f7731..e85863e 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ dotnet-launcher [options...] [args...] ``` ----------------------------- -| Tizen.Runtime.Coreclr.dll | +| Tizen.Runtime.dll | ------------+---------------+ | | libcoreclr.so | | +---------------+ diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs b/Tizen.Runtime/CoreClr/AssemblyLoader.cs old mode 100755 new mode 100644 similarity index 69% rename from Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs rename to Tizen.Runtime/CoreClr/AssemblyLoader.cs index 3423d80..c6de690 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyLoader.cs +++ b/Tizen.Runtime/CoreClr/AssemblyLoader.cs @@ -26,19 +26,13 @@ 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[] s_suffixes = new string[] { NativeDllAssemblySuffix, DllAssemblySuffix, ExeAssemblySuffix }; - - private SortedSet _dllDirectories = new SortedSet(); - private SortedSet _nativeDirectories = new SortedSet(); - - private HashSet _assemblyCache = new HashSet(); + private static readonly string[] Suffixes = new string[] { NativeDllAssemblySuffix, DllAssemblySuffix, ExeAssemblySuffix }; + private SortedSet DllDirectoriesSet = new SortedSet(); + private SortedSet NativeDirectoriesSet = new SortedSet(); + private HashSet AssemblyCacheSet = new HashSet(); public AssemblyLoader() { @@ -47,28 +41,28 @@ namespace Tizen.Runtime.Coreclr public IEnumerable DllDirectories { - get { return _dllDirectories; } + get { return DllDirectoriesSet; } } public IEnumerable NativeDirectories { - get { return _nativeDirectories; } + get { return NativeDirectoriesSet; } } public void AddSearchableDirectory(string directory) { if (Directory.Exists(directory)) { - _dllDirectories.Add(directory); - _nativeDirectories.Add(directory); + DllDirectoriesSet.Add(directory); + NativeDirectoriesSet.Add(directory); foreach (var file in Directory.GetFiles(directory)) { var info = new FileInfo(file); - if (s_suffixes.Contains(info.Extension)) + if (Suffixes.Contains(info.Extension)) { - _assemblyCache.Add(info); + AssemblyCacheSet.Add(info); } } } @@ -76,20 +70,15 @@ namespace Tizen.Runtime.Coreclr public void RemoveSearchableDirectory(string directory) { - _dllDirectories.Remove(directory); - _nativeDirectories.Remove(directory); + DllDirectoriesSet.Remove(directory); + NativeDirectoriesSet.Remove(directory); - _assemblyCache.RemoveWhere(x => x.DirectoryName == directory); + AssemblyCacheSet.RemoveWhere(x => x.DirectoryName == directory); } public Assembly LoadFromPath(string path) { - if (0 == string.Compare(path, // strA - path.Length - NativeDllAssemblySuffix.Length, // indexA - NativeAssemblyInfix, // strB - 0, // indexB - NativeAssemblyInfix.Length, // length - StringComparison.OrdinalIgnoreCase)) // options + if (string.Compare(path, path.Length - NativeDllAssemblySuffix.Length, NativeAssemblyInfix, 0, NativeAssemblyInfix.Length, StringComparison.OrdinalIgnoreCase) == 0) { return LoadFromNativeImagePath(path, null); } @@ -125,9 +114,9 @@ namespace Tizen.Runtime.Coreclr private Assembly Resolve(AssemblyName assemblyName) { - foreach (string suffix in s_suffixes) + foreach (string suffix in Suffixes) { - var info = _assemblyCache.FirstOrDefault(x => x.Name == assemblyName.Name + suffix); + var info = AssemblyCacheSet.FirstOrDefault(x => x.Name == assemblyName.Name + suffix); if (info != null) { diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs b/Tizen.Runtime/CoreClr/AssemblyManager.cs similarity index 81% rename from Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs rename to Tizen.Runtime/CoreClr/AssemblyManager.cs index ed3907e..d8b19f5 100644 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr/AssemblyManager.cs +++ b/Tizen.Runtime/CoreClr/AssemblyManager.cs @@ -25,29 +25,37 @@ 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)] + [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)) + 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); + CurrentAssemblyLoaderContext.AddSearchableDirectory(binDir.FullName); } - if (Directory.Exists(libdir.FullName)) + + if (Directory.Exists(libDir.FullName)) { - CurrentAssemblyLoaderContext.AddSearchableDirectory(libdir.FullName); + CurrentAssemblyLoaderContext.AddSearchableDirectory(libDir.FullName); } + Execute(path, argv); } - catch(Exception e) + catch (Exception e) { ALog.Debug("Exception in Launch()"); PrintException(e); @@ -66,22 +74,13 @@ namespace Tizen.Runtime.Coreclr ALog.Debug($"Failed to Initialized"); } } - catch(Exception e) + catch (Exception e) { ALog.Debug("Exception at Preparing"); PrintException(e); } } - private static void PrintException(Exception exception) - { - while (exception != null) - { - ALog.Debug(exception.ToString()); - exception = exception.InnerException; - } - } - public static void UnhandledExceptionHandler(object sender, object args) { TypeInfo unhandledExceptionEventArgsType = @@ -97,17 +96,17 @@ namespace Tizen.Runtime.Coreclr { try { - // Set UnhandledException handler with reflection - // we must replace this to no reflection method after AppDomain is comming in used net standard + /// 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); + 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}); + addMethod.Invoke(appDomain, new[] {handler}); } catch (Exception e) { @@ -125,6 +124,7 @@ namespace Tizen.Runtime.Coreclr PrintException(e); return false; } + return true; } @@ -137,9 +137,17 @@ namespace Tizen.Runtime.Coreclr { 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}); + 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 { @@ -153,10 +161,13 @@ namespace Tizen.Runtime.Coreclr } } - public static AssemblyLoader CurrentAssemblyLoaderContext + private static void PrintException(Exception exception) { - get; - private set; + while (exception != null) + { + ALog.Debug(exception.ToString()); + exception = exception.InnerException; + } } } diff --git a/Tizen.Runtime/Tizen.Runtime/Log.cs b/Tizen.Runtime/Log.cs similarity index 56% rename from Tizen.Runtime/Tizen.Runtime/Log.cs rename to Tizen.Runtime/Log.cs index 70d5b21..86b7e6f 100644 --- a/Tizen.Runtime/Tizen.Runtime/Log.cs +++ b/Tizen.Runtime/Log.cs @@ -21,84 +21,57 @@ using System.Runtime.CompilerServices; namespace Tizen.Runtime { -#if CLOG - internal static class Log + internal static class ALog { - static void Print(string tag, string message) - { - string[] lines = message.Split('\r'); - foreach (string line in lines) - { - Console.WriteLine($"{tag} : {message}"); - } - } - - public static void Debug(string tag, string message) - { - Print($"D/{tag}", message); - } - - public static void Info(string tag, string message) - { - Print($"I/{tag}", message); - } + const string Library = "libdlog.so.0"; + const string Tag = "DOTNET_LAUNCHER"; - public static void Error(string tag, string message) + internal enum LogPriority { - Print($"E/{tag}", message); + DLOG_UNKNOWN = 0, + DLOG_DEFAULT, + DLOG_VERBOSE, + DLOG_DEBUG, + DLOG_INFO, + DLOG_WARN, + DLOG_ERROR, + DLOG_FATAL, + DLOG_SILENT, + DLOG_PRIO_MAX, } - } -#endif - internal static class ALog - { - const string Library = "libdlog.so.0"; - const string TAG = "DOTNET_LAUNCHER"; public static void Debug(string message, [CallerFilePath] string file = "", - [CallerMemberName] string func = "", + [CallerMemberName] string function = "", [CallerLineNumber] int line = 0) { - Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); + Print(LogPriority.DLOG_DEBUG, Tag, message, file, function, line); } public static void Info(string message, [CallerFilePath] string file = "", - [CallerMemberName] string func = "", + [CallerMemberName] string function = "", [CallerLineNumber] int line = 0) { - Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); + Print(LogPriority.DLOG_INFO, Tag, message, file, function, line); } public static void Error(string message, [CallerFilePath] string file = "", - [CallerMemberName] string func = "", + [CallerMemberName] string function = "", [CallerLineNumber] int line = 0) { - Print(LogPriority.DLOG_DEBUG, TAG, message, file, func, line); + Print(LogPriority.DLOG_ERROR, Tag, message, file, function, line); } - 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, - } + [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 func, int line) + private static void Print(LogPriority priority, string tag, string message, string file, string function, int line) { - FileInfo finfo = new FileInfo(file); - Print(priority, tag, "%s: %s(%d) > %s", finfo.Name, func, line, message); + FileInfo fileInfo = new FileInfo(file); + Print(priority, tag, "%s: %s(%d) > %s", fileInfo.Name, function, line, message); } - [DllImportAttribute(Library, EntryPoint = "dlog_print")] - internal static extern int Print(LogPriority prio, string tag, string fmt, string file, string func, int line, string msg); } } diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj b/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj deleted file mode 100644 index c08b73f..0000000 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr.csproj +++ /dev/null @@ -1,90 +0,0 @@ - - - - - Debug - AnyCPU - library - Tizen.Runtime.Coreclr - - - - .NETStandard - v1.5 - .NETStandard,Version=v1.5 - false - true - $(NoWarn);1701;1702 - - - - true - full - bin/ - DEBUG;TRACE - - - - pdbonly - true - bin/ - TRACE - - - - - - $(DefineConstants);CLOG - - - - - - - - - - - - - - - - - - - - - - - <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory) - <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory) - true - - - - - - <_Parameter1>PreloadPath=$(PreloadPath) - - - - - - - - - diff --git a/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json b/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json deleted file mode 100644 index ff2957d..0000000 --- a/Tizen.Runtime/Tizen.Runtime.Coreclr.project.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "dependencies": { - "NETStandard.Library": "1.6.0", - "System.Runtime.Loader": "4.0.0" - }, - "frameworks": { - "netstandard1.5": {} - } -} - diff --git a/Tizen.Runtime/Tizen.Runtime.csproj b/Tizen.Runtime/Tizen.Runtime.csproj new file mode 100644 index 0000000..a232a3a --- /dev/null +++ b/Tizen.Runtime/Tizen.Runtime.csproj @@ -0,0 +1,11 @@ + + + + netstandard1.6 + + + + + + + \ No newline at end of file diff --git a/Tizen.Runtime/Tizen.Runtime.snk b/Tizen.Runtime/Tizen.Runtime.snk deleted file mode 100644 index d09238fad5d4ac1671b141956034cca2ec3ce802..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 599 zcmV-d0;v550ssI2Bme+XQ$aES1ONaL0002(DGq5;*iDNmD`i!-W57Gx1KS<*(EK%3 zW@B-ZpEPiJ0fkn2_41G@5}84M{UB8~_RT4uZL3`+#TA8&{$_d&u>Cb>&i6riJ-$y6 zuB_`PSeaKUOC)MY%xjZE{2`Isnfaoi?2(H)pBE z1Xh7WLmh?%QqZWwun;}Hx8_jq>#heY*CApiQ7I;cFK6G8`TMr8Z3sO>Wwq|_K-Z%s z;P2$CvTD;C!#sg|0ZrX&h=RkOfW+@t$YU^?)jC{*p+dsOx(-o({!dOjgKh^tw<7&{ z^sgy+GVAnmKDer~rk7Zm#LdH!jI)4Kj{d`zc1@zij|;CUgc zs)cT0>q!UX)fhEr+O7o*w=R?B2l~UYrKC^NL#vc1x}(U-r^19lSv0>Kgc^?*0drAG z7}{#(d}nE8Q=U!@B$^Uvm?guBL0Go+c|JBw)sYMoiSvhE_YrZ`zgZ~WT0o17&E=O# zQU}2^(7;Ny6{||(84$e=!b`svpBzxi!5|