VirtualBox

Changeset 96573 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Sep 2, 2022 2:04:12 AM (2 years ago)
Author:
vboxsync
Message:

IPRT/nocrt: Fail fast and safer stack corruption. bugref:10261

Location:
trunk/src/VBox/Runtime
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/compiler/vcc/stack-vcc.asm

    r96568 r96573  
    4747%include "iprt/asmdefs.mac"
    4848%include "iprt/x86.mac"
     49%ifdef RT_ARCH_AMD64
     50 %include "iprt/win/context-amd64.mac"
     51%else
     52 %include "iprt/win/context-x86.mac"
     53%endif
    4954
    5055
     
    112117;*********************************************************************************************************************************
    113118BEGINCODE
    114 extern NAME(_RTC_StackVarCorrupted)
    115 extern NAME(_RTC_SecurityCookieMismatch)
     119extern NAME(rtVccStackVarCorrupted)
     120extern NAME(rtVccSecurityCookieMismatch)
     121extern NAME(rtVccRangeCheckFailed)
    116122%ifdef RT_ARCH_X86
    117 extern NAME(_RTC_CheckEspFailed)
     123extern NAME(rtVccCheckEspFailed)
    118124%endif
    119125
     
    292298%endif
    293299        cmp     dword [xBP + xCX - 4], VARIABLE_MARKER_PRE
    294         jne     .corrupted
     300        jne     rtVccCheckStackVarsFailed
    295301
    296302        ; Marker after the variable.
     
    300306%endif
    301307        cmp     dword [xBP + xCX], VARIABLE_MARKER_POST
    302         jne     .corrupted
     308        jne     rtVccCheckStackVarsFailed
    303309
    304310        ;
     
    316322        pop     xBP
    317323        ret
    318 
    319         ;
    320         ; Complain about corrupt variable.
    321         ;
    322 .corrupted:
     324ENDPROC_RAW     FASTCALL_NAME(_RTC_CheckStackVars, 8)
     325
     326;
     327; Sub-function for _RTC_CheckStackVars, for purposes of SEH64 unwinding.
     328;
     329; Note! While we consider this fatal and will terminate the application, the
     330;       compiler guys do not seem to think it is all that horrible and will
     331;       report failure, maybe do an int3, and then try continue execution.
     332;
     333BEGINPROC_RAW   rtVccCheckStackVarsFailed
     334        nop     ;push    xBP - done in parent function
     335        SEH64_PUSH_xBP
     336        mov     xCX, xBP                    ; xCX = caller pStackFrame. xBP free to become frame pointer.
     337        mov     xBP, xSP
     338        SEH64_SET_FRAME_xBP 0
     339        pushf
    323340        push    xAX
    324         push    xDX
     341        SEH64_PUSH_GREG xAX
     342        sub     xSP, CONTEXT_SIZE + 20h
     343        SEH64_ALLOCATE_STACK (CONTEXT_SIZE + 20h)
     344        SEH64_END_PROLOGUE
     345
     346        lea     xAX, [xBP - CONTEXT_SIZE]
     347        call    NAME(rtVccCaptureContext)
     348
     349        ; rtVccStackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar, PCONTEXT)
     350.again:
    325351%ifdef RT_ARCH_AMD64
    326         sub     xSP, 28h
    327         mov     xCX, xBP                ; frame pointer + variable descriptor.
    328 %else
    329         push    xBP                     ; save EBP
    330         push    xDX                     ; parameter 2 - variable descriptor
    331         push    xBP                     ; parameter 1 - frame pointer.
    332         lea     xBP, [xSP + 3*xCB]      ; turn it into a frame pointer during the call for better unwind.
    333 %endif
    334 
    335         call    NAME(_RTC_StackVarCorrupted)
    336 
    337 %ifdef RT_ARCH_AMD64
    338         add     xSP, 28h
    339 %else
    340         add     xSP, xCB * 4            ; parameters
    341         pop     xBP
    342 %endif
    343         pop     xDX
    344         pop     xAX
    345         jmp     .advance
    346 ENDPROC_RAW     FASTCALL_NAME(_RTC_CheckStackVars, 8)
     352        lea     r8, [xBP - CONTEXT_SIZE]
     353%else
     354        lea     xAX, [xBP - CONTEXT_SIZE]
     355        mov     [xSP + 8], xAX
     356        mov     [xSP + 4], xDX
     357        mov     [xSP], xCX
     358%endif
     359        call    NAME(rtVccStackVarCorrupted)
     360        jmp     .again
     361ENDPROC_RAW     rtVccCheckStackVarsFailed
    347362
    348363
     
    351366; Called to follow up on a 'CMP ESP, EBP' kind of instruction,
    352367; expected to report failure if the compare failed.
     368;
     369; Note! While we consider this fatal and will terminate the application, the
     370;       compiler guys do not seem to think it is all that horrible and will
     371;       report failure, maybe do an int3, and then try continue execution.
    353372;
    354373ALIGNCODE(16)
     
    358377
    359378.unexpected_esp:
    360         push    ebp
    361         mov     ebp, esp
    362         push    eax
    363         push    ecx
    364         push    edx
    365 
    366         ; DECLASM(void) _RTC_CheckEspFailed(uintptr_t uEip, uintptr_t uEsp, uintptr_t uEbp)
    367         push    dword [ebp]
    368         lea     edx, [ebp + 8]
    369         push    edx
    370         mov     ecx, [ebp + 8]
    371         push    ecx
    372         call    NAME(_RTC_CheckEspFailed)
    373 
    374         pop     edx
    375         pop     ecx
    376         pop     eax
    377         leave
    378         ret
     379        push    xBP
     380        SEH64_PUSH_xBP
     381        mov     xBP, xSP
     382        SEH64_SET_FRAME_xBP 0
     383        pushf
     384        push    xAX
     385        SEH64_PUSH_GREG xAX
     386        sub     xSP, CONTEXT_SIZE + 20h
     387        SEH64_ALLOCATE_STACK (CONTEXT_SIZE + 20h)
     388        SEH64_END_PROLOGUE
     389
     390        lea     xAX, [xBP - CONTEXT_SIZE]
     391        call    NAME(rtVccCaptureContext)
     392
     393        ; rtVccCheckEspFailed(PCONTEXT)
     394.again:
     395        lea     xAX, [xBP - CONTEXT_SIZE]
     396%ifdef RT_ARCH_AMD64
     397        mov     xCX, xAX
     398%else
     399        mov     [xSP], xAX
     400%endif
     401        call    NAME(rtVccCheckEspFailed)
     402        jmp     .again
     403
    379404ENDPROC   _RTC_CheckEsp
    380405%endif ; RT_ARCH_X86
     
    459484
    460485;;
    461 ; Checks if the secuity cookie ok, complaining and terminating if it isn't.
     486; Checks if the security cookie ok, complaining and terminating if it isn't.
    462487;
    463488ALIGNCODE(16)
     
    465490        SEH64_END_PROLOGUE
    466491        cmp     xCX, [NAME(__security_cookie) xWrtRIP]
    467         jne     .corrupted
     492        jne     rtVccSecurityCookieFailed
    468493        ;; amd64 version checks if the top 16 bits are zero, we skip that for now.
    469494        ret
    470 
    471 .corrupted:
     495ENDPROC_RAW     FASTCALL_NAME(__security_check_cookie, 4)
     496
     497; Sub-function for __security_check_cookie, for purposes of SEH64 unwinding.
     498BEGINPROC_RAW   rtVccSecurityCookieFailed
     499        push    xBP
     500        SEH64_PUSH_xBP
     501        mov     xBP, xSP
     502        SEH64_SET_FRAME_xBP 0
     503        pushf
     504        push    xAX
     505        SEH64_PUSH_GREG xAX
     506        sub     xSP, CONTEXT_SIZE + 20h
     507        SEH64_ALLOCATE_STACK (CONTEXT_SIZE + 20h)
     508        SEH64_END_PROLOGUE
     509
     510        lea     xAX, [xBP - CONTEXT_SIZE]
     511        call    NAME(rtVccCaptureContext)
     512
     513        ; rtVccSecurityCookieMismatch(uCookie, PCONTEXT)
     514.again:
    472515%ifdef RT_ARCH_AMD64
    473         jmp     NAME(_RTC_SecurityCookieMismatch)
    474 %else
    475         push    ebp
    476         mov     ebp, esp
    477         push    ecx
    478         call    NAME(_RTC_SecurityCookieMismatch)
    479         pop     ecx
    480         leave
     516        lea     xDX, [xBP - CONTEXT_SIZE]
     517%else
     518        lea     xAX, [xBP - CONTEXT_SIZE]
     519        mov     [xSP + 4], xAX
     520        mov     [xSP], xCX
     521%endif
     522        call    NAME(rtVccSecurityCookieMismatch)
     523        jmp     .again
     524ENDPROC_RAW     rtVccSecurityCookieFailed
     525
     526
     527;;
     528; Generated when using /GS - buffer security checks - so, fatal.
     529;
     530; Doesn't seem to take any parameters.
     531;
     532BEGINPROC __report_rangecheckfailure
     533        push    xBP
     534        SEH64_PUSH_xBP
     535        mov     xBP, xSP
     536        SEH64_SET_FRAME_xBP 0
     537        pushf
     538        push    xAX
     539        SEH64_PUSH_GREG xAX
     540        sub     xSP, CONTEXT_SIZE + 20h
     541        SEH64_ALLOCATE_STACK (CONTEXT_SIZE + 20h)
     542        SEH64_END_PROLOGUE
     543
     544        lea     xAX, [xBP - CONTEXT_SIZE]
     545        call    NAME(rtVccCaptureContext)
     546
     547        ; rtVccRangeCheckFailed(PCONTEXT)
     548.again:
     549        lea     xAX, [xBP - CONTEXT_SIZE]
     550%ifdef RT_ARCH_AMD64
     551        mov     xCX, xAX
     552%else
     553        mov     [xSP], xAX
     554%endif
     555        call    NAME(rtVccRangeCheckFailed)
     556        jmp     .again
     557ENDPROC   __report_rangecheckfailure
     558
     559
     560%if 0 ; Currently not treating these as completely fatal, just like the
     561      ; compiler guys do.  I'm sure the compiler only generate these calls
     562      ; if it thinks a variable could be used uninitialized, however I'm not
     563      ; really sure if there is a runtime check in addition or if it's an
     564      ; action that always will be taken in a code path deemed to be bad.
     565      ; Judging from the warnings, the compile time analysis leave lots to be
     566      ; desired (lots of false positives).
     567;;
     568; Not entirely sure how and when the compiler generates these.
     569; extern "C" void __cdecl _RTC_UninitUse(const char *pszVar)
     570BEGINPROC   _RTC_UninitUse
     571        push    xBP
     572        SEH64_PUSH_xBP
     573        mov     xBP, xSP
     574        SEH64_SET_FRAME_xBP 0
     575        pushf
     576        push    xAX
     577        SEH64_PUSH_GREG xAX
     578        sub     xSP, CONTEXT_SIZE + 20h
     579        SEH64_ALLOCATE_STACK (CONTEXT_SIZE + 20h)
     580        SEH64_END_PROLOGUE
     581
     582        lea     xAX, [xBP - CONTEXT_SIZE]
     583        call    NAME(rtVccCaptureContext)
     584
     585        extern NAME(rtVccUninitializedVariableUse)
     586        ; rtVccUninitializedVariableUse(const char *pszVar, PCONTEXT)
     587.again:
     588%ifdef RT_ARCH_AMD64
     589        lea     xDX, [xBP - CONTEXT_SIZE]
     590%else
     591        lea     xAX, [xBP - CONTEXT_SIZE]
     592        mov     [xSP + xCB], xAX
     593        mov     xAX, [xBP + xCB * 2]
     594        mov     [xSP], xAX
     595%endif
     596        call    NAME(rtVccUninitializedVariableUse)
     597        jmp     .again
     598ENDPROC     _RTC_UninitUse
     599%endif
     600
     601;;
     602; Internal worker that creates a CONTEXT record for the caller.
     603;
     604; This expects a old-style stack frame setup, with xBP as base, such that:
     605;       xBP+xCB*1:  Return address  -> Rip/Eip
     606;       xBP+xCB*0:  Return xBP      -> Rbp/Ebp
     607;       xBP-xCB*1:  EFLAGS          -> EFlags
     608;       xBP-xCB*2:  Saved xAX       -> Rax/Eax
     609;
     610; @param    pCtx        xAX     Pointer to a CONTEXT structure.
     611;
     612BEGINPROC rtVccCaptureContext
     613        SEH64_END_PROLOGUE
     614
     615%ifdef RT_ARCH_AMD64
     616        mov     [xAX + CONTEXT.Rcx], rcx
     617        mov     [xAX + CONTEXT.Rdx], rdx
     618        mov     rcx, [xBP - xCB*2]
     619        mov     [xAX + CONTEXT.Rax], ecx
     620        mov     [xAX + CONTEXT.Rbx], rbx
     621        lea     rcx, [xBP + xCB*2]
     622        mov     [xAX + CONTEXT.Rsp], rcx
     623        mov     rdx, [xBP]
     624        mov     [xAX + CONTEXT.Rbp], rdx
     625        mov     [xAX + CONTEXT.Rdi], rdi
     626        mov     [xAX + CONTEXT.Rsi], rsi
     627        mov     [xAX + CONTEXT.R8], r8
     628        mov     [xAX + CONTEXT.R9], r9
     629        mov     [xAX + CONTEXT.R10], r10
     630        mov     [xAX + CONTEXT.R11], r11
     631        mov     [xAX + CONTEXT.R12], r12
     632        mov     [xAX + CONTEXT.R13], r13
     633        mov     [xAX + CONTEXT.R14], r14
     634        mov     [xAX + CONTEXT.R15], r15
     635
     636        mov     rcx, [xBP + xCB*1]
     637        mov     [xAX + CONTEXT.Rip], rcx
     638        mov     edx, [xBP - xCB*1]
     639        mov     [xAX + CONTEXT.EFlags], edx
     640
     641        mov     dx, ss
     642        mov     [xAX + CONTEXT.SegSs], dx
     643        mov     cx, cs
     644        mov     [xAX + CONTEXT.SegCs], cx
     645        mov     dx, ds
     646        mov     [xAX + CONTEXT.SegDs], dx
     647        mov     cx, es
     648        mov     [xAX + CONTEXT.SegEs], cx
     649        mov     dx, fs
     650        mov     [xAX + CONTEXT.SegFs], dx
     651        mov     cx, gs
     652        mov     [xAX + CONTEXT.SegGs], cx
     653
     654        mov     dword [xAX + CONTEXT.ContextFlags], CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS
     655
     656        ; Clear stuff we didn't set.
     657        xor     edx, edx
     658        mov     [xAX + CONTEXT.P1Home], rdx
     659        mov     [xAX + CONTEXT.P2Home], rdx
     660        mov     [xAX + CONTEXT.P3Home], rdx
     661        mov     [xAX + CONTEXT.P4Home], rdx
     662        mov     [xAX + CONTEXT.P5Home], rdx
     663        mov     [xAX + CONTEXT.P6Home], rdx
     664        mov     [xAX + CONTEXT.MxCsr], edx
     665        mov     [xAX + CONTEXT.Dr0], rdx
     666        mov     [xAX + CONTEXT.Dr1], rdx
     667        mov     [xAX + CONTEXT.Dr2], rdx
     668        mov     [xAX + CONTEXT.Dr3], rdx
     669        mov     [xAX + CONTEXT.Dr6], rdx
     670        mov     [xAX + CONTEXT.Dr7], rdx
     671
     672        mov     ecx, CONTEXT_size - CONTEXT.FltSave
     673        AssertCompile(((CONTEXT_size - CONTEXT.FltSave) % 8) == 0)
     674.again:
     675        mov     [xAX + CONTEXT.FltSave + xCX - 8], rdx
     676        sub     ecx, 8
     677        jnz     .again
     678
     679        ; Restore edx and ecx.
     680        mov     rcx, [xAX + CONTEXT.Rcx]
     681        mov     rdx, [xAX + CONTEXT.Rdx]
     682
     683%elifdef RT_ARCH_X86
     684
     685        mov     [xAX + CONTEXT.Ecx], ecx
     686        mov     [xAX + CONTEXT.Edx], edx
     687        mov     ecx, [xBP - xCB*2]
     688        mov     [xAX + CONTEXT.Eax], ecx
     689        mov     [xAX + CONTEXT.Ebx], ebx
     690        lea     ecx, [xBP + xCB*2]
     691        mov     [xAX + CONTEXT.Esp], ecx
     692        mov     edx, [xBP]
     693        mov     [xAX + CONTEXT.Ebp], edx
     694        mov     [xAX + CONTEXT.Edi], edi
     695        mov     [xAX + CONTEXT.Esi], esi
     696
     697        mov     ecx, [xBP + xCB]
     698        mov     [xAX + CONTEXT.Eip], ecx
     699        mov     ecx, [xBP - xCB*1]
     700        mov     [xAX + CONTEXT.EFlags], ecx
     701
     702        mov     dx, ss
     703        movzx   edx, dx
     704        mov     [xAX + CONTEXT.SegSs], edx
     705        mov     cx, cs
     706        movzx   ecx, cx
     707        mov     [xAX + CONTEXT.SegCs], ecx
     708        mov     dx, ds
     709        movzx   edx, dx
     710        mov     [xAX + CONTEXT.SegDs], edx
     711        mov     cx, es
     712        movzx   ecx, cx
     713        mov     [xAX + CONTEXT.SegEs], ecx
     714        mov     dx, fs
     715        movzx   edx, dx
     716        mov     [xAX + CONTEXT.SegFs], edx
     717        mov     cx, gs
     718        movzx   ecx, cx
     719        mov     [xAX + CONTEXT.SegGs], ecx
     720
     721        mov     dword [xAX + CONTEXT.ContextFlags], CONTEXT_CONTROL | CONTEXT_INTEGER | CONTEXT_SEGMENTS
     722
     723        ; Clear stuff we didn't set.
     724        xor     edx, edx
     725        mov     [xAX + CONTEXT.Dr0], edx
     726        mov     [xAX + CONTEXT.Dr1], edx
     727        mov     [xAX + CONTEXT.Dr2], edx
     728        mov     [xAX + CONTEXT.Dr3], edx
     729        mov     [xAX + CONTEXT.Dr6], edx
     730        mov     [xAX + CONTEXT.Dr7], edx
     731
     732        mov     ecx, CONTEXT_size - CONTEXT.ExtendedRegisters
     733.again:
     734        mov     [xAX + CONTEXT.ExtendedRegisters + xCX - 4], edx
     735        sub     ecx, 4
     736        jnz     .again
     737
     738        ; Restore edx and ecx.
     739        mov     ecx, [xAX + CONTEXT.Ecx]
     740        mov     edx, [xAX + CONTEXT.Edx]
     741
     742%else
     743 %error RT_ARCH
     744%endif
    481745        ret
    482 %endif
    483 ENDPROC_RAW     FASTCALL_NAME(__security_check_cookie, 4)
    484 
    485 
    486 
    487 ; Not stack related stubs.
    488 BEGINPROC __report_rangecheckfailure
    489         SEH64_END_PROLOGUE
    490         int3
    491 ENDPROC   __report_rangecheckfailure
    492 
     746ENDPROC   rtVccCaptureContext
     747
  • trunk/src/VBox/Runtime/common/compiler/vcc/stacksup-vcc.cpp

    r96420 r96573  
    4848
    4949#include "internal/compiler-vcc.h"
     50#ifdef IN_RING3
     51# include <iprt/win/windows.h>
     52# include "../../../r3/win/internal-r3-win.h" /* ugly, but need some windows API function pointers */
     53#endif
    5054
    5155
     
    117121
    118122
    119 DECLASM(void) _RTC_StackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar)
     123/**
     124 * Reports a security error.
     125 *
     126 * @param   uFastFailCode   The fast fail code.
     127 * @param   pCpuCtx         The CPU context at the failure location.
     128 */
     129static DECL_NO_RETURN(void) rtVccFatalSecurityErrorWithCtx(uint32_t uFastFailCode, PCONTEXT pCpuCtx)
     130{
     131#ifdef IN_RING3
     132    /*
     133     * Use the __fastfail() approach if available, it is more secure than the stuff below:
     134     */
     135    if (g_pfnIsProcessorFeaturePresent && g_pfnIsProcessorFeaturePresent(PF_FASTFAIL_AVAILABLE))
     136        __fastfail(uFastFailCode);
     137
     138    /*
     139     * Fallback for legacy systems.
     140     */
     141    if (g_pfnIsDebuggerPresent && g_pfnIsDebuggerPresent())
     142        __debugbreak();
     143
     144    /* If we can, clear the unhandled exception filter and report and unhandled exception. */
     145    if (g_pfnSetUnhandledExceptionFilter && g_pfnUnhandledExceptionFilter)
     146    {
     147        g_pfnSetUnhandledExceptionFilter(NULL);
     148
     149        EXCEPTION_RECORD   XcptRec  =
     150        {
     151            /* .ExceptionCode = */          STATUS_STACK_BUFFER_OVERRUN,
     152            /* .ExceptionFlags = */         EXCEPTION_NONCONTINUABLE,
     153            /* .ExceptionRecord = */        NULL,
     154# ifdef RT_ARCH_AMD64
     155            /* .ExceptionAddress = */       (void *)pCpuCtx->Rip,
     156# elif defined(RT_ARCH_X86)
     157            /* .ExceptionAddress = */       (void *)pCpuCtx->Eip,
     158# else
     159#  error "Port me!"
     160# endif
     161            /* .NumberParameters = */       1,
     162            /* .ExceptionInformation = */   { uFastFailCode, }
     163        };
     164
     165        EXCEPTION_POINTERS XcptPtrs = { &XcptRec, pCpuCtx };
     166        g_pfnUnhandledExceptionFilter(&XcptPtrs);
     167    }
     168
     169    for (;;)
     170        TerminateProcess(GetCurrentProcess(), STATUS_STACK_BUFFER_OVERRUN);
     171
     172#else
     173# error "Port ME!"
     174#endif
     175}
     176
     177
     178DECLASM(void) rtVccStackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar, PCONTEXT pCpuCtx)
    120179{
    121180#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     
    132191    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
    133192#endif
    134     RT_BREAKPOINT();
    135 }
    136 
    137 
    138 DECLASM(void) _RTC_SecurityCookieMismatch(uintptr_t uCookie)
     193    rtVccFatalSecurityErrorWithCtx(FAST_FAIL_INCORRECT_STACK, pCpuCtx);
     194}
     195
     196
     197DECLASM(void) rtVccSecurityCookieMismatch(uintptr_t uCookie, PCONTEXT pCpuCtx)
    139198{
    140199#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     
    150209    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
    151210#endif
    152     RT_BREAKPOINT();
     211    rtVccFatalSecurityErrorWithCtx(FAST_FAIL_STACK_COOKIE_CHECK_FAILURE, pCpuCtx);
    153212}
    154213
    155214
    156215#ifdef RT_ARCH_X86
    157 DECLASM(void) _RTC_CheckEspFailed(uintptr_t uEip, uintptr_t uEsp, uintptr_t uEbp)
     216DECLASM(void) rtVccCheckEspFailed(PCONTEXT pCpuCtx)
    158217{
    159218# ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    160219    RTAssertMsg2("\n\n!!ESP check failed!!\n\n"
    161220                 "eip=%p esp=%p ebp=%p\n",
    162                  uEip, uEsp, uEbp);
     221                 pCpuCtx->Eip, pCpuCtx->Esp, pCpuCtx->Ebp);
    163222# else
    164223    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!ESP check failed!!\r\n\r\n"
    165224                                       "eip="));
    166     rtNoCrtFatalWritePtr((void *)uEip);
     225    rtNoCrtFatalWritePtr((void *)pCpuCtx->Eip);
    167226    rtNoCrtFatalWrite(RT_STR_TUPLE(" esp="));
    168     rtNoCrtFatalWritePtr((void *)uEsp);
     227    rtNoCrtFatalWritePtr((void *)pCpuCtx->Esp);
    169228    rtNoCrtFatalWrite(RT_STR_TUPLE(" ebp="));
    170     rtNoCrtFatalWritePtr((void *)uEbp);
     229    rtNoCrtFatalWritePtr((void *)pCpuCtx->Ebp);
    171230    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
    172231# endif
    173     RT_BREAKPOINT();
    174 }
    175 #endif
    176 
    177 
    178 extern "C" void __cdecl _RTC_UninitUse(const char *pszVar)
    179 {
    180 #ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    181     RTAssertMsg2("\n\n!!Used uninitialized variable %s at %p!!\n\n",
    182                  pszVar ? pszVar : "", ASMReturnAddress());
    183 #else
    184     rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Used uninitialized variable "));
    185     rtNoCrtFatalWriteStr(pszVar);
    186     rtNoCrtFatalWrite(RT_STR_TUPLE(" at "));
    187     rtNoCrtFatalWritePtr(ASMReturnAddress());
    188     rtNoCrtFatalWriteEnd(RT_STR_TUPLE("!!\r\n\r\n"));
    189 #endif
    190     RT_BREAKPOINT();
    191 }
     232    rtVccFatalSecurityErrorWithCtx(FAST_FAIL_INCORRECT_STACK, pCpuCtx);
     233}
     234#endif
    192235
    193236
     
    220263            rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
    221264#endif
    222             RT_BREAKPOINT();
     265#ifdef IN_RING3
     266            if (g_pfnIsDebuggerPresent && g_pfnIsDebuggerPresent())
     267#endif
     268                RT_BREAKPOINT();
    223269        }
    224270        pHead = pHead->pNext;
     
    228274}
    229275
     276
     277
     278
     279/** Whether or not this should be a fatal issue remains to be seen. See
     280 *  explanation in stack-vcc.asm.  */
     281#if 0
     282DECLASM(void) rtVccUninitializedVariableUse(const char *pszVar, PCONTEXT pCpuCtx)
     283#else
     284extern "C" void __cdecl _RTC_UninitUse(const char *pszVar)
     285#endif
     286{
     287#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     288    RTAssertMsg2("\n\n!!Used uninitialized variable %s at %p!!\n\n",
     289                 pszVar ? pszVar : "", ASMReturnAddress());
     290#else
     291    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Used uninitialized variable "));
     292    rtNoCrtFatalWriteStr(pszVar);
     293    rtNoCrtFatalWrite(RT_STR_TUPLE(" at "));
     294    rtNoCrtFatalWritePtr(ASMReturnAddress());
     295    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("!!\r\n\r\n"));
     296#endif
     297#if 0
     298    rtVccFatalSecurityErrorWithCtx(FAST_FAIL_FATAL_APP_EXIT, pCpuCtx);
     299#else
     300# ifdef IN_RING3
     301    if (g_pfnIsDebuggerPresent && g_pfnIsDebuggerPresent())
     302# endif
     303        RT_BREAKPOINT();
     304#endif
     305}
     306
  • trunk/src/VBox/Runtime/r3/win/init-win.cpp

    r96505 r96573  
    8282/** The GetCurrentThreadStackLimits API. */
    8383static PFNGETCURRENTTHREADSTACKLIMITS           g_pfnGetCurrentThreadStackLimits = NULL;
    84 /** SetUnhandledExceptionFilter. */
    85 static PFNSETUNHANDLEDEXCEPTIONFILTER           g_pfnSetUnhandledExceptionFilter = NULL;
    8684/** The previous unhandled exception filter. */
    8785static LPTOP_LEVEL_EXCEPTION_FILTER             g_pfnUnhandledXcptFilter = NULL;
     
    9997DECL_HIDDEN_DATA(decltype(GetQueuedCompletionStatus) *)         g_pfnGetQueuedCompletionStatus = NULL;
    10098DECL_HIDDEN_DATA(decltype(PostQueuedCompletionStatus) *)        g_pfnPostQueuedCompletionStatus = NULL;
     99DECL_HIDDEN_DATA(decltype(IsProcessorFeaturePresent) *)         g_pfnIsProcessorFeaturePresent = NULL;
     100DECL_HIDDEN_DATA(decltype(SetUnhandledExceptionFilter) *)       g_pfnSetUnhandledExceptionFilter = NULL;
     101DECL_HIDDEN_DATA(decltype(UnhandledExceptionFilter) *)          g_pfnUnhandledExceptionFilter = NULL;
    101102
    102103/** The native ntdll.dll handle. */
     
    536537     */
    537538    g_pfnGetCurrentThreadStackLimits = (PFNGETCURRENTTHREADSTACKLIMITS)GetProcAddress(g_hModKernel32, "GetCurrentThreadStackLimits");
    538     g_pfnSetUnhandledExceptionFilter = (PFNSETUNHANDLEDEXCEPTIONFILTER)GetProcAddress(g_hModKernel32, "SetUnhandledExceptionFilter");
     539    g_pfnSetUnhandledExceptionFilter = (decltype(SetUnhandledExceptionFilter) *)GetProcAddress(g_hModKernel32, "SetUnhandledExceptionFilter");
     540    g_pfnUnhandledExceptionFilter    = (decltype(UnhandledExceptionFilter) *)   GetProcAddress(g_hModKernel32, "UnhandledExceptionFilter");
    539541    if (g_pfnSetUnhandledExceptionFilter && !g_pfnUnhandledXcptFilter)
    540542    {
     
    583585    g_pfnGetQueuedCompletionStatus  = (decltype(GetQueuedCompletionStatus) *) GetProcAddress(g_hModKernel32, "GetQueuedCompletionStatus");
    584586    g_pfnPostQueuedCompletionStatus = (decltype(PostQueuedCompletionStatus) *)GetProcAddress(g_hModKernel32, "PostQueuedCompletionStatus");
     587    g_pfnIsProcessorFeaturePresent  = (decltype(IsProcessorFeaturePresent) *) GetProcAddress(g_hModKernel32, "IsProcessorFeaturePresent");
    585588
    586589    Assert(g_pfnGetHandleInformation       || g_enmWinVer < kRTWinOSType_NT351);
     
    593596    Assert(g_pfnGetQueuedCompletionStatus  || g_enmWinVer < kRTWinOSType_NT350);
    594597    Assert(g_pfnPostQueuedCompletionStatus || g_enmWinVer < kRTWinOSType_NT350);
     598    Assert(g_pfnIsProcessorFeaturePresent  || g_enmWinVer < kRTWinOSType_NT4);
    595599
    596600    /*
  • trunk/src/VBox/Runtime/r3/win/internal-r3-win.h

    r96505 r96573  
    129129extern DECL_HIDDEN_DATA(decltype(GetQueuedCompletionStatus) *)          g_pfnGetQueuedCompletionStatus;
    130130extern DECL_HIDDEN_DATA(decltype(PostQueuedCompletionStatus) *)         g_pfnPostQueuedCompletionStatus;
     131extern DECL_HIDDEN_DATA(decltype(SetUnhandledExceptionFilter) *)        g_pfnSetUnhandledExceptionFilter;
     132extern DECL_HIDDEN_DATA(decltype(UnhandledExceptionFilter) *)           g_pfnUnhandledExceptionFilter;
     133extern DECL_HIDDEN_DATA(decltype(IsProcessorFeaturePresent) *)          g_pfnIsProcessorFeaturePresent;
    131134
    132135
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