Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_TRACE_SEQ_H
0003 #define _LINUX_TRACE_SEQ_H
0004 
0005 #include <linux/seq_buf.h>
0006 
0007 #include <asm/page.h>
0008 
0009 /*
0010  * Trace sequences are used to allow a function to call several other functions
0011  * to create a string of data to use (up to a max of PAGE_SIZE).
0012  */
0013 
0014 struct trace_seq {
0015     char            buffer[PAGE_SIZE];
0016     struct seq_buf      seq;
0017     int         full;
0018 };
0019 
0020 static inline void
0021 trace_seq_init(struct trace_seq *s)
0022 {
0023     seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
0024     s->full = 0;
0025 }
0026 
0027 /**
0028  * trace_seq_used - amount of actual data written to buffer
0029  * @s: trace sequence descriptor
0030  *
0031  * Returns the amount of data written to the buffer.
0032  *
0033  * IMPORTANT!
0034  *
0035  * Use this instead of @s->seq.len if you need to pass the amount
0036  * of data from the buffer to another buffer (userspace, or what not).
0037  * The @s->seq.len on overflow is bigger than the buffer size and
0038  * using it can cause access to undefined memory.
0039  */
0040 static inline int trace_seq_used(struct trace_seq *s)
0041 {
0042     return seq_buf_used(&s->seq);
0043 }
0044 
0045 /**
0046  * trace_seq_buffer_ptr - return pointer to next location in buffer
0047  * @s: trace sequence descriptor
0048  *
0049  * Returns the pointer to the buffer where the next write to
0050  * the buffer will happen. This is useful to save the location
0051  * that is about to be written to and then return the result
0052  * of that write.
0053  */
0054 static inline char *
0055 trace_seq_buffer_ptr(struct trace_seq *s)
0056 {
0057     return s->buffer + seq_buf_used(&s->seq);
0058 }
0059 
0060 /**
0061  * trace_seq_has_overflowed - return true if the trace_seq took too much
0062  * @s: trace sequence descriptor
0063  *
0064  * Returns true if too much data was added to the trace_seq and it is
0065  * now full and will not take anymore.
0066  */
0067 static inline bool trace_seq_has_overflowed(struct trace_seq *s)
0068 {
0069     return s->full || seq_buf_has_overflowed(&s->seq);
0070 }
0071 
0072 /*
0073  * Currently only defined when tracing is enabled.
0074  */
0075 #ifdef CONFIG_TRACING
0076 extern __printf(2, 3)
0077 void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
0078 extern __printf(2, 0)
0079 void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
0080 extern void
0081 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
0082 extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
0083 extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
0084                  int cnt);
0085 extern void trace_seq_puts(struct trace_seq *s, const char *str);
0086 extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
0087 extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
0088 extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
0089                 unsigned int len);
0090 extern int trace_seq_path(struct trace_seq *s, const struct path *path);
0091 
0092 extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
0093                  int nmaskbits);
0094 
0095 extern int trace_seq_hex_dump(struct trace_seq *s, const char *prefix_str,
0096                   int prefix_type, int rowsize, int groupsize,
0097                   const void *buf, size_t len, bool ascii);
0098 
0099 #else /* CONFIG_TRACING */
0100 static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
0101 {
0102 }
0103 static inline void
0104 trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
0105 {
0106 }
0107 
0108 static inline void
0109 trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
0110           int nmaskbits)
0111 {
0112 }
0113 
0114 static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
0115 {
0116     return 0;
0117 }
0118 static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
0119                     int cnt)
0120 {
0121     return 0;
0122 }
0123 static inline void trace_seq_puts(struct trace_seq *s, const char *str)
0124 {
0125 }
0126 static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
0127 {
0128 }
0129 static inline void
0130 trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
0131 {
0132 }
0133 static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
0134                        unsigned int len)
0135 {
0136 }
0137 static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
0138 {
0139     return 0;
0140 }
0141 #endif /* CONFIG_TRACING */
0142 
0143 #endif /* _LINUX_TRACE_SEQ_H */