SET(DOTNET_LAUNCHER_UTIL "dotnet_launcher_util")
SET(${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES
- util/utils.cc
- util/plugin_manager.cc
+ tool/r2r_checker.cc
util/path_manager.cc
+ util/plugin_manager.cc
+ util/utils.cc
)
ADD_LIBRARY(${DOTNET_LAUNCHER_UTIL} SHARED ${${DOTNET_LAUNCHER_UTIL}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER_UTIL} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
+TARGET_INCLUDE_DIRECTORIES(${DOTNET_LAUNCHER_UTIL} PRIVATE ${RUNTIME_DIR}/src/ ${RUNTIME_DIR}/src/pal ${RUNTIME_DIR}/src/pal/inc ${RUNTIME_DIR}/src/pal/inc/rt)
TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER_UTIL} ${${PROJECT_NAME}_LDFLAGS} "-ldl" boost_filesystem boost_system)
SET(DOTNET_LAUNCHER_CORE "dotnet_launcher_core")
SET(NI_COMMON "ni_common")
SET(${NI_COMMON}_SOURCE_FILES
tool/ni_common.cc
- tool/r2r_checker.cc
)
ADD_LIBRARY(${NI_COMMON} SHARED ${${NI_COMMON}_SOURCE_FILES})
SET_TARGET_PROPERTIES(${NI_COMMON} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB})
-TARGET_INCLUDE_DIRECTORIES(${NI_COMMON} PRIVATE ${RUNTIME_DIR}/src/ ${RUNTIME_DIR}/src/pal ${RUNTIME_DIR}/src/pal/inc ${RUNTIME_DIR}/src/pal/inc/rt)
TARGET_LINK_LIBRARIES(${NI_COMMON} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON})
SET(PROFILE_COMMON "profile_common")
#include "log.h"
#include "launcher_env.h"
-const char* __coreclr_lib = "/usr/share/dotnet.tizen/netcoreapp/libcoreclr.so";
-const char* __dotnet_loader = "/usr/bin/dotnet-loader";
+static const char* __coreclr_lib = "/usr/share/dotnet.tizen/netcoreapp/libcoreclr.so";
+static const char* __dotnet_loader = "/usr/bin/dotnet-loader";
typedef int (*coreclr_preload_assembly_ptr)(const char* assemblyPath);
typedef int (*launcher_real_main_ptr)(int argc, char *argv[]);
/**
* @brief resolve bin/runtimes directory if exist.
- * @return 0 if success, otherwise -1
*/
-int resolveAllApps();
+void resolveAllApps();
#endif /* __MULTI_TAEGET_RESOLVER_H__ */
#include <string>
-bool isR2RImage(std::string fileName);
-unsigned int getSizeOfImage(std::string fileName);
+/**
+ * @brief check the file is r2r image or not.
+ * @param[in] file name
+ * @return return true when the file is r2r image.
+ */
+bool isR2RImage(const std::string& fileName);
+
+unsigned int getSizeOfImage(const std::string& fileName);
#endif /* __R2R_CHECKER_H__ */
bool isManagedAssembly(const std::string& filePath);
/**
- * @brief check the file is native image or not.
- * @param[in] file path
- * @return return true when the file is native image.
- */
-bool isNativeImage(const std::string& filePath);
-
-/**
* @brief Resolve assembly files from directories and append their paths to the given list.
* @remark If a native image exists for an assembly in the same directory, it will be used.
* If multiple assemblies of the same name exist, the first one will be used.
typedef struct _xmlDoc xmlDoc;
typedef xmlDoc* xmlDocPtr;
-bool pluginInstalled = false;
+static bool pluginInstalled = false;
extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId)
{
#endif
#define LOG_TAG "DOTNET_INSTALLER_PLUGIN"
-bool aotPluginInstalled = false;
-bool aotPluginFinished = false;
+static bool aotPluginInstalled = false;
+static bool aotPluginFinished = false;
extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
{
#include "coreclr_host.h"
#include "log.h"
#include "utils.h"
+#include "r2r_checker.h"
static const char* CLR_PATH = "/usr/share/dotnet.tizen/netcoreapp";
static const char* TOOL_PATH = "/home/owner/share/.dotnet/tools";
_SERR("Unknown option %s.", argv[0]);
DisplayUsage();
return -1;
- } else if (isManagedAssembly(arg) || isNativeImage(arg)) {
+ } else if (isManagedAssembly(arg) || isR2RImage(arg)) {
if (!isFile(arg)) {
_SERR("The specified file does not exist.");
return -1;
#define _unused(x) ((void)(x))
-struct sigaction sig_abrt_new;
-struct sigaction sig_abrt_old;
+static struct sigaction sig_abrt_new;
+static struct sigaction sig_abrt_old;
static bool checkOnSigabrt = false;
static bool checkOnTerminate = false;
}
//sh-3.2# dotnettool --resolve-all-app
else if (cmd == "--resolve-all-app") {
- int ret = resolveAllApps();
- if (ret != 0) {
- _SERR("Failed to remove unused multi-targeting files");
- }
+ resolveAllApps();
}
//sh-3.2# dotnettool --rm-app-profile [pkgId] [pkgId] ...
else if (cmd == "--rm-app-profile") {
return 0;
}
-int resolveAllApps()
+void resolveAllApps()
{
int ret = 0;
pkgmgrinfo_appinfo_filter_h handle;
ret = pkgmgrinfo_appinfo_filter_create(&handle);
if (ret != PMINFO_R_OK) {
- return -1;
+ _SERR("Failed to create pkgmgrinfo");
+ return;
}
ret = pkgmgrinfo_appinfo_filter_add_string(handle, PMINFO_APPINFO_PROP_APP_TYPE, "dotnet");
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_filter_destroy(handle);
- return -1;
+ _SERR("Failed to add pkgmgrinfo filter app type");
+ return;
}
ret = pkgmgrinfo_appinfo_filter_foreach_appinfo(handle, appResolveCb, NULL);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_filter_destroy(handle);
- return -1;
+ _SERR("Failed to remove unused multi-targeting files");
+ return;
}
pkgmgrinfo_appinfo_filter_destroy(handle);
-
- return 0;
}
return true;
}
-static std::string getNIFilePath(const std::string& dllPath)
+static std::string getNIFilePath(const std::string& absDllPath, NIOption* opt)
{
+ std::string dllPath = absDllPath;
+ if (opt->flags & NI_FLAGS_APPNI) {
+ std::string niDirPath;
+ std::string niTmpDirPath;
+ std::string prevPath;
+
+ prevPath = getBaseName(absDllPath);
+ niDirPath = concatPath(prevPath, APP_NI_SUB_DIR);
+ niTmpDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR);
+
+ if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) {
+ niTmpDirPath = replaceAll(niTmpDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
+ niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
+ _INFO("App is installed in RO area. Change NI path to RW area(%s).", niTmpDirPath.c_str());
+ }
+
+ if (!isDirectory(niDirPath)) {
+ if (!createDirsAndCopyOwnerShip(niTmpDirPath, prevPath)) {
+ niTmpDirPath = prevPath;
+ _SERR("fail to create dir (%s)", niTmpDirPath.c_str());
+ }
+ dllPath = concatPath(niTmpDirPath, getFileName(absDllPath));
+ } else {
+ dllPath = concatPath(niDirPath, getFileName(absDllPath));
+ }
+ }
+
size_t index = dllPath.find_last_of(".");
if (index == std::string::npos) {
_SERR("File doesnot contain extension. fail to get NI file name");
return niPath;
}
-static std::string getAppNIFilePath(const std::string& absDllPath, NIOption* opt)
+static bool checkNIExistence(const std::string& absDllPath, NIOption* opt)
{
- std::string niDirPath;
- std::string prevPath;
-
- prevPath = getBaseName(absDllPath);
- niDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR);
-
- if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) {
- niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
- _SERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str());
- _ERR("App is installed in RO area. Change NI path to RW area(%s).", niDirPath.c_str());
- }
-
- if (!isDirectory(niDirPath)) {
- if (!createDirsAndCopyOwnerShip(niDirPath, prevPath)) {
- niDirPath = prevPath;
- _SERR("fail to create dir (%s)", niDirPath.c_str());
- }
- }
-
- return getNIFilePath(concatPath(niDirPath, getFileName(absDllPath)));
-}
-
-static bool checkNIExistence(const std::string& absDllPath)
-{
- std::string absNIPath = getNIFilePath(absDllPath);
+ std::string absNIPath = getNIFilePath(absDllPath, opt);
if (absNIPath.empty()) {
return false;
}
return false;
}
-static bool checkAppNIExistence(const std::string& absDllPath, NIOption* opt)
-{
- std::string absNIPath = getAppNIFilePath(absDllPath, opt);
- if (absNIPath.empty()) {
- return false;
- }
-
- if (isFile(absNIPath)) {
- return true;
- }
-
- return false;
-}
-
static bool checkDllExistInDir(const std::string& path)
{
bool ret = false;
auto func = [&ret](const std::string& f_path, const std::string& f_name) {
- if (isManagedAssembly(f_name) || isNativeImage(f_name)) {
+ if (isManagedAssembly(f_name) || isR2RImage(f_name)) {
ret = true;
}
};
}
/*
- * Get the list of managed files in the specific directory
- * Absolute paths of managed files are stored at the result list.
- * If native image already exist in the same directory, managed file is ignored.
- */
-static ni_error_e getTargetDllList(const std::string& path, std::vector<std::string>& fileList)
-{
- if (!isDirectory(path)) {
- return NI_ERROR_INVALID_PARAMETER;
- }
-
- auto func = [&fileList](const std::string& f_path, const std::string& f_name) {
- if (isManagedAssembly(f_path) && !checkNIExistence(f_path)) {
- fileList.push_back(getAbsolutePath(f_path));
- }
- };
-
- scanFilesInDirectory(path, func, 0);
-
- return NI_ERROR_NONE;
-}
-
-/*
- * Get the list of managed files in the specific directory of Application
+ * Get the list of managed files in the specific directory (of Application)
* Absolute paths of managed files are stored at the result list.
- * If native image already exist in the .native_image directory, managed file is ignored.
- *
+ * If native image already exist in the (same / .native_image) directory, managed file is ignored.
*/
-static ni_error_e getAppTargetDllList(const std::string& path, std::vector<std::string>& fileList, NIOption *opt)
+static ni_error_e getTargetDllList(const std::string& path, std::vector<std::string>& fileList, NIOption *opt)
{
if (!isDirectory(path)) {
return NI_ERROR_INVALID_PARAMETER;
}
auto func = [&fileList, opt](const std::string& f_path, const std::string& f_name) {
- if (isManagedAssembly(f_path) && !checkAppNIExistence(f_path, opt)) {
+ if (isManagedAssembly(f_path) && !checkNIExistence(f_path, opt)) {
fileList.push_back(getAbsolutePath(f_path));
}
};
// if AppNI then move ni.dll file to .native_image and copy pdb to .native_image
if (opt->flags & NI_FLAGS_APPNI) {
- outFile = getAppNIFilePath(dllPath, opt);
+ outFile = getNIFilePath(dllPath, opt);
makePdbSymlinkForNI(dllPath, outFile);
if (opt->flags & NI_FLAGS_INPUT_BUBBLE && opt->flags & NI_FLAGS_NO_PIPELINE) {
{
for (auto& dllPath : dllList) {
std::string niPath;
- if (opt->flags & NI_FLAGS_APPNI) {
- niPath = getAppNIFilePath(dllPath, opt);
- } else {
- niPath = getNIFilePath(dllPath);
- }
+ niPath = getNIFilePath(dllPath, opt);
+
#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
uintptr_t baseAddr = 0;
if (isTPADll(dllPath)) {
if (isDirectory(niTmpPath)) {
if (rename(niTmpPath.c_str(), niPath.c_str())) {
_SERR("Fail to rename from .native_image_tmp to .native_image");
+ } else {
+ _SOUT("Success to rename from %s to %s", niTmpPath.c_str(), niPath.c_str());
}
}
}
if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
for (auto &dll : dllList) {
std::string tmpFile;
- std::string niFile;
- if (opt->flags & NI_FLAGS_APPNI) {
- niFile = getAppNIFilePath(dll, opt);
- } else {
- niFile = getNIFilePath(dll);
- }
+ std::string niFile = getNIFilePath(dll, opt);
tmpFile = niFile + ".tmp";
if (exist(tmpFile)) {
return NI_ERROR_NO_SUCH_FILE;
}
+ if (checkNIExistence(dllFile, opt)) {
+ _SERR("Native image file is already exist : %s", dllFile.c_str());
+ return NI_ERROR_ALREADY_EXIST;
+ }
+
if (!isManagedAssembly(dllFile)) {
_SERR("Failed. Input parameter is not managed dll (%s)\n", dllFile.c_str());
return NI_ERROR_INVALID_PARAMETER;
}
- if (checkNIExistence(dllFile)) {
- _SERR("Native image file is already exist : %s", dllFile.c_str());
- return NI_ERROR_ALREADY_EXIST;
- }
-
std::vector<std::string> dllList;
dllList.push_back(getAbsolutePath(dllFile));
return doAOTList(dllList, refPaths, opt);
// get managed file list from targetPath
std::vector<std::string> dllList;
- ret = getTargetDllList(targetPath, dllList);
+ ret = getTargetDllList(targetPath, dllList, opt);
if (ret != NI_ERROR_NONE) {
return ret;
}
std::vector<std::string> niList;
for (auto &dll : dllList) {
- if (!checkNIExistence(dll)) {
+ if (!checkNIExistence(dll, opt)) {
needNIList.push_back(dll);
}
- niList.push_back(getNIFilePath(dll));
+ niList.push_back(getNIFilePath(dll, opt));
}
if (!needNIList.empty()) {
if (ret != NI_ERROR_NONE) {
return ret;
}
- } else if (opt->flags & NI_FLAGS_APPNI) {
- ret = getAppTargetDllList(path, fileList, opt);
- if (ret != NI_ERROR_NONE) {
- return ret;
- }
} else {
- ret = getTargetDllList(path, fileList);
+ ret = getTargetDllList(path, fileList, opt);
if (ret != NI_ERROR_NONE) {
return ret;
}
void removeNIUnderDirs(const std::string& rootPaths)
{
auto convert = [](const std::string& path, const std::string& filename) {
- if (isNativeImage(path)) {
+ if (isR2RImage(path)) {
std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll");
if (exist(assemblyPath)) {
if (remove(path.c_str())) {
{
IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
if (!pNTHeaders) {
- _SERR("Invalid NT Header");
return false;
}
return false;
}
-bool isR2RImage(std::string fileName)
+bool isR2RImage(const std::string& fileName)
{
int fd;
struct stat sb;
if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) {
- _SERR("File Not Found: %s", fileName.c_str());
return false;
}
void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (pAddr == MAP_FAILED) {
- _SERR("Fail to Map File: %s", fileName.c_str());
close(fd);
return false;
}
return ret;
}
-unsigned int getSizeOfImage(std::string fileName)
+unsigned int getSizeOfImage(const std::string& fileName)
{
int fd;
struct stat sb;
if ((fd = open(fileName.c_str(), O_RDONLY)) == -1) {
- _SERR("File Not Found: %s", fileName.c_str());
return 0;
}
void* pAddr = mmap(NULL, sb.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (pAddr == MAP_FAILED) {
- _SERR("Fail to Map File: %s", fileName.c_str());
close(fd);
return 0;
}
IMAGE_NT_HEADERS* pNTHeaders = getNTHeaders(pAddr);
if (!pNTHeaders) {
- _SERR("Invalid NT Header");
munmap(pAddr, sb.st_size);
close(fd);
return 0;
#include "utils.h"
#include "tac_common.h"
#include "db_manager.h"
+#include "r2r_checker.h"
#ifdef LOG_TAG
#undef LOG_TAG
static sqlite3 *tac_db = NULL;
static sqlite3 *tlc_db = NULL;
-std::vector<std::string> restore_nuget;
-std::vector<std::string> restore_library;
+static std::vector<std::string> restore_nuget;
+static std::vector<std::string> restore_library;
static void cleanupDirectory()
{
std::string fileName = symlinkAssembly.path().filename().string();
if (isSymlinkFile(symPath)) {
std::string originPath = bf::read_symlink(symPath).string();
- if (!isNativeImage(symPath)) {
+ if (!isR2RImage(symPath)) {
std::string dllPath = concatPath(binDir, fileName);
if (!copyFile(originPath, dllPath)) {
_SERR("Failed to copy of %s", dllPath.c_str());
#undef __STR
#undef __XSTR
-std::vector<std::string> nugetPackagesAssembliesSha;
-std::vector<std::string> tacDB;
-std::vector<std::string> createDirectories;
-std::vector<std::string> createLibraries;
-std::vector<std::string> updateTac;
-tac_state tacState = TAC_STATE_NONE;
+static std::vector<std::string> nugetPackagesAssembliesSha;
+static std::vector<std::string> tacDB;
+static std::vector<std::string> createDirectories;
+static std::vector<std::string> createLibraries;
+static std::vector<std::string> updateTac;
+static tac_state tacState = TAC_STATE_NONE;
static sqlite3 *tac_db = NULL;
static sqlite3 *tlc_db = NULL;
-bool tacPluginInstalled = false;
-bool tacPluginFinished = false;
+static bool tacPluginInstalled = false;
+static bool tacPluginFinished = false;
static void createSHA256Info(std::string sha256Info, std::string nugetPackage)
{
static PluginFunc* __pluginFunc = NULL;
static void* __pluginLib;
-bool initializedPluginManager = false;
+static bool initializedPluginManager = false;
int initializePluginManager(const char* appType)
{
#include "log.h"
#include "utils.h"
#include "path_manager.h"
+#include "r2r_checker.h"
static bool iCompare(const std::string& a, int aOffset, const std::string& b, int bOffset, int length)
{
bool isManagedAssembly(const std::string& fileName)
{
- return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) && !isNativeImage(fileName);
-}
-
-bool isNativeImage(const std::string& fileName)
-{
- return iCompare(fileName, fileName.size()-7, ".ni", 0, 3);
+ return iCompare(fileName, fileName.size()-4, ".dll", 0, 4) && !isR2RImage(fileName);
}
std::string concatPath(const std::string& path1, const std::string& path2)
std::string token;
while (std::getline(ss, token, ':')) {
- out.push_back(token);
+ if (token != "") {
+ out.push_back(token);
+ }
}
}
std::unordered_map<std::string, std::string> assemPaths;
auto reader = [&assems, &assemPaths](const std::string& path, const std::string& filename) {
- if (isManagedAssembly(filename) || isNativeImage(filename)) {
+ if (isManagedAssembly(filename) || isR2RImage(filename)) {
std::string assem = getAssemblyNameFromPath(filename);
if (assemPaths.count(assem) == 0) {
assems.push_back(assem);
assemPaths[assem] = path;
- } else if (isManagedAssembly(assemPaths[assem]) && isNativeImage(filename)) {
+ } else if (isManagedAssembly(assemPaths[assem]) && isR2RImage(filename)) {
// Update only if a native image is found in the same directory.
// For example, if we have two directories = { X, Y } where X contains A.dll and
// Y contains both A.dll and A.ni.dll, always A.dll in X will be used.