]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
9504504c SR |
2 | #ifndef _LINUX_TRACE_SEQ_H |
3 | #define _LINUX_TRACE_SEQ_H | |
4 | ||
3a161d99 | 5 | #include <linux/seq_buf.h> |
6d723736 | 6 | |
78be6914 WZ |
7 | #include <asm/page.h> |
8 | ||
9504504c SR |
9 | /* |
10 | * Trace sequences are used to allow a function to call several other functions | |
40fc60e3 | 11 | * to create a string of data to use. |
6f42249f SRG |
12 | * |
13 | * Have the trace seq to be 8K which is typically PAGE_SIZE * 2 on | |
14 | * most architectures. The TRACE_SEQ_BUFFER_SIZE (which is | |
15 | * TRACE_SEQ_SIZE minus the other fields of trace_seq), is the | |
16 | * max size the output of a trace event may be. | |
9504504c SR |
17 | */ |
18 | ||
6f42249f SRG |
19 | #define TRACE_SEQ_SIZE 8192 |
20 | #define TRACE_SEQ_BUFFER_SIZE (TRACE_SEQ_SIZE - \ | |
40fc60e3 SRG |
21 | (sizeof(struct seq_buf) + sizeof(size_t) + sizeof(int))) |
22 | ||
9504504c | 23 | struct trace_seq { |
40fc60e3 | 24 | char buffer[TRACE_SEQ_BUFFER_SIZE]; |
3a161d99 | 25 | struct seq_buf seq; |
d0ed46b6 | 26 | size_t readpos; |
d184b31c | 27 | int full; |
9504504c SR |
28 | }; |
29 | ||
30 | static inline void | |
31 | trace_seq_init(struct trace_seq *s) | |
32 | { | |
40fc60e3 | 33 | seq_buf_init(&s->seq, s->buffer, TRACE_SEQ_BUFFER_SIZE); |
d184b31c | 34 | s->full = 0; |
d0ed46b6 | 35 | s->readpos = 0; |
9504504c SR |
36 | } |
37 | ||
5ac48378 SRRH |
38 | /** |
39 | * trace_seq_used - amount of actual data written to buffer | |
40 | * @s: trace sequence descriptor | |
41 | * | |
42 | * Returns the amount of data written to the buffer. | |
43 | * | |
44 | * IMPORTANT! | |
45 | * | |
46 | * Use this instead of @s->seq.len if you need to pass the amount | |
47 | * of data from the buffer to another buffer (userspace, or what not). | |
48 | * The @s->seq.len on overflow is bigger than the buffer size and | |
49 | * using it can cause access to undefined memory. | |
50 | */ | |
51 | static inline int trace_seq_used(struct trace_seq *s) | |
52 | { | |
53 | return seq_buf_used(&s->seq); | |
54 | } | |
55 | ||
7b039cb4 SRRH |
56 | /** |
57 | * trace_seq_buffer_ptr - return pointer to next location in buffer | |
58 | * @s: trace sequence descriptor | |
59 | * | |
60 | * Returns the pointer to the buffer where the next write to | |
61 | * the buffer will happen. This is useful to save the location | |
62 | * that is about to be written to and then return the result | |
63 | * of that write. | |
64 | */ | |
d9a9280a | 65 | static inline char * |
7b039cb4 SRRH |
66 | trace_seq_buffer_ptr(struct trace_seq *s) |
67 | { | |
5ac48378 | 68 | return s->buffer + seq_buf_used(&s->seq); |
7b039cb4 SRRH |
69 | } |
70 | ||
19a7fe20 SRRH |
71 | /** |
72 | * trace_seq_has_overflowed - return true if the trace_seq took too much | |
73 | * @s: trace sequence descriptor | |
74 | * | |
75 | * Returns true if too much data was added to the trace_seq and it is | |
76 | * now full and will not take anymore. | |
77 | */ | |
78 | static inline bool trace_seq_has_overflowed(struct trace_seq *s) | |
79 | { | |
3a161d99 | 80 | return s->full || seq_buf_has_overflowed(&s->seq); |
19a7fe20 SRRH |
81 | } |
82 | ||
9504504c SR |
83 | /* |
84 | * Currently only defined when tracing is enabled. | |
85 | */ | |
86 | #ifdef CONFIG_TRACING | |
b9075fa9 | 87 | extern __printf(2, 3) |
dba39448 | 88 | void trace_seq_printf(struct trace_seq *s, const char *fmt, ...); |
b9075fa9 | 89 | extern __printf(2, 0) |
dba39448 SRRH |
90 | void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args); |
91 | extern void | |
9504504c | 92 | trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary); |
a63ce5b3 | 93 | extern int trace_print_seq(struct seq_file *m, struct trace_seq *s); |
36aabfff SRRH |
94 | extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, |
95 | int cnt); | |
dba39448 SRRH |
96 | extern void trace_seq_puts(struct trace_seq *s, const char *str); |
97 | extern void trace_seq_putc(struct trace_seq *s, unsigned char c); | |
98 | extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len); | |
99 | extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, | |
36aabfff | 100 | unsigned int len); |
38eff289 | 101 | extern int trace_seq_path(struct trace_seq *s, const struct path *path); |
9504504c | 102 | |
dba39448 | 103 | extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, |
4449bf92 SRRH |
104 | int nmaskbits); |
105 | ||
ef56e047 PM |
106 | extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str, |
107 | int prefix_type, int rowsize, int groupsize, | |
108 | const void *buf, size_t len, bool ascii); | |
a9c4bdd5 | 109 | char *trace_seq_acquire(struct trace_seq *s, unsigned int len); |
ef56e047 | 110 | |
9504504c | 111 | #else /* CONFIG_TRACING */ |
bfd5a5e8 DH |
112 | static inline __printf(2, 3) |
113 | void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) | |
9504504c | 114 | { |
9504504c | 115 | } |
dba39448 | 116 | static inline void |
9504504c SR |
117 | trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) |
118 | { | |
9504504c SR |
119 | } |
120 | ||
dba39448 | 121 | static inline void |
4449bf92 SRRH |
122 | trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, |
123 | int nmaskbits) | |
124 | { | |
4449bf92 SRRH |
125 | } |
126 | ||
a63ce5b3 | 127 | static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s) |
9504504c | 128 | { |
a63ce5b3 | 129 | return 0; |
9504504c | 130 | } |
36aabfff SRRH |
131 | static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, |
132 | int cnt) | |
9504504c SR |
133 | { |
134 | return 0; | |
135 | } | |
dba39448 | 136 | static inline void trace_seq_puts(struct trace_seq *s, const char *str) |
9504504c | 137 | { |
9504504c | 138 | } |
dba39448 | 139 | static inline void trace_seq_putc(struct trace_seq *s, unsigned char c) |
9504504c | 140 | { |
9504504c | 141 | } |
dba39448 | 142 | static inline void |
36aabfff | 143 | trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len) |
9504504c | 144 | { |
9504504c | 145 | } |
dba39448 | 146 | static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, |
36aabfff | 147 | unsigned int len) |
9504504c | 148 | { |
9504504c | 149 | } |
38eff289 | 150 | static inline int trace_seq_path(struct trace_seq *s, const struct path *path) |
9504504c SR |
151 | { |
152 | return 0; | |
153 | } | |
a9c4bdd5 LY |
154 | static inline char *trace_seq_acquire(struct trace_seq *s, unsigned int len) |
155 | { | |
156 | return NULL; | |
157 | } | |
9504504c SR |
158 | #endif /* CONFIG_TRACING */ |
159 | ||
160 | #endif /* _LINUX_TRACE_SEQ_H */ |