VirtualBox

Changeset 96388 in vbox


Ignore:
Timestamp:
Aug 20, 2022 11:08:15 PM (2 years ago)
Author:
vboxsync
Message:

IPRT/nocrt: Introduced an internal rtNoCrtFatalMsg/Write API to be used instead of RTMsgError and RTAssertMsg2 to report no-CRT init and runtime issues. The other two drags in hundreds of KBs of unnecessary code. bugref:10261

Location:
trunk/src/VBox/Runtime
Files:
1 added
8 edited

Legend:

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

    r96373 r96388  
    20822082        r3/win/nocrt-startup-dll-win.cpp \
    20832083        r3/win/nocrt-startup-common-win.cpp \
     2084        r3/win/nocrt-fatal-write-win.cpp \
    20842085        r3/win/nocrt-alloc-win.cpp \
    20852086        r3/win/nocrt-RTLogWriteStdErr-win.cpp \
  • trunk/src/VBox/Runtime/common/compiler/vcc/purecall-vcc.cpp

    r95915 r96388  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #include "internal/iprt.h"
     31#include "internal/nocrt.h"
    3232
    3333#include <iprt/asm.h>
    34 #include <iprt/assert.h>
     34#ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     35# include <iprt/assert.h>
     36#endif
    3537
    3638#include "internal/compiler-vcc.h"
     
    3941extern "C" int __cdecl _purecall(void)
    4042{
     43#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    4144    RTAssertMsg2("\n\n!!%p called _purecall!!\n\n", ASMReturnAddress());
     45#else
     46    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!_purecall called from "));
     47    rtNoCrtFatalWritePtr(ASMReturnAddress());
     48    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("!!\r\n\r\n"));
     49#endif
    4250    RT_BREAKPOINT();
    4351    return 0;
  • trunk/src/VBox/Runtime/common/compiler/vcc/stacksup-vcc.cpp

    r96370 r96388  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #include "internal/iprt.h"
     31#include "internal/nocrt.h"
    3232
    3333#include <iprt/asm.h>
    3434#include <iprt/asm-amd64-x86.h>
    35 #include <iprt/assert.h>
     35#ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     36# include <iprt/assert.h>
     37#endif
    3638
    3739#include "internal/compiler-vcc.h"
     
    107109DECLASM(void) _RTC_StackVarCorrupted(uint8_t *pbFrame, RTC_VAR_DESC_T const *pVar)
    108110{
     111#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    109112    RTAssertMsg2("\n\n!!Stack corruption!!\n\n"
    110113                 "%p LB %#x - %s\n",
    111114                 pbFrame + pVar->offFrame, pVar->cbVar, pVar->pszName);
     115#else
     116    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Stack corruption!!\r\n\r\n"));
     117    rtNoCrtFatalWritePtr(pbFrame + pVar->offFrame);
     118    rtNoCrtFatalWrite(RT_STR_TUPLE(" LB "));
     119    rtNoCrtFatalWriteX32(pVar->cbVar);
     120    rtNoCrtFatalWrite(RT_STR_TUPLE(" - "));
     121    rtNoCrtFatalWriteStr(pVar->pszName);
     122    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
     123#endif
    112124    RT_BREAKPOINT();
    113125}
     
    116128DECLASM(void) _RTC_SecurityCookieMismatch(uintptr_t uCookie)
    117129{
     130#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    118131    RTAssertMsg2("\n\n!!Stack cookie corruption!!\n\n"
    119132                 "expected %p, found %p\n",
    120133                 __security_cookie, uCookie);
     134#else
     135    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Stack cookie corruption!!\r\n\r\n"
     136                                        "expected"));
     137    rtNoCrtFatalWritePtr((void *)__security_cookie);
     138    rtNoCrtFatalWrite(RT_STR_TUPLE(", found "));
     139    rtNoCrtFatalWritePtr((void *)uCookie);
     140    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
     141#endif
    121142    RT_BREAKPOINT();
    122143}
     
    126147DECLASM(void) _RTC_CheckEspFailed(uintptr_t uEip, uintptr_t uEsp, uintptr_t uEbp)
    127148{
     149# ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    128150    RTAssertMsg2("\n\n!!ESP check failed!!\n\n"
    129151                 "eip=%p esp=%p ebp=%p\n",
    130152                 uEip, uEsp, uEbp);
     153# else
     154    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!ESP check failed!!\r\n\r\n"
     155                                       "eip="));
     156    rtNoCrtFatalWritePtr((void *)uEip);
     157    rtNoCrtFatalWrite(RT_STR_TUPLE(" esp="));
     158    rtNoCrtFatalWritePtr((void *)uEsp);
     159    rtNoCrtFatalWrite(RT_STR_TUPLE(" ebp="));
     160    rtNoCrtFatalWritePtr((void *)uEbp);
     161    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
     162# endif
    131163    RT_BREAKPOINT();
    132164}
     
    136168extern "C" void __cdecl _RTC_UninitUse(const char *pszVar)
    137169{
     170#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    138171    RTAssertMsg2("\n\n!!Used uninitialized variable %s at %p!!\n\n",
    139172                 pszVar ? pszVar : "", ASMReturnAddress());
     173#else
     174    rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Used uninitialized variable "));
     175    rtNoCrtFatalWriteStr(pszVar);
     176    rtNoCrtFatalWrite(RT_STR_TUPLE(" at "));
     177    rtNoCrtFatalWritePtr(ASMReturnAddress());
     178    rtNoCrtFatalWriteEnd(RT_STR_TUPLE("!!\r\n\r\n"));
     179#endif
    140180    RT_BREAKPOINT();
    141181}
     
    159199        else
    160200        {
     201#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    161202            RTAssertMsg2("\n\n!!Stack corruption (alloca)!!\n\n"
    162203                         "%p LB %#x\n",
    163204                         pHead, pHead->cb);
     205#else
     206            rtNoCrtFatalWriteBegin(RT_STR_TUPLE("\r\n\r\n!!Stack corruption (alloca)!!\r\n\r\n"));
     207            rtNoCrtFatalWritePtr(pHead);
     208            rtNoCrtFatalWrite(RT_STR_TUPLE(" LB "));
     209            rtNoCrtFatalWriteX64(pHead->cb);
     210            rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
     211#endif
    164212            RT_BREAKPOINT();
    165213        }
  • trunk/src/VBox/Runtime/common/string/strformatnum.cpp

    r94300 r96388  
    3333#include "internal/iprt.h"
    3434
    35 #include <iprt/assert.h>
    3635#include <iprt/errcore.h>
    3736#include "internal/string.h"
  • trunk/src/VBox/Runtime/include/internal/nocrt.h

    r96052 r96388  
    7474PRTNOCRTTHREADDATA rtNoCrtThreadDataGet(void);
    7575
     76#ifdef IN_RING3
     77void rtNoCrtFatalWriteBegin(const char *pchMsg, size_t cchMsg);
     78void rtNoCrtFatalWrite(const char *pchMsg, size_t cchMsg);
     79void rtNoCrtFatalWriteEnd(const char *pchMsg, size_t cchMsg);
     80void rtNoCrtFatalWriteStr(const char *pszMsg);
     81void rtNoCrtFatalWritePtr(void const *pv);
     82void rtNoCrtFatalWriteX64(uint64_t uValue);
     83void rtNoCrtFatalWriteX32(uint32_t uValue);
     84void rtNoCrtFatalWriteRc(int rc);
     85void rtNoCrtFatalWriteWinRc(uint32_t rc);
     86
     87void rtNoCrtFatalMsg(const char *pchMsg, size_t cchMsg);
     88void rtNoCrtFatalMsgWithRc(const char *pchMsg, size_t cchMsg, int rc);
     89#endif
     90
    7691
    7792#endif /* !IPRT_INCLUDED_INTERNAL_nocrt_h */
  • trunk/src/VBox/Runtime/r3/win/nocrt-mainCRTStartup-win.asm

    r95831 r96388  
    2828%include "iprt/asmdefs.mac"
    2929
    30 extern  CustomMainEntrypoint
     30extern  NAME(CustomMainEntrypoint)
    3131BEGINPROC mainCRTStartup
    32         jmp     CustomMainEntrypoint
     32        jmp     NAME(CustomMainEntrypoint)
    3333ENDPROC   mainCRTStartup
    3434
  • trunk/src/VBox/Runtime/r3/win/nocrt-startup-common-win.cpp

    r95870 r96388  
    2929*   Header Files                                                                                                                 *
    3030*********************************************************************************************************************************/
    31 #include "internal/iprt.h"
     31#include "internal/nocrt.h"
    3232#include "internal/process.h"
    3333
    3434#include <iprt/nt/nt-and-windows.h>
     35#ifndef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     36# include <iprt/assert.h>
     37#endif
    3538#include <iprt/getopt.h>
    3639#include <iprt/message.h>
     
    7174        }
    7275        else
     76        {
     77#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    7378            RTMsgError("initProcExecPath: RTUtf16ToUtf8Ex failed: %Rrc\n", rc);
     79#else
     80            rtNoCrtFatalMsgWithRc(RT_STR_TUPLE("initProcExecPath: RTUtf16ToUtf8Ex failed: "), rc);
     81#endif
     82        }
    7483    }
    7584    else
     85    {
     86#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    7687        RTMsgError("initProcExecPath: GetModuleFileNameW failed: %Rhrc\n", GetLastError());
     88#else
     89        rtNoCrtFatalWriteBegin(RT_STR_TUPLE("initProcExecPath: GetModuleFileNameW failed: "));
     90        rtNoCrtFatalWriteWinRc(GetLastError());
     91        rtNoCrtFatalWrite(RT_STR_TUPLE("\r\n"));
     92#endif
     93    }
    7794}
    7895
  • trunk/src/VBox/Runtime/r3/win/nocrt-startup-exe-win.cpp

    r95892 r96388  
    3131*   Header Files                                                                                                                 *
    3232*********************************************************************************************************************************/
    33 #include "internal/iprt.h"
     33#include "internal/nocrt.h"
    3434#include "internal/process.h"
    3535
     
    9898         * Get and convert the command line to argc/argv format.
    9999         */
     100        rcExit = RTEXITCODE_INIT;
    100101        UNICODE_STRING const *pCmdLine = pPeb->ProcessParameters ? &pPeb->ProcessParameters->CommandLine : NULL;
    101102        if (pCmdLine)
     
    118119                }
    119120                else
    120                     rcExit = RTMsgErrorExitFailure("Error parsing command line: %Rrc\n", rc);
     121#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     122                    RTMsgError("Error parsing command line: %Rrc\n", rc);
     123#else
     124                    rtNoCrtFatalMsgWithRc(RT_STR_TUPLE("Error parsing command line: "), rc);
     125#endif
    121126            }
    122127            else
    123                 rcExit = RTMsgErrorExitFailure("Failed to convert command line to UTF-8: %Rrc\n", rc);
     128#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     129                RTMsgError("Failed to convert command line to UTF-8: %Rrc\n", rc);
     130#else
     131                rtNoCrtFatalMsgWithRc(RT_STR_TUPLE("Failed to convert command line to UTF-8: "), rc);
     132#endif
    124133        }
    125134        else
    126             rcExit = RTMsgErrorExitFailure("No command line\n");
     135#ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
     136            RTMsgError("No command line\n");
     137#else
     138            rtNoCrtFatalMsg(RT_STR_TUPLE("No command line\r\n"));
     139#endif
    127140        rtTerminateProcess(rcExit, true /*fDoAtExit*/);
    128141    }
     
    130143    else
    131144    {
     145# ifdef IPRT_NOCRT_WITHOUT_FATAL_WRITE
    132146        RTMsgError("A C static initializor failed (%d)\n", rcExit);
     147# else
     148        rtNoCrtFatalWriteBegin(RT_STR_TUPLE("A C static initializor failed ("));
     149        rtNoCrtFatalWriteWinRc(rcExit);
     150        rtNoCrtFatalWriteEnd(RT_STR_TUPLE("\r\n"));
     151# endif
    133152        rtTerminateProcess(rcExit, false /*fDoAtExit*/);
    134153    }
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