Example #1
0
        private static string ConvertDotNetFrameworkArchitectureToProcessorArchitecture(Microsoft.Build.Utilities.DotNetFrameworkArchitecture architecture)
        {
            switch (architecture)
            {
            case Microsoft.Build.Utilities.DotNetFrameworkArchitecture.Current:
                return(ProcessorArchitecture.CurrentProcessArchitecture);

            case Microsoft.Build.Utilities.DotNetFrameworkArchitecture.Bitness32:
                return("x86");

            case Microsoft.Build.Utilities.DotNetFrameworkArchitecture.Bitness64:
            {
                NativeMethodsShared.SYSTEM_INFO lpSystemInfo = new NativeMethodsShared.SYSTEM_INFO();
                NativeMethodsShared.GetNativeSystemInfo(ref lpSystemInfo);
                ushort wProcessorArchitecture = lpSystemInfo.wProcessorArchitecture;
                switch (wProcessorArchitecture)
                {
                case 0:
                    return(null);

                case 6:
                    return("IA64");
                }
                if (wProcessorArchitecture != 9)
                {
                    return(null);
                }
                return("AMD64");
            }
            }
            ErrorUtilities.ThrowInternalErrorUnreachable();
            return(null);
        }
        /// <summary>
        /// We need a static constructor to retrieve the running ProcessorArchitecture that way we can
        /// Avoid using optimized code that will not run correctly on IA64 due to alignment issues
        /// </summary>
        static MSBuildNameIgnoreCaseComparer()
        {
            NativeMethodsShared.SYSTEM_INFO systemInfo = new NativeMethodsShared.SYSTEM_INFO();

            NativeMethodsShared.GetSystemInfo(ref systemInfo);

            s_runningProcessorArchitecture = systemInfo.wProcessorArchitecture;
        }
Example #3
0
        private static string GetCurrentProcessArchitecture()
        {
            string str    = null;
            IntPtr module = NativeMethodsShared.LoadLibrary("kernel32.dll");

            try
            {
                if (!(module != NativeMethodsShared.NullIntPtr))
                {
                    return(str);
                }
                IntPtr procAddress = NativeMethodsShared.GetProcAddress(module, "IsWow64Process");
                if (procAddress == NativeMethodsShared.NullIntPtr)
                {
                    return("x86");
                }
                IsWow64ProcessDelegate delegateForFunctionPointer = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(procAddress, typeof(IsWow64ProcessDelegate));
                bool flag = false;
                if (!delegateForFunctionPointer(Process.GetCurrentProcess().Handle, out flag))
                {
                    return(str);
                }
                if (flag)
                {
                    return("x86");
                }
                NativeMethodsShared.SYSTEM_INFO lpSystemInfo = new NativeMethodsShared.SYSTEM_INFO();
                NativeMethodsShared.GetSystemInfo(ref lpSystemInfo);
                switch (lpSystemInfo.wProcessorArchitecture)
                {
                case 0:
                    return("x86");

                case 6:
                    return("IA64");

                case 9:
                    return("AMD64");
                }
                str = null;
            }
            finally
            {
                if (module != NativeMethodsShared.NullIntPtr)
                {
                    NativeMethodsShared.FreeLibrary(module);
                }
            }
            return(str);
        }
        internal static string ProcessorArchitectureIntToString(NativeMethodsShared.SYSTEM_INFO systemInfo)
        {
            switch (systemInfo.wProcessorArchitecture)
            {
            case NativeMethodsShared.PROCESSOR_ARCHITECTURE_INTEL:
                return(BuildUtilities.ProcessorArchitecture.X86);

            case NativeMethodsShared.PROCESSOR_ARCHITECTURE_AMD64:
                return(BuildUtilities.ProcessorArchitecture.AMD64);

            case NativeMethodsShared.PROCESSOR_ARCHITECTURE_IA64:
                return(BuildUtilities.ProcessorArchitecture.IA64);

            case NativeMethodsShared.PROCESSOR_ARCHITECTURE_ARM:
                return(BuildUtilities.ProcessorArchitecture.ARM);

            // unknown architecture? return null
            default:
                return(null);
            }
        }
 public void ValidateCurrentProcessorArchitectureCall()
 {
     NativeMethodsShared.SYSTEM_INFO systemInfo = new NativeMethodsShared.SYSTEM_INFO();
     NativeMethodsShared.GetSystemInfo(ref systemInfo);
     Assert.AreEqual(ProcessorArchitectureIntToString(systemInfo), BuildUtilities.ProcessorArchitecture.CurrentProcessArchitecture, "BuildUtilities.ProcessorArchitecture.CurrentProcessArchitecture returned an invalid match");
 }
        /// <summary>
        /// Gets the processor architecture of the currently running process
        /// </summary>
        /// <returns>null if unknown architecture or error, one of the known architectures otherwise</returns>
        static private string GetCurrentProcessArchitecture()
        {
            string architecture = null;

            IntPtr kernel32Dll = NativeMethodsShared.LoadLibrary("kernel32.dll");

            try
            {
                if (kernel32Dll != NativeMethodsShared.NullIntPtr)
                {
                    // This method gets the current architecture from the currently running msbuild.
                    // If the entry point is missing, we're running on Kernel older than WinXP
                    // http://msdn.microsoft.com/en-us/library/ms684139.aspx
                    IntPtr isWow64ProcessHandle = NativeMethodsShared.GetProcAddress(kernel32Dll, "IsWow64Process");

                    if (isWow64ProcessHandle == NativeMethodsShared.NullIntPtr)
                    {
                        architecture = ProcessorArchitecture.X86;
                    }
                    else
                    {
                        // entry point present, check if running in WOW
                        IsWow64ProcessDelegate isWow64Process = (IsWow64ProcessDelegate)Marshal.GetDelegateForFunctionPointer(isWow64ProcessHandle, typeof(IsWow64ProcessDelegate));
                        bool isWow64 = false;
                        bool success = isWow64Process(Process.GetCurrentProcess().Handle, out isWow64);

                        if (success)
                        {
                            // if it's running on WOW, must be an x86 process
                            if (isWow64)
                            {
                                architecture = ProcessorArchitecture.X86;
                            }
                            else
                            {
                                // it's a native process. Check the system architecture to determine the process architecture.
                                NativeMethodsShared.SYSTEM_INFO systemInfo = new NativeMethodsShared.SYSTEM_INFO();

                                NativeMethodsShared.GetSystemInfo(ref systemInfo);

                                switch (systemInfo.wProcessorArchitecture)
                                {
                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_INTEL:
                                    architecture = ProcessorArchitecture.X86;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_AMD64:
                                    architecture = ProcessorArchitecture.AMD64;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_IA64:
                                    architecture = ProcessorArchitecture.IA64;
                                    break;

                                case NativeMethodsShared.PROCESSOR_ARCHITECTURE_ARM:
                                    architecture = ProcessorArchitecture.ARM;
                                    break;

                                // unknown architecture? return null
                                default:
                                    architecture = null;
                                    break;
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (kernel32Dll != NativeMethodsShared.NullIntPtr)
                {
                    NativeMethodsShared.FreeLibrary(kernel32Dll);
                }
            }

            return(architecture);
        }