1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_TRACE_SEQ_H
3 #define _LINUX_TRACE_SEQ_H
5 #include <linux/seq_buf.h>
10 * Trace sequences are used to allow a function to call several other functions
11 * to create a string of data to use (up to a max of PAGE_SIZE).
15 char buffer[PAGE_SIZE];
22 trace_seq_init(struct trace_seq *s)
24 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
30 * trace_seq_used - amount of actual data written to buffer
31 * @s: trace sequence descriptor
33 * Returns the amount of data written to the buffer.
37 * Use this instead of @s->seq.len if you need to pass the amount
38 * of data from the buffer to another buffer (userspace, or what not).
39 * The @s->seq.len on overflow is bigger than the buffer size and
40 * using it can cause access to undefined memory.
42 static inline int trace_seq_used(struct trace_seq *s)
44 return seq_buf_used(&s->seq);
48 * trace_seq_buffer_ptr - return pointer to next location in buffer
49 * @s: trace sequence descriptor
51 * Returns the pointer to the buffer where the next write to
52 * the buffer will happen. This is useful to save the location
53 * that is about to be written to and then return the result
57 trace_seq_buffer_ptr(struct trace_seq *s)
59 return s->buffer + seq_buf_used(&s->seq);
63 * trace_seq_has_overflowed - return true if the trace_seq took too much
64 * @s: trace sequence descriptor
66 * Returns true if too much data was added to the trace_seq and it is
67 * now full and will not take anymore.
69 static inline bool trace_seq_has_overflowed(struct trace_seq *s)
71 return s->full || seq_buf_has_overflowed(&s->seq);
75 * Currently only defined when tracing is enabled.
79 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
81 void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
83 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
84 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
85 extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
87 extern void trace_seq_puts(struct trace_seq *s, const char *str);
88 extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
89 extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
90 extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
92 extern int trace_seq_path(struct trace_seq *s, const struct path *path);
94 extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
97 extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str,
98 int prefix_type, int rowsize, int groupsize,
99 const void *buf, size_t len, bool ascii);
100 char *trace_seq_acquire(struct trace_seq *s, unsigned int len);
102 #else /* CONFIG_TRACING */
103 static inline __printf(2, 3)
104 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
108 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
113 trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
118 static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
122 static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
127 static inline void trace_seq_puts(struct trace_seq *s, const char *str)
130 static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
134 trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
137 static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
141 static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
145 static inline char *trace_seq_acquire(struct trace_seq *s, unsigned int len)
149 #endif /* CONFIG_TRACING */
151 #endif /* _LINUX_TRACE_SEQ_H */