예제 #1
0
        // Keep in sync:
        // S.M.A.CommandProcessorBase.CheckForSevereException
        // S.M.A.Internal.ConsoleHost.CheckForSevereException
        // S.M.A.Commands.CommandsCommon.CheckForSevereException
        // S.M.A.Commands.UtilityCommon.CheckForSevereException
        /// <summary>
        /// Checks whether the exception is a severe exception which should
        /// cause immediate process failure.
        /// </summary>
        /// <param name="cmdlet"></param>
        /// <param name="e"></param>
        /// <remarks>
        /// CB says 02/23/2005: I personally would err on the side
        /// of treating OOM like an application exception, rather than
        /// a critical system failure.I think this will be easier to justify
        /// in Orcas, if we tease apart the two cases of OOM better.
        /// But even in Whidbey, how likely is it that we couldnt JIT
        /// some backout code?  At that point, the process or possibly
        /// the machine is likely to stop executing soon no matter
        /// what you do in this routine.  So I would just consider
        /// AccessViolationException.  (I understand why you have SO here,
        /// at least temporarily).
        /// </remarks>
        internal static void CheckForSevereException(Cmdlet cmdlet, Exception e)
        {
            if (e is AccessViolationException || e is StackOverflowException)
            {
                try
                {
                    if (!alreadyFailing)
                    {
                        alreadyFailing = true;

                        // Log a command health event for this critical error.
                        MshLog.LogCommandHealthEvent(
                            cmdlet.Context,
                            e,
                            Severity.Critical);
                    }
                }
                finally
                {
                    if (!designForTestability_SkipFailFast)
                    {
                        WindowsErrorReporting.FailFast(e);
                    }
                }
            }
        }
예제 #2
0
        // Keep in sync:
        // S.M.A.CommandProcessorBase.CheckForSevereException
        // S.M.A.Internal.ConsoleHost.CheckForSevereException
        // S.M.A.Commands.CommandsCommon.CheckForSevereException
        // S.M.A.Commands.UtilityCommon.CheckForSevereException
        /// <summary>
        /// Checks whether the exception is a severe exception which should
        /// cause immediate process failure.
        /// </summary>
        /// <param name="cmdlet">can be null</param>
        /// <param name="e"></param>
        /// <remarks>
        /// CB says 02/23/2005: I personally would err on the side
        /// of treating OOM like an application exception, rather than
        /// a critical system failure.I think this will be easier to justify
        /// in Orcas, if we tease apart the two cases of OOM better.
        /// But even in Whidbey, how likely is it that we couldnt JIT
        /// some backout code?  At that point, the process or possibly
        /// the machine is likely to stop executing soon no matter
        /// what you do in this routine.  So I would just consider
        /// AccessViolationException.  (I understand why you have SO here,
        /// at least temporarily).
        /// </remarks>
        internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e)
        {
            if (e is AccessViolationException || e is StackOverflowException)
            {
                try
                {
                    if (!alreadyFailing)
                    {
                        alreadyFailing = true;

                        // Get the ExecutionContext from the thread.
                        ExecutionContext context =
                            (null != cmdlet)
                                ? cmdlet.Context
                                : LocalPipeline.GetExecutionContextFromTLS();

                        // Log a command health event for this critical error.
                        MshLog.LogCommandHealthEvent(context, e, Severity.Critical);
                    }
                }
                finally
                {
                    if (!designForTestability_SkipFailFast)
                    {
                        WindowsErrorReporting.FailFast(e);
                    }
                }
            }
        }
예제 #3
0
 internal static void CheckForSevereException(Cmdlet cmdlet, Exception e)
 {
     if (e as AccessViolationException != null || e as StackOverflowException != null)
     {
         try
         {
             if (!CommandsCommon.alreadyFailing)
             {
                 CommandsCommon.alreadyFailing = true;
                 MshLog.LogCommandHealthEvent(cmdlet.Context, e, Severity.Critical);
             }
         }
         finally
         {
             if (!CommandsCommon.designForTestability_SkipFailFast)
             {
                 WindowsErrorReporting.FailFast(e);
             }
         }
     }
 }
예제 #4
0
 internal static void CheckForSevereException(PSCmdlet cmdlet, Exception e)
 {
     if ((e is AccessViolationException) || (e is StackOverflowException))
     {
         try
         {
             if (!alreadyFailing)
             {
                 alreadyFailing = true;
                 ExecutionContext executionContext = (cmdlet != null) ? cmdlet.Context : LocalPipeline.GetExecutionContextFromTLS();
                 MshLog.LogCommandHealthEvent(executionContext, e, Severity.Critical);
             }
         }
         finally
         {
             if (!designForTestability_SkipFailFast)
             {
                 WindowsErrorReporting.FailFast(e);
             }
         }
     }
 }
예제 #5
0
#pragma warning restore 1573
#else
        public int Start(string consoleFilePath, string[] args)
#endif
        {
#if !CORECLR
            // For long-path support, Full .NET requires some AppContext switches;
            // (for CoreCLR this is Not needed, because CoreCLR supports long paths by default)
            // internally in .NET they are cached once retrieved and are typically hit very early during an application run;
            // so per .NET team's recommendation, we are setting them as soon as we enter managed code.
            EnableLongPathsInDotNetIfAvailable();
#endif
            System.Management.Automation.Runspaces.EarlyStartup.Init();

            // Set ETW activity Id
            Guid activityId = EtwActivity.GetActivityId();

            if (activityId == Guid.Empty)
            {
                EtwActivity.SetActivityId(EtwActivity.CreateActivityId());
            }

            PSEtwLog.LogOperationalInformation(PSEventId.Perftrack_ConsoleStartupStart, PSOpcode.WinStart,
                                               PSTask.PowershellConsoleStartup, PSKeyword.UseAlwaysOperational);

#if !CORECLR
            // Register crash reports in non-server mode
            WindowsErrorReporting.RegisterWindowsErrorReporting(false);
#endif

            try
            {
                // Windows Vista and later support non-traditional UI fallback ie., a
                // user on an Arabic machine can choose either French or English(US) as
                // UI fallback language.
                // CLR does not support this (non-traditional) fallback mechanism.
                // The currentUICulture returned NativeCultureResolver supports this non
                // traditional fallback on Vista. So it is important to set currentUICulture
                // in the beginning before we do anything.
                ClrFacade.SetCurrentThreadUiCulture(NativeCultureResolver.UICulture);
                ClrFacade.SetCurrentThreadCulture(NativeCultureResolver.Culture);

                RunspaceConfigForSingleShell configuration = null;
                PSConsoleLoadException       warning       = null;
                //      PSSnapInException will cause the control to return back to the native code
                //      and stuff the EXCEPINFO field with the message of the exception.
                //      The native code will print this out and exit the process.
                if (string.IsNullOrEmpty(consoleFilePath))
                {
#if DEBUG
                    // Special switches for debug mode to allow self-hosting on InitialSessionState instead
                    // of runspace configuration...
                    if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-iss", StringComparison.OrdinalIgnoreCase))
                    {
                        ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
                        configuration = null;
                    }
                    else if (args.Length > 0 && !String.IsNullOrEmpty(args[0]) && args[0].Equals("-isswait", StringComparison.OrdinalIgnoreCase))
                    {
                        Console.WriteLine("Attach the debugger and hit enter to continue:");
                        Console.ReadLine();
                        ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
                        configuration = null;
                    }
                    else
                    {
                        ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
                        configuration = null;
                    }
#else
                    ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
                    configuration = null;
#endif
                }
                else
                {
                    //TODO : Deprecate RunspaceConfiguration and use InitialSessionState
                    configuration =
                        RunspaceConfigForSingleShell.Create(consoleFilePath, out warning);
                }
                int exitCode = 0;
                try
                {
#if CORECLR
                    var banner = ManagedEntranceStrings.ShellBannerNonWindowsPowerShell;
#else
                    var banner = ManagedEntranceStrings.ShellBanner;
#endif
                    exitCode = Microsoft.PowerShell.ConsoleShell.Start(
                        configuration,
                        banner,
                        ManagedEntranceStrings.ShellHelp,
                        warning == null ? null : warning.Message,
                        args);
                }
                catch (System.Management.Automation.Host.HostException e)
                {
                    if (e.InnerException != null && e.InnerException.GetType() == typeof(System.ComponentModel.Win32Exception))
                    {
                        System.ComponentModel.Win32Exception win32e = e.InnerException as System.ComponentModel.Win32Exception;

                        // These exceptions are caused by killing conhost.exe
                        // 1236, network connection aborted by local system
                        // 0x6, invalid console handle
                        if (win32e.NativeErrorCode == 0x6 || win32e.NativeErrorCode == 1236)
                        {
                            return(exitCode);
                        }
                    }
#if CORECLR
                    System.Environment.FailFast(e.Message);
#else
                    WindowsErrorReporting.FailFast(e);
#endif
                }
                catch (Exception e)
                {
#if CORECLR
                    System.Management.Automation.Environment.FailFast(e.Message);
#else
                    // exceptions caught here should cause Watson.
                    // Must call FailFast; otherwise the exception will be returned to the native code
                    // which will just print out the exception message without Watson
                    WindowsErrorReporting.FailFast(e);
#endif
                }
                return(exitCode);
            }
            finally
            {
#if !CORECLR
                WindowsErrorReporting.WaitForPendingReports();
#endif
            }
        }
예제 #6
0
        public int Start(string consoleFilePath, string[] args)
        {
            int    num;
            string message;
            Guid   activityId = EtwActivity.GetActivityId();

            if (activityId == Guid.Empty)
            {
                EtwActivity.SetActivityId(EtwActivity.CreateActivityId());
            }
            PSEtwLog.LogOperationalInformation(PSEventId.Perftrack_ConsoleStartupStart, PSOpcode.WinStart, PSTask.PowershellConsoleStartup, PSKeyword.UseAlwaysOperational, new object[0]);
            WindowsErrorReporting.RegisterWindowsErrorReporting(false);
            try
            {
                Thread.CurrentThread.CurrentUICulture = NativeCultureResolver.UICulture;
                Thread.CurrentThread.CurrentCulture   = NativeCultureResolver.Culture;
                RunspaceConfigForSingleShell runspaceConfigForSingleShell = null;
                PSConsoleLoadException       pSConsoleLoadException       = null;
                if (!string.IsNullOrEmpty(consoleFilePath))
                {
                    runspaceConfigForSingleShell = RunspaceConfigForSingleShell.Create(consoleFilePath, out pSConsoleLoadException);
                }
                else
                {
                    ConsoleHost.DefaultInitialSessionState = InitialSessionState.CreateDefault2();
                    runspaceConfigForSingleShell           = null;
                    if (Process.GetCurrentProcess().MainWindowHandle != IntPtr.Zero)
                    {
                        ConsoleHost.DefaultInitialSessionState.WarmUpTabCompletionOnIdle = true;
                    }
                }
                int num1 = 0;
                try
                {
                    RunspaceConfigForSingleShell runspaceConfigForSingleShell1 = runspaceConfigForSingleShell;
                    string shellBanner = ManagedEntranceStrings.ShellBanner;
                    string shellHelp   = ManagedEntranceStrings.ShellHelp;
                    if (pSConsoleLoadException == null)
                    {
                        message = null;
                    }
                    else
                    {
                        message = pSConsoleLoadException.Message;
                    }
                    num1 = ConsoleShell.Start(runspaceConfigForSingleShell1, shellBanner, shellHelp, message, args);
                }
                catch (HostException hostException1)
                {
                    HostException hostException = hostException1;
                    if (hostException.InnerException != null && hostException.InnerException.GetType() == typeof(Win32Exception))
                    {
                        Win32Exception innerException = hostException.InnerException as Win32Exception;
                        if (innerException.NativeErrorCode == 6 || innerException.NativeErrorCode == 0x4d4)
                        {
                            num = num1;
                            return(num);
                        }
                    }
                    WindowsErrorReporting.FailFast(hostException);
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    WindowsErrorReporting.FailFast(exception);
                }
                num = num1;
            }
            finally
            {
                WindowsErrorReporting.WaitForPendingReports();
            }
            return(num);
        }