VirtualBox

Changeset 96559 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Aug 31, 2022 1:20:39 AM (2 years ago)
Author:
vboxsync
Message:

IPRT/nocrt: GSHandlerCheck_SEH and a basic C_specific_handler. bugref:10261

Location:
trunk/src/VBox/Runtime
Files:
1 added
3 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/Makefile.kmk

    r96542 r96559  
    21212121        common/compiler/vcc/guard-vcc.asm \
    21222122        common/compiler/vcc/stack-vcc.asm \
    2123         common/compiler/vcc/stack-except-vcc.cpp
     2123        common/compiler/vcc/stack-except-vcc.cpp \
     2124        common/compiler/vcc/stack-except-seh-vcc.cpp \
     2125        common/compiler/vcc/except-seh-vcc.cpp
    21242126  RuntimeR3_SOURCES.win.x86 = $(RuntimeBaseR3_SOURCES.win.x86) \
    21252127        r3/win/nocrt-atexit-win.asm \
  • trunk/src/VBox/Runtime/common/compiler/vcc/except-vcc.h

    r96420 r96559  
    4141#endif
    4242
     43#define __C_specific_handler their___C_specific_handler
     44#include <iprt/win/windows.h>
     45#undef __C_specific_handler
    4346
    4447#include <iprt/types.h>
    4548#include <iprt/assertcompile.h>
     49
     50
     51RT_C_DECLS_BEGIN
    4652
    4753#if 0
     
    128134        {
    129135            uint32_t    fEHandler : 1;
    130 #define GS_HANDLER_OFF_COOKIE_IS_EHANDLER   RT_BIT(0)
     136#define GS_HANDLER_OFF_COOKIE_IS_EHANDLER   RT_BIT(0) /**< Handles exceptions. */
    131137            uint32_t    fUHandler : 1;
    132 #define GS_HANDLER_OFF_COOKIE_IS_UHANDLER   RT_BIT(1)
     138#define GS_HANDLER_OFF_COOKIE_IS_UHANDLER   RT_BIT(1) /**< Handles unwind. */
    133139            uint32_t    fHasAlignment : 1;
    134 #define GS_HANDLER_OFF_COOKIE_HAS_ALIGNMENT RT_BIT(2)
     140#define GS_HANDLER_OFF_COOKIE_HAS_ALIGNMENT RT_BIT(2) /**< Has the uAlignmentMask member. */
    135141        } Bits;
    136142#define GS_HANDLER_OFF_COOKIE_MASK          UINT32_C(0xfffffff8) /**< Mask to apply to offCookie to the the value. */
     
    138144    } u;
    139145    int32_t             offAlignedBase;
     146    /** This field is only there when GS_HANDLER_OFF_COOKIE_HAS_ALIGNMENT is set.
     147     * it seems. */
    140148    uint32_t            uAlignmentMask;
    141149} GS_HANDLER_DATA;
     
    150158#endif
    151159
     160#if defined(RT_ARCH_AMD64)
     161EXCEPTION_DISPOSITION __C_specific_handler(PEXCEPTION_RECORD pXcptRec, PEXCEPTION_REGISTRATION_RECORD pXcptRegRec,
     162                                           PCONTEXT pCpuCtx, PDISPATCHER_CONTEXT pDispCtx);
     163#endif
     164
     165RT_C_DECLS_END
     166
    152167#endif /* !IPRT_INCLUDED_SRC_common_compiler_vcc_except_vcc_h */
    153168
  • trunk/src/VBox/Runtime/common/compiler/vcc/stack-except-seh-vcc.cpp

    r96556 r96559  
    11/* $Id$ */
    22/** @file
    3  * IPRT - Visual C++ Compiler - Stack Checking, __GSHandlerCheck.
     3 * IPRT - Visual C++ Compiler - Stack Checking, __GSHandlerCheck_SEH.
    44 */
    55
     
    4141#include "internal/nocrt.h"
    4242
    43 #include <iprt/win/windows.h>
    44 
    45 #include <iprt/asm.h>
    46 #include <iprt/asm-amd64-x86.h>
    47 #ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    48 # include <iprt/assert.h>
    49 #endif
    50 
    51 #include "internal/compiler-vcc.h"
    5243#include "except-vcc.h"
    5344
     
    6556 * triggering an exception.
    6657 *
    67  * This does not call any C++ exception handlers, as it's probably (still
    68  * figuring this stuff out) only used when C++ exceptions are disabled.
     58 * This is called for windows' structured exception handling (SEH), i.e. the
     59 * __try/__except/__finally stuff in Visual C++, for which the compiler
     60 * generates somewhat different strctures compared to the plain __GSHanderCheck
     61 * scenario.
    6962 *
    7063 * @returns Exception disposition.
     
    7669 */
    7770extern "C" __declspec(guard(suppress))
    78 EXCEPTION_DISPOSITION __GSHandlerCheck(PEXCEPTION_RECORD pXcptRec, PEXCEPTION_REGISTRATION_RECORD pXcptRegRec,
    79                                        PCONTEXT pCpuCtx, PDISPATCHER_CONTEXT pDispCtx)
     71EXCEPTION_DISPOSITION __GSHandlerCheck_SEH(PEXCEPTION_RECORD pXcptRec, PEXCEPTION_REGISTRATION_RECORD pXcptRegRec,
     72                                           PCONTEXT pCpuCtx, PDISPATCHER_CONTEXT pDispCtx)
    8073{
    81     RT_NOREF(pXcptRec, pCpuCtx);
     74    /*
     75     * The HandlerData points to a scope table, which is then followed by GS_HANDLER_DATA.
     76     *
     77     * Sample offCookie values: 0521H (tst.cpp), 02caH (installNetLwf), and 0502H (installNetFlt).
     78     */
     79    SCOPE_TABLE const *pScopeTable  = (SCOPE_TABLE const *)pDispCtx->HandlerData;
     80    PCGS_HANDLER_DATA  pHandlerData = (PCGS_HANDLER_DATA)&pScopeTable->ScopeRecord[pScopeTable->Count];
    8281
    8382    /*
    8483     * Locate the stack cookie and call the regular stack cookie checker routine.
     84     * (Same code as in __GSHandlerCheck, fixes applies both places.)
    8585     */
    86     PCGS_HANDLER_DATA pHandlerData = (PCGS_HANDLER_DATA)pDispCtx->HandlerData;
    87 
    8886    /* Calculate the cookie address and read it. */
    8987    uintptr_t uPtrFrame = (uintptr_t)pXcptRegRec;
     
    107105    __security_check_cookie(uCookie ^ uXorAddr);
    108106
     107
     108    /*
     109     * Now call the handler if the GS handler data indicates that we ought to.
     110     */
     111    if (  (IS_UNWINDING(pXcptRec->ExceptionFlags) ? GS_HANDLER_OFF_COOKIE_IS_UHANDLER : GS_HANDLER_OFF_COOKIE_IS_EHANDLER)
     112        & pHandlerData->u.offCookie)
     113        return __C_specific_handler(pXcptRec, pXcptRegRec, pCpuCtx, pDispCtx);
     114
    109115    return ExceptionContinueSearch;
    110116}
  • trunk/src/VBox/Runtime/common/compiler/vcc/stack-except-vcc.cpp

    r96420 r96559  
    4141#include "internal/nocrt.h"
    4242
    43 #include <iprt/win/windows.h>
    44 
    45 #include <iprt/asm.h>
    46 #include <iprt/asm-amd64-x86.h>
    47 #ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    48 # include <iprt/assert.h>
    49 #endif
    50 
    51 #include "internal/compiler-vcc.h"
    5243#include "except-vcc.h"
    5344
     
    8273
    8374    /*
    84      * Locate the stack cookie and call the regular stack cookie checker routine.
     75     * Only GS handler data here.
    8576     */
    8677    PCGS_HANDLER_DATA pHandlerData = (PCGS_HANDLER_DATA)pDispCtx->HandlerData;
    8778
     79    /*
     80     * Locate the stack cookie and call the regular stack cookie checker routine.
     81     * (Same code as in __GSHandlerCheck_SEH, fixes applies both places.)
     82     */
    8883    /* Calculate the cookie address and read it. */
    8984    uintptr_t uPtrFrame = (uintptr_t)pXcptRegRec;
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