#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<std::string>& 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<std::string>& directories, std::string& tpaList);
-bool FileNotExist(const std::string& path);
-std::string JoinStrings(const std::vector<std::string>& strings, const char* const delimeter);
+bool fileNotExist(const std::string& path);
+std::string joinStrings(const std::vector<std::string>& strings, const char* const delimeter);
typedef std::function<void (const char*, const char*)> 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__ */
#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<char*const*>(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<char*const*>(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<std::string> 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<const char*> 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<char* const*>(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<std::string> 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<const char*> 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<char* const*>(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<count; i++)
- {
- app_paths += root_paths[i];
- app_paths += ':';
- }
- if (app_paths.back() == ':')
- app_paths.pop_back();
-
- auto convert = [&app_paths, ignores, igcount, &cb](const char* path, const char* name)
- {
- for (int i=0; i<igcount; i++)
- {
- if (strcmp(path, ignores[i]) == 0)
- return;
- }
- std::string ni;
- if (IsManagedAssembly(path) && !IsNativeImage(path) && !NIExist(path, ni))
- {
- crossgen(path, app_paths.c_str());
- if (NIExist(path, ni))
- {
- // change owner and groups for generated ni file.
- struct stat info;
- if (!stat(path, &info))
- {
- if (chown(ni.c_str(), info.st_uid, info.st_gid) == -1)
- {
- _ERR("Failed to change owner and group name");
- }
- }
-
- if (cb != nullptr)
- {
- cb(ni.c_str());
- }
- }
- }
- };
-
- for (int i=0; i<count; i++)
- {
- ScanFilesInDir(root_paths[i], convert, -1);
- }
+ std::string appPaths;
+ for (int i = 0; i < count; i++) {
+ appPaths += rootPaths[i];
+ appPaths += ':';
+ }
+
+ if (appPaths.back() == ':')
+ appPaths.pop_back();
+
+ auto convert = [&appPaths, ignores, igcount, &cb](const char* path, const char* name) {
+ for (int i = 0; i < igcount; i++) {
+ if (strcmp(path, ignores[i]) == 0)
+ return;
+ }
+ std::string ni;
+ if (isManagedAssembly(path) && !isNativeImage(path) && !niExist(path, ni)) {
+ crossgen(path, appPaths.c_str());
+ if (niExist(path, ni)) {
+ // change owner and groups for generated ni file.
+ struct stat info;
+ if (!stat(path, &info)) {
+ if (chown(ni.c_str(), info.st_uid, info.st_gid) == -1)
+ _ERR("Failed to change owner and group name");
+ }
+
+ if (cb != nullptr)
+ cb(ni.c_str());
+ }
+ }
+ };
+
+ for (int i = 0; i < count; i++)
+ scanFilesInDir(rootPaths[i], convert, -1);
}
-void create_ni_under_dirs(const char* root_paths[], int count, after_create cb)
+void createNiUnderDirs(const char* rootPaths[], int count, afterCreate cb)
{
- create_ni_under_dirs(root_paths, count, nullptr, 0, cb);
+ createNiUnderDirs(rootPaths, count, nullptr, 0, cb);
}
-void create_ni_under_dirs(const char* root_paths[], int count)
+void createNiUnderDirs(const char* rootPaths[], int count)
{
- create_ni_under_dirs(root_paths, count, nullptr);
+ createNiUnderDirs(rootPaths, count, nullptr);
}
-int create_ni_under_pkg_root(const char* pkg_name)
+int createNiUnderPkgRoot(const char* pkgName)
{
- std::string pkgroot;
- if (get_root_path(pkg_name, pkgroot) < 0)
- {
- return 1;
- }
-
- //printf("pkgroot : %s\n", pkgroot.c_str());
-
- std::string bindir = ConcatPath(pkgroot, "bin");
- std::string libdir = ConcatPath(pkgroot, "lib");
-
- //printf("bindir : %s\n", bindir.c_str());
- //printf("libdir : %s\n", libdir.c_str());
- _INFO("bindir : %s", bindir.c_str());
- _INFO("libdir : %s", libdir.c_str());
-
- const char* paths[] = {
- bindir.c_str(),
- libdir.c_str()
- };
-
- // change smack label for generated ni file.
- std::string label = "User::Pkg::" + std::string(pkg_name) + "::RO";
- create_ni_under_dirs(paths, 2, [label](const char* ni){
- smack_(ni, label.c_str());
- });
-
- return 0;
+ std::string pkgRoot;
+ if (getRootPath(pkgName, pkgRoot) < 0)
+ return 1;
+
+ std::string binDir = concatPath(pkgRoot, "bin");
+ std::string libDir = concatPath(pkgRoot, "lib");
+ _INFO("bindir : %s", binDir.c_str());
+ _INFO("libdir : %s", libDir.c_str());
+
+ const char* paths[] = {
+ binDir.c_str(),
+ libDir.c_str()
+ };
+
+ // change smack label for generated ni file.
+ std::string label = "User::Pkg::" + std::string(pkgName) + "::RO";
+ createNiUnderDirs(paths, 2, [label](const char* ni) {
+ smack_(ni, label.c_str());
+ });
+
+ return 0;
}
#include <functional>
-typedef std::function<void (const char*)> 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<void (const char*)> 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__ */
#include <algorithm>
#include <vector>
-std::vector<const char*> get_cmd_args(char** begin, char** end)
+std::vector<const char*> getCmdArgs(char** begin, char** end)
{
- std::vector<const char*> list;
- for (char** itr = begin+1; itr != end; itr++)
- {
- if (strncmp(*itr, "--", 2) != 0)
- list.push_back(*itr);
- }
- return list;
+ std::vector<const char*> 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] <root paths or pkg name>\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] <root paths or pkg name>\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<const char*> args = get_cmd_args(argv, argv+argc);
+ std::vector<const char*> 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;
}
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__ */
#include <glib.h>
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);
}
*
*/
-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<bool*>(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<bool*>(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);
}
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<PreparedFunctionPtr>(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<LaunchFunctionPtr>(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<PreparedFunctionPtr>(preparedFunctionDelegate);
+
+ if (preparedFunction != nullptr)
+ preparedFunction();
+
+ void *launchFunctionDelegate;
+ st = createDelegate(__hostHandle, __domainId,
+ "Tizen.Runtime",
+ "Tizen.Runtime.Coreclr.AssemblyManager",
+ "Launch", &launchFunctionDelegate);
+ if (st < 0) {
+ _ERR("Create delegate for Launch managed function is fail! (0x%08x)", st);
+ return 1;
+ }
+ launchFunction = reinterpret_cast<LaunchFunctionPtr>(launchFunctionDelegate);
#endif
- return 0;
+ 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<std::string> 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<std::string> 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
}
* 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 {
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
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;
}
#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<std::string> 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<std::string> 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<char *>("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<char *>("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: <program> [OPTIONS] [ARGUMENTS]\n"
- "Runs <program>.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: <program> [OPTIONS] [ARGUMENTS]\n"
+ "Runs <program>.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<const char*> 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<argc; i++)
- {
- vargs.push_back(argv[i]);
- }
-
- const char** new_args = &vargs[0];
- setenv("SECONDPASS", "1", 1);
- status = execvp(new_args[0], (char *const *)new_args);
- 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
- ))
- {
- // Invalid command line
- 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;
+ /// service_app_begin
+ char *rootPath = getenv("AUL_ROOT_PATH");
+ char *secondPass = getenv("SECONDPASS");
+
+ // This routine check whether _SCD_DEBUG_ flag is set(1) or not.
+ // In second pass, this routine is skipped.
+ if (secondPass == NULL) {
+ // run service_app routine to extract _SCD_DEBUG_
+ char ad[50] = {0, };
+ service_app_lifecycle_callback_s eventCallback;
+ eventCallback.create = service_app_create;
+ eventCallback.terminate = service_app_terminate;
+ eventCallback.app_control = service_app_control;
+ // FIXME: casting of argv is safe ?
+ service_app_main(argc, (char**)argv, &eventCallback, ad);
+
+ char buf[PATH_MAX];
+ vector<const char*> 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;
}
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;
class LaunchpadAdapterImpl : public LaunchpadAdapter
{
- public:
- LaunchpadAdapterImpl() :
- callbacks(),
- adapter(),
- launcher(nullptr),
- isLaunched(false)
- { }
- void LoaderMain(int argc, char* argv[]) override;
-
- std::map<int, FdHandler> 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<int, FdHandler> 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<LaunchpadAdapterImpl*>(data); \
- if (self == nullptr) \
- { \
- _ERR("No LaunchpadImplData"); \
- } else
+ LaunchpadAdapterImpl* self = static_cast<LaunchpadAdapterImpl*>(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_Handler_Flags>(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_Handler_Flags>(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
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<void()> OnCreate = nullptr;
- std::function<void(const AppInfo&, int, char**)> OnLaunch = nullptr;
- std::function<void(const AppInfo&, int, char**)> OnTerminate = nullptr;
+ public:
+ virtual void loaderMain(int argc, char* argv[]) = 0;
+ std::function<void()> onCreate = nullptr;
+ std::function<void(const AppInfo&, int, char**)> onLaunch = nullptr;
+ std::function<void(const AppInfo&, int, char**)> onTerminate = nullptr;
};
extern LaunchpadAdapter& Launchpad;
} // namespace runtime
} // namespace tizen
-#endif // __LAUNCHER_INTERFACE_H__
+#endif /* __LAUNCHER_INTERFACE_H__ */
int main(int argc, char *argv[])
{
- int i;
- bool standalone = false;
- const char* standalonePath = nullptr;
-
- std::vector<char*> vargs;
-
- // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter
- for (i=1; i<argc; i++)
- {
- if (VersionOption.compare(argv[i]) == 0)
- {
- printf("Dotnet launcher Version %s\n", LAUNCHER_VERSION_STR);
- return 0;
- }
- else if (StandaloneOption.compare(argv[i]) == 0)
- {
- standalone = true;
-
- if (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<LauncherInterface> runtime;
-
- using tizen::runtime::dotnetcore::CoreRuntime;
- std::unique_ptr<LauncherInterface> 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<char*> vargs;
+
+ // start index 1 to avoid passing executable name "dotnet-launcher" as a parameter
+ for (i = 1; i <argc; i++) {
+ if (VersionOption.compare(argv[i]) == 0) {
+ printf("Dotnet launcher Version %s\n", LAUNCHER_VERSION_STR);
+ return 0;
+ } else if (StandaloneOption.compare(argv[i]) == 0) {
+ standalone = true;
+
+ if (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<LauncherInterface> runtime;
+
+ using tizen::runtime::dotnetcore::CoreRuntime;
+ std::unique_ptr<LauncherInterface> 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;
}
#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<int>(a.length()) - length >= a_offset &&
- static_cast<int>(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<int>(a.length()) - length >= aOffset &&
+ static_cast<int>(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<std::string>& strings, const char* const delimeter)
+std::string joinStrings(const std::vector<std::string>& 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<std::string>(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<std::string>(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<AssemblyFile>
- {
- std::size_t operator () (const AssemblyFile& f) const
- {
- const std::size_t h1 = std::hash<std::string>{}(f.noext);
- const std::size_t h2 = std::hash<std::string>{}(f.ext);
-
- return h1 ^ (h2 << 1);
- }
- };
+namespace std {
+ template<>
+ struct hash<AssemblyFile> {
+ std::size_t operator () (const AssemblyFile& f) const {
+ const std::size_t h1 = std::hash<std::string>{}(f.noExt);
+ const std::size_t h2 = std::hash<std::string>{}(f.ext);
+
+ return h1 ^ (h2 << 1);
+ }
+ };
}
-void AssembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList)
+void assembliesInDirectory(const std::vector<std::string>& directories, std::string& tpaList)
{
- std::map<std::string, std::string> assemblyList;
- std::map<std::string, std::string> 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<std::map<std::string, std::string>::iterator, bool> ret;
- ret = tmpList.insert(std::pair<std::string, std::string>(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<std::string, std::string>::iterator it;
- for (it = assemblyList.begin(); it != assemblyList.end(); it++)
- {
- tpaList += it->second + ':';
- }
- if (tpaList.back() == ':')
- {
- tpaList.pop_back();
- }
+ std::map<std::string, std::string> assemblyList;
+ std::map<std::string, std::string> 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<std::map<std::string, std::string>::iterator, bool> ret;
+ ret = tmpList.insert(std::pair<std::string, std::string>(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<std::string, std::string>::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<std::string> 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<std::string> 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
```
-----------------------------
-| Tizen.Runtime.Coreclr.dll |
+| Tizen.Runtime.dll |
------------+---------------+
| | libcoreclr.so |
| +---------------+
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<string> _dllDirectories = new SortedSet<string>();
- private SortedSet<string> _nativeDirectories = new SortedSet<string>();
-
- private HashSet<FileInfo> _assemblyCache = new HashSet<FileInfo>();
+ private static readonly string[] Suffixes = new string[] { NativeDllAssemblySuffix, DllAssemblySuffix, ExeAssemblySuffix };
+ private SortedSet<string> DllDirectoriesSet = new SortedSet<string>();
+ private SortedSet<string> NativeDirectoriesSet = new SortedSet<string>();
+ private HashSet<FileInfo> AssemblyCacheSet = new HashSet<FileInfo>();
public AssemblyLoader()
{
public IEnumerable<string> DllDirectories
{
- get { return _dllDirectories; }
+ get { return DllDirectoriesSet; }
}
public IEnumerable<string> 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);
}
}
}
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);
}
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)
{
{
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);
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 =
{
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)
{
PrintException(e);
return false;
}
+
return true;
}
{
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
{
}
}
- public static AssemblyLoader CurrentAssemblyLoaderContext
+ private static void PrintException(Exception exception)
{
- get;
- private set;
+ while (exception != null)
+ {
+ ALog.Debug(exception.ToString());
+ exception = exception.InnerException;
+ }
}
}
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);
}
}
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="14.0" InitialTargets="CheckConfig" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-
- <PropertyGroup>
- <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
- <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <OutputType>library</OutputType>
- <AssemblyName>Tizen.Runtime.Coreclr</AssemblyName>
- </PropertyGroup>
-
- <PropertyGroup>
- <TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
- <TargetFrameworkVersion>v1.5</TargetFrameworkVersion>
- <NuGetTargetMoniker>.NETStandard,Version=v1.5</NuGetTargetMoniker>
- <AddAdditionalExplicitAssemblyReferences>false</AddAdditionalExplicitAssemblyReferences>
- <NoStdLib>true</NoStdLib>
- <NoWarn>$(NoWarn);1701;1702</NoWarn>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)' == 'Debug'">
- <DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <OutputPath>bin/</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
- </PropertyGroup>
-
- <PropertyGroup Condition=" '$(Configuration)' == 'Release'">
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin/</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
- </PropertyGroup>
-
-<!-- Roslyn Not Support Assembly Signing yet.
- <PropertyGroup>
- <SignAssembly>true</SignAssembly>
- <AssemblyOriginatorKeyFile>Tizen.Runtime.snk</AssemblyOriginatorKeyFile>
- </PropertyGroup>
--->
-
- <PropertyGroup>
- <DefineConstants Condition=" '$(CLOG)' != '' ">$(DefineConstants);CLOG</DefineConstants>
- </PropertyGroup>
-
- <ItemGroup>
- <Compile Include="Tizen.Runtime.Coreclr/AssemblyManager.cs" />
- <Compile Include="Tizen.Runtime.Coreclr/AssemblyLoader.cs" />
- <Compile Include="Tizen.Runtime/Log.cs" />
- <Compile Include="Tizen.Runtime/DefaultConfigAttribute.cs" />
- </ItemGroup>
-
- <Target Name="CheckConfig">
- <Message Text="MSBuildProjectDirectory = $(MSBuildProjectDirectory)"/>
- </Target>
-
- <ItemGroup>
- <None Include="Tizen.Runtime.Coreclr.project.json" />
- </ItemGroup>
-
- <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-
- <PropertyGroup>
- <!-- https://github.com/dotnet/corefxlab/tree/master/samples/NetCoreSample and
- https://docs.microsoft.com/en-us/dotnet/articles/core/tutorials/target-dotnetcore-with-msbuild
- -->
- <!-- We don't use any of MSBuild's resolution logic for resolving the framework, so just set these two
- properties to any folder that exists to skip the GetReferenceAssemblyPaths task (not target) and
- to prevent it from outputting a warning (MSB3644).
- -->
- <_TargetFrameworkDirectories>$(MSBuildThisFileDirectory)</_TargetFrameworkDirectories>
- <_FullFrameworkReferenceAssemblyPaths>$(MSBuildThisFileDirectory)</_FullFrameworkReferenceAssemblyPaths>
- <AutoUnifyAssemblyReferences>true</AutoUnifyAssemblyReferences>
- </PropertyGroup>
-
- <Target Name="BeforeCompile">
- <ItemGroup>
- <AssemblyAttributes Include="DefaultConfigAttribute" Condition=" $(PreloadPath) != '' ">
- <_Parameter1>PreloadPath=$(PreloadPath)</_Parameter1>
- </AssemblyAttributes>
- </ItemGroup>
-
- <WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)"
- Language="C#"
- OutputDirectory="$(IntermediateOutputPath)"
- OutputFile="Config.cs">
- <Output TaskParameter="OutputFile" ItemName="Compile" />
- </WriteCodeFragment>
-
- </Target>
-</Project>
+++ /dev/null
-{
- "dependencies": {
- "NETStandard.Library": "1.6.0",
- "System.Runtime.Loader": "4.0.0"
- },
- "frameworks": {
- "netstandard1.5": {}
- }
-}
-
--- /dev/null
+<Project Sdk="Microsoft.NET.Sdk">
+
+ <PropertyGroup>
+ <TargetFramework>netstandard1.6</TargetFramework>
+ </PropertyGroup>
+
+ <ItemGroup>
+ <PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
+ </ItemGroup>
+
+</Project>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an AS IS BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-using System;
-using System.Collections.Generic;
-
-[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
-public class DefaultConfigAttribute : Attribute {
- public DefaultConfigAttribute() : this(string.Empty) {}
- public DefaultConfigAttribute(string txt)
- {
- int eq_pos = txt.IndexOf('=');
- if (eq_pos == -1)
- throw new FormatException("Config must be written like \"Key1=Value1\"");
-
- Key = txt.Substring(0, eq_pos).Trim();
- Value = txt.Substring(eq_pos+1).Trim();
- }
-
- public string Key { get; private set; }
- public string Value { get; private set; }
-}
-DRUNTIME_DIR=%{_runtime_dir} \
-DCROSSGEN_PATH=%{_device_api_dir}/crossgen \
%if %{use_managed_launcher}
- -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Coreclr.dll \
+ -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.dll \
%endif
-DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \
-DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \
make %{?jobs:-j%jobs} VERBOSE=1
-nuget restore Tizen.Runtime/Tizen.Runtime.Coreclr.project.json
-
-xbuild \
- /p:Configuration=%{_dotnet_build_conf} \
- Tizen.Runtime/Tizen.Runtime.Coreclr.csproj
+%dotnet_build Tizen.Runtime
%install
rm -rf %{buildroot}
%make_install
%if %{use_managed_launcher}
-install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Coreclr.dll %{buildroot}%{_bindir}
+install -p -m 644 Tizen.Runtime/bin/*/*/Tizen.Runtime.dll %{buildroot}%{_bindir}
%endif
mkdir -p %{buildroot}%{_native_lib_dir}
%caps(cap_mac_admin,cap_setgid=ei) %{_install_plugin_dir}/libui-application.so
%caps(cap_mac_admin,cap_setgid=ei) %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so
%if %{use_managed_launcher}
-%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll
+%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.dll
%endif
%files -n scd-launcher
+++ /dev/null
-#!/bin/sh
-
-#CoreFXRefPath=`readlink -e ../dlls/corefx_refs/`
-#TizenDeviceAPIPath=`readlink -e ../dlls/tizen_deviceapis/`
-CoreFXRefPath=`readlink -e ../dlls/desktop/`
-TizenDeviceAPIPath=`readlink -e ../dlls/tizen_deviceapis/`
-RoslynCscDir=/home/idkiller/work/runtime/roslyn/Binaries/Debug/csccore
-RoslynCscExe=csc
-
-RuntimeDir=/usr/share/dotnet/shared/Microsoft.NETCore.App/2.0.0
-TizenDeviceAPIDir=`readlink -e ../dlls/tizen_deviceapis/`
-PreloadPath=`readlink -e ./preloads`
-
-
-mkdir build
-cd build
-#xbuild /t:Clean ../Tizen.Runtime/Tizen.Runtime.csproj
-#xbuild /verbosity:diagnostic /p:CLOG=1 /p:ExternalCscPath=/home/idkiller/work/runtime/roslyn/Binaries/Debug/csccore/csc.exe /p:LauncherConfigPath=$LauncherConfigPath /p:CoreFXRefPath=$CoreFXRefPath /p:TizenDeviceAPIPath=$TizenDeviceAPIPath ../Tizen.Runtime/Tizen.Runtime.csproj
-#xbuild /p:CLOG=1 /p:ExternalCscDir=$RoslynCscDir /p:ExternalCscExe=$RoslynCscExe /p:LauncherConfigPath=$LauncherConfigPath /p:CoreFXRefPath=$CoreFXRefPath /p:TizenDeviceAPIPath=$TizenDeviceAPIPath /p:PreloadPath=$PreloadPath ../Tizen.Runtime/Tizen.Runtime.csproj
-#cp ../Tizen.Runtime/bin/Tizen.Runtime.* .
-
-cmake -DCMAKE_BUILD_TYPE=Debug -DNO_TIZEN=1 -DLAUNCHER_ASSEMBLY_PATH=Tizen.Runtime.exe -DDEVICE_API_DIR=$TizenDeviceAPIDir -DRUNTIME_DIR=$RuntimeDir ../NativeLauncher/
-make -j16