VirtualBox

Ignore:
Timestamp:
Dec 23, 2022 4:55:55 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/nocrt: Fixes to C_specific_handler. bugref:10261 ticketref:21303

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/compiler/vcc/except-seh-vcc.cpp

    r96559 r97861  
    4848#endif
    4949
     50
     51/**
     52 * Calls an exception filter w/o doing any control guard checks.
     53 *
     54 * Doing this within an inline function to prevent disabling CFG for any other
     55 * calls that __C_specific_handler might be doing.
     56 *
     57 * Presumably, the presumption here is that since the target address here is
     58 * taken from tables assumed to be readonly and generated by the compiler, there
     59 * is no need to do any CFG checks.  Besides, the target isn't a function that
     60 * is safe to be called out of context and thus doesn't belong in the CFG tables
     61 * in any way.
     62 */
     63__declspec(guard(ignore))
     64DECLINLINE(LONG) CallFilterFunction(PEXCEPTION_FILTER pfnFilter, PEXCEPTION_POINTERS pXcptPtrs,
     65                                    PEXCEPTION_REGISTRATION_RECORD pXcptRegRec)
     66{
     67    return pfnFilter(pXcptPtrs, pXcptRegRec);
     68}
     69
     70
     71/**
     72 * Calls an exception finally block w/o doing any control guard checks.
     73 *
     74 * See CallFilterFunction for details.
     75 */
     76__declspec(guard(ignore))
     77DECLINLINE(void) CallFinallyFunction(PTERMINATION_HANDLER const pfnTermHandler, BOOLEAN fAbend,
     78                                     PEXCEPTION_REGISTRATION_RECORD pXcptRegRec)
     79{
     80    pfnTermHandler(fAbend, pXcptRegRec);
     81}
    5082
    5183
     
    112144                        PEXCEPTION_FILTER  const pfnFilter = (PEXCEPTION_FILTER)(pDispCtx->ImageBase + uFltTermHandler);
    113145                        EXCEPTION_POINTERS       XcptPtrs  = { pXcptRec, pCpuCtx };
    114                         /** @todo shouldn't we do a guard check on this call? */
    115                         lRet = pfnFilter(&XcptPtrs, pXcptRegRec);
     146                        lRet = CallFilterFunction(pfnFilter, &XcptPtrs, pXcptRegRec);
    116147
    117148                        AssertCompile(EXCEPTION_CONTINUE_SEARCH == 0);
     
    120151                    }
    121152
    122                     /* Return if we're supposed to continue execution (the convension
     153                    /* Return if we're supposed to continue execution (the convention
    123154                       it to match negative values rather than the exact defined value):  */
    124155                    AssertCompile(EXCEPTION_CONTINUE_EXECUTION == -1);
     
    152183                                 ? pDispCtx->TargetIp - pDispCtx->ImageBase
    153184                                 : UINT32_MAX;
     185        //RTAssertMsg2("__C_specific_handler: unwind: idxScope=%#x cScopes=%#x uTargetPc=%#x fXcpt=%#x\n", idxScope, cScopes, uTargetPc, pXcptRec->ExceptionFlags);
    154186
    155187        for (; idxScope < cScopes; idxScope++)
     
    177209                            uint32_t const uTgtEnd    = pScopeTab->ScopeRecord[idxTgtScope].EndAddress;
    178210                            uint32_t const cbTgtScope = uTgtEnd - uTgtBegin;
    179                             if (   uTargetPc - uTgtBegin < uTgtBegin
     211                            if (   uTargetPc - uTgtBegin < cbTgtScope
    180212                                && uTgtBegin < uTgtEnd /* paranoia */)
     213                            {
     214                                //RTAssertMsg2("__C_specific_handler: ExceptionContinueSearch (#1)\n");
    181215                                return ExceptionContinueSearch;
     216                            }
    182217                        }
    183218                }
     
    188223                    PTERMINATION_HANDLER const pfnTermHandler = (PTERMINATION_HANDLER)(pDispCtx->ImageBase + uFltTermHandler);
    189224                    pDispCtx->ScopeIndex = idxScope + 1;
    190                     /** @todo shouldn't we do a guard check on this call? */
    191                     pfnTermHandler(TRUE /*fAbend*/, pXcptRegRec);
     225                    //RTAssertMsg2("__C_specific_handler: Calling __finally %p (idxScope=%#x)\n", pfnTermHandler, idxScope);
     226                    CallFinallyFunction(pfnTermHandler, TRUE /*fAbend*/, pXcptRegRec);
    192227                }
    193228                /* Exception filter & handler entries are skipped, unless the exception
     
    196231                else if (   uXcptHandler == uTargetPc
    197232                         && (pXcptRec->ExceptionFlags & EXCEPTION_TARGET_UNWIND))
     233                {
     234                    //RTAssertMsg2("__C_specific_handler: ExceptionContinueSearch (#2)\n");
    198235                    return ExceptionContinueSearch;
     236                }
    199237            }
    200238        }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette