Changeset 90857 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Aug 24, 2021 9:13:13 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/log.cpp
r90850 r90857 32 32 #include "internal/iprt.h" 33 33 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> 42 40 #ifdef IN_RING3 43 41 # include <iprt/env.h> … … 193 191 char szR0ThreadName[16]; 194 192 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 196 194 /** @name File logging bits for the logger. 197 195 * @{ */ … … 233 231 AssertCompileMemberAlignment(RTLOGGERINTERNAL, cbRingBufUnflushed, sizeof(uint64_t)); 234 232 #ifdef IN_RING3 235 /** The size of the RTLOGGERINTERNAL structure in ring-0. */236 # define RTLOGGERINTERNAL_R0_SIZE RT_UOFFSETOF(RTLOGGERINTERNAL, pfnPhase)237 233 AssertCompileMemberAlignment(RTLOGGERINTERNAL, hFile, sizeof(void *)); 238 234 AssertCompileMemberAlignment(RTLOGGERINTERNAL, cbHistoryFileMax, sizeof(uint64_t)); … … 259 255 * Internal Functions * 260 256 *********************************************************************************************************************************/ 261 #ifndef IN_RC262 257 static unsigned rtlogGroupFlags(const char *psz); 263 #endif264 258 #ifdef IN_RING0 265 259 static void rtR0LogLoggerExFallback(uint32_t fDestFlags, uint32_t fFlags, PRTLOGGERINTERNAL pInt, … … 269 263 static int rtR3LogOpenFileDestination(PRTLOGGERINTERNAL pLoggerInt, PRTERRINFO pErrInfo); 270 264 #endif 271 #ifndef IN_RC272 265 static void rtLogRingBufFlush(PRTLOGGERINTERNAL pLoggerInt); 273 #endif274 266 static void rtlogFlush(PRTLOGGERINTERNAL pLoggerInt, bool fNeedSpace); 275 267 static DECLCALLBACK(size_t) rtLogOutput(void *pv, const char *pachChars, size_t cbChars); 276 268 static void rtlogLoggerExVLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup, 277 269 const char *pszFormat, va_list args); 278 #ifndef IN_RC279 270 static void rtlogLoggerExFLocked(PRTLOGGERINTERNAL pLoggerInt, unsigned fFlags, unsigned iGroup, const char *pszFormat, ...); 280 #endif281 271 282 272 … … 284 274 * Global Variables * 285 275 *********************************************************************************************************************************/ 286 #ifndef IN_RC287 276 /** Default logger instance. */ 288 277 static PRTLOGGER g_pLogger; 289 278 /** Default release logger instance. */ 290 279 static PRTLOGGER g_pRelLogger; 291 #else292 /** Default logger instance. Make it weak because our RC module loader does not293 * necessarily resolve this symbol and the compiler _must_ check if this is294 * 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_DARWIN297 extern "C" DECLIMPORT(RTLOGGERRC) g_Logger;298 /** Default release logger instance. */299 extern "C" DECLIMPORT(RTLOGGERRC) g_RelLogger;300 # else301 extern "C" DECLWEAK(DECLIMPORT(RTLOGGERRC)) g_Logger;302 /** Default release logger instance. */303 extern "C" DECLWEAK(DECLIMPORT(RTLOGGERRC)) g_RelLogger;304 # endif305 #endif /* IN_RC */306 280 #ifdef IN_RING3 307 281 /** The RTThreadGetWriteLockCount() change caused by the logger mutex semaphore. */ … … 425 399 DECLINLINE(int) rtlogLock(PRTLOGGERINTERNAL pLoggerInt) 426 400 { 427 #ifndef IN_RC428 401 AssertMsgReturn(pLoggerInt->Core.u32Magic == RTLOGGER_MAGIC, ("%#x != %#x\n", pLoggerInt->Core.u32Magic, RTLOGGER_MAGIC), 429 402 VERR_INVALID_MAGIC); … … 438 411 return rc; 439 412 } 440 #else441 NOREF(pLoggerInt);442 #endif443 413 return VINF_SUCCESS; 444 414 } … … 451 421 DECLINLINE(void) rtlogUnlock(PRTLOGGERINTERNAL pLoggerInt) 452 422 { 453 #ifndef IN_RC454 423 if (pLoggerInt->hSpinMtx != NIL_RTSEMSPINMUTEX) 455 424 RTSemSpinMutexRelease(pLoggerInt->hSpinMtx); 456 #else457 NOREF(pLoggerInt);458 #endif459 425 return; 460 426 } 461 427 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 510 429 511 430 /** … … 548 467 } 549 468 550 # 469 #endif /* IN_RING3 */ 551 470 552 471 /** … … 2001 1920 } 2002 1921 1922 2003 1923 /** 2004 1924 * Helper for RTLogGetGroupSettings. … … 2006 1926 static int rtLogGetGroupSettingsAddOne(const char *pszName, uint32_t fGroup, char **ppszBuf, size_t *pcchBuf, bool *pfNotFirst) 2007 1927 { 2008 # 2009 # 2010 # 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) 2011 1931 2012 1932 /* … … 2044 1964 return VERR_BUFFER_OVERFLOW; 2045 1965 2046 # 2047 # 2048 # 1966 #undef APPEND_PSZ 1967 #undef APPEND_SZ 1968 #undef APPEND_CH 2049 1969 return VINF_SUCCESS; 2050 1970 } … … 2123 2043 RT_EXPORT_SYMBOL(RTLogQueryGroupSettings); 2124 2044 2125 #endif /* !IN_RC */2126 2045 2127 2046 /** … … 2258 2177 2259 2178 2260 #ifdef IN_RING32261 2179 RTDECL(uint32_t) RTLogSetGroupLimit(PRTLOGGER pLogger, uint32_t cMaxEntriesPerGroup) 2262 2180 { … … 2280 2198 return cOld; 2281 2199 } 2282 #endif 2200 RT_EXPORT_SYMBOL(RTLogSetGroupLimit); 2283 2201 2284 2202 … … 2308 2226 } 2309 2227 RT_EXPORT_SYMBOL(RTLogSetR0ThreadNameF); 2310 #endif 2311 2312 #ifndef IN_RC 2228 #endif /* IN_RING0 */ 2229 2313 2230 2314 2231 /** … … 3101 3018 RT_EXPORT_SYMBOL(RTLogBulkWrite); 3102 3019 3103 #endif /* !IN_RC */3104 3020 3105 3021 /** … … 3164 3080 * Common worker for RTLogDefaultInstance and RTLogDefaultInstanceEx. 3165 3081 */ 3082 DECL_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 */ 3166 3101 DECL_FORCE_INLINE(PRTLOGGER) rtLogDefaultInstanceCommon(void) 3167 3102 { 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 3173 3106 /* 3174 3107 * Check per thread loggers first. … … 3182 3115 return g_aPerThreadLoggers[i].pLogger; 3183 3116 } 3184 # 3117 #endif /* IN_RING0 */ 3185 3118 3186 3119 /* 3187 3120 * If no per thread logger, use the default one. 3188 3121 */ 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; 3193 3128 } 3194 3129 … … 3238 3173 DECL_FORCE_INLINE(PRTLOGGER) rtLogGetDefaultInstanceCommon(void) 3239 3174 { 3240 #ifdef IN_RC 3241 return &g_Logger; 3242 #else 3243 # ifdef IN_RING0 3175 #ifdef IN_RING0 3244 3176 /* 3245 3177 * Check per thread loggers first. … … 3253 3185 return g_aPerThreadLoggers[i].pLogger; 3254 3186 } 3255 # 3187 #endif /* IN_RING0 */ 3256 3188 3257 3189 return g_pLogger; 3258 #endif3259 3190 } 3260 3191 … … 3278 3209 3279 3210 3280 #ifndef IN_RC3281 3211 /** 3282 3212 * Sets the default logger instance. … … 3290 3220 } 3291 3221 RT_EXPORT_SYMBOL(RTLogSetDefaultInstance); 3292 #endif /* !IN_RC */3293 3222 3294 3223 … … 3304 3233 * current thread use 0. 3305 3234 */ 3306 RT DECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey)3235 RTR0DECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey) 3307 3236 { 3308 3237 int rc; … … 3382 3311 RTDECL(PRTLOGGER) RTLogRelGetDefaultInstance(void) 3383 3312 { 3384 #ifdef IN_RC3385 return &g_RelLogger;3386 #else /* !IN_RC */3387 3313 return g_pRelLogger; 3388 #endif /* !IN_RC */3389 3314 } 3390 3315 RT_EXPORT_SYMBOL(RTLogRelGetDefaultInstance); … … 3393 3318 RTDECL(PRTLOGGER) RTLogRelGetDefaultInstanceEx(uint32_t fFlagsAndGroup) 3394 3319 { 3395 #ifdef IN_RC3396 PRTLOGGERINTERNAL pLoggerInt = &g_RelLogger;3397 #else3398 3320 PRTLOGGERINTERNAL pLoggerInt = (PRTLOGGERINTERNAL)g_pRelLogger; 3399 #endif3400 3321 if (pLoggerInt) 3401 3322 pLoggerInt = rtLogCheckGroupFlagsWorker(pLoggerInt, fFlagsAndGroup); … … 3405 3326 3406 3327 3407 #ifndef IN_RC3408 3328 /** 3409 3329 * Sets the default logger instance. … … 3417 3337 } 3418 3338 RT_EXPORT_SYMBOL(RTLogRelSetDefaultInstance); 3419 #endif /* !IN_RC */3420 3339 3421 3340 … … 3494 3413 */ 3495 3414 if ( (pLoggerInt->fFlags & RTLOGFLAGS_DISABLED) 3496 #ifndef IN_RC3497 3415 || !pLoggerInt->fDestFlags 3498 #endif3499 3416 || !pszFormat || !*pszFormat) 3500 3417 return; … … 3519 3436 * Check restrictions and call worker. 3520 3437 */ 3521 #ifndef IN_RC3522 3438 if (RT_UNLIKELY( (pLoggerInt->fFlags & RTLOGFLAGS_RESTRICT_GROUPS) 3523 3439 && iGroup < pLoggerInt->cGroups … … 3540 3456 } 3541 3457 else 3542 #endif3543 3458 rtlogLoggerExVLocked(pLoggerInt, fFlags, iGroup, pszFormat, args); 3544 3459 … … 3550 3465 RT_EXPORT_SYMBOL(RTLogLoggerExV); 3551 3466 3552 3553 3467 #ifdef IN_RING0 3468 3554 3469 /** 3555 3470 * For rtR0LogLoggerExFallbackOutput and rtR0LogLoggerExFallbackFlush. … … 3706 3621 RTLogFormatV(rtR0LogLoggerExFallbackOutput, &This, pszFormat, va); 3707 3622 } 3623 3708 3624 #endif /* IN_RING0 */ 3709 3710 3625 3711 3626 /** … … 3737 3652 } 3738 3653 RT_EXPORT_SYMBOL(RTLogDumpPrintfV); 3739 3740 3654 3741 3655 #ifdef IN_RING3 … … 3958 3872 3959 3873 #endif /* IN_RING3 */ 3960 3961 3874 3962 3875 /** … … 4363 4276 if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_MS_PROG) 4364 4277 { 4365 #if defined(IN_RING3) || defined(IN_RC)4278 #ifndef IN_RING0 4366 4279 uint64_t u64 = RTTimeProgramMilliTS(); 4367 4280 #else … … 4398 4311 { 4399 4312 4400 #if defined(IN_RING3) || defined(IN_RC)4313 #ifndef IN_RING0 4401 4314 uint64_t u64 = RTTimeProgramMicroTS(); 4402 4315 #else … … 4436 4349 if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_PID) 4437 4350 { 4438 #ifndef IN_RC4439 4351 RTPROCESS Process = RTProcSelf(); 4440 #else4441 RTPROCESS Process = NIL_RTPROCESS;4442 #endif4443 4352 psz += RTStrFormatNumber(psz, Process, 16, sizeof(RTPROCESS) * 2, 0, RTSTR_F_ZEROPAD); 4444 4353 *psz++ = ' '; … … 4448 4357 if (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_TID) 4449 4358 { 4450 #ifndef IN_RC4451 4359 RTNATIVETHREAD Thread = RTThreadNativeSelf(); 4452 #else4453 RTNATIVETHREAD Thread = NIL_RTNATIVETHREAD;4454 #endif4455 4360 psz += RTStrFormatNumber(psz, Thread, 16, sizeof(RTNATIVETHREAD) * 2, 0, RTSTR_F_ZEROPAD); 4456 4361 *psz++ = ' '; … … 4483 4388 #define CCH_PREFIX_10 CCH_PREFIX_09 + 17 4484 4389 4485 #ifndef IN_RC4486 4390 if ( (pLoggerInt->fFlags & RTLOGFLAGS_PREFIX_CUSTOM) 4487 4391 && pLoggerInt->pfnPrefix) … … 4490 4394 *psz++ = ' '; /* +32 */ 4491 4395 } 4492 #endif4493 4396 #define CCH_PREFIX_11 CCH_PREFIX_10 + 32 4494 4397 … … 4596 4499 continue; 4597 4500 } 4501 4502 /* 4503 * Done with the prefixing. Copy message text past the next newline. 4504 */ 4598 4505 4599 4506 /* how much */ … … 4717 4624 4718 4625 4719 #ifndef IN_RC4720 4626 /** 4721 4627 * For calling rtlogLoggerExVLocked. … … 4736 4642 va_end(va); 4737 4643 } 4738 #endif /* !IN_RC */ 4739 4644
Note:
See TracChangeset
for help on using the changeset viewer.