Esempio n. 1
0
        public static void xxExceptionHandler()
        {
            // capture this register immediately
            var exceptionObject = Intrinsic.GetExceptionRegister();

            var stackFrame = GetStackFrame(1);

            for (uint i = 0; ; i++)
            {
                var returnAddress = GetReturnAddressFromStackFrame(stackFrame);

                if (returnAddress.IsNull)
                {
                    // hit the top of stack!
                    Fault(0XBAD00002, i);
                }

                var exceptionType = new TypeDefinition(exceptionObject.LoadPointer());

                var methodDef = GetMethodDefinitionViaMethodExceptionLookup(returnAddress);

                if (!methodDef.IsNull)
                {
                    var protectedRegion = GetProtectedRegionEntryByAddress(returnAddress - 1, exceptionType, methodDef);

                    if (!protectedRegion.IsNull)
                    {
                        // found handler for current method, call it

                        var  methodStart   = methodDef.Method;
                        uint handlerOffset = protectedRegion.HandlerOffset;
                        var  jumpTarget    = methodStart + handlerOffset;

                        uint stackSize     = methodDef.StackSize & 0xFFFF;                     // lower 16-bits only
                        var  previousFrame = GetPreviousStackFrame(stackFrame);
                        var  newStack      = previousFrame - stackSize;

                        //Native.FrameJump(jumpTarget, newStack, previousFrame, exceptionObject.ToInt32());
                    }
                }

                // no handler in method, go up the stack
                stackFrame = GetPreviousStackFrame(stackFrame);
            }
        }