Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / include / linux / trace_seq.h
blob6609b39a723261cf9e0dc3afc154f28d66f98ce2
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>
7 #include <asm/page.h>
9 /*
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).
14 struct trace_seq {
15 unsigned char buffer[PAGE_SIZE];
16 struct seq_buf seq;
17 int full;
20 static inline void
21 trace_seq_init(struct trace_seq *s)
23 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
24 s->full = 0;
27 /**
28 * trace_seq_used - amount of actual data written to buffer
29 * @s: trace sequence descriptor
31 * Returns the amount of data written to the buffer.
33 * IMPORTANT!
35 * Use this instead of @s->seq.len if you need to pass the amount
36 * of data from the buffer to another buffer (userspace, or what not).
37 * The @s->seq.len on overflow is bigger than the buffer size and
38 * using it can cause access to undefined memory.
40 static inline int trace_seq_used(struct trace_seq *s)
42 return seq_buf_used(&s->seq);
45 /**
46 * trace_seq_buffer_ptr - return pointer to next location in buffer
47 * @s: trace sequence descriptor
49 * Returns the pointer to the buffer where the next write to
50 * the buffer will happen. This is useful to save the location
51 * that is about to be written to and then return the result
52 * of that write.
54 static inline unsigned char *
55 trace_seq_buffer_ptr(struct trace_seq *s)
57 return s->buffer + seq_buf_used(&s->seq);
60 /**
61 * trace_seq_has_overflowed - return true if the trace_seq took too much
62 * @s: trace sequence descriptor
64 * Returns true if too much data was added to the trace_seq and it is
65 * now full and will not take anymore.
67 static inline bool trace_seq_has_overflowed(struct trace_seq *s)
69 return s->full || seq_buf_has_overflowed(&s->seq);
73 * Currently only defined when tracing is enabled.
75 #ifdef CONFIG_TRACING
76 extern __printf(2, 3)
77 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
78 extern __printf(2, 0)
79 void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
80 extern void
81 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
82 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
83 extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
84 int cnt);
85 extern void trace_seq_puts(struct trace_seq *s, const char *str);
86 extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
87 extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
88 extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
89 unsigned int len);
90 extern int trace_seq_path(struct trace_seq *s, const struct path *path);
92 extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
93 int nmaskbits);
95 #else /* CONFIG_TRACING */
96 static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
99 static inline void
100 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
104 static inline void
105 trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
106 int nmaskbits)
110 static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
112 return 0;
114 static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
115 int cnt)
117 return 0;
119 static inline void trace_seq_puts(struct trace_seq *s, const char *str)
122 static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
125 static inline void
126 trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
129 static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
130 unsigned int len)
133 static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
135 return 0;
137 #endif /* CONFIG_TRACING */
139 #endif /* _LINUX_TRACE_SEQ_H */