LCOV - code coverage report
Current view: top level - include/linux - printk.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 5 8 62.5 %
Date: 2014-02-18 Functions: 0 0 -
Branches: 9 18 50.0 %

           Branch data     Line data    Source code
       1                 :            : #ifndef __KERNEL_PRINTK__
       2                 :            : #define __KERNEL_PRINTK__
       3                 :            : 
       4                 :            : #include <stdarg.h>
       5                 :            : #include <linux/init.h>
       6                 :            : #include <linux/kern_levels.h>
       7                 :            : #include <linux/linkage.h>
       8                 :            : 
       9                 :            : extern const char linux_banner[];
      10                 :            : extern const char linux_proc_banner[];
      11                 :            : extern const char linux_scm_version_banner[];
      12                 :            : 
      13                 :            : static inline int printk_get_level(const char *buffer)
      14                 :            : {
      15 [ +  + ][ +  - ]:        573 :         if (buffer[0] == KERN_SOH_ASCII && buffer[1]) {
         [ +  - ][ +  - ]
      16 [ +  - ][ +  - ]:        310 :                 switch (buffer[1]) {
      17                 :            :                 case '0' ... '7':
      18                 :            :                 case 'd':       /* KERN_DEFAULT */
      19                 :        310 :                         return buffer[1];
      20                 :            :                 }
      21                 :            :         }
      22                 :            :         return 0;
      23                 :            : }
      24                 :            : 
      25                 :            : static inline const char *printk_skip_level(const char *buffer)
      26                 :            : {
      27         [ +  - ]:        155 :         if (printk_get_level(buffer)) {
      28         [ +  - ]:        155 :                 switch (buffer[1]) {
      29                 :            :                 case '0' ... '7':
      30                 :            :                 case 'd':       /* KERN_DEFAULT */
      31                 :          0 :                         return buffer + 2;
      32                 :            :                 }
      33                 :            :         }
      34                 :            :         return buffer;
      35                 :            : }
      36                 :            : 
      37                 :            : extern int console_printk[];
      38                 :            : 
      39                 :            : #define console_loglevel (console_printk[0])
      40                 :            : #define default_message_loglevel (console_printk[1])
      41                 :            : #define minimum_console_loglevel (console_printk[2])
      42                 :            : #define default_console_loglevel (console_printk[3])
      43                 :            : 
      44                 :            : static inline void console_silent(void)
      45                 :            : {
      46                 :            :         console_loglevel = 0;
      47                 :            : }
      48                 :            : 
      49                 :            : static inline void console_verbose(void)
      50                 :            : {
      51         [ #  # ]:          0 :         if (console_loglevel)
      52                 :          0 :                 console_loglevel = 15;
      53                 :            : }
      54                 :            : 
      55                 :            : struct va_format {
      56                 :            :         const char *fmt;
      57                 :            :         va_list *va;
      58                 :            : };
      59                 :            : 
      60                 :            : /*
      61                 :            :  * FW_BUG
      62                 :            :  * Add this to a message where you are sure the firmware is buggy or behaves
      63                 :            :  * really stupid or out of spec. Be aware that the responsible BIOS developer
      64                 :            :  * should be able to fix this issue or at least get a concrete idea of the
      65                 :            :  * problem by reading your message without the need of looking at the kernel
      66                 :            :  * code.
      67                 :            :  *
      68                 :            :  * Use it for definite and high priority BIOS bugs.
      69                 :            :  *
      70                 :            :  * FW_WARN
      71                 :            :  * Use it for not that clear (e.g. could the kernel messed up things already?)
      72                 :            :  * and medium priority BIOS bugs.
      73                 :            :  *
      74                 :            :  * FW_INFO
      75                 :            :  * Use this one if you want to tell the user or vendor about something
      76                 :            :  * suspicious, but generally harmless related to the firmware.
      77                 :            :  *
      78                 :            :  * Use it for information or very low priority BIOS bugs.
      79                 :            :  */
      80                 :            : #define FW_BUG          "[Firmware Bug]: "
      81                 :            : #define FW_WARN         "[Firmware Warn]: "
      82                 :            : #define FW_INFO         "[Firmware Info]: "
      83                 :            : 
      84                 :            : /*
      85                 :            :  * HW_ERR
      86                 :            :  * Add this to a message for hardware errors, so that user can report
      87                 :            :  * it to hardware vendor instead of LKML or software vendor.
      88                 :            :  */
      89                 :            : #define HW_ERR          "[Hardware Error]: "
      90                 :            : 
      91                 :            : /*
      92                 :            :  * Dummy printk for disabled debugging statements to use whilst maintaining
      93                 :            :  * gcc's format and side-effect checking.
      94                 :            :  */
      95                 :            : static inline __printf(1, 2)
      96                 :            : int no_printk(const char *fmt, ...)
      97                 :            : {
      98                 :            :         return 0;
      99                 :            : }
     100                 :            : 
     101                 :            : #ifdef CONFIG_EARLY_PRINTK
     102                 :            : extern asmlinkage __printf(1, 2)
     103                 :            : void early_printk(const char *fmt, ...);
     104                 :            : void early_vprintk(const char *fmt, va_list ap);
     105                 :            : #else
     106                 :            : static inline __printf(1, 2) __cold
     107                 :            : void early_printk(const char *s, ...) { }
     108                 :            : #endif
     109                 :            : 
     110                 :            : #ifdef CONFIG_PRINTK
     111                 :            : asmlinkage __printf(5, 0)
     112                 :            : int vprintk_emit(int facility, int level,
     113                 :            :                  const char *dict, size_t dictlen,
     114                 :            :                  const char *fmt, va_list args);
     115                 :            : 
     116                 :            : asmlinkage __printf(1, 0)
     117                 :            : int vprintk(const char *fmt, va_list args);
     118                 :            : 
     119                 :            : asmlinkage __printf(5, 6) __cold
     120                 :            : asmlinkage int printk_emit(int facility, int level,
     121                 :            :                            const char *dict, size_t dictlen,
     122                 :            :                            const char *fmt, ...);
     123                 :            : 
     124                 :            : asmlinkage __printf(1, 2) __cold
     125                 :            : int printk(const char *fmt, ...);
     126                 :            : 
     127                 :            : /*
     128                 :            :  * Special printk facility for scheduler use only, _DO_NOT_USE_ !
     129                 :            :  */
     130                 :            : __printf(1, 2) __cold int printk_sched(const char *fmt, ...);
     131                 :            : 
     132                 :            : /*
     133                 :            :  * Please don't use printk_ratelimit(), because it shares ratelimiting state
     134                 :            :  * with all other unrelated printk_ratelimit() callsites.  Instead use
     135                 :            :  * printk_ratelimited() or plain old __ratelimit().
     136                 :            :  */
     137                 :            : extern int __printk_ratelimit(const char *func);
     138                 :            : #define printk_ratelimit() __printk_ratelimit(__func__)
     139                 :            : extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
     140                 :            :                                    unsigned int interval_msec);
     141                 :            : 
     142                 :            : extern int printk_delay_msec;
     143                 :            : extern int dmesg_restrict;
     144                 :            : extern int kptr_restrict;
     145                 :            : 
     146                 :            : extern void wake_up_klogd(void);
     147                 :            : 
     148                 :            : void log_buf_kexec_setup(void);
     149                 :            : void __init setup_log_buf(int early);
     150                 :            : void dump_stack_set_arch_desc(const char *fmt, ...);
     151                 :            : void dump_stack_print_info(const char *log_lvl);
     152                 :            : void show_regs_print_info(const char *log_lvl);
     153                 :            : #else
     154                 :            : static inline __printf(1, 0)
     155                 :            : int vprintk(const char *s, va_list args)
     156                 :            : {
     157                 :            :         return 0;
     158                 :            : }
     159                 :            : static inline __printf(1, 2) __cold
     160                 :            : int printk(const char *s, ...)
     161                 :            : {
     162                 :            :         return 0;
     163                 :            : }
     164                 :            : static inline __printf(1, 2) __cold
     165                 :            : int printk_sched(const char *s, ...)
     166                 :            : {
     167                 :            :         return 0;
     168                 :            : }
     169                 :            : static inline int printk_ratelimit(void)
     170                 :            : {
     171                 :            :         return 0;
     172                 :            : }
     173                 :            : static inline bool printk_timed_ratelimit(unsigned long *caller_jiffies,
     174                 :            :                                           unsigned int interval_msec)
     175                 :            : {
     176                 :            :         return false;
     177                 :            : }
     178                 :            : 
     179                 :            : static inline void wake_up_klogd(void)
     180                 :            : {
     181                 :            : }
     182                 :            : 
     183                 :            : static inline void log_buf_kexec_setup(void)
     184                 :            : {
     185                 :            : }
     186                 :            : 
     187                 :            : static inline void setup_log_buf(int early)
     188                 :            : {
     189                 :            : }
     190                 :            : 
     191                 :            : static inline void dump_stack_set_arch_desc(const char *fmt, ...)
     192                 :            : {
     193                 :            : }
     194                 :            : 
     195                 :            : static inline void dump_stack_print_info(const char *log_lvl)
     196                 :            : {
     197                 :            : }
     198                 :            : 
     199                 :            : static inline void show_regs_print_info(const char *log_lvl)
     200                 :            : {
     201                 :            : }
     202                 :            : #endif
     203                 :            : 
     204                 :            : extern asmlinkage void dump_stack(void) __cold;
     205                 :            : 
     206                 :            : #ifndef pr_fmt
     207                 :            : #define pr_fmt(fmt) fmt
     208                 :            : #endif
     209                 :            : 
     210                 :            : #define pr_emerg(fmt, ...) \
     211                 :            :         printk(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
     212                 :            : #define pr_alert(fmt, ...) \
     213                 :            :         printk(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
     214                 :            : #define pr_crit(fmt, ...) \
     215                 :            :         printk(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
     216                 :            : #define pr_err(fmt, ...) \
     217                 :            :         printk(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
     218                 :            : #define pr_warning(fmt, ...) \
     219                 :            :         printk(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
     220                 :            : #define pr_warn pr_warning
     221                 :            : #define pr_notice(fmt, ...) \
     222                 :            :         printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
     223                 :            : #define pr_info(fmt, ...) \
     224                 :            :         printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
     225                 :            : #define pr_cont(fmt, ...) \
     226                 :            :         printk(KERN_CONT fmt, ##__VA_ARGS__)
     227                 :            : 
     228                 :            : /* pr_devel() should produce zero code unless DEBUG is defined */
     229                 :            : #ifdef DEBUG
     230                 :            : #define pr_devel(fmt, ...) \
     231                 :            :         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     232                 :            : #else
     233                 :            : #define pr_devel(fmt, ...) \
     234                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     235                 :            : #endif
     236                 :            : 
     237                 :            : #include <linux/dynamic_debug.h>
     238                 :            : 
     239                 :            : /* If you are writing a driver, please use dev_dbg instead */
     240                 :            : #if defined(CONFIG_DYNAMIC_DEBUG)
     241                 :            : /* dynamic_pr_debug() uses pr_fmt() internally so we don't need it here */
     242                 :            : #define pr_debug(fmt, ...) \
     243                 :            :         dynamic_pr_debug(fmt, ##__VA_ARGS__)
     244                 :            : #elif defined(DEBUG)
     245                 :            : #define pr_debug(fmt, ...) \
     246                 :            :         printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     247                 :            : #else
     248                 :            : #define pr_debug(fmt, ...) \
     249                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     250                 :            : #endif
     251                 :            : 
     252                 :            : /*
     253                 :            :  * Print a one-time message (analogous to WARN_ONCE() et al):
     254                 :            :  */
     255                 :            : 
     256                 :            : #ifdef CONFIG_PRINTK
     257                 :            : #define printk_once(fmt, ...)                   \
     258                 :            : ({                                              \
     259                 :            :         static bool __print_once;               \
     260                 :            :                                                 \
     261                 :            :         if (!__print_once) {                    \
     262                 :            :                 __print_once = true;            \
     263                 :            :                 printk(fmt, ##__VA_ARGS__);     \
     264                 :            :         }                                       \
     265                 :            : })
     266                 :            : #else
     267                 :            : #define printk_once(fmt, ...)                   \
     268                 :            :         no_printk(fmt, ##__VA_ARGS__)
     269                 :            : #endif
     270                 :            : 
     271                 :            : #define pr_emerg_once(fmt, ...)                                 \
     272                 :            :         printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
     273                 :            : #define pr_alert_once(fmt, ...)                                 \
     274                 :            :         printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
     275                 :            : #define pr_crit_once(fmt, ...)                                  \
     276                 :            :         printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
     277                 :            : #define pr_err_once(fmt, ...)                                   \
     278                 :            :         printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
     279                 :            : #define pr_warn_once(fmt, ...)                                  \
     280                 :            :         printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
     281                 :            : #define pr_notice_once(fmt, ...)                                \
     282                 :            :         printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
     283                 :            : #define pr_info_once(fmt, ...)                                  \
     284                 :            :         printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
     285                 :            : #define pr_cont_once(fmt, ...)                                  \
     286                 :            :         printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__)
     287                 :            : 
     288                 :            : #if defined(DEBUG)
     289                 :            : #define pr_devel_once(fmt, ...)                                 \
     290                 :            :         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     291                 :            : #else
     292                 :            : #define pr_devel_once(fmt, ...)                                 \
     293                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     294                 :            : #endif
     295                 :            : 
     296                 :            : /* If you are writing a driver, please use dev_dbg instead */
     297                 :            : #if defined(DEBUG)
     298                 :            : #define pr_debug_once(fmt, ...)                                 \
     299                 :            :         printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     300                 :            : #else
     301                 :            : #define pr_debug_once(fmt, ...)                                 \
     302                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     303                 :            : #endif
     304                 :            : 
     305                 :            : /*
     306                 :            :  * ratelimited messages with local ratelimit_state,
     307                 :            :  * no local ratelimit_state used in the !PRINTK case
     308                 :            :  */
     309                 :            : #ifdef CONFIG_PRINTK
     310                 :            : #define printk_ratelimited(fmt, ...)                                    \
     311                 :            : ({                                                                      \
     312                 :            :         static DEFINE_RATELIMIT_STATE(_rs,                              \
     313                 :            :                                       DEFAULT_RATELIMIT_INTERVAL,       \
     314                 :            :                                       DEFAULT_RATELIMIT_BURST);         \
     315                 :            :                                                                         \
     316                 :            :         if (__ratelimit(&_rs))                                              \
     317                 :            :                 printk(fmt, ##__VA_ARGS__);                             \
     318                 :            : })
     319                 :            : #else
     320                 :            : #define printk_ratelimited(fmt, ...)                                    \
     321                 :            :         no_printk(fmt, ##__VA_ARGS__)
     322                 :            : #endif
     323                 :            : 
     324                 :            : #define pr_emerg_ratelimited(fmt, ...)                                  \
     325                 :            :         printk_ratelimited(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__)
     326                 :            : #define pr_alert_ratelimited(fmt, ...)                                  \
     327                 :            :         printk_ratelimited(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__)
     328                 :            : #define pr_crit_ratelimited(fmt, ...)                                   \
     329                 :            :         printk_ratelimited(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__)
     330                 :            : #define pr_err_ratelimited(fmt, ...)                                    \
     331                 :            :         printk_ratelimited(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__)
     332                 :            : #define pr_warn_ratelimited(fmt, ...)                                   \
     333                 :            :         printk_ratelimited(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__)
     334                 :            : #define pr_notice_ratelimited(fmt, ...)                                 \
     335                 :            :         printk_ratelimited(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__)
     336                 :            : #define pr_info_ratelimited(fmt, ...)                                   \
     337                 :            :         printk_ratelimited(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__)
     338                 :            : /* no pr_cont_ratelimited, don't do that... */
     339                 :            : 
     340                 :            : #if defined(DEBUG)
     341                 :            : #define pr_devel_ratelimited(fmt, ...)                                  \
     342                 :            :         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     343                 :            : #else
     344                 :            : #define pr_devel_ratelimited(fmt, ...)                                  \
     345                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     346                 :            : #endif
     347                 :            : 
     348                 :            : /* If you are writing a driver, please use dev_dbg instead */
     349                 :            : #if defined(CONFIG_DYNAMIC_DEBUG)
     350                 :            : /* descriptor check is first to prevent flooding with "callbacks suppressed" */
     351                 :            : #define pr_debug_ratelimited(fmt, ...)                                  \
     352                 :            : do {                                                                    \
     353                 :            :         static DEFINE_RATELIMIT_STATE(_rs,                              \
     354                 :            :                                       DEFAULT_RATELIMIT_INTERVAL,       \
     355                 :            :                                       DEFAULT_RATELIMIT_BURST);         \
     356                 :            :         DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);                 \
     357                 :            :         if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) &&    \
     358                 :            :             __ratelimit(&_rs))                                              \
     359                 :            :                 __dynamic_pr_debug(&descriptor, fmt, ##__VA_ARGS__);        \
     360                 :            : } while (0)
     361                 :            : #elif defined(DEBUG)
     362                 :            : #define pr_debug_ratelimited(fmt, ...)                                  \
     363                 :            :         printk_ratelimited(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     364                 :            : #else
     365                 :            : #define pr_debug_ratelimited(fmt, ...) \
     366                 :            :         no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__)
     367                 :            : #endif
     368                 :            : 
     369                 :            : extern const struct file_operations kmsg_fops;
     370                 :            : 
     371                 :            : enum {
     372                 :            :         DUMP_PREFIX_NONE,
     373                 :            :         DUMP_PREFIX_ADDRESS,
     374                 :            :         DUMP_PREFIX_OFFSET
     375                 :            : };
     376                 :            : extern void hex_dump_to_buffer(const void *buf, size_t len,
     377                 :            :                                int rowsize, int groupsize,
     378                 :            :                                char *linebuf, size_t linebuflen, bool ascii);
     379                 :            : #ifdef CONFIG_PRINTK
     380                 :            : extern void print_hex_dump(const char *level, const char *prefix_str,
     381                 :            :                            int prefix_type, int rowsize, int groupsize,
     382                 :            :                            const void *buf, size_t len, bool ascii);
     383                 :            : #if defined(CONFIG_DYNAMIC_DEBUG)
     384                 :            : #define print_hex_dump_bytes(prefix_str, prefix_type, buf, len) \
     385                 :            :         dynamic_hex_dump(prefix_str, prefix_type, 16, 1, buf, len, true)
     386                 :            : #else
     387                 :            : extern void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
     388                 :            :                                  const void *buf, size_t len);
     389                 :            : #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
     390                 :            : #else
     391                 :            : static inline void print_hex_dump(const char *level, const char *prefix_str,
     392                 :            :                                   int prefix_type, int rowsize, int groupsize,
     393                 :            :                                   const void *buf, size_t len, bool ascii)
     394                 :            : {
     395                 :            : }
     396                 :            : static inline void print_hex_dump_bytes(const char *prefix_str, int prefix_type,
     397                 :            :                                         const void *buf, size_t len)
     398                 :            : {
     399                 :            : }
     400                 :            : 
     401                 :            : #endif
     402                 :            : 
     403                 :            : #if defined(CONFIG_DYNAMIC_DEBUG)
     404                 :            : #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,  \
     405                 :            :                              groupsize, buf, len, ascii)        \
     406                 :            :         dynamic_hex_dump(prefix_str, prefix_type, rowsize,      \
     407                 :            :                          groupsize, buf, len, ascii)
     408                 :            : #else
     409                 :            : #define print_hex_dump_debug(prefix_str, prefix_type, rowsize,          \
     410                 :            :                              groupsize, buf, len, ascii)                \
     411                 :            :         print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize,    \
     412                 :            :                        groupsize, buf, len, ascii)
     413                 :            : #endif /* defined(CONFIG_DYNAMIC_DEBUG) */
     414                 :            : 
     415                 :            : #endif

Generated by: LCOV version 1.9