Blame view

include/linux/trace_seq.h 3.75 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
9504504cb   Steven Rostedt   tracing: make tra...
2
3
  #ifndef _LINUX_TRACE_SEQ_H
  #define _LINUX_TRACE_SEQ_H
3a161d99c   Steven Rostedt (Red Hat)   tracing: Create s...
4
  #include <linux/seq_buf.h>
6d723736e   Steven Rostedt   tracing/events: a...
5

78be6914c   Wu Zhangjin   tracing: fix unde...
6
  #include <asm/page.h>
9504504cb   Steven Rostedt   tracing: make tra...
7
8
  /*
   * Trace sequences are used to allow a function to call several other functions
6d3f1e12f   Jiri Olsa   tracing: Remove c...
9
   * to create a string of data to use (up to a max of PAGE_SIZE).
9504504cb   Steven Rostedt   tracing: make tra...
10
11
12
13
   */
  
  struct trace_seq {
  	unsigned char		buffer[PAGE_SIZE];
3a161d99c   Steven Rostedt (Red Hat)   tracing: Create s...
14
  	struct seq_buf		seq;
d184b31c0   Johannes Berg   tracing: Add full...
15
  	int			full;
9504504cb   Steven Rostedt   tracing: make tra...
16
17
18
19
20
  };
  
  static inline void
  trace_seq_init(struct trace_seq *s)
  {
3a161d99c   Steven Rostedt (Red Hat)   tracing: Create s...
21
  	seq_buf_init(&s->seq, s->buffer, PAGE_SIZE);
d184b31c0   Johannes Berg   tracing: Add full...
22
  	s->full = 0;
9504504cb   Steven Rostedt   tracing: make tra...
23
  }
7b039cb4c   Steven Rostedt (Red Hat)   tracing: Add trac...
24
  /**
5ac483784   Steven Rostedt (Red Hat)   tracing: Use trac...
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
   * trace_seq_used - amount of actual data written to buffer
   * @s: trace sequence descriptor
   *
   * Returns the amount of data written to the buffer.
   *
   * IMPORTANT!
   *
   * Use this instead of @s->seq.len if you need to pass the amount
   * of data from the buffer to another buffer (userspace, or what not).
   * The @s->seq.len on overflow is bigger than the buffer size and
   * using it can cause access to undefined memory.
   */
  static inline int trace_seq_used(struct trace_seq *s)
  {
  	return seq_buf_used(&s->seq);
  }
  
  /**
7b039cb4c   Steven Rostedt (Red Hat)   tracing: Add trac...
43
44
45
46
47
48
49
50
51
52
53
   * trace_seq_buffer_ptr - return pointer to next location in buffer
   * @s: trace sequence descriptor
   *
   * Returns the pointer to the buffer where the next write to
   * the buffer will happen. This is useful to save the location
   * that is about to be written to and then return the result
   * of that write.
   */
  static inline unsigned char *
  trace_seq_buffer_ptr(struct trace_seq *s)
  {
5ac483784   Steven Rostedt (Red Hat)   tracing: Use trac...
54
  	return s->buffer + seq_buf_used(&s->seq);
7b039cb4c   Steven Rostedt (Red Hat)   tracing: Add trac...
55
  }
19a7fe206   Steven Rostedt (Red Hat)   tracing: Add trac...
56
57
58
59
60
61
62
63
64
  /**
   * trace_seq_has_overflowed - return true if the trace_seq took too much
   * @s: trace sequence descriptor
   *
   * Returns true if too much data was added to the trace_seq and it is
   * now full and will not take anymore.
   */
  static inline bool trace_seq_has_overflowed(struct trace_seq *s)
  {
3a161d99c   Steven Rostedt (Red Hat)   tracing: Create s...
65
  	return s->full || seq_buf_has_overflowed(&s->seq);
19a7fe206   Steven Rostedt (Red Hat)   tracing: Add trac...
66
  }
9504504cb   Steven Rostedt   tracing: make tra...
67
68
69
70
  /*
   * Currently only defined when tracing is enabled.
   */
  #ifdef CONFIG_TRACING
b9075fa96   Joe Perches   treewide: use __p...
71
  extern __printf(2, 3)
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
72
  void trace_seq_printf(struct trace_seq *s, const char *fmt, ...);
b9075fa96   Joe Perches   treewide: use __p...
73
  extern __printf(2, 0)
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
74
75
  void trace_seq_vprintf(struct trace_seq *s, const char *fmt, va_list args);
  extern void
9504504cb   Steven Rostedt   tracing: make tra...
76
  trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary);
a63ce5b30   Steven Rostedt   tracing: Buffer t...
77
  extern int trace_print_seq(struct seq_file *m, struct trace_seq *s);
36aabfff5   Steven Rostedt (Red Hat)   tracing: Clean up...
78
79
  extern int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  			     int cnt);
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
80
81
82
83
  extern void trace_seq_puts(struct trace_seq *s, const char *str);
  extern void trace_seq_putc(struct trace_seq *s, unsigned char c);
  extern void trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len);
  extern void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff5   Steven Rostedt (Red Hat)   tracing: Clean up...
84
  				unsigned int len);
38eff2892   Al Viro   constify path arg...
85
  extern int trace_seq_path(struct trace_seq *s, const struct path *path);
9504504cb   Steven Rostedt   tracing: make tra...
86

dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
87
  extern void trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
4449bf927   Steven Rostedt (Red Hat)   tracing: Add __bi...
88
  			     int nmaskbits);
9504504cb   Steven Rostedt   tracing: make tra...
89
  #else /* CONFIG_TRACING */
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
90
  static inline void trace_seq_printf(struct trace_seq *s, const char *fmt, ...)
9504504cb   Steven Rostedt   tracing: make tra...
91
  {
9504504cb   Steven Rostedt   tracing: make tra...
92
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
93
  static inline void
9504504cb   Steven Rostedt   tracing: make tra...
94
95
  trace_seq_bprintf(struct trace_seq *s, const char *fmt, const u32 *binary)
  {
9504504cb   Steven Rostedt   tracing: make tra...
96
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
97
  static inline void
4449bf927   Steven Rostedt (Red Hat)   tracing: Add __bi...
98
99
100
  trace_seq_bitmask(struct trace_seq *s, const unsigned long *maskp,
  		  int nmaskbits)
  {
4449bf927   Steven Rostedt (Red Hat)   tracing: Add __bi...
101
  }
a63ce5b30   Steven Rostedt   tracing: Buffer t...
102
  static inline int trace_print_seq(struct seq_file *m, struct trace_seq *s)
9504504cb   Steven Rostedt   tracing: make tra...
103
  {
a63ce5b30   Steven Rostedt   tracing: Buffer t...
104
  	return 0;
9504504cb   Steven Rostedt   tracing: make tra...
105
  }
36aabfff5   Steven Rostedt (Red Hat)   tracing: Clean up...
106
107
  static inline int trace_seq_to_user(struct trace_seq *s, char __user *ubuf,
  				    int cnt)
9504504cb   Steven Rostedt   tracing: make tra...
108
109
110
  {
  	return 0;
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
111
  static inline void trace_seq_puts(struct trace_seq *s, const char *str)
9504504cb   Steven Rostedt   tracing: make tra...
112
  {
9504504cb   Steven Rostedt   tracing: make tra...
113
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
114
  static inline void trace_seq_putc(struct trace_seq *s, unsigned char c)
9504504cb   Steven Rostedt   tracing: make tra...
115
  {
9504504cb   Steven Rostedt   tracing: make tra...
116
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
117
  static inline void
36aabfff5   Steven Rostedt (Red Hat)   tracing: Clean up...
118
  trace_seq_putmem(struct trace_seq *s, const void *mem, unsigned int len)
9504504cb   Steven Rostedt   tracing: make tra...
119
  {
9504504cb   Steven Rostedt   tracing: make tra...
120
  }
dba39448a   Steven Rostedt (Red Hat)   tracing: Remove r...
121
  static inline void trace_seq_putmem_hex(struct trace_seq *s, const void *mem,
36aabfff5   Steven Rostedt (Red Hat)   tracing: Clean up...
122
  				       unsigned int len)
9504504cb   Steven Rostedt   tracing: make tra...
123
  {
9504504cb   Steven Rostedt   tracing: make tra...
124
  }
38eff2892   Al Viro   constify path arg...
125
  static inline int trace_seq_path(struct trace_seq *s, const struct path *path)
9504504cb   Steven Rostedt   tracing: make tra...
126
127
128
129
130
131
  {
  	return 0;
  }
  #endif /* CONFIG_TRACING */
  
  #endif /* _LINUX_TRACE_SEQ_H */