ftrace: return error on failed modified text.
[safe/jmp/linux-2.6] / include / linux / ftrace.h
1 #ifndef _LINUX_FTRACE_H
2 #define _LINUX_FTRACE_H
3
4 #include <linux/linkage.h>
5 #include <linux/fs.h>
6 #include <linux/ktime.h>
7 #include <linux/init.h>
8 #include <linux/types.h>
9 #include <linux/kallsyms.h>
10
11 #ifdef CONFIG_FUNCTION_TRACER
12
13 extern int ftrace_enabled;
14 extern int
15 ftrace_enable_sysctl(struct ctl_table *table, int write,
16                      struct file *filp, void __user *buffer, size_t *lenp,
17                      loff_t *ppos);
18
19 typedef void (*ftrace_func_t)(unsigned long ip, unsigned long parent_ip);
20
21 struct ftrace_ops {
22         ftrace_func_t     func;
23         struct ftrace_ops *next;
24 };
25
26 /*
27  * The ftrace_ops must be a static and should also
28  * be read_mostly.  These functions do modify read_mostly variables
29  * so use them sparely. Never free an ftrace_op or modify the
30  * next pointer after it has been registered. Even after unregistering
31  * it, the next pointer may still be used internally.
32  */
33 int register_ftrace_function(struct ftrace_ops *ops);
34 int unregister_ftrace_function(struct ftrace_ops *ops);
35 void clear_ftrace_function(void);
36
37 extern void ftrace_stub(unsigned long a0, unsigned long a1);
38
39 #else /* !CONFIG_FUNCTION_TRACER */
40 # define register_ftrace_function(ops) do { } while (0)
41 # define unregister_ftrace_function(ops) do { } while (0)
42 # define clear_ftrace_function(ops) do { } while (0)
43 static inline void ftrace_kill_atomic(void) { }
44 #endif /* CONFIG_FUNCTION_TRACER */
45
46 #ifdef CONFIG_DYNAMIC_FTRACE
47 # define FTRACE_HASHBITS        10
48 # define FTRACE_HASHSIZE        (1<<FTRACE_HASHBITS)
49
50 enum {
51         FTRACE_FL_FREE          = (1 << 0),
52         FTRACE_FL_FAILED        = (1 << 1),
53         FTRACE_FL_FILTER        = (1 << 2),
54         FTRACE_FL_ENABLED       = (1 << 3),
55         FTRACE_FL_NOTRACE       = (1 << 4),
56         FTRACE_FL_CONVERTED     = (1 << 5),
57         FTRACE_FL_FROZEN        = (1 << 6),
58 };
59
60 struct dyn_ftrace {
61         struct hlist_node node;
62         unsigned long     ip; /* address of mcount call-site */
63         unsigned long     flags;
64 };
65
66 int ftrace_force_update(void);
67 void ftrace_set_filter(unsigned char *buf, int len, int reset);
68
69 /* defined in arch */
70 extern int ftrace_ip_converted(unsigned long ip);
71 extern unsigned char *ftrace_nop_replace(void);
72 extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
73 extern int ftrace_dyn_arch_init(void *data);
74 extern int ftrace_mcount_set(unsigned long *data);
75 extern int ftrace_update_ftrace_func(ftrace_func_t func);
76 extern void ftrace_caller(void);
77 extern void ftrace_call(void);
78 extern void mcount_call(void);
79
80 /**
81  * ftrace_modify_code - modify code segment
82  * @ip: the address of the code segment
83  * @old_code: the contents of what is expected to be there
84  * @new_code: the code to patch in
85  *
86  * This is a very sensitive operation and great care needs
87  * to be taken by the arch.  The operation should carefully
88  * read the location, check to see if what is read is indeed
89  * what we expect it to be, and then on success of the compare,
90  * it should write to the location.
91  *
92  * Return must be:
93  *  0 on success
94  *  -EFAULT on error reading the location
95  *  -EINVAL on a failed compare of the contents
96  *  -EPERM  on error writing to the location
97  * Any other value will be considered a failure.
98  */
99 extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
100                               unsigned char *new_code);
101
102 extern int skip_trace(unsigned long ip);
103
104 extern void ftrace_release(void *start, unsigned long size);
105
106 extern void ftrace_disable_daemon(void);
107 extern void ftrace_enable_daemon(void);
108
109 #else
110 # define skip_trace(ip)                         ({ 0; })
111 # define ftrace_force_update()                  ({ 0; })
112 # define ftrace_set_filter(buf, len, reset)     do { } while (0)
113 # define ftrace_disable_daemon()                do { } while (0)
114 # define ftrace_enable_daemon()                 do { } while (0)
115 static inline void ftrace_release(void *start, unsigned long size) { }
116 #endif /* CONFIG_DYNAMIC_FTRACE */
117
118 /* totally disable ftrace - can not re-enable after this */
119 void ftrace_kill(void);
120 void ftrace_kill_atomic(void);
121
122 static inline void tracer_disable(void)
123 {
124 #ifdef CONFIG_FUNCTION_TRACER
125         ftrace_enabled = 0;
126 #endif
127 }
128
129 /*
130  * Ftrace disable/restore without lock. Some synchronization mechanism
131  * must be used to prevent ftrace_enabled to be changed between
132  * disable/restore.
133  */
134 static inline int __ftrace_enabled_save(void)
135 {
136 #ifdef CONFIG_FUNCTION_TRACER
137         int saved_ftrace_enabled = ftrace_enabled;
138         ftrace_enabled = 0;
139         return saved_ftrace_enabled;
140 #else
141         return 0;
142 #endif
143 }
144
145 static inline void __ftrace_enabled_restore(int enabled)
146 {
147 #ifdef CONFIG_FUNCTION_TRACER
148         ftrace_enabled = enabled;
149 #endif
150 }
151
152 #ifdef CONFIG_FRAME_POINTER
153 /* TODO: need to fix this for ARM */
154 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
155 # define CALLER_ADDR1 ((unsigned long)__builtin_return_address(1))
156 # define CALLER_ADDR2 ((unsigned long)__builtin_return_address(2))
157 # define CALLER_ADDR3 ((unsigned long)__builtin_return_address(3))
158 # define CALLER_ADDR4 ((unsigned long)__builtin_return_address(4))
159 # define CALLER_ADDR5 ((unsigned long)__builtin_return_address(5))
160 # define CALLER_ADDR6 ((unsigned long)__builtin_return_address(6))
161 #else
162 # define CALLER_ADDR0 ((unsigned long)__builtin_return_address(0))
163 # define CALLER_ADDR1 0UL
164 # define CALLER_ADDR2 0UL
165 # define CALLER_ADDR3 0UL
166 # define CALLER_ADDR4 0UL
167 # define CALLER_ADDR5 0UL
168 # define CALLER_ADDR6 0UL
169 #endif
170
171 #ifdef CONFIG_IRQSOFF_TRACER
172   extern void time_hardirqs_on(unsigned long a0, unsigned long a1);
173   extern void time_hardirqs_off(unsigned long a0, unsigned long a1);
174 #else
175 # define time_hardirqs_on(a0, a1)               do { } while (0)
176 # define time_hardirqs_off(a0, a1)              do { } while (0)
177 #endif
178
179 #ifdef CONFIG_PREEMPT_TRACER
180   extern void trace_preempt_on(unsigned long a0, unsigned long a1);
181   extern void trace_preempt_off(unsigned long a0, unsigned long a1);
182 #else
183 # define trace_preempt_on(a0, a1)               do { } while (0)
184 # define trace_preempt_off(a0, a1)              do { } while (0)
185 #endif
186
187 #ifdef CONFIG_TRACING
188 extern void
189 ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3);
190
191 /**
192  * ftrace_printk - printf formatting in the ftrace buffer
193  * @fmt: the printf format for printing
194  *
195  * Note: __ftrace_printk is an internal function for ftrace_printk and
196  *       the @ip is passed in via the ftrace_printk macro.
197  *
198  * This function allows a kernel developer to debug fast path sections
199  * that printk is not appropriate for. By scattering in various
200  * printk like tracing in the code, a developer can quickly see
201  * where problems are occurring.
202  *
203  * This is intended as a debugging tool for the developer only.
204  * Please refrain from leaving ftrace_printks scattered around in
205  * your code.
206  */
207 # define ftrace_printk(fmt...) __ftrace_printk(_THIS_IP_, fmt)
208 extern int
209 __ftrace_printk(unsigned long ip, const char *fmt, ...)
210         __attribute__ ((format (printf, 2, 3)));
211 extern void ftrace_dump(void);
212 #else
213 static inline void
214 ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3) { }
215 static inline int
216 ftrace_printk(const char *fmt, ...) __attribute__ ((format (printf, 1, 0)));
217
218 static inline int
219 ftrace_printk(const char *fmt, ...)
220 {
221         return 0;
222 }
223 static inline void ftrace_dump(void) { }
224 #endif
225
226 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
227 extern void ftrace_init(void);
228 extern void ftrace_init_module(unsigned long *start, unsigned long *end);
229 #else
230 static inline void ftrace_init(void) { }
231 static inline void
232 ftrace_init_module(unsigned long *start, unsigned long *end) { }
233 #endif
234
235
236 struct boot_trace {
237         pid_t                   caller;
238         char                    func[KSYM_NAME_LEN];
239         int                     result;
240         unsigned long long      duration;               /* usecs */
241         ktime_t                 calltime;
242         ktime_t                 rettime;
243 };
244
245 #ifdef CONFIG_BOOT_TRACER
246 extern void trace_boot(struct boot_trace *it, initcall_t fn);
247 extern void start_boot_trace(void);
248 extern void stop_boot_trace(void);
249 #else
250 static inline void trace_boot(struct boot_trace *it, initcall_t fn) { }
251 static inline void start_boot_trace(void) { }
252 static inline void stop_boot_trace(void) { }
253 #endif
254
255
256
257 #endif /* _LINUX_FTRACE_H */