Beispiel #1
0
#pragma warning disable 0618
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                string clrName = Path.GetFileNameWithoutExtension(module.FileName).ToLower();

                if (clrName != "clr" && clrName != "mscorwks" && clrName != "coreclr" && clrName != "mrt100_app" && clrName != "libcoreclr")
                {
                    continue;
                }

                ClrFlavor flavor;
                switch (clrName)
                {
                case "mrt100_app":
                    _native = module;
                    continue;

                case "libcoreclr":
                case "coreclr":
                    flavor = ClrFlavor.Core;
                    break;

                default:
                    flavor = ClrFlavor.Desktop;
                    break;
                }

                bool isLinux = clrName == "libcoreclr";

                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), DacInfo.GetDacFileName(flavor, Architecture));

                if (isLinux)
                {
                    dacLocation = Path.ChangeExtension(dacLocation, ".so");
                }

                if (isLinux)
                {
                    if (!File.Exists(dacLocation))
                    {
                        dacLocation = Path.GetFileName(dacLocation);
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version         = module.Version;
                string      dacAgnosticName = DacInfo.GetDacRequestFileName(flavor, Architecture, Architecture, version);
                string      dacFileName     = DacInfo.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version);

                DacInfo dacInfo = new DacInfo(_dataReader, dacAgnosticName, Architecture)
                {
                    FileSize  = module.FileSize,
                    TimeStamp = module.TimeStamp,
                    FileName  = dacFileName,
                    Version   = module.Version
                };

                module.IsRuntime = true; //strange logic here (originally from the ClrInfo constructor)

                versions.Add(new ClrInfo(this, flavor, module, dacInfo, dacLocation));
            }

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }
Beispiel #2
0
#pragma warning disable 0618
        private ClrInfo[] InitVersions()
        {
            List <ClrInfo> versions = new List <ClrInfo>();

            foreach (ModuleInfo module in EnumerateModules())
            {
                string clrName = Path.GetFileNameWithoutExtension(module.FileName).ToLower();

                if (clrName != "clr" && clrName != "mscorwks" && clrName != "coreclr" && clrName != "mrt100_app" && clrName != "libcoreclr")
                {
                    continue;
                }

                ClrFlavor flavor;
                switch (clrName)
                {
                case "mrt100_app":
                    _native = module;
                    continue;

                case "libcoreclr":
                case "coreclr":
                    flavor = ClrFlavor.Core;
                    break;

                default:
                    flavor = ClrFlavor.Desktop;
                    break;
                }

                bool isLinux = clrName == "libcoreclr";

                const string LinuxDacFileName = "libmscordaccore.so";

                string dacLocation = Path.Combine(Path.GetDirectoryName(module.FileName), isLinux ? LinuxDacFileName : DacInfo.GetDacFileName(flavor, Architecture));

                if (isLinux)
                {
                    if (File.Exists(dacLocation))
                    {
                        // Works around issue https://github.com/dotnet/coreclr/issues/20205
                        int    processId     = Process.GetCurrentProcess().Id;
                        string tempDirectory = Path.Combine(Path.GetTempPath(), "clrmd" + processId.ToString());
                        Directory.CreateDirectory(tempDirectory);

                        string symlink = Path.Combine(tempDirectory, LinuxDacFileName);
                        if (LinuxFunctions.symlink(dacLocation, symlink) == 0)
                        {
                            dacLocation = symlink;
                        }
                    }
                    else
                    {
                        dacLocation = LinuxDacFileName;
                    }
                }
                else if (!File.Exists(dacLocation) || !PlatformFunctions.IsEqualFileVersion(dacLocation, module.Version))
                {
                    dacLocation = null;
                }

                VersionInfo version = module.Version;
                string      dacAgnosticName;
                string      dacFileName;
                if (isLinux)
                {
                    // Linux never has a "long" named DAC
                    dacAgnosticName = LinuxDacFileName;
                    dacFileName     = LinuxDacFileName;
                }
                else
                {
                    dacAgnosticName = DacInfo.GetDacRequestFileName(flavor, Architecture, Architecture, version);
                    dacFileName     = DacInfo.GetDacRequestFileName(flavor, IntPtr.Size == 4 ? Architecture.X86 : Architecture.Amd64, Architecture, version);
                }

                DacInfo dacInfo = new DacInfo(_dataReader, dacAgnosticName, Architecture)
                {
                    FileSize  = module.FileSize,
                    TimeStamp = module.TimeStamp,
                    FileName  = dacFileName,
                    Version   = module.Version
                };

                module.IsRuntime = true; //strange logic here (originally from the ClrInfo constructor)

                versions.Add(new ClrInfo(this, flavor, module, dacInfo, dacLocation));
            }

            ClrInfo[] result = versions.ToArray();
            Array.Sort(result);
            return(result);
        }