at v6.7 4.2 kB view raw
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 size_t readpos; 18 int full; 19}; 20 21static inline void 22trace_seq_init(struct trace_seq *s) 23{ 24 seq_buf_init(&s->seq, s->buffer, PAGE_SIZE); 25 s->full = 0; 26 s->readpos = 0; 27} 28 29/** 30 * trace_seq_used - amount of actual data written to buffer 31 * @s: trace sequence descriptor 32 * 33 * Returns the amount of data written to the buffer. 34 * 35 * IMPORTANT! 36 * 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. 41 */ 42static inline int trace_seq_used(struct trace_seq *s) 43{ 44 return seq_buf_used(&s->seq); 45} 46 47/** 48 * trace_seq_buffer_ptr - return pointer to next location in buffer 49 * @s: trace sequence descriptor 50 * 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 54 * of that write. 55 */ 56static inline char * 57trace_seq_buffer_ptr(struct trace_seq *s) 58{ 59 return s->buffer + seq_buf_used(&s->seq); 60} 61 62/** 63 * trace_seq_has_overflowed - return true if the trace_seq took too much 64 * @s: trace sequence descriptor 65 * 66 * Returns true if too much data was added to the trace_seq and it is 67 * now full and will not take anymore. 68 */ 69static inline bool trace_seq_has_overflowed(struct trace_seq *s) 70{ 71 return s->full || seq_buf_has_overflowed(&s->seq); 72} 73 74/* 75 * Currently only defined when tracing is enabled. 76 */ 77#ifdef CONFIG_TRACING 78extern __printf(2, 3) 79void trace_seq_printf(struct trace_seq *s, const char *fmt, ...); 80extern __printf(2, 0) 81void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args); 82extern void 83trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary); 84extern int trace_print_seq(struct seq_file *m, struct trace_seq *s); 85extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, 86 int cnt); 87extern void trace_seq_puts(struct trace_seq *s, const char *str); 88extern void trace_seq_putc(struct trace_seq *s, unsigned char c); 89extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len); 90extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, 91 unsigned int len); 92extern int trace_seq_path(struct trace_seq *s, const struct path *path); 93 94extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, 95 int nmaskbits); 96 97extern 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); 100char *trace_seq_acquire(struct trace_seq *s, unsigned int len); 101 102#else /* CONFIG_TRACING */ 103static inline __printf(2, 3) 104void trace_seq_printf(struct trace_seq *s, const char *fmt, ...) 105{ 106} 107static inline void 108trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary) 109{ 110} 111 112static inline void 113trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp, 114 int nmaskbits) 115{ 116} 117 118static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s) 119{ 120 return 0; 121} 122static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf, 123 int cnt) 124{ 125 return 0; 126} 127static inline void trace_seq_puts(struct trace_seq *s, const char *str) 128{ 129} 130static inline void trace_seq_putc(struct trace_seq *s, unsigned char c) 131{ 132} 133static inline void 134trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len) 135{ 136} 137static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem, 138 unsigned int len) 139{ 140} 141static inline int trace_seq_path(struct trace_seq *s, const struct path *path) 142{ 143 return 0; 144} 145static inline char *trace_seq_acquire(struct trace_seq *s, unsigned int len) 146{ 147 return NULL; 148} 149#endif /* CONFIG_TRACING */ 150 151#endif /* _LINUX_TRACE_SEQ_H */