- Timestamp:
- Aug 24, 2021 9:13:13 PM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/log.h
r90840 r90857 153 153 154 154 /** Logger structure. */ 155 #if defined(IN_RC) && !defined(DOXYGEN_RUNNING)156 typedef struct RTLOGGERRC RTLOGGER;157 #else158 155 typedef struct RTLOGGER RTLOGGER; 159 #endif160 156 /** Pointer to logger structure. */ 161 157 typedef RTLOGGER *PRTLOGGER; 162 158 /** Pointer to const logger structure. */ 163 159 typedef const RTLOGGER *PCRTLOGGER; 164 165 166 /** Guest context logger structure. */167 typedef struct RTLOGGERRC RTLOGGERRC;168 /** Pointer to guest context logger structure. */169 typedef RTLOGGERRC *PRTLOGGERRC;170 /** Pointer to const guest context logger structure. */171 typedef const RTLOGGERRC *PCRTLOGGERRC;172 160 173 161 … … 477 465 /** Log destinations that can be changed via RTLogChangeDestinations. */ 478 466 #define RTLOG_DST_CHANGE_MASK UINT32_C(0x4000001e) 479 480 481 RTDECL(void) RTLogPrintfEx(void *pvInstance, unsigned fFlags, unsigned iGroup,482 const char *pszFormat, ...) RT_IPRT_FORMAT_ATTR(4, 5);483 467 484 468 … … 1711 1695 1712 1696 1713 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)1714 1697 /** 1715 1698 * Sets the default release logger instance. … … 1719 1702 */ 1720 1703 RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger); 1721 #endif1722 1704 1723 1705 /** … … 1930 1912 1931 1913 /** 1932 * Gets the default logger instance .1914 * Gets the default logger instance (does not create one). 1933 1915 * 1934 1916 * @returns Pointer to default logger instance if availble, otherwise NULL. … … 1937 1919 1938 1920 /** 1939 * Gets the default logger instance if enabled .1921 * Gets the default logger instance if enabled (does not create one). 1940 1922 * 1941 1923 * @returns Pointer to default logger instance, if group has the specified … … 1946 1928 RTDECL(PRTLOGGER) RTLogGetDefaultInstanceEx(uint32_t fFlagsAndGroup); 1947 1929 1948 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)1949 1930 /** 1950 1931 * Sets the default logger instance. … … 1954 1935 */ 1955 1936 RTDECL(PRTLOGGER) RTLogSetDefaultInstance(PRTLOGGER pLogger); 1956 #endif1957 1937 1958 1938 #ifdef IN_RING0 … … 1967 1947 * current thread use 0. 1968 1948 */ 1969 RT DECL(int)RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);1949 RTR0DECL(int) RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey); 1970 1950 #endif /* IN_RING0 */ 1971 1951 1972 1973 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING) 1974 /** 1975 * Creates the default logger instance for a iprt users. 1952 /** 1953 * Creates the default logger instance for IPRT users. 1976 1954 * 1977 1955 * Any user of the logging features will need to implement … … 1980 1958 * @returns Pointer to the logger instance. 1981 1959 */ 1982 RTDECL(PRTLOGGER) RTLogDefaultInit(void); 1983 #endif 1984 1985 /** 1986 * 1960 RTDECL(PRTLOGGER) RTLogDefaultInit(void); 1961 1962 /** 1987 1963 * This is the 2nd half of what RTLogGetDefaultInstanceEx() and 1988 1964 * RTLogRelGetDefaultInstanceEx() does. … … 1995 1971 */ 1996 1972 RTDECL(PRTLOGGER) RTLogCheckGroupFlags(PRTLOGGER pLogger, uint32_t fFlagsAndGroup); 1997 1998 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)1999 1973 2000 1974 /** … … 2110 2084 2111 2085 /** 2112 * Create a logger instance for singled threaded ring-0 usage. 2086 * Destroys a logger instance. 2087 * 2088 * The instance is flushed and all output destinations closed (where applicable). 2113 2089 * 2114 2090 * @returns iprt status code. 2115 * 2116 * @param pLogger Where to create the logger instance. 2117 * @param cbLogger The amount of memory available for the logger instance. 2118 * @param pLoggerR0Ptr The ring-0 address corresponding to @a pLogger. 2119 * @param pfnLoggerR0Ptr Pointer to logger wrapper function. 2120 * @param pfnFlushR0Ptr Pointer to flush function. 2121 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values. 2122 * @param fDestFlags The destination flags. 2123 * @param pszThreadName The thread name to report in ring-0 when 2124 * RTLOGFLAGS_PREFIX_THREAD is set. 2125 */ 2126 RTDECL(int) RTLogCreateForR0(PRTLOGGER pLogger, size_t cbLogger, 2127 RTR0PTR pLoggerR0Ptr, RTR0PTR pfnLoggerR0Ptr, RTR0PTR pfnFlushR0Ptr, 2128 uint32_t fFlags, uint32_t fDestFlags, char const *pszThreadName); 2129 2130 /** 2131 * Calculates the minimum size of a ring-0 logger instance. 2132 * 2133 * @returns The minimum size. 2134 * @param cGroups The number of groups. 2135 * @param fFlags Relevant flags. 2136 */ 2137 RTDECL(size_t) RTLogCalcSizeForR0(uint32_t cGroups, uint32_t fFlags); 2138 2139 /** 2140 * Destroys a logger instance. 2141 * 2142 * The instance is flushed and all output destinations closed (where applicable). 2143 * 2144 * @returns iprt status code. 2145 * @param pLogger The logger instance which close destroyed. NULL is fine. 2091 * @param pLogger The logger instance which close destroyed. NULL is fine. 2146 2092 */ 2147 2093 RTDECL(int) RTLogDestroy(PRTLOGGER pLogger); 2148 2149 /**2150 * Create a logger instance clone for RC usage.2151 *2152 * @returns iprt status code.2153 *2154 * @param pLogger The logger instance to be cloned.2155 * @param pLoggerRC Where to create the RC logger instance.2156 * @param cbLoggerRC Amount of memory allocated to for the RC logger2157 * instance clone.2158 * @param pfnLoggerRCPtr Pointer to logger wrapper function for this2159 * instance (RC Ptr).2160 * @param pfnFlushRCPtr Pointer to flush function (RC Ptr).2161 * @param fFlags Logger instance flags, a combination of the RTLOGFLAGS_* values.2162 */2163 RTDECL(int) RTLogCloneRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC, size_t cbLoggerRC,2164 RTRCPTR pfnLoggerRCPtr, RTRCPTR pfnFlushRCPtr, uint32_t fFlags);2165 2166 /**2167 * Flushes a RC logger instance to a R3 logger.2168 *2169 * @returns iprt status code.2170 * @param pLogger The R3 logger instance to flush pLoggerRC to. If NULL2171 * the default logger is used.2172 * @param pLoggerRC The RC logger instance to flush.2173 */2174 RTDECL(void) RTLogFlushRC(PRTLOGGER pLogger, PRTLOGGERRC pLoggerRC);2175 2176 /**2177 * Flushes the buffer in one logger instance onto another logger.2178 *2179 * @returns iprt status code.2180 *2181 * @param pSrcLogger The logger instance to flush.2182 * @param pDstLogger The logger instance to flush onto.2183 * If NULL the default logger will be used.2184 */2185 RTDECL(void) RTLogFlushToLogger(PRTLOGGER pSrcLogger, PRTLOGGER pDstLogger);2186 2187 /**2188 * Flushes a R0 logger instance to a R3 logger.2189 *2190 * @returns iprt status code.2191 * @param pLogger The R3 logger instance to flush pLoggerR0 to. If NULL2192 * the default logger is used.2193 * @param pLoggerR0 The R0 logger instance to flush.2194 */2195 RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0);2196 2094 2197 2095 /** … … 2206 2104 2207 2105 /** 2208 * Same as RTLogSetCustomPrefixCallback for loggers created by 2209 * RTLogCreateForR0. 2106 * Set the thread name for a thread specific ring-0 logger. 2210 2107 * 2211 2108 * @returns IPRT status code. 2212 * @param pLogger The logger instance. 2213 * @param pLoggerR0Ptr The ring-0 address corresponding to @a pLogger. 2214 * @param pfnCallbackR0Ptr The callback. 2215 * @param pvUserR0Ptr The user argument for the callback. 2216 * */ 2217 RTDECL(int) RTLogSetCustomPrefixCallbackForR0(PRTLOGGER pLogger, RTR0PTR pLoggerR0Ptr, 2218 RTR0PTR pfnCallbackR0Ptr, RTR0PTR pvUserR0Ptr); 2219 2220 /** 2221 * Copies the group settings and flags from logger instance to another. 2222 * 2223 * @returns IPRT status code. 2224 * @param pDstLogger The destination logger instance. 2225 * @param pDstLoggerR0Ptr The ring-0 address corresponding to @a pDstLogger. 2226 * @param pSrcLogger The source logger instance. If NULL the default one is used. 2227 * @param fFlagsOr OR mask for the flags. 2228 * @param fFlagsAnd AND mask for the flags. 2229 */ 2230 RTDECL(int) RTLogCopyGroupsAndFlagsForR0(PRTLOGGER pDstLogger, RTR0PTR pDstLoggerR0Ptr, 2231 PCRTLOGGER pSrcLogger, uint32_t fFlagsOr, uint32_t fFlagsAnd); 2232 2233 /** 2234 * Set the thread name for a thread specific ring-0 logger. 2235 * 2236 * @returns IPRT status code. 2237 * @param pLogger The logger. NULL is not allowed. 2238 * @param pszNameFmt The format string for the thread name. 2239 * @param ... Format arguments. 2109 * @param pLogger The logger. NULL is not allowed. 2110 * @param pszNameFmt The format string for the thread name. 2111 * @param ... Format arguments. 2240 2112 */ 2241 2113 RTR0DECL(int) RTLogSetR0ThreadNameF(PRTLOGGER pLogger, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(1, 2); … … 2245 2117 * 2246 2118 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. 2247 * @param pLogger 2248 * @param pszBuf 2249 * @param cchBuf The size of the output buffer. Must be greater2250 * thanzero.2119 * @param pLogger Logger instance (NULL for default logger). 2120 * @param pszBuf The output buffer. 2121 * @param cchBuf The size of the output buffer. Must be greater than 2122 * zero. 2251 2123 */ 2252 2124 RTDECL(int) RTLogQueryGroupSettings(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf); … … 2263 2135 RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszValue); 2264 2136 2265 #endif /* !IN_RC || DOXYGEN_RUNNING */2266 2267 2137 /** 2268 2138 * Sets the max number of entries per group. … … 2279 2149 RTDECL(uint32_t) RTLogSetGroupLimit(PRTLOGGER pLogger, uint32_t cMaxEntriesPerGroup); 2280 2150 2281 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)2282 2283 2151 /** 2284 2152 * Gets the current flag settings for the given logger. 2285 2153 * 2286 2154 * @returns Logger flags, UINT64_MAX if no logger. 2287 * @param pLogger 2155 * @param pLogger Logger instance (NULL for default logger). 2288 2156 */ 2289 2157 RTDECL(uint64_t) RTLogGetFlags(PRTLOGGER pLogger); … … 2294 2162 * @returns IPRT status code. Returns VINF_SUCCESS if no default logger and @a 2295 2163 * pLogger is NULL. 2296 * @param pLogger 2297 * @param fSet 2298 * @param fClear 2299 * 2164 * @param pLogger Logger instance (NULL for default logger). 2165 * @param fSet Mask of flags to set (OR). 2166 * @param fClear Mask of flags to clear (NAND). This is allowed to 2167 * include invalid flags - e.g. UINT64_MAX is okay. 2300 2168 */ 2301 2169 RTDECL(int) RTLogChangeFlags(PRTLOGGER pLogger, uint64_t fSet, uint64_t fClear); 2302 2303 #endif2304 2170 2305 2171 /** … … 2320 2186 * 2321 2187 * @returns The old state. 2322 * @param pLogger The logger instance (NULL is an alias for the2323 * defaultlogger).2324 * @param fBuffered 2188 * @param pLogger The logger instance (NULL is an alias for the default 2189 * logger). 2190 * @param fBuffered The new state. 2325 2191 */ 2326 2192 RTDECL(bool) RTLogSetBuffering(PRTLOGGER pLogger, bool fBuffered); 2327 2193 2328 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)2329 2330 2194 /** 2331 2195 * Get the current log flags as a string. 2332 2196 * 2333 2197 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. 2334 * @param pLogger 2335 * @param pszBuf 2336 * @param cchBuf The size of the output buffer. Must be greater2337 * thanzero.2198 * @param pLogger Logger instance (NULL for default logger). 2199 * @param pszBuf The output buffer. 2200 * @param cchBuf The size of the output buffer. Must be greater than 2201 * zero. 2338 2202 */ 2339 2203 RTDECL(int) RTLogQueryFlags(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf); … … 2343 2207 * 2344 2208 * @returns Logger destination flags, UINT32_MAX if no logger. 2345 * @param pLogger 2209 * @param pLogger Logger instance (NULL for default logger). 2346 2210 */ 2347 2211 RTDECL(uint32_t) RTLogGetDestinations(PRTLOGGER pLogger); … … 2355 2219 * @returns IPRT status code. Returns VINF_SUCCESS if no default logger and @a 2356 2220 * pLogger is NULL. 2357 * @param pLogger 2358 * @param fSet 2359 * @param fClear 2221 * @param pLogger Logger instance (NULL for default logger). 2222 * @param fSet Mask of destinations to set (OR). 2223 * @param fClear Mask of destinations to clear (NAND). 2360 2224 */ 2361 2225 RTDECL(int) RTLogChangeDestinations(PRTLOGGER pLogger, uint32_t fSet, uint32_t fClear); … … 2365 2229 * 2366 2230 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. 2367 * @param pLogger 2368 * @param pszValue 2231 * @param pLogger Logger instance (NULL for default logger). 2232 * @param pszValue The value to parse. 2369 2233 */ 2370 2234 RTDECL(int) RTLogDestinations(PRTLOGGER pLogger, char const *pszValue); … … 2374 2238 * 2375 2239 * @returns IPRT status code. 2376 * @param pLogger 2377 * @param pErrInfo 2240 * @param pLogger Logger instance (NULL for default logger). 2241 * @param pErrInfo Where to return extended error info. Optional. 2378 2242 */ 2379 2243 RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo); … … 2383 2247 * 2384 2248 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW. 2385 * @param pLogger Logger instance (NULL for default logger). 2386 * @param pszBuf The output buffer. 2387 * @param cchBuf The size of the output buffer. Must be greater 2388 * than 0. 2249 * @param pLogger Logger instance (NULL for default logger). 2250 * @param pszBuf The output buffer. 2251 * @param cchBuf The size of the output buffer. Must be greater than 0. 2389 2252 */ 2390 2253 RTDECL(int) RTLogQueryDestinations(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf); … … 2433 2296 * 2434 2297 * @returns IRPT status code. 2435 * @param pLogger 2436 * @param pch 2437 * @param cch 2298 * @param pLogger The logger instance (NULL for default logger). 2299 * @param pch Pointer to the block of bulk log text to write. 2300 * @param cch Size of the block of bulk log text to write. 2438 2301 */ 2439 2302 RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pch, size_t cch); 2440 2441 #endif /* !IN_RC || DOXYGEN_RUNNING */2442 2303 2443 2304 /** … … 2527 2388 * Dumper vprintf-like function outputting to a logger. 2528 2389 * 2529 * @param pvUser Pointer to the logger instance to use, NULL for2530 * defaultinstance.2531 * @param pszFormat 2532 * @param va 2390 * @param pvUser Pointer to the logger instance to use, NULL for default 2391 * instance. 2392 * @param pszFormat Format string. 2393 * @param va Format arguments. 2533 2394 */ 2534 2395 RTDECL(void) RTLogDumpPrintfV(void *pvUser, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0); … … 2589 2450 RTDECL(size_t) RTLogComPrintfV(const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(1, 0); 2590 2451 2591 2592 #if 0 /* not implemented yet */2593 2594 /** Indicates that the semaphores shall be used to notify the other2595 * part about buffer changes. */2596 #define LOGHOOKBUFFER_FLAGS_SEMAPHORED 12597 2598 /**2599 * Log Hook Buffer.2600 * Use to communicate between the logger and a log consumer.2601 */2602 typedef struct RTLOGHOOKBUFFER2603 {2604 /** Write pointer. */2605 volatile void *pvWrite;2606 /** Read pointer. */2607 volatile void *pvRead;2608 /** Buffer start. */2609 void *pvStart;2610 /** Buffer end (exclusive). */2611 void *pvEnd;2612 /** Signaling semaphore used by the writer to wait on a full buffer.2613 * Only used when indicated in flags. */2614 void *pvSemWriter;2615 /** Signaling semaphore used by the read to wait on an empty buffer.2616 * Only used when indicated in flags. */2617 void *pvSemReader;2618 /** Buffer flags. Current reserved and set to zero. */2619 volatile unsigned fFlags;2620 } RTLOGHOOKBUFFER;2621 /** Pointer to a log hook buffer. */2622 typedef RTLOGHOOKBUFFER *PRTLOGHOOKBUFFER;2623 2624 2625 /**2626 * Register a logging hook.2627 *2628 * This type of logging hooks are expecting different threads acting2629 * producer and consumer. They share a circular buffer which have two2630 * pointers one for each end. When the buffer is full there are two2631 * alternatives (indicated by a buffer flag), either wait for the2632 * consumer to get it's job done, or to write a generic message saying2633 * buffer overflow.2634 *2635 * Since the waiting would need a signal semaphore, we'll skip that for now.2636 *2637 * @returns iprt status code.2638 * @param pBuffer Pointer to a logger hook buffer.2639 */2640 RTDECL(int) RTLogRegisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);2641 2642 /**2643 * Deregister a logging hook registered with RTLogRegisterHook().2644 *2645 * @returns iprt status code.2646 * @param pBuffer Pointer to a logger hook buffer.2647 */2648 RTDECL(int) RTLogDeregisterHook(PRTLOGGER pLogger, PRTLOGHOOKBUFFER pBuffer);2649 2650 #endif /* not implemented yet */2651 2652 2653 2654 2452 /** 2655 2453 * Write log buffer to a debugger (RTLOGDEST_DEBUGGER). -
trunk/include/iprt/mangling.h
r90829 r90857 1432 1432 # define RTLogBulkUpdate RT_MANGLER(RTLogBulkUpdate) 1433 1433 # define RTLogBulkWrite RT_MANGLER(RTLogBulkWrite) 1434 # define RTLogCalcSizeForR0 RT_MANGLER(RTLogCalcSizeForR0)1435 1434 # define RTLogChangeDestinations RT_MANGLER(RTLogChangeDestinations) 1436 1435 # define RTLogChangeFlags RT_MANGLER(RTLogChangeFlags) … … 1440 1439 # define RTLogComPrintf RT_MANGLER(RTLogComPrintf) 1441 1440 # define RTLogComPrintfV RT_MANGLER(RTLogComPrintfV) 1442 # define RTLogCopyGroupsAndFlagsForR0 RT_MANGLER(RTLogCopyGroupsAndFlagsForR0)1443 1441 # define RTLogCreate RT_MANGLER(RTLogCreate) 1444 1442 # define RTLogCreateEx RT_MANGLER(RTLogCreateEx) 1445 1443 # define RTLogCreateExV RT_MANGLER(RTLogCreateExV) 1446 # define RTLogCreateForR0 RT_MANGLER(RTLogCreateForR0)1447 1444 # define RTLogDefaultInit RT_MANGLER(RTLogDefaultInit) 1448 1445 # define RTLogDefaultInstance RT_MANGLER(RTLogDefaultInstance) … … 1452 1449 # define RTLogFlags RT_MANGLER(RTLogFlags) 1453 1450 # define RTLogFlush RT_MANGLER(RTLogFlush) 1454 # define RTLogFlushRC RT_MANGLER(RTLogFlushRC)1455 # define RTLogFlushR0 RT_MANGLER(RTLogFlushR0)1456 # define RTLogFlushToLogger RT_MANGLER(RTLogFlushToLogger)1457 1451 # define RTLogFormatV RT_MANGLER(RTLogFormatV) 1458 1452 # define RTLogGetDefaultInstance RT_MANGLER(RTLogGetDefaultInstance) -
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.