Keep api for backward-compatibility and code clean-up (#82)
author조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>
Wed, 17 Jul 2019 22:36:23 +0000 (07:36 +0900)
committerGitHub Enterprise <noreply-CODE@samsung.com>
Wed, 17 Jul 2019 22:36:23 +0000 (07:36 +0900)
"ni-common.h" contains exposed API set. That APIs already used in VD tools
So, the interface should not be changed for compatibility.

And the parameter "doGenUniqueBaseSystem" can be removed.
We decided to apply the base address to the TPA dll only.
So, we can decied whether applying the base address or not with TPA list checking.

NativeLauncher/inc/ni_common.h
NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
NativeLauncher/tool/dotnettool.cc
NativeLauncher/tool/ni_common.cc
NativeLauncher/tool/nitool.cc
NativeLauncher/tool/tac_common.cc

index 9483ece..3f3de82 100644 (file)
@@ -56,26 +56,24 @@ void finalizeNICommon();
 /**
  * @brief create native images (NI file) for Platform DLLs (.NETCore + TizenFX)
  */
-void createNiPlatform(bool enableR2R, bool doGenUniqueBaseSystem);
+void createNiPlatform(bool enableR2R);
 
 /**
  * @brief create native image for specific dll with file path.
  * @param[i] dllPath file path to generate native image
  * @param[i] enableR2R enable ready-to-run mode
- * @param[i] doGenUniqueBaseSystem flag whether to generate unique default base address
  * @return ni_error_e
  */
-ni_error_e createNiDll(const std::string& dllPath, bool enableR2R, bool doGenUniqueBaseSystem);
+ni_error_e createNiDll(const std::string& dllPath, bool enableR2R);
 
 /**
  * @brief create native images with files under specific directory.
  * @param[i] rootPaths directories whicn contains DLLs
  * @param[i] count number of rootPath
  * @param[i] enableR2R enable ready-to-run mode
- * @param[i] doGenUniqueBaseSystem flag whether to generate unique default base address
  * @param[i] isAppNI if you want to create ni files under nativeImage directory, set it true
  */
-void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool doGenUniqueBaseSystem, bool isAppNI = false);
+void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool isAppNI = false);
 
 /**
  * @brief create native images for specific package. (All DLLs)
index 494dddc..af9c323 100644 (file)
@@ -83,7 +83,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
                                        std::string originPath = bf::read_symlink(symPath).string();
                                        std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
                                        if (!bf::exists(originNiPath)) {
-                                               if(createNiDll(originPath, false, false) != NI_ERROR_NONE) {
+                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
                                                        _ERR("Failed to create NI file [%s]", originPath.c_str());
                                                        return -1;
                                                }
index 76ed563..a6d3e01 100644 (file)
@@ -88,8 +88,6 @@ int main(int argc, char* argv[])
        bool disableTacMode = false;
        bool enableTacMode = false;
 
-       bool doGenUniqueBaseSystem = true;
-
        NiCommonOption option = {std::string(), std::string(), std::string()};
        if (initNICommon(&option) != NI_ERROR_NONE) {
                fprintf(stderr, "Fail to initialize NI Common\n");
@@ -104,7 +102,7 @@ int main(int argc, char* argv[])
                help(argv[0]);
                return 0;
        } else if (cmdOptionExists(argv, argv+argc, "--ni-system")) {
-               createNiPlatform(enableR2R, doGenUniqueBaseSystem);
+               createNiPlatform(enableR2R);
                return 0;
        } else if (cmdOptionExists(argv, argv+argc, "--ni-dll")) {
                dllMode = true;
@@ -210,7 +208,7 @@ int main(int argc, char* argv[])
                // donot return error code for generation failure.
                // we have to run crossgen for all input dlls.
                for (const std::string dll : args) {
-                       int ret = createNiDll(dll, enableR2R, doGenUniqueBaseSystem);
+                       int ret = createNiDll(dll, enableR2R);
                        if (ret == NI_ERROR_ALREADY_EXIST) {
                                // skip for already exist case
                        } else if (ret != NI_ERROR_NONE) {
@@ -218,7 +216,7 @@ int main(int argc, char* argv[])
                        }
                }
        } else if (dirMode) {
-               createNiUnderDirs(args.data(), args.size(), enableR2R, doGenUniqueBaseSystem);
+               createNiUnderDirs(args.data(), args.size(), enableR2R);
        } else if (disableTacMode) {
                for (const std::string pkg : args) {
                        int ret = disableTACPackage(pkg);
index 309f1cd..5c29aa9 100644 (file)
@@ -182,14 +182,8 @@ static uintptr_t getNextBaseAddr()
 }
 
 // Save base address of system ni image to file
-static void updateBaseAddrFile(const std::string &dllPath, uintptr_t baseAddr)
+static void updateBaseAddrFile(const std::string &absNiPath, uintptr_t baseAddr)
 {
-       std::string absNiPath = getNiFilePath(dllPath);
-       if (absNiPath.empty()) {
-               fprintf(stderr, "Failed to get ni file path for %s\n", dllPath.c_str());
-               return;
-       }
-
        uintptr_t niSize = getFileSize(absNiPath);
        if (niSize == 0) {
                fprintf(stderr, "File %s doesn't exist\n", absNiPath.c_str());
@@ -221,7 +215,7 @@ static bool isTPADll(const std::string &dllPath)
 #endif
 
 // baseAddr should be checked in file before getting here
-static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, uintptr_t baseAddr = 0, bool isAppNI = false)
+static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, bool isAppNI = false)
 {
        if (!isFileExist(dllPath)) {
                fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str());
@@ -249,6 +243,14 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                absNiPath = getAppNIPath(absNiPath);
        }
 
+#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
+       uintptr_t baseAddr = 0;
+
+       if (isTPADll(dllPath)) {
+               baseAddr = getNextBaseAddr();
+       }
+#endif
+
        pid_t pid = fork();
        if (pid == -1)
                return NI_ERROR_UNKNOWN;
@@ -261,6 +263,11 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
                        // niEixst() return false for System.Private.Corelib.dll
                        if (isFileExist(absNiPath)) {
                                updateAssemblyInfo(absDllPath, absNiPath);
+#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
+                               if (baseAddr != 0) {
+                                       updateBaseAddrFile(absNiPath, baseAddr);
+                               }
+#endif
                                return NI_ERROR_NONE;
                        } else {
                                fprintf(stderr, "Fail to create native image for %s\n", dllPath.c_str());
@@ -352,28 +359,15 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
        return 0;
 }
 
-static void createCoreLibNI(bool enableR2R, bool doGenUniqueBaseSystem)
+static void createCoreLibNI(bool enableR2R)
 {
        std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll");
        std::string niCoreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.ni.dll");
        std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup");
 
        if (!isFileExist(coreLibBackup)) {
-               uintptr_t baseAddr = 0;
-
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-               if (doGenUniqueBaseSystem) {
-                       baseAddr = getNextBaseAddr();
-               }
-#endif
-
-               if (!crossgen(coreLib, std::string(), enableR2R, baseAddr)) {
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-                       if (doGenUniqueBaseSystem && baseAddr != 0) {
-                               updateBaseAddrFile(coreLib, baseAddr);
-                       }
-#endif
 
+               if (!crossgen(coreLib, std::string(), enableR2R)) {
                        if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
                                fprintf(stderr, "Failed to rename System.Private.CoreLib.dll\n");
                        }
@@ -426,43 +420,29 @@ void finalizeNICommon()
 }
 
 
-void createNiPlatform(bool enableR2R, bool doGenUniqueBaseSystem)
+void createNiPlatform(bool enableR2R)
 {
        const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()};
-       createNiUnderDirs(platformDirs, 2, enableR2R, doGenUniqueBaseSystem);
+       createNiUnderDirs(platformDirs, 2, enableR2R);
 }
 
-ni_error_e createNiDll(const std::string& dllPath, bool enableR2R, bool doGenUniqueBaseSystem)
+ni_error_e createNiDll(const std::string& dllPath, bool enableR2R)
 {
-       createCoreLibNI(enableR2R, doGenUniqueBaseSystem);
+       createCoreLibNI(enableR2R);
        // System.Private.CoreLib.dll is generated in the createCoreLibNI function.
        // Skip if input dll is System.Private.CoreLib.dll
        if (dllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
                return NI_ERROR_NONE;
        }
 
-       uintptr_t baseAddr = 0;
-
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-       if (doGenUniqueBaseSystem && isTPADll(dllPath)) {
-               baseAddr = getNextBaseAddr();
-       }
-#endif
-
-       ni_error_e status = crossgen(dllPath, std::string(), enableR2R, baseAddr);
-
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-       if (doGenUniqueBaseSystem && baseAddr != 0) {
-               updateBaseAddrFile(dllPath, baseAddr);
-       }
-#endif
+       ni_error_e status = crossgen(dllPath, std::string(), enableR2R);
 
        return status;
 }
 
-void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool doGenUniqueBaseSystem, bool isAppNI)
+void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool isAppNI)
 {
-       createCoreLibNI(enableR2R, doGenUniqueBaseSystem);
+       createCoreLibNI(enableR2R);
 
        std::string appPaths;
        for (int i = 0; i < count; i++) {
@@ -473,22 +453,8 @@ void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R,
        if (appPaths.back() == ':')
                appPaths.pop_back();
 
-       auto convert = [&appPaths, enableR2R, doGenUniqueBaseSystem, isAppNI](const std::string& path, const char* name) {
-               uintptr_t baseAddr = 0;
-
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-               if (doGenUniqueBaseSystem && !isAppNI && isTPADll(path)) {
-                       baseAddr = getNextBaseAddr();
-               }
-#endif
-
-               if (!crossgen(path, appPaths.c_str(), enableR2R, baseAddr, isAppNI)) {
-#ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT
-                       if (doGenUniqueBaseSystem && !isAppNI && baseAddr != 0) {
-                               updateBaseAddrFile(path, baseAddr);
-                       }
-#endif
-
+       auto convert = [&appPaths, enableR2R, isAppNI](const std::string& path, const char* name) {
+               if (!crossgen(path, appPaths.c_str(), enableR2R, isAppNI)) {
                        waitInterval();
                }
        };
@@ -510,7 +476,7 @@ ni_error_e createNiUnderPkgRoot(const std::string& pkgId, bool enableR2R)
        std::string tacDir = concatPath(binDir, TAC_SYMLINK_SUB_DIR);
        std::string paths[] = {binDir, libDir, tacDir};
 
-       createNiUnderDirs(paths, 3, enableR2R, false, true);
+       createNiUnderDirs(paths, 3, enableR2R, true);
 
        return NI_ERROR_NONE;
 }
@@ -533,7 +499,7 @@ ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string&
                                std::string originPath = bf::read_symlink(dllPath).string();
                                std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
                                if (!bf::exists(originNiPath)) {
-                                       if(createNiDll(originPath, false, false) != NI_ERROR_NONE) {
+                                       if(createNiDll(originPath, false) != NI_ERROR_NONE) {
                                                fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
                                                return NI_ERROR_UNKNOWN;
                                        }
@@ -548,7 +514,7 @@ ni_error_e createNiDllUnderPkgRoot(const std::string& pkgId, const std::string&
                }
                return NI_ERROR_NONE;
        } else {
-               return crossgen(dllPath, paths, enableR2R, 0, true);
+               return crossgen(dllPath, paths, enableR2R, true);
        }
 }
 
index 53c5016..1b35305 100644 (file)
@@ -51,8 +51,6 @@ int main(int argc, char* argv[])
        bool enableR2R = false;
        bool pkgDllMode = false;
 
-       bool doGenUniqueBaseSystem = true;
-
        NiCommonOption option = {std::string(), std::string(), std::string()};
        if (initNICommon(&option) != NI_ERROR_NONE) {
                fprintf(stderr, "Fail to initialize NI Common\n");
@@ -67,7 +65,7 @@ int main(int argc, char* argv[])
                help(argv[0]);
                return 0;
        } else if (cmdOptionExists(argv, argv+argc, "--system")) {
-               createNiPlatform(enableR2R, doGenUniqueBaseSystem);
+               createNiPlatform(enableR2R);
                return 0;
        } else if (cmdOptionExists(argv, argv+argc, "--dll")) {
                dllMode = true;
@@ -140,7 +138,7 @@ int main(int argc, char* argv[])
                // donot return error code for generation failure.
                // we have to run crossgen for all input dlls.
                for (const std::string dll : args) {
-                       int ret = createNiDll(dll, enableR2R, doGenUniqueBaseSystem);
+                       int ret = createNiDll(dll, enableR2R);
                        if (ret == NI_ERROR_ALREADY_EXIST) {
                                // skip for already exist case
                        } else if (ret != NI_ERROR_NONE) {
@@ -148,7 +146,7 @@ int main(int argc, char* argv[])
                        }
                }
        } else if (dirMode) {
-               createNiUnderDirs(args.data(), args.size(), enableR2R, doGenUniqueBaseSystem);
+               createNiUnderDirs(args.data(), args.size(), enableR2R);
        }
 
        return 0;
index 3c401ec..185aaf0 100644 (file)
@@ -288,7 +288,7 @@ tac_error_e createTACPackage(const std::string& pkgId)
                                        std::string originPath = bf::read_symlink(symPath).string();
                                        std::string originNiPath = originPath.substr(0, originPath.rfind(".dll")) + ".ni.dll";
                                        if (!bf::exists(originNiPath)) {
-                                               if(createNiDll(originPath, false, false) != NI_ERROR_NONE) {
+                                               if(createNiDll(originPath, false) != NI_ERROR_NONE) {
                                                        fprintf(stderr, "Failed to create NI file [%s]\n", originPath.c_str());
                                                        return TAC_ERROR_UNKNOWN;
                                                }
@@ -322,7 +322,7 @@ tac_error_e regenerateTAC()
                        strstr(path.c_str(), TAC_APP_LIST_RESTORE_DB) != NULL ||
                        strstr(path.c_str(), TAC_SHA_256_INFO) != NULL)
                        return;
-               if(createNiDll(path, false, false) != NI_ERROR_NONE) {
+               if(createNiDll(path, false) != NI_ERROR_NONE) {
                        fprintf(stderr, "Failed to create NI file [%s]\n", path.c_str());
                        return;
                }