trace_seq.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #ifndef _LINUX_TRACE_SEQ_H
  2. #define _LINUX_TRACE_SEQ_H
  3. #include <linux/fs.h>
  4. #include <asm/page.h>
  5. /*
  6. * Trace sequences are used to allow a function to call several other functions
  7. * to create a string of data to use (up to a max of PAGE_SIZE).
  8. */
  9. struct trace_seq {
  10. unsigned char buffer[PAGE_SIZE];
  11. unsigned int len;
  12. unsigned int readpos;
  13. int full;
  14. };
  15. static inline void
  16. trace_seq_init(struct trace_seq *s)
  17. {
  18. s->len = 0;
  19. s->readpos = 0;
  20. s->full = 0;
  21. }
  22. /**
  23. * trace_seq_buffer_ptr - return pointer to next location in buffer
  24. * @s: trace sequence descriptor
  25. *
  26. * Returns the pointer to the buffer where the next write to
  27. * the buffer will happen. This is useful to save the location
  28. * that is about to be written to and then return the result
  29. * of that write.
  30. */
  31. static inline unsigned char *
  32. trace_seq_buffer_ptr(struct trace_seq *s)
  33. {
  34. return s->buffer + s->len;
  35. }
  36. /**
  37. * trace_seq_has_overflowed - return true if the trace_seq took too much
  38. * @s: trace sequence descriptor
  39. *
  40. * Returns true if too much data was added to the trace_seq and it is
  41. * now full and will not take anymore.
  42. */
  43. static inline bool trace_seq_has_overflowed(struct trace_seq *s)
  44. {
  45. return s->full || s->len > PAGE_SIZE - 1;
  46. }
  47. /*
  48. * Currently only defined when tracing is enabled.
  49. */
  50. #ifdef CONFIG_TRACING
  51. extern __printf(2, 3)
  52. void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
  53. extern __printf(2, 0)
  54. void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
  55. extern void
  56. trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
  57. extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
  58. extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  59. int cnt);
  60. extern void trace_seq_puts(struct trace_seq *s, const char *str);
  61. extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
  62. extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
  63. extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
  64. unsigned int len);
  65. extern int trace_seq_path(struct trace_seq *s, const struct path *path);
  66. extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
  67. int nmaskbits);
  68. #else /* CONFIG_TRACING */
  69. static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
  70. {
  71. }
  72. static inline void
  73. trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
  74. {
  75. }
  76. static inline void
  77. trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
  78. int nmaskbits)
  79. {
  80. }
  81. static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
  82. {
  83. return 0;
  84. }
  85. static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  86. int cnt)
  87. {
  88. return 0;
  89. }
  90. static inline void trace_seq_puts(struct trace_seq *s, const char *str)
  91. {
  92. }
  93. static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
  94. {
  95. }
  96. static inline void
  97. trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
  98. {
  99. }
  100. static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
  101. unsigned int len)
  102. {
  103. }
  104. static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
  105. {
  106. return 0;
  107. }
  108. #endif /* CONFIG_TRACING */
  109. #endif /* _LINUX_TRACE_SEQ_H */