From: 최종헌/Common Platform Lab(SR)/Engineer/삼성전자 Date: Thu, 18 Jun 2020 04:10:33 +0000 (+0900) Subject: Check the native image with ildasm when using --ni* option of dotnettool (#167) X-Git-Tag: accepted/tizen/5.5/unified/20200623.152346~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=396cbe41dd69599c3b769a14a4839330b57baa72;p=platform%2Fcore%2Fdotnet%2Flauncher.git Check the native image with ildasm when using --ni* option of dotnettool (#167) Change-Id: I351c1c1978c6daa24a7cb2378ed3206df43c11eb --- diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 970bbb2..52ea3ef 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -404,13 +404,37 @@ static bool isCoreLibPrepared(DWORD flags) } } +static bool hasCoreLibNI() +{ + FILE *fp; + char buff[1024]; + std::string ildasm = concatPath(getRuntimeDir(), "ildasm"); + std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll"); + std::string cmd = ildasm + " " + coreLib + " | grep '\\.corflags'"; + fp = popen(cmd.c_str(), "r"); + if (fp != NULL) { + while (fgets(buff, sizeof(buff), fp) != NULL) { + buff[strlen(buff) - 1] = '\0'; + } + std::string corflag = replaceAll(buff, ".corflags", ""); + corflag.erase(std::remove(corflag.begin(), corflag.end(), ' '), corflag.end()); + // CorFlags.ILLibrary=0x00000004 (.ni.dll) + if (!strcmp(corflag.substr(0, 10).c_str(), "0x00000004")) { + pclose(fp); + return true; + } + pclose(fp); + } + return false; +} + static ni_error_e createCoreLibNI(DWORD flags) { 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 (!isFile(coreLibBackup)) { + if (!isFile(coreLibBackup) && !hasCoreLibNI()) { if (!crossgen(coreLib, std::string(), flags)) { if (rename(coreLib.c_str(), coreLibBackup.c_str())) { fprintf(stderr, "Failed to rename System.Private.CoreLib.dll\n"); @@ -690,8 +714,17 @@ void removeNIPlatform() std::string coreLib = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll"); std::string coreLibBackup = concatPath(getRuntimeDir(), "System.Private.CoreLib.dll.Backup"); - if (!isFile(coreLibBackup)) { - return; + if (hasCoreLibNI()) { + if (!isFile(coreLibBackup)) { + return; + } + + if (remove(coreLib.c_str())) { + fprintf(stderr, "Failed to remove System.Private.CoreLib native image file\n"); + } + if (rename(coreLibBackup.c_str(), coreLib.c_str())) { + fprintf(stderr, "Failed to rename System.Private.CoreLib.Backup to origin\n"); + } } #ifdef UNIQUE_DEFAULT_BASE_ADDR_SUPPORT @@ -702,14 +735,6 @@ void removeNIPlatform() } #endif - if (remove(coreLib.c_str())) { - fprintf(stderr, "Failed to remove System.Private.CoreLib native image file\n"); - } - - if (rename(coreLibBackup.c_str(), coreLib.c_str())) { - fprintf(stderr, "Failed to rename System.Private.CoreLib.Backup to origin\n"); - } - const std::string platformDirs[] = {getRuntimeDir(), getTizenFXDir()}; removeNIUnderDirs(platformDirs, 2);