Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1/* SPDX-License-Identifier: GPL-2.0 */
2#ifndef _LINUX_TRACE_SEQ_H
3#define _LINUX_TRACE_SEQ_H
4
5#include <linux/seq_buf.h>
6
7#include <asm/page.h>
8
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).
12 */
13
14struct trace_seq {
15 char buffer[PAGE_SIZE];
16 struct seq_buf seq;
17 int full;
18};
19
20static inline void
21trace_seq_init(struct trace_seq *s)
22{
23 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
24 s->full = 0;
25}
26
27/**
28 * trace_seq_used - amount of actual data written to buffer
29 * @s: trace sequence descriptor
30 *
31 * Returns the amount of data written to the buffer.
32 *
33 * IMPORTANT!
34 *
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.
39 */
40static inline int trace_seq_used(struct trace_seq *s)
41{
42 return seq_buf_used(&s->seq);
43}
44
45/**
46 * trace_seq_buffer_ptr - return pointer to next location in buffer
47 * @s: trace sequence descriptor
48 *
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.
53 */
54static inline char *
55trace_seq_buffer_ptr(struct trace_seq *s)
56{
57 return s->buffer + seq_buf_used(&s->seq);
58}
59
60/**
61 * trace_seq_has_overflowed - return true if the trace_seq took too much
62 * @s: trace sequence descriptor
63 *
64 * Returns true if too much data was added to the trace_seq and it is
65 * now full and will not take anymore.
66 */
67static inline bool trace_seq_has_overflowed(struct trace_seq *s)
68{
69 return s->full || seq_buf_has_overflowed(&s->seq);
70}
71
72/*
73 * Currently only defined when tracing is enabled.
74 */
75#ifdef CONFIG_TRACING
76extern __printf(2, 3)
77void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
78extern __printf(2, 0)
79void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
80extern void
81trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
82extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
83extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
84 int cnt);
85extern void trace_seq_puts(struct trace_seq *s, const char *str);
86extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
87extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
88extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
89 unsigned int len);
90extern int trace_seq_path(struct trace_seq *s, const struct path *path);
91
92extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
93 int nmaskbits);
94
95extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str,
96 int prefix_type, int rowsize, int groupsize,
97 const void *buf, size_t len, bool ascii);
98char *trace_seq_acquire(struct trace_seq *s, unsigned int len);
99
100#else /* CONFIG_TRACING */
101static inline __printf(2, 3)
102void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
103{
104}
105static inline void
106trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
107{
108}
109
110static inline void
111trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
112 int nmaskbits)
113{
114}
115
116static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
117{
118 return 0;
119}
120static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
121 int cnt)
122{
123 return 0;
124}
125static inline void trace_seq_puts(struct trace_seq *s, const char *str)
126{
127}
128static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
129{
130}
131static inline void
132trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
133{
134}
135static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
136 unsigned int len)
137{
138}
139static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
140{
141 return 0;
142}
143static inline char *trace_seq_acquire(struct trace_seq *s, unsigned int len)
144{
145 return NULL;
146}
147#endif /* CONFIG_TRACING */
148
149#endif /* _LINUX_TRACE_SEQ_H */