VirtualBox

Changeset 90857 in vbox for trunk


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

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/log.h

    r90840 r90857  
    153153
    154154/** Logger structure. */
    155 #if defined(IN_RC) && !defined(DOXYGEN_RUNNING)
    156 typedef struct RTLOGGERRC RTLOGGER;
    157 #else
    158155typedef struct RTLOGGER RTLOGGER;
    159 #endif
    160156/** Pointer to logger structure. */
    161157typedef RTLOGGER *PRTLOGGER;
    162158/** Pointer to const logger structure. */
    163159typedef 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;
    172160
    173161
     
    477465/** Log destinations that can be changed via RTLogChangeDestinations. */
    478466#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);
    483467
    484468
     
    17111695
    17121696
    1713 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
    17141697/**
    17151698 * Sets the default release logger instance.
     
    17191702 */
    17201703RTDECL(PRTLOGGER) RTLogRelSetDefaultInstance(PRTLOGGER pLogger);
    1721 #endif
    17221704
    17231705/**
     
    19301912
    19311913/**
    1932  * Gets the default logger instance.
     1914 * Gets the default logger instance (does not create one).
    19331915 *
    19341916 * @returns Pointer to default logger instance if availble, otherwise NULL.
     
    19371919
    19381920/**
    1939  * Gets the default logger instance if enabled.
     1921 * Gets the default logger instance if enabled (does not create one).
    19401922 *
    19411923 * @returns Pointer to default logger instance, if group has the specified
     
    19461928RTDECL(PRTLOGGER)   RTLogGetDefaultInstanceEx(uint32_t fFlagsAndGroup);
    19471929
    1948 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
    19491930/**
    19501931 * Sets the default logger instance.
     
    19541935 */
    19551936RTDECL(PRTLOGGER)   RTLogSetDefaultInstance(PRTLOGGER pLogger);
    1956 #endif
    19571937
    19581938#ifdef IN_RING0
     
    19671947 *                      current thread use 0.
    19681948 */
    1969 RTDECL(int)         RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
     1949RTR0DECL(int)       RTLogSetDefaultInstanceThread(PRTLOGGER pLogger, uintptr_t uKey);
    19701950#endif /* IN_RING0 */
    19711951
    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.
    19761954 *
    19771955 * Any user of the logging features will need to implement
     
    19801958 * @returns Pointer to the logger instance.
    19811959 */
    1982 RTDECL(PRTLOGGER) RTLogDefaultInit(void);
    1983 #endif
    1984 
    1985 /**
    1986  *
     1960RTDECL(PRTLOGGER)   RTLogDefaultInit(void);
     1961
     1962/**
    19871963 * This is the 2nd half of what RTLogGetDefaultInstanceEx() and
    19881964 * RTLogRelGetDefaultInstanceEx() does.
     
    19951971 */
    19961972RTDECL(PRTLOGGER)   RTLogCheckGroupFlags(PRTLOGGER pLogger, uint32_t fFlagsAndGroup);
    1997 
    1998 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
    19991973
    20001974/**
     
    21102084
    21112085/**
    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).
    21132089 *
    21142090 * @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.
    21462092 */
    21472093RTDECL(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 logger
    2157  *                              instance clone.
    2158  * @param   pfnLoggerRCPtr      Pointer to logger wrapper function for this
    2159  *                              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 NULL
    2171  *                      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 NULL
    2192  *                       the default logger is used.
    2193  * @param   pLoggerR0    The R0 logger instance to flush.
    2194  */
    2195 RTDECL(void) RTLogFlushR0(PRTLOGGER pLogger, PRTLOGGER pLoggerR0);
    21962094
    21972095/**
     
    22062104
    22072105/**
    2208  * Same as RTLogSetCustomPrefixCallback for loggers created by
    2209  * RTLogCreateForR0.
     2106 * Set the thread name for a thread specific ring-0 logger.
    22102107 *
    22112108 * @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.
    22402112 */
    22412113RTR0DECL(int) RTLogSetR0ThreadNameF(PRTLOGGER pLogger, const char *pszNameFmt, ...) RT_IPRT_FORMAT_ATTR(1, 2);
     
    22452117 *
    22462118 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
    2247  * @param   pLogger             Logger instance (NULL for default logger).
    2248  * @param   pszBuf              The output buffer.
    2249  * @param   cchBuf              The size of the output buffer. Must be greater
    2250  *                              than zero.
     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.
    22512123 */
    22522124RTDECL(int) RTLogQueryGroupSettings(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
     
    22632135RTDECL(int) RTLogGroupSettings(PRTLOGGER pLogger, const char *pszValue);
    22642136
    2265 #endif /* !IN_RC || DOXYGEN_RUNNING */
    2266 
    22672137/**
    22682138 * Sets the max number of entries per group.
     
    22792149RTDECL(uint32_t) RTLogSetGroupLimit(PRTLOGGER pLogger, uint32_t cMaxEntriesPerGroup);
    22802150
    2281 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
    2282 
    22832151/**
    22842152 * Gets the current flag settings for the given logger.
    22852153 *
    22862154 * @returns Logger flags, UINT64_MAX if no logger.
    2287  * @param   pLogger             Logger instance (NULL for default logger).
     2155 * @param   pLogger     Logger instance (NULL for default logger).
    22882156 */
    22892157RTDECL(uint64_t) RTLogGetFlags(PRTLOGGER pLogger);
     
    22942162 * @returns IPRT status code.  Returns VINF_SUCCESS if no default logger and @a
    22952163 *          pLogger is NULL.
    2296  * @param   pLogger             Logger instance (NULL for default logger).
    2297  * @param   fSet                Mask of flags to set (OR).
    2298  * @param   fClear              Mask of flags to clear (NAND).  This is allowed to
    2299  *                              include invalid flags - e.g. UINT64_MAX is okay.
     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.
    23002168 */
    23012169RTDECL(int) RTLogChangeFlags(PRTLOGGER pLogger, uint64_t fSet, uint64_t fClear);
    2302 
    2303 #endif
    23042170
    23052171/**
     
    23202186 *
    23212187 * @returns The old state.
    2322  * @param   pLogger         The logger instance (NULL is an alias for the
    2323  *                          default logger).
    2324  * @param   fBuffered       The new state.
     2188 * @param   pLogger     The logger instance (NULL is an alias for the default
     2189 *                      logger).
     2190 * @param   fBuffered   The new state.
    23252191 */
    23262192RTDECL(bool) RTLogSetBuffering(PRTLOGGER pLogger, bool fBuffered);
    23272193
    2328 #if !defined(IN_RC) || defined(DOXYGEN_RUNNING)
    2329 
    23302194/**
    23312195 * Get the current log flags as a string.
    23322196 *
    23332197 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
    2334  * @param   pLogger             Logger instance (NULL for default logger).
    2335  * @param   pszBuf              The output buffer.
    2336  * @param   cchBuf              The size of the output buffer. Must be greater
    2337  *                              than zero.
     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.
    23382202 */
    23392203RTDECL(int) RTLogQueryFlags(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
     
    23432207 *
    23442208 * @returns Logger destination flags, UINT32_MAX if no logger.
    2345  * @param   pLogger             Logger instance (NULL for default logger).
     2209 * @param   pLogger     Logger instance (NULL for default logger).
    23462210 */
    23472211RTDECL(uint32_t) RTLogGetDestinations(PRTLOGGER pLogger);
     
    23552219 * @returns IPRT status code.  Returns VINF_SUCCESS if no default logger and @a
    23562220 *          pLogger is NULL.
    2357  * @param   pLogger            Logger instance (NULL for default logger).
    2358  * @param   fSet               Mask of destinations to set (OR).
    2359  * @param   fClear             Mask of destinations to clear (NAND).
     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).
    23602224 */
    23612225RTDECL(int) RTLogChangeDestinations(PRTLOGGER pLogger, uint32_t fSet, uint32_t fClear);
     
    23652229 *
    23662230 * @returns VINF_SUCCESS or VERR_BUFFER_OVERFLOW.
    2367  * @param   pLogger             Logger instance (NULL for default logger).
    2368  * @param   pszValue            The value to parse.
     2231 * @param   pLogger     Logger instance (NULL for default logger).
     2232 * @param   pszValue    The value to parse.
    23692233 */
    23702234RTDECL(int) RTLogDestinations(PRTLOGGER pLogger, char const *pszValue);
     
    23742238 *
    23752239 * @returns IPRT status code.
    2376  * @param   pLogger             Logger instance (NULL for default logger).
    2377  * @param   pErrInfo            Where to return extended error info.  Optional.
     2240 * @param   pLogger     Logger instance (NULL for default logger).
     2241 * @param   pErrInfo    Where to return extended error info.  Optional.
    23782242 */
    23792243RTDECL(int) RTLogClearFileDelayFlag(PRTLOGGER pLogger, PRTERRINFO pErrInfo);
     
    23832247 *
    23842248 * @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.
    23892252 */
    23902253RTDECL(int) RTLogQueryDestinations(PRTLOGGER pLogger, char *pszBuf, size_t cchBuf);
     
    24332296 *
    24342297 * @returns IRPT status code.
    2435  * @param   pLogger             The logger instance (NULL for default logger).
    2436  * @param   pch                 Pointer to the block of bulk log text to write.
    2437  * @param   cch                 Size of the block of bulk log text to write.
     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.
    24382301 */
    24392302RTDECL(int) RTLogBulkWrite(PRTLOGGER pLogger, const char *pch, size_t cch);
    2440 
    2441 #endif /* !IN_RC || DOXYGEN_RUNNING */
    24422303
    24432304/**
     
    25272388 * Dumper vprintf-like function outputting to a logger.
    25282389 *
    2529  * @param   pvUser          Pointer to the logger instance to use, NULL for
    2530  *                          default instance.
    2531  * @param   pszFormat       Format string.
    2532  * @param   va              Format arguments.
     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.
    25332394 */
    25342395RTDECL(void) RTLogDumpPrintfV(void *pvUser, const char *pszFormat, va_list va) RT_IPRT_FORMAT_ATTR(2, 0);
     
    25892450RTDECL(size_t)  RTLogComPrintfV(const char *pszFormat, va_list args) RT_IPRT_FORMAT_ATTR(1, 0);
    25902451
    2591 
    2592 #if 0 /* not implemented yet */
    2593 
    2594 /** Indicates that the semaphores shall be used to notify the other
    2595  * part about buffer changes. */
    2596 #define LOGHOOKBUFFER_FLAGS_SEMAPHORED      1
    2597 
    2598 /**
    2599  * Log Hook Buffer.
    2600  * Use to communicate between the logger and a log consumer.
    2601  */
    2602 typedef struct RTLOGHOOKBUFFER
    2603 {
    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 acting
    2629  * producer and consumer. They share a circular buffer which have two
    2630  * pointers one for each end. When the buffer is full there are two
    2631  * alternatives (indicated by a buffer flag), either wait for the
    2632  * consumer to get it's job done, or to write a generic message saying
    2633  * 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 
    26542452/**
    26552453 * Write log buffer to a debugger (RTLOGDEST_DEBUGGER).
  • trunk/include/iprt/mangling.h

    r90829 r90857  
    14321432# define RTLogBulkUpdate                                RT_MANGLER(RTLogBulkUpdate)
    14331433# define RTLogBulkWrite                                 RT_MANGLER(RTLogBulkWrite)
    1434 # define RTLogCalcSizeForR0                             RT_MANGLER(RTLogCalcSizeForR0)
    14351434# define RTLogChangeDestinations                        RT_MANGLER(RTLogChangeDestinations)
    14361435# define RTLogChangeFlags                               RT_MANGLER(RTLogChangeFlags)
     
    14401439# define RTLogComPrintf                                 RT_MANGLER(RTLogComPrintf)
    14411440# define RTLogComPrintfV                                RT_MANGLER(RTLogComPrintfV)
    1442 # define RTLogCopyGroupsAndFlagsForR0                   RT_MANGLER(RTLogCopyGroupsAndFlagsForR0)
    14431441# define RTLogCreate                                    RT_MANGLER(RTLogCreate)
    14441442# define RTLogCreateEx                                  RT_MANGLER(RTLogCreateEx)
    14451443# define RTLogCreateExV                                 RT_MANGLER(RTLogCreateExV)
    1446 # define RTLogCreateForR0                               RT_MANGLER(RTLogCreateForR0)
    14471444# define RTLogDefaultInit                               RT_MANGLER(RTLogDefaultInit)
    14481445# define RTLogDefaultInstance                           RT_MANGLER(RTLogDefaultInstance)
     
    14521449# define RTLogFlags                                     RT_MANGLER(RTLogFlags)
    14531450# define RTLogFlush                                     RT_MANGLER(RTLogFlush)
    1454 # define RTLogFlushRC                                   RT_MANGLER(RTLogFlushRC)
    1455 # define RTLogFlushR0                                   RT_MANGLER(RTLogFlushR0)
    1456 # define RTLogFlushToLogger                             RT_MANGLER(RTLogFlushToLogger)
    14571451# define RTLogFormatV                                   RT_MANGLER(RTLogFormatV)
    14581452# define RTLogGetDefaultInstance                        RT_MANGLER(RTLogGetDefaultInstance)
  • 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