示例#1
0
        internal static unsafe void UnhandledExceptionFailFastViaClasslib(
            RhFailFastReason reason, object unhandledException, IntPtr classlibAddress, ref ExInfo exInfo)
        {
            IntPtr pFailFastFunction =
                (IntPtr)InternalCalls.RhpGetClasslibFunctionFromCodeAddress(classlibAddress, ClassLibFunctionId.FailFast);

            if (pFailFastFunction == IntPtr.Zero)
            {
                FailFastViaClasslib(
                    reason,
                    unhandledException,
                    classlibAddress);
            }

            // 16-byte align the context.  This is overkill on x86 and ARM, but simplifies things slightly.
            const int contextAlignment = 16;
            byte *    pbBuffer         = stackalloc byte[sizeof(OSCONTEXT) + contextAlignment];
            void *    pContext         = PointerAlign(pbBuffer, contextAlignment);

            InternalCalls.RhpCopyContextFromExInfo(pContext, sizeof(OSCONTEXT), exInfo._pExContext);

            try
            {
                ((delegate * < RhFailFastReason, object, IntPtr, void *, void >)pFailFastFunction)
                    (reason, unhandledException, exInfo._pExContext->IP, pContext);
            }
            catch when(true)
            {
                // disallow all exceptions leaking out of callbacks
            }

            // The classlib's function should never return and should not throw. If it does, then we fail our way...
            FallbackFailFast(reason, unhandledException);
        }
示例#2
0
        internal unsafe static void UnhandledExceptionFailFastViaClasslib(
            RhFailFastReason reason, Exception unhandledException, ref ExInfo exInfo)
        {
            IntPtr pFailFastFunction = (IntPtr)InternalCalls.RhpGetClasslibFunction(exInfo._pExContext->IP,
                                                                                    ClassLibFunctionId.FailFast);

            if (pFailFastFunction == IntPtr.Zero)
            {
                FailFastViaClasslib(
                    reason,
                    unhandledException,
                    exInfo._pExContext->IP);
            }

            // 16-byte align the context.  This is overkill on x86 and ARM, but simplifies things slightly.
            const int contextAlignment = 16;
            byte *    pbBuffer         = stackalloc byte[sizeof(OSCONTEXT) + contextAlignment];
            void *    pContext         = PointerAlign(pbBuffer, contextAlignment);

            // We 'normalized' the faulting IP of hardware faults to behave like return addresses.  Undo this
            // normalization here so that we report the correct thing in the exception context record.
            if ((exInfo._kind & ExKind.KindMask) == ExKind.HardwareFault)
            {
                exInfo._pExContext->IP = (IntPtr)(((byte *)exInfo._pExContext->IP) - c_IPAdjustForHardwareFault);
            }

            InternalCalls.RhpCopyContextFromExInfo(pContext, sizeof(OSCONTEXT), exInfo._pExContext);

            try
            {
                CalliIntrinsics.CallVoid(pFailFastFunction, reason, unhandledException, (IntPtr)pContext);
            }
            catch
            {
                // Unfortunately, this catch turns into "catch (System.Object)", which will not catch
                // exceptions thrown from the class library because their objects do not derive from our
                // System.Object.
                //
                // @TODO: Use a filtered catch whose filter always returns 'true'.
            }

            // The classlib's funciton should never return and should not throw. If it does, then we fail our way...
            FailFast(reason, unhandledException);
        }
示例#3
0
        internal unsafe static void UnhandledExceptionFailFastViaClasslib(
            RhFailFastReason reason, object unhandledException, IntPtr classlibAddress, ref ExInfo exInfo)
        {
            IntPtr pFailFastFunction =
                (IntPtr)InternalCalls.RhpGetClasslibFunction(classlibAddress, ClassLibFunctionId.FailFast);

            if (pFailFastFunction == IntPtr.Zero)
            {
                FailFastViaClasslib(
                    reason,
                    unhandledException,
                    classlibAddress);
            }

            // 16-byte align the context.  This is overkill on x86 and ARM, but simplifies things slightly.
            const int contextAlignment = 16;
            byte *    pbBuffer         = stackalloc byte[sizeof(OSCONTEXT) + contextAlignment];
            void *    pContext         = PointerAlign(pbBuffer, contextAlignment);

            // We 'normalized' the faulting IP of hardware faults to behave like return addresses.  Undo this
            // normalization here so that we report the correct thing in the exception context record.
            if ((exInfo._kind & ExKind.KindMask) == ExKind.HardwareFault)
            {
                exInfo._pExContext->IP = (IntPtr)(((byte *)exInfo._pExContext->IP) - c_IPAdjustForHardwareFault);
            }

            InternalCalls.RhpCopyContextFromExInfo(pContext, sizeof(OSCONTEXT), exInfo._pExContext);

            try
            {
                CalliIntrinsics.CallVoid(pFailFastFunction, reason, unhandledException, exInfo._pExContext->IP, (IntPtr)pContext);
            }
            catch
            {
                // disallow all exceptions leaking out of callbacks
            }

            // The classlib's funciton should never return and should not throw. If it does, then we fail our way...
            FallbackFailFast(reason, unhandledException);
        }