VirtualBox

Changeset 90857 in vbox for trunk/src/VBox/Runtime/common


Ignore:
Timestamp:
Aug 24, 2021 9:13:13 PM (3 years ago)
Author:
vboxsync
Message:

IPRT/log: Kicked out all the IN_RC stuff. Cleanups. bugref:10086

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/log/log.cpp

    r90850 r90857  
    3232#include "internal/iprt.h"
    3333
    34 #ifndef IN_RC
    35 # include <iprt/alloc.h>
    36 # include <iprt/crc.h>
    37 # include <iprt/process.h>
    38 # include <iprt/semaphore.h>
    39 # include <iprt/thread.h>
    40 # include <iprt/mp.h>
    41 #endif
     34#include <iprt/alloc.h>
     35#include <iprt/crc.h>
     36#include <iprt/process.h>
     37#include <iprt/semaphore.h>
     38#include <iprt/thread.h>
     39#include <iprt/mp.h>
    4240#ifdef IN_RING3
    4341# include <iprt/env.h>
     
    193191    char                    szR0ThreadName[16];
    194192
    195 #ifdef IN_RING3 /* Note! Must be at the end! */ /** @todo r=bird: figure out why it must be at the end... */
     193#ifdef IN_RING3
    196194    /** @name File logging bits for the logger.
    197195     * @{ */
     
    233231AssertCompileMemberAlignment(RTLOGGERINTERNAL, cbRingBufUnflushed, sizeof(uint64_t));
    234232#ifdef IN_RING3
    235 /** The size of the RTLOGGERINTERNAL structure in ring-0.  */
    236 # define RTLOGGERINTERNAL_R0_SIZE       RT_UOFFSETOF(RTLOGGERINTERNAL, pfnPhase)
    237233AssertCompileMemberAlignment(RTLOGGERINTERNAL, hFile, sizeof(void *));
    238234AssertCompileMemberAlignment(RTLOGGERINTERNAL, cbHistoryFileMax, sizeof(uint64_t));
     
    259255*   Internal Functions                                                                                                           *
    260256*********************************************************************************************************************************/
    261 #ifndef IN_RC
    262257static unsigned rtlogGroupFlags(const char *psz);
    263 #endif
    264258#ifdef IN_RING0
    265259static void rtR0LogLoggerExFallback(uint32_t fDestFlags, uint32_t fFlags, PRTLOGGERINTERNAL pInt,
     
    269263static int  rtR3LogOpenFileDestination(PRTLOGGERINTERNAL pLoggerInt, PRTERRINFO pErrInfo);
    270264#endif
    271 #ifndef IN_RC
    272265static void rtLogRingBufFlush(PRTLOGGERINTERNAL pLoggerInt);
    273 #endif
    274266static void rtlogFlush(PRTLOGGERINTERNAL pLoggerInt, bool fNeedSpace);
    275267static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars);
    276268static void rtlogLoggerExVLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup,
    277269                                 const char *pszFormat, va_list args);
    278 #ifndef IN_RC
    279270static void rtlogLoggerExFLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...);
    280 #endif
    281271
    282272
     
    284274*   Global Variables                                                                                                             *
    285275*********************************************************************************************************************************/
    286 #ifndef IN_RC
    287276/** Default logger instance. */
    288277static PRTLOGGER                    g_pLogger;
    289278/** Default release logger instance. */
    290279static PRTLOGGER                    g_pRelLogger;
    291 #else
    292 /** Default logger instance. Make it weak because our RC module loader does not
    293  *  necessarily resolve this symbol and the compiler _must_ check if this is
    294  *  the case or not. That doesn't work for Darwin (``incompatible feature used:
    295  *  .weak_reference (must specify "-dynamic" to be used'') */
    296 # ifdef RT_OS_DARWIN
    297 extern "C" DECLIMPORT(RTLOGGERRC)   g_Logger;
    298 /** Default release logger instance. */
    299 extern "C" DECLIMPORT(RTLOGGERRC)   g_RelLogger;
    300 # else
    301 extern "C" DECLWEAK(DECLIMPORT(RTLOGGERRC)) g_Logger;
    302 /** Default release logger instance. */
    303 extern "C" DECLWEAK(DECLIMPORT(RTLOGGERRC)) g_RelLogger;
    304 # endif
    305 #endif /* IN_RC */
    306280#ifdef IN_RING3
    307281/** The RTThreadGetWriteLockCount() change caused by the logger mutex semaphore. */
     
    425399DECLINLINE(int) rtlogLock(PRTLOGGERINTERNAL pLoggerInt)
    426400{
    427 #ifndef IN_RC
    428401    AssertMsgReturn(pLoggerInt->Core.u32Magic == RTLOGGER_MAGIC, ("%#x != %#x\n", pLoggerInt->Core.u32Magic, RTLOGGER_MAGIC),
    429402                    VERR_INVALID_MAGIC);
     
    438411            return rc;
    439412    }
    440 #else
    441     NOREF(pLoggerInt);
    442 #endif
    443413    return VINF_SUCCESS;
    444414}
     
    451421DECLINLINE(void) rtlogUnlock(PRTLOGGERINTERNAL pLoggerInt)
    452422{
    453 #ifndef IN_RC
    454423    if (pLoggerInt->hSpinMtx != NIL_RTSEMSPINMUTEX)
    455424        RTSemSpinMutexRelease(pLoggerInt->hSpinMtx);
    456 #else
    457     NOREF(pLoggerInt);
    458 #endif
    459425    return;
    460426}
    461427
    462 #ifndef IN_RC
    463 # ifdef IN_RING3
    464 
    465 #  ifdef SOME_UNUSED_FUNCTION
    466 /**
    467  * Logging to file, output callback.
    468  *
    469  * @param  pvArg        User argument.
    470  * @param  pachChars    Pointer to an array of utf-8 characters.
    471  * @param  cbChars      Number of bytes in the character array pointed to by pachChars.
    472  */
    473 static DECLCALLBACK(size_t) rtlogPhaseWrite(void *pvArg, const char *pachChars, size_t cbChars)
    474 {
    475     PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)pvArg;
    476     RTFileWrite(pLoggerInt->hFile, pachChars, cbChars, NULL);
    477     return cbChars;
    478 }
    479 
    480 
    481 /**
    482  * Callback to format VBox formatting extentions.
    483  * See @ref pg_rt_str_format for a reference on the format types.
    484  *
    485  * @returns The number of bytes formatted.
    486  * @param   pvArg           Formatter argument.
    487  * @param   pfnOutput       Pointer to output function.
    488  * @param   pvArgOutput     Argument for the output function.
    489  * @param   ppszFormat      Pointer to the format string pointer. Advance this till the char
    490  *                          after the format specifier.
    491  * @param   pArgs           Pointer to the argument list. Use this to fetch the arguments.
    492  * @param   cchWidth        Format Width. -1 if not specified.
    493  * @param   cchPrecision    Format Precision. -1 if not specified.
    494  * @param   fFlags          Flags (RTSTR_NTFS_*).
    495  * @param   chArgSize       The argument size specifier, 'l' or 'L'.
    496  */
    497 static DECLCALLBACK(size_t) rtlogPhaseFormatStr(void *pvArg, PFNRTSTROUTPUT pfnOutput, void *pvArgOutput,
    498                                                 const char **ppszFormat, va_list *pArgs, int cchWidth,
    499                                                 int cchPrecision, unsigned fFlags, char chArgSize)
    500 {
    501     char ch = *(*ppszFormat)++;
    502 
    503     AssertMsgFailed(("Invalid logger phase format type '%%%c%.10s'!\n", ch, *ppszFormat)); NOREF(ch);
    504 
    505     return 0;
    506 }
    507 
    508 #  endif /* SOME_UNUSED_FUNCTION */
    509 
     428#ifdef IN_RING3
    510429
    511430/**
     
    548467}
    549468
    550 # endif /* IN_RING3 */
     469#endif /* IN_RING3 */
    551470
    552471/**
     
    20011920}
    20021921
     1922
    20031923/**
    20041924 * Helper for RTLogGetGroupSettings.
     
    20061926static int rtLogGetGroupSettingsAddOne(const char *pszName, uint32_t fGroup, char **ppszBuf, size_t *pcchBuf, bool *pfNotFirst)
    20071927{
    2008 # define APPEND_PSZ(psz,cch) do { memcpy(*ppszBuf, (psz), (cch)); *ppszBuf += (cch); *pcchBuf -= (cch); } while (0)
    2009 # define APPEND_SZ(sz)       APPEND_PSZ(sz, sizeof(sz) - 1)
    2010 # define APPEND_CH(ch)       do { **ppszBuf = (ch); *ppszBuf += 1; *pcchBuf -= 1; } while (0)
     1928#define APPEND_PSZ(psz,cch) do { memcpy(*ppszBuf, (psz), (cch)); *ppszBuf += (cch); *pcchBuf -= (cch); } while (0)
     1929#define APPEND_SZ(sz)       APPEND_PSZ(sz, sizeof(sz) - 1)
     1930#define APPEND_CH(ch)       do { **ppszBuf = (ch); *ppszBuf += 1; *pcchBuf -= 1; } while (0)
    20111931
    20121932    /*
     
    20441964        return VERR_BUFFER_OVERFLOW;
    20451965
    2046 # undef APPEND_PSZ
    2047 # undef APPEND_SZ
    2048 # undef APPEND_CH
     1966#undef APPEND_PSZ
     1967#undef APPEND_SZ
     1968#undef APPEND_CH
    20491969    return VINF_SUCCESS;
    20501970}
     
    21232043RT_EXPORT_SYMBOL(RTLogQueryGroupSettings);
    21242044
    2125 #endif /* !IN_RC */
    21262045
    21272046/**
     
    22582177
    22592178
    2260 #ifdef IN_RING3
    22612179RTDECL(uint32_t) RTLogSetGroupLimit(PRTLOGGER pLogger, uint32_t cMaxEntriesPerGroup)
    22622180{
     
    22802198    return cOld;
    22812199}
    2282 #endif
     2200RT_EXPORT_SYMBOL(RTLogSetGroupLimit);
    22832201
    22842202
     
    23082226}
    23092227RT_EXPORT_SYMBOL(RTLogSetR0ThreadNameF);
    2310 #endif
    2311 
    2312 #ifndef IN_RC
     2228#endif /* IN_RING0 */
     2229
    23132230
    23142231/**
     
    31013018RT_EXPORT_SYMBOL(RTLogBulkWrite);
    31023019
    3103 #endif /* !IN_RC */
    31043020
    31053021/**
     
    31643080 * Common worker for RTLogDefaultInstance and RTLogDefaultInstanceEx.
    31653081 */
     3082DECL_NO_INLINE(static, PRTLOGGER) rtLogDefaultInstanceCreateNew(void)
     3083{
     3084    PRTLOGGER pRet = RTLogDefaultInit();
     3085    if (pRet)
     3086    {
     3087        bool fRc = ASMAtomicCmpXchgPtr(&g_pLogger, pRet, NULL);
     3088        if (!fRc)
     3089        {
     3090            RTLogDestroy(pRet);
     3091            pRet = g_pLogger;
     3092        }
     3093    }
     3094    return pRet;
     3095}
     3096
     3097
     3098/**
     3099 * Common worker for RTLogDefaultInstance and RTLogDefaultInstanceEx.
     3100 */
    31663101DECL_FORCE_INLINE(PRTLOGGER) rtLogDefaultInstanceCommon(void)
    31673102{
    3168 #ifdef IN_RC
    3169     return &g_Logger;
    3170 
    3171 #else /* !IN_RC */
    3172 # ifdef IN_RING0
     3103    PRTLOGGER pRet;
     3104
     3105#ifdef IN_RING0
    31733106    /*
    31743107     * Check per thread loggers first.
     
    31823115                return g_aPerThreadLoggers[i].pLogger;
    31833116    }
    3184 # endif /* IN_RING0 */
     3117#endif /* IN_RING0 */
    31853118
    31863119    /*
    31873120     * If no per thread logger, use the default one.
    31883121     */
    3189     if (!g_pLogger)
    3190         g_pLogger = RTLogDefaultInit();
    3191     return g_pLogger;
    3192 #endif /* !IN_RC */
     3122    pRet = g_pLogger;
     3123    if (RT_LIKELY(pRet))
     3124    { /* likely */ }
     3125    else
     3126        pRet = rtLogDefaultInstanceCreateNew();
     3127    return pRet;
    31933128}
    31943129
     
    32383173DECL_FORCE_INLINE(PRTLOGGER) rtLogGetDefaultInstanceCommon(void)
    32393174{
    3240 #ifdef IN_RC
    3241     return &g_Logger;
    3242 #else
    3243 # ifdef IN_RING0
     3175#ifdef IN_RING0
    32443176    /*
    32453177     * Check per thread loggers first.
     
    32533185                return g_aPerThreadLoggers[i].pLogger;
    32543186    }
    3255 # endif /* IN_RING0 */
     3187#endif /* IN_RING0 */
    32563188
    32573189    return g_pLogger;
    3258 #endif
    32593190}
    32603191
     
    32783209
    32793210
    3280 #ifndef IN_RC
    32813211/**
    32823212 * Sets the default logger instance.
     
    32903220}
    32913221RT_EXPORT_SYMBOL(RTLogSetDefaultInstance);
    3292 #endif /* !IN_RC */
    32933222
    32943223
     
    33043233 *                      current thread use 0.
    33053234 */
    3306 RTDECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey)
     3235RTR0DECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey)
    33073236{
    33083237    int             rc;
     
    33823311RTDECL(PRTLOGGER)   RTLogRelGetDefaultInstance(void)
    33833312{
    3384 #ifdef IN_RC
    3385     return &g_RelLogger;
    3386 #else /* !IN_RC */
    33873313    return g_pRelLogger;
    3388 #endif /* !IN_RC */
    33893314}
    33903315RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstance);
     
    33933318RTDECL(PRTLOGGER)   RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup)
    33943319{
    3395 #ifdef IN_RC
    3396     PRTLOGGERINTERNAL pLoggerInt = &g_RelLogger;
    3397 #else
    33983320    PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)g_pRelLogger;
    3399 #endif
    34003321    if (pLoggerInt)
    34013322        pLoggerInt = rtLogCheckGroupFlagsWorker(pLoggerInt, fFlagsAndGroup);
     
    34053326
    34063327
    3407 #ifndef IN_RC
    34083328/**
    34093329 * Sets the default logger instance.
     
    34173337}
    34183338RT_EXPORT_SYMBOL(RTLogRelSetDefaultInstance);
    3419 #endif /* !IN_RC */
    34203339
    34213340
     
    34943413     */
    34953414    if (    (pLoggerInt->fFlags & RTLOGFLAGS_DISABLED)
    3496 #ifndef IN_RC
    34973415        || !pLoggerInt->fDestFlags
    3498 #endif
    34993416        || !pszFormat || !*pszFormat)
    35003417        return;
     
    35193436     * Check restrictions and call worker.
    35203437     */
    3521 #ifndef IN_RC
    35223438    if (RT_UNLIKELY(   (pLoggerInt->fFlags & RTLOGFLAGS_RESTRICT_GROUPS)
    35233439                    && iGroup < pLoggerInt->cGroups
     
    35403456    }
    35413457    else
    3542 #endif
    35433458        rtlogLoggerExVLocked(pLoggerInt, fFlags, iGroup, pszFormat, args);
    35443459
     
    35503465RT_EXPORT_SYMBOL(RTLogLoggerExV);
    35513466
    3552 
    35533467#ifdef IN_RING0
     3468
    35543469/**
    35553470 * For rtR0LogLoggerExFallbackOutput and rtR0LogLoggerExFallbackFlush.
     
    37063621    RTLogFormatV(rtR0LogLoggerExFallbackOutput, &This, pszFormat, va);
    37073622}
     3623
    37083624#endif /* IN_RING0 */
    3709 
    37103625
    37113626/**
     
    37373652}
    37383653RT_EXPORT_SYMBOL(RTLogDumpPrintfV);
    3739 
    37403654
    37413655#ifdef IN_RING3
     
    39583872
    39593873#endif /* IN_RING3 */
    3960 
    39613874
    39623875/**
     
    43634276                if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_MS_PROG)
    43644277                {
    4365 #if defined(IN_RING3) || defined(IN_RC)
     4278#ifndef IN_RING0
    43664279                    uint64_t u64 = RTTimeProgramMilliTS();
    43674280#else
     
    43984311                {
    43994312
    4400 #if defined(IN_RING3) || defined(IN_RC)
     4313#ifndef IN_RING0
    44014314                    uint64_t u64 = RTTimeProgramMicroTS();
    44024315#else
     
    44364349                if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_PID)
    44374350                {
    4438 #ifndef IN_RC
    44394351                    RTPROCESS Process = RTProcSelf();
    4440 #else
    4441                     RTPROCESS Process = NIL_RTPROCESS;
    4442 #endif
    44434352                    psz += RTStrFormatNumber(psz, Process, 16, sizeof(RTPROCESS) * 2, 0, RTSTR_F_ZEROPAD);
    44444353                    *psz++ = ' ';
     
    44484357                if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TID)
    44494358                {
    4450 #ifndef IN_RC
    44514359                    RTNATIVETHREAD Thread = RTThreadNativeSelf();
    4452 #else
    4453                     RTNATIVETHREAD Thread = NIL_RTNATIVETHREAD;
    4454 #endif
    44554360                    psz += RTStrFormatNumber(psz, Thread, 16, sizeof(RTNATIVETHREAD) * 2, 0, RTSTR_F_ZEROPAD);
    44564361                    *psz++ = ' ';
     
    44834388#define CCH_PREFIX_10   CCH_PREFIX_09 + 17
    44844389
    4485 #ifndef IN_RC
    44864390                if (    (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_CUSTOM)
    44874391                    &&  pLoggerInt->pfnPrefix)
     
    44904394                    *psz++ = ' ';                                                               /* +32 */
    44914395                }
    4492 #endif
    44934396#define CCH_PREFIX_11   CCH_PREFIX_10 + 32
    44944397
     
    45964499                continue;
    45974500            }
     4501
     4502            /*
     4503             * Done with the prefixing. Copy message text past the next newline.
     4504             */
    45984505
    45994506            /* how much */
     
    47174624
    47184625
    4719 #ifndef IN_RC
    47204626/**
    47214627 * For calling rtlogLoggerExVLocked.
     
    47364642    va_end(va);
    47374643}
    4738 #endif /* !IN_RC */
    4739 
     4644
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