VirtualBox

Changeset 96442 in vbox


Ignore:
Timestamp:
Aug 23, 2022 2:12:35 PM (2 years ago)
Author:
vboxsync
Message:

IPRT: Split out the public init data into separate files and made it possible to check if IPRT is initialized w/o dragging in the init code. Added tweak to stream.cpp so it'll work w/o IPRT init in debug builds. bugref:10261

Location:
trunk/src/VBox/Runtime
Files:
2 added
7 edited

Legend:

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

    r96420 r96442  
    780780        r3/http-server.cpp \
    781781        r3/init.cpp \
     782        r3/init-data.cpp \
     783        r3/process-data.cpp \
    782784        r3/memsafer-r3.cpp \
    783785        r3/path.cpp \
     
    24372439        r3/generic/semspinmutex-r3-generic.cpp \
    24382440        r3/init.cpp \
     2441        r3/init-data.cpp \
     2442        r3/process-data.cpp \
    24392443        r3/memsafer-r3.cpp \
    24402444        r3/path.cpp \
  • trunk/src/VBox/Runtime/include/internal/initterm.h

    r96407 r96442  
    6666#endif /* IN_RING0 */
    6767
     68#ifdef IN_RING3
     69
     70extern DECL_HIDDEN_DATA(int32_t volatile)   g_crtR3Users;
     71extern DECL_HIDDEN_DATA(bool volatile)      g_frtR3Initializing;
     72extern DECL_HIDDEN_DATA(bool volatile)      g_frtAtExitCalled;
     73
     74/**
     75 * Internal version of RTR3InitIsInitialized.
     76 */
     77DECLINLINE(bool) rtInitIsInitialized(void)
     78{
     79    return g_crtR3Users >= 1 && !g_frtR3Initializing;
     80}
     81
     82#endif
     83
    6884RT_C_DECLS_END
    6985
  • trunk/src/VBox/Runtime/include/internal/process.h

    r96407 r96442  
    5050extern DECL_HIDDEN_DATA(char)           g_szrtProcExePath[RTPATH_MAX];
    5151extern DECL_HIDDEN_DATA(size_t)         g_cchrtProcExePath;
    52 extern DECL_HIDDEN_DATA(size_t)         g_cchrtProcDir;
     52extern DECL_HIDDEN_DATA(size_t)         g_cchrtProcExeDir;
    5353extern DECL_HIDDEN_DATA(size_t)         g_offrtProcName;
    54 extern DECL_HIDDEN_DATA(bool volatile)  g_frtAtExitCalled;
    5554
    5655/**
  • trunk/src/VBox/Runtime/r3/init.cpp

    r96407 r96442  
    8585#include "init.h"
    8686#include "internal/alignmentchecks.h"
     87#include "internal/initterm.h"
    8788#include "internal/path.h"
    8889#include "internal/process.h"
     
    9495*   Global Variables                                                                                                             *
    9596*********************************************************************************************************************************/
    96 /** The number of calls to RTR3Init*. */
    97 static int32_t volatile     g_cUsers = 0;
    98 /** Whether we're currently initializing the IPRT. */
    99 static bool volatile        g_fInitializing = false;
    100 
    101 #if !defined(IPRT_NO_CRT) || !defined(RT_OS_WINDOWS)
    102 /** The process path.
    103  * This is used by RTPathExecDir and RTProcGetExecutablePath and set by rtProcInitName. */
    104 DECL_HIDDEN_DATA(char)      g_szrtProcExePath[RTPATH_MAX];
    105 /** The length of g_szrtProcExePath. */
    106 DECL_HIDDEN_DATA(size_t)    g_cchrtProcExePath;
    107 /** The offset of the process name into g_szrtProcExePath. */
    108 DECL_HIDDEN_DATA(size_t)    g_offrtProcName;
    109 #endif
    110 /** The length of directory path component of g_szrtProcExePath. */
    111 DECL_HIDDEN_DATA(size_t)    g_cchrtProcDir;
    112 
    11397/** The IPRT init flags. */
    11498static uint32_t             g_fInitFlags;
     
    121105static char **              g_papszrtOrgArgs;
    122106
    123 /**
    124  * Program start nanosecond TS.
    125  */
    126 DECL_HIDDEN_DATA(uint64_t)  g_u64ProgramStartNanoTS;
    127 
    128 /**
    129  * The process identifier of the running process.
    130  */
    131 DECL_HIDDEN_DATA(RTPROCESS) g_ProcessSelf = NIL_RTPROCESS;
    132 
    133 /**
    134  * The current process priority.
    135  */
    136 DECL_HIDDEN_DATA(RTPROCPRIORITY)  g_enmProcessPriority = RTPROCPRIORITY_DEFAULT;
    137 
    138 /**
    139  * Set if the atexit callback has been called, i.e. indicating
    140  * that the process is terminating.
    141  */
    142 DECL_HIDDEN_DATA(bool volatile)   g_frtAtExitCalled = false;
    143 
    144107#ifdef IPRT_WITH_ALIGNMENT_CHECKS
    145108/**
     
    170133    ASMAtomicWriteBool(&g_frtAtExitCalled, true);
    171134
    172     if (g_cUsers > 0)
     135    if (g_crtR3Users > 0)
    173136    {
    174137        PRTLOGGER pLogger = RTLogGetDefaultInstance();
     
    249212     */
    250213    ssize_t offName;
    251     g_cchrtProcExePath = RTPathParseSimple(g_szrtProcExePath, &g_cchrtProcDir, &offName, NULL);
     214    g_cchrtProcExePath = RTPathParseSimple(g_szrtProcExePath, &g_cchrtProcExeDir, &offName, NULL);
    252215    g_offrtProcName = offName;
    253216    return VINF_SUCCESS;
     
    599562     * first one, the real init, is running (second assertion).
    600563     */
    601     int32_t cUsers = ASMAtomicIncS32(&g_cUsers);
     564    int32_t cUsers = ASMAtomicIncS32(&g_crtR3Users);
    602565    if (cUsers != 1)
    603566    {
    604567        AssertMsg(cUsers > 1, ("%d\n", cUsers));
    605         Assert(!g_fInitializing);
     568        Assert(!g_frtR3Initializing);
    606569
    607570#if !defined(IN_GUEST) && !defined(RT_NO_GIP)
     
    640603     * Do the initialization.
    641604     */
    642     ASMAtomicWriteBool(&g_fInitializing, true);
     605    ASMAtomicWriteBool(&g_frtR3Initializing, true);
    643606    int rc = rtR3InitBody(fFlags, cArgs, ppapszArgs, pszProgramPath);
    644     ASMAtomicWriteBool(&g_fInitializing, false);
     607    ASMAtomicWriteBool(&g_frtR3Initializing, false);
    645608    if (RT_FAILURE(rc))
    646609    {
    647610        /* failure */
    648         ASMAtomicDecS32(&g_cUsers);
     611        ASMAtomicDecS32(&g_crtR3Users);
    649612        return rc;
    650613    }
     
    686649RTR3DECL(bool) RTR3InitIsInitialized(void)
    687650{
    688     return g_cUsers >= 1 && !g_fInitializing;
     651    return g_crtR3Users >= 1 && !g_frtR3Initializing;
    689652}
    690653
  • trunk/src/VBox/Runtime/r3/path.cpp

    r96407 r96442  
    7979     * Calc the length and check if there is space before copying.
    8080     */
    81     size_t cch = g_cchrtProcDir;
     81    size_t cch = g_cchrtProcExeDir;
    8282    if (cch < cchPath)
    8383    {
  • trunk/src/VBox/Runtime/r3/stream.cpp

    r96407 r96442  
    8989#include "internal/alignmentchecks.h"
    9090#include "internal/magics.h"
     91#ifdef IPRT_NO_CRT
     92# include "internal/initterm.h"
     93#endif
    9194
    9295#ifdef RTSTREAM_STANDALONE
     
    362365
    363366    /* The native stream lock are normally not recursive. */
    364     int rc = RTCritSectInitEx(pCritSect, RTCRITSECT_FLAGS_NO_NESTING,
    365                               NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemSpinMutex");
     367    uint32_t fFlags = RTCRITSECT_FLAGS_NO_NESTING;
     368# ifdef IPRT_NO_CRT
     369    /* IPRT is often used deliberatly without initialization in no-CRT
     370       binaries (for instance VBoxAddInstallNt3x.exe), so in order to avoid
     371       asserting in the lock validator we add the bootstrap hack that disable
     372       lock validation for the section. */
     373    if (!rtInitIsInitialized())
     374        fFlags |= RTCRITSECT_FLAGS_BOOTSTRAP_HACK;
     375# endif
     376    int rc = RTCritSectInitEx(pCritSect, fFlags, NIL_RTLOCKVALCLASS, RTLOCKVAL_SUB_CLASS_NONE, "RTSemSpinMutex");
    366377    if (RT_SUCCESS(rc))
    367378    {
  • trunk/src/VBox/Runtime/r3/win/nocrt-startup-common-win.cpp

    r96407 r96442  
    5353
    5454#include "internal/compiler-vcc.h"
    55 
    56 
    57 /*********************************************************************************************************************************
    58 *   Global Variables                                                                                                             *
    59 *********************************************************************************************************************************/
    60 RT_C_DECLS_BEGIN
    61 DECL_HIDDEN_DATA(char)      g_szrtProcExePath[RTPATH_MAX] = "Unknown.exe";
    62 DECL_HIDDEN_DATA(size_t)    g_cchrtProcExePath = 11;
    63 DECL_HIDDEN_DATA(size_t)    g_cchrtProcExeDir = 0;
    64 DECL_HIDDEN_DATA(size_t)    g_offrtProcName = 0;
    65 RT_C_DECLS_END
     55#include "internal/process.h"
    6656
    6757
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