trace_seq.h 3.2 KB

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