Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_TRACE_SEQ_H |
| 2 | #define _LINUX_TRACE_SEQ_H |
| 3 | |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 4 | #include <linux/seq_buf.h> |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 5 | |
Wu Zhangjin | 78be691 | 2009-06-14 14:52:30 +0800 | [diff] [blame] | 6 | #include <asm/page.h> |
| 7 | |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 8 | /* |
| 9 | * Trace sequences are used to allow a function to call several other functions |
Jiri Olsa | 6d3f1e1 | 2009-10-23 19:36:19 -0400 | [diff] [blame] | 10 | * to create a string of data to use (up to a max of PAGE_SIZE). |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | struct trace_seq { |
| 14 | unsigned char buffer[PAGE_SIZE]; |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 15 | struct seq_buf seq; |
Johannes Berg | d184b31 | 2009-11-25 16:10:14 +0100 | [diff] [blame] | 16 | int full; |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | static inline void |
| 20 | trace_seq_init(struct trace_seq *s) |
| 21 | { |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 22 | seq_buf_init(&s->seq, s->buffer, PAGE_SIZE); |
Johannes Berg | d184b31 | 2009-11-25 16:10:14 +0100 | [diff] [blame] | 23 | s->full = 0; |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 24 | } |
| 25 | |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 26 | /** |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 27 | * trace_seq_used - amount of actual data written to buffer |
| 28 | * @s: trace sequence descriptor |
| 29 | * |
| 30 | * Returns the amount of data written to the buffer. |
| 31 | * |
| 32 | * IMPORTANT! |
| 33 | * |
| 34 | * Use this instead of @s->seq.len if you need to pass the amount |
| 35 | * of data from the buffer to another buffer (userspace, or what not). |
| 36 | * The @s->seq.len on overflow is bigger than the buffer size and |
| 37 | * using it can cause access to undefined memory. |
| 38 | */ |
| 39 | static inline int trace_seq_used(struct trace_seq *s) |
| 40 | { |
| 41 | return seq_buf_used(&s->seq); |
| 42 | } |
| 43 | |
| 44 | /** |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 45 | * trace_seq_buffer_ptr - return pointer to next location in buffer |
| 46 | * @s: trace sequence descriptor |
| 47 | * |
| 48 | * Returns the pointer to the buffer where the next write to |
| 49 | * the buffer will happen. This is useful to save the location |
| 50 | * that is about to be written to and then return the result |
| 51 | * of that write. |
| 52 | */ |
| 53 | static inline unsigned char * |
| 54 | trace_seq_buffer_ptr(struct trace_seq *s) |
| 55 | { |
Steven Rostedt (Red Hat) | 5ac48378 | 2014-11-14 15:49:41 -0500 | [diff] [blame] | 56 | return s->buffer + seq_buf_used(&s->seq); |
Steven Rostedt (Red Hat) | 7b039cb | 2014-06-26 09:42:41 -0400 | [diff] [blame] | 57 | } |
| 58 | |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 59 | /** |
| 60 | * trace_seq_has_overflowed - return true if the trace_seq took too much |
| 61 | * @s: trace sequence descriptor |
| 62 | * |
| 63 | * Returns true if too much data was added to the trace_seq and it is |
| 64 | * now full and will not take anymore. |
| 65 | */ |
| 66 | static inline bool trace_seq_has_overflowed(struct trace_seq *s) |
| 67 | { |
Steven Rostedt (Red Hat) | 3a161d9 | 2014-06-25 15:54:42 -0400 | [diff] [blame] | 68 | return s->full || seq_buf_has_overflowed(&s->seq); |
Steven Rostedt (Red Hat) | 19a7fe2 | 2014-11-12 10:29:54 -0500 | [diff] [blame] | 69 | } |
| 70 | |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 71 | /* |
| 72 | * Currently only defined when tracing is enabled. |
| 73 | */ |
| 74 | #ifdef CONFIG_TRACING |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 75 | extern __printf(2, 3) |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 76 | void trace_seq_printf(struct trace_seq *s, const char *fmt, ...); |
Joe Perches | b9075fa | 2011-10-31 17:11:33 -0700 | [diff] [blame] | 77 | extern __printf(2, 0) |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 78 | void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args); |
| 79 | extern void |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 80 | trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary); |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 81 | extern int trace_print_seq(struct seq_file *m, struct trace_seq *s); |
Steven Rostedt (Red Hat) | 36aabff | 2014-06-20 17:38:01 -0400 | [diff] [blame] | 82 | extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, |
| 83 | int cnt); |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 84 | extern void trace_seq_puts(struct trace_seq *s, const char *str); |
| 85 | extern void trace_seq_putc(struct trace_seq *s, unsigned char c); |
| 86 | extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len); |
| 87 | extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, |
Steven Rostedt (Red Hat) | 36aabff | 2014-06-20 17:38:01 -0400 | [diff] [blame] | 88 | unsigned int len); |
Al Viro | 38eff28 | 2012-03-14 21:51:10 -0400 | [diff] [blame] | 89 | extern int trace_seq_path(struct trace_seq *s, const struct path *path); |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 90 | |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 91 | extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 92 | int nmaskbits); |
| 93 | |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 94 | #else /* CONFIG_TRACING */ |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 95 | static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 96 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 97 | } |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 98 | static inline void |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 99 | trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) |
| 100 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 103 | static inline void |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 104 | trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, |
| 105 | int nmaskbits) |
| 106 | { |
Steven Rostedt (Red Hat) | 4449bf9 | 2014-05-06 13:10:24 -0400 | [diff] [blame] | 107 | } |
| 108 | |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 109 | static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 110 | { |
Steven Rostedt | a63ce5b | 2009-12-07 09:11:39 -0500 | [diff] [blame] | 111 | return 0; |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 112 | } |
Steven Rostedt (Red Hat) | 36aabff | 2014-06-20 17:38:01 -0400 | [diff] [blame] | 113 | static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, |
| 114 | int cnt) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 115 | { |
| 116 | return 0; |
| 117 | } |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 118 | static inline void trace_seq_puts(struct trace_seq *s, const char *str) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 119 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 120 | } |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 121 | static inline void trace_seq_putc(struct trace_seq *s, unsigned char c) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 122 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 123 | } |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 124 | static inline void |
Steven Rostedt (Red Hat) | 36aabff | 2014-06-20 17:38:01 -0400 | [diff] [blame] | 125 | trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 126 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 127 | } |
Steven Rostedt (Red Hat) | dba3944 | 2014-11-12 18:07:22 -0500 | [diff] [blame] | 128 | static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, |
Steven Rostedt (Red Hat) | 36aabff | 2014-06-20 17:38:01 -0400 | [diff] [blame] | 129 | unsigned int len) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 130 | { |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 131 | } |
Al Viro | 38eff28 | 2012-03-14 21:51:10 -0400 | [diff] [blame] | 132 | static inline int trace_seq_path(struct trace_seq *s, const struct path *path) |
Steven Rostedt | 9504504 | 2009-04-11 12:59:57 -0400 | [diff] [blame] | 133 | { |
| 134 | return 0; |
| 135 | } |
| 136 | #endif /* CONFIG_TRACING */ |
| 137 | |
| 138 | #endif /* _LINUX_TRACE_SEQ_H */ |