Frederic Weisbecker | 47788c5 | 2009-04-08 20:40:59 +0200 | [diff] [blame] | 1 | #include <trace/syscall.h> |
Josh Stone | 1c569f0 | 2009-08-24 14:43:14 -0700 | [diff] [blame] | 2 | #include <trace/events/syscalls.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 3 | #include <linux/slab.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 4 | #include <linux/kernel.h> |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 5 | #include <linux/ftrace.h> |
Ingo Molnar | cdd6c48 | 2009-09-21 12:02:48 +0200 | [diff] [blame] | 6 | #include <linux/perf_event.h> |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 7 | #include <asm/syscall.h> |
| 8 | |
| 9 | #include "trace_output.h" |
| 10 | #include "trace.h" |
| 11 | |
Frederic Weisbecker | 5be71b6 | 2009-03-15 22:10:37 +0100 | [diff] [blame] | 12 | static DEFINE_MUTEX(syscall_trace_lock); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 13 | static int sys_refcount_enter; |
| 14 | static int sys_refcount_exit; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 15 | static DECLARE_BITMAP(enabled_enter_syscalls, NR_syscalls); |
| 16 | static DECLARE_BITMAP(enabled_exit_syscalls, NR_syscalls); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 17 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 18 | static int syscall_enter_register(struct ftrace_event_call *event, |
| 19 | enum trace_reg type); |
| 20 | static int syscall_exit_register(struct ftrace_event_call *event, |
| 21 | enum trace_reg type); |
| 22 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 23 | static int syscall_enter_define_fields(struct ftrace_event_call *call); |
| 24 | static int syscall_exit_define_fields(struct ftrace_event_call *call); |
| 25 | |
| 26 | static struct list_head * |
| 27 | syscall_get_enter_fields(struct ftrace_event_call *call) |
| 28 | { |
| 29 | struct syscall_metadata *entry = call->data; |
| 30 | |
| 31 | return &entry->enter_fields; |
| 32 | } |
| 33 | |
| 34 | static struct list_head * |
| 35 | syscall_get_exit_fields(struct ftrace_event_call *call) |
| 36 | { |
| 37 | struct syscall_metadata *entry = call->data; |
| 38 | |
| 39 | return &entry->exit_fields; |
| 40 | } |
| 41 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 42 | struct ftrace_event_class event_class_syscall_enter = { |
| 43 | .system = "syscalls", |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 44 | .reg = syscall_enter_register, |
| 45 | .define_fields = syscall_enter_define_fields, |
| 46 | .get_fields = syscall_get_enter_fields, |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 47 | }; |
| 48 | |
| 49 | struct ftrace_event_class event_class_syscall_exit = { |
| 50 | .system = "syscalls", |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 51 | .reg = syscall_exit_register, |
| 52 | .define_fields = syscall_exit_define_fields, |
| 53 | .get_fields = syscall_get_exit_fields, |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 54 | }; |
| 55 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 56 | extern unsigned long __start_syscalls_metadata[]; |
| 57 | extern unsigned long __stop_syscalls_metadata[]; |
| 58 | |
| 59 | static struct syscall_metadata **syscalls_metadata; |
| 60 | |
| 61 | static struct syscall_metadata *find_syscall_meta(unsigned long syscall) |
| 62 | { |
| 63 | struct syscall_metadata *start; |
| 64 | struct syscall_metadata *stop; |
| 65 | char str[KSYM_SYMBOL_LEN]; |
| 66 | |
| 67 | |
| 68 | start = (struct syscall_metadata *)__start_syscalls_metadata; |
| 69 | stop = (struct syscall_metadata *)__stop_syscalls_metadata; |
| 70 | kallsyms_lookup(syscall, NULL, NULL, NULL, str); |
| 71 | |
| 72 | for ( ; start < stop; start++) { |
| 73 | /* |
| 74 | * Only compare after the "sys" prefix. Archs that use |
| 75 | * syscall wrappers may have syscalls symbols aliases prefixed |
| 76 | * with "SyS" instead of "sys", leading to an unwanted |
| 77 | * mismatch. |
| 78 | */ |
| 79 | if (start->name && !strcmp(start->name + 3, str + 3)) |
| 80 | return start; |
| 81 | } |
| 82 | return NULL; |
| 83 | } |
| 84 | |
| 85 | static struct syscall_metadata *syscall_nr_to_meta(int nr) |
| 86 | { |
| 87 | if (!syscalls_metadata || nr >= NR_syscalls || nr < 0) |
| 88 | return NULL; |
| 89 | |
| 90 | return syscalls_metadata[nr]; |
| 91 | } |
| 92 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 93 | enum print_line_t |
| 94 | print_syscall_enter(struct trace_iterator *iter, int flags) |
| 95 | { |
| 96 | struct trace_seq *s = &iter->seq; |
| 97 | struct trace_entry *ent = iter->ent; |
| 98 | struct syscall_trace_enter *trace; |
| 99 | struct syscall_metadata *entry; |
| 100 | int i, ret, syscall; |
| 101 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 102 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 103 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 104 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 105 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 106 | if (!entry) |
| 107 | goto end; |
| 108 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 109 | if (entry->enter_event->id != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 110 | WARN_ON_ONCE(1); |
| 111 | goto end; |
| 112 | } |
| 113 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 114 | ret = trace_seq_printf(s, "%s(", entry->name); |
| 115 | if (!ret) |
| 116 | return TRACE_TYPE_PARTIAL_LINE; |
| 117 | |
| 118 | for (i = 0; i < entry->nb_args; i++) { |
| 119 | /* parameter types */ |
Li Zefan | ba8b3a4 | 2009-08-17 16:55:18 +0800 | [diff] [blame] | 120 | if (trace_flags & TRACE_ITER_VERBOSE) { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 121 | ret = trace_seq_printf(s, "%s ", entry->types[i]); |
| 122 | if (!ret) |
| 123 | return TRACE_TYPE_PARTIAL_LINE; |
| 124 | } |
| 125 | /* parameter values */ |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 126 | ret = trace_seq_printf(s, "%s: %lx%s", entry->args[i], |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 127 | trace->args[i], |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 128 | i == entry->nb_args - 1 ? "" : ", "); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 129 | if (!ret) |
| 130 | return TRACE_TYPE_PARTIAL_LINE; |
| 131 | } |
| 132 | |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 133 | ret = trace_seq_putc(s, ')'); |
| 134 | if (!ret) |
| 135 | return TRACE_TYPE_PARTIAL_LINE; |
| 136 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 137 | end: |
Li Zefan | 4539f07 | 2009-08-20 16:13:35 +0800 | [diff] [blame] | 138 | ret = trace_seq_putc(s, '\n'); |
| 139 | if (!ret) |
| 140 | return TRACE_TYPE_PARTIAL_LINE; |
| 141 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 142 | return TRACE_TYPE_HANDLED; |
| 143 | } |
| 144 | |
| 145 | enum print_line_t |
| 146 | print_syscall_exit(struct trace_iterator *iter, int flags) |
| 147 | { |
| 148 | struct trace_seq *s = &iter->seq; |
| 149 | struct trace_entry *ent = iter->ent; |
| 150 | struct syscall_trace_exit *trace; |
| 151 | int syscall; |
| 152 | struct syscall_metadata *entry; |
| 153 | int ret; |
| 154 | |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 155 | trace = (typeof(trace))ent; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 156 | syscall = trace->nr; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 157 | entry = syscall_nr_to_meta(syscall); |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 158 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 159 | if (!entry) { |
| 160 | trace_seq_printf(s, "\n"); |
| 161 | return TRACE_TYPE_HANDLED; |
| 162 | } |
| 163 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 164 | if (entry->exit_event->id != ent->type) { |
Jason Baron | 64c12e0 | 2009-08-10 16:52:53 -0400 | [diff] [blame] | 165 | WARN_ON_ONCE(1); |
| 166 | return TRACE_TYPE_UNHANDLED; |
| 167 | } |
| 168 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 169 | ret = trace_seq_printf(s, "%s -> 0x%lx\n", entry->name, |
| 170 | trace->ret); |
| 171 | if (!ret) |
| 172 | return TRACE_TYPE_PARTIAL_LINE; |
| 173 | |
| 174 | return TRACE_TYPE_HANDLED; |
| 175 | } |
| 176 | |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 177 | extern char *__bad_type_size(void); |
| 178 | |
| 179 | #define SYSCALL_FIELD(type, name) \ |
| 180 | sizeof(type) != sizeof(trace.name) ? \ |
| 181 | __bad_type_size() : \ |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 182 | #type, #name, offsetof(typeof(trace), name), \ |
| 183 | sizeof(trace.name), is_signed_type(type) |
Li Zefan | e697196 | 2009-08-19 15:52:25 +0800 | [diff] [blame] | 184 | |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 185 | static |
| 186 | int __set_enter_print_fmt(struct syscall_metadata *entry, char *buf, int len) |
| 187 | { |
| 188 | int i; |
| 189 | int pos = 0; |
| 190 | |
| 191 | /* When len=0, we just calculate the needed length */ |
| 192 | #define LEN_OR_ZERO (len ? len - pos : 0) |
| 193 | |
| 194 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 195 | for (i = 0; i < entry->nb_args; i++) { |
| 196 | pos += snprintf(buf + pos, LEN_OR_ZERO, "%s: 0x%%0%zulx%s", |
| 197 | entry->args[i], sizeof(unsigned long), |
| 198 | i == entry->nb_args - 1 ? "" : ", "); |
| 199 | } |
| 200 | pos += snprintf(buf + pos, LEN_OR_ZERO, "\""); |
| 201 | |
| 202 | for (i = 0; i < entry->nb_args; i++) { |
| 203 | pos += snprintf(buf + pos, LEN_OR_ZERO, |
| 204 | ", ((unsigned long)(REC->%s))", entry->args[i]); |
| 205 | } |
| 206 | |
| 207 | #undef LEN_OR_ZERO |
| 208 | |
| 209 | /* return the length of print_fmt */ |
| 210 | return pos; |
| 211 | } |
| 212 | |
| 213 | static int set_syscall_print_fmt(struct ftrace_event_call *call) |
| 214 | { |
| 215 | char *print_fmt; |
| 216 | int len; |
| 217 | struct syscall_metadata *entry = call->data; |
| 218 | |
| 219 | if (entry->enter_event != call) { |
| 220 | call->print_fmt = "\"0x%lx\", REC->ret"; |
| 221 | return 0; |
| 222 | } |
| 223 | |
| 224 | /* First: called with 0 length to calculate the needed length */ |
| 225 | len = __set_enter_print_fmt(entry, NULL, 0); |
| 226 | |
| 227 | print_fmt = kmalloc(len + 1, GFP_KERNEL); |
| 228 | if (!print_fmt) |
| 229 | return -ENOMEM; |
| 230 | |
| 231 | /* Second: actually write the @print_fmt */ |
| 232 | __set_enter_print_fmt(entry, print_fmt, len + 1); |
| 233 | call->print_fmt = print_fmt; |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | static void free_syscall_print_fmt(struct ftrace_event_call *call) |
| 239 | { |
| 240 | struct syscall_metadata *entry = call->data; |
| 241 | |
| 242 | if (entry->enter_event == call) |
| 243 | kfree(call->print_fmt); |
| 244 | } |
| 245 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 246 | static int syscall_enter_define_fields(struct ftrace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 247 | { |
| 248 | struct syscall_trace_enter trace; |
Lai Jiangshan | 31c16b1 | 2009-12-01 16:23:30 +0800 | [diff] [blame] | 249 | struct syscall_metadata *meta = call->data; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 250 | int ret; |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 251 | int i; |
| 252 | int offset = offsetof(typeof(trace), args); |
| 253 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 254 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 255 | if (ret) |
| 256 | return ret; |
| 257 | |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 258 | for (i = 0; i < meta->nb_args; i++) { |
Frederic Weisbecker | aeaeae1 | 2009-08-27 05:09:51 +0200 | [diff] [blame] | 259 | ret = trace_define_field(call, meta->types[i], |
| 260 | meta->args[i], offset, |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 261 | sizeof(unsigned long), 0, |
| 262 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 263 | offset += sizeof(unsigned long); |
| 264 | } |
| 265 | |
| 266 | return ret; |
| 267 | } |
| 268 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame^] | 269 | static int syscall_exit_define_fields(struct ftrace_event_call *call) |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 270 | { |
| 271 | struct syscall_trace_exit trace; |
| 272 | int ret; |
| 273 | |
Lai Jiangshan | 0f1ef51 | 2009-11-26 15:49:33 +0800 | [diff] [blame] | 274 | ret = trace_define_field(call, SYSCALL_FIELD(int, nr), FILTER_OTHER); |
| 275 | if (ret) |
| 276 | return ret; |
| 277 | |
Tom Zanussi | 26a5074 | 2009-10-06 01:09:50 -0500 | [diff] [blame] | 278 | ret = trace_define_field(call, SYSCALL_FIELD(long, ret), |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 279 | FILTER_OTHER); |
Li Zefan | 540b7b8 | 2009-08-19 15:54:51 +0800 | [diff] [blame] | 280 | |
| 281 | return ret; |
| 282 | } |
| 283 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 284 | void ftrace_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 285 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 286 | struct syscall_trace_enter *entry; |
| 287 | struct syscall_metadata *sys_data; |
| 288 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 289 | struct ring_buffer *buffer; |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 290 | int size; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 291 | int syscall_nr; |
| 292 | |
| 293 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 294 | if (syscall_nr < 0) |
| 295 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 296 | if (!test_bit(syscall_nr, enabled_enter_syscalls)) |
| 297 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 298 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 299 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 300 | if (!sys_data) |
| 301 | return; |
| 302 | |
| 303 | size = sizeof(*entry) + sizeof(unsigned long) * sys_data->nb_args; |
| 304 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 305 | event = trace_current_buffer_lock_reserve(&buffer, |
| 306 | sys_data->enter_event->id, size, 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 307 | if (!event) |
| 308 | return; |
| 309 | |
| 310 | entry = ring_buffer_event_data(event); |
| 311 | entry->nr = syscall_nr; |
| 312 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, entry->args); |
| 313 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 314 | if (!filter_current_check_discard(buffer, sys_data->enter_event, |
| 315 | entry, event)) |
| 316 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 317 | } |
| 318 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 319 | void ftrace_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 320 | { |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 321 | struct syscall_trace_exit *entry; |
| 322 | struct syscall_metadata *sys_data; |
| 323 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 324 | struct ring_buffer *buffer; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 325 | int syscall_nr; |
| 326 | |
| 327 | syscall_nr = syscall_get_nr(current, regs); |
Hendrik Brueckner | cd0980f | 2009-08-25 14:50:27 +0200 | [diff] [blame] | 328 | if (syscall_nr < 0) |
| 329 | return; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 330 | if (!test_bit(syscall_nr, enabled_exit_syscalls)) |
| 331 | return; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 332 | |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 333 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 334 | if (!sys_data) |
| 335 | return; |
| 336 | |
Lai Jiangshan | fcc1943 | 2009-12-01 16:23:36 +0800 | [diff] [blame] | 337 | event = trace_current_buffer_lock_reserve(&buffer, |
| 338 | sys_data->exit_event->id, sizeof(*entry), 0, 0); |
Frederic Weisbecker | bed1ffc | 2009-03-13 15:42:11 +0100 | [diff] [blame] | 339 | if (!event) |
| 340 | return; |
| 341 | |
| 342 | entry = ring_buffer_event_data(event); |
| 343 | entry->nr = syscall_nr; |
| 344 | entry->ret = syscall_get_return_value(current, regs); |
| 345 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 346 | if (!filter_current_check_discard(buffer, sys_data->exit_event, |
| 347 | entry, event)) |
| 348 | trace_current_buffer_unlock_commit(buffer, event, 0, 0); |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 349 | } |
| 350 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 351 | int reg_event_syscall_enter(struct ftrace_event_call *call) |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 352 | { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 353 | int ret = 0; |
| 354 | int num; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 355 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 356 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 357 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 358 | return -ENOSYS; |
| 359 | mutex_lock(&syscall_trace_lock); |
| 360 | if (!sys_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 361 | ret = register_trace_sys_enter(ftrace_syscall_enter, NULL); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 362 | if (!ret) { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 363 | set_bit(num, enabled_enter_syscalls); |
| 364 | sys_refcount_enter++; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 365 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 366 | mutex_unlock(&syscall_trace_lock); |
| 367 | return ret; |
Frederic Weisbecker | ee08c6e | 2009-03-07 05:52:59 +0100 | [diff] [blame] | 368 | } |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 369 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 370 | void unreg_event_syscall_enter(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 371 | { |
| 372 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 373 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 374 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 375 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 376 | return; |
| 377 | mutex_lock(&syscall_trace_lock); |
| 378 | sys_refcount_enter--; |
| 379 | clear_bit(num, enabled_enter_syscalls); |
| 380 | if (!sys_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 381 | unregister_trace_sys_enter(ftrace_syscall_enter, NULL); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 382 | mutex_unlock(&syscall_trace_lock); |
| 383 | } |
| 384 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 385 | int reg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 386 | { |
| 387 | int ret = 0; |
| 388 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 389 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 390 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 391 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 392 | return -ENOSYS; |
| 393 | mutex_lock(&syscall_trace_lock); |
| 394 | if (!sys_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 395 | ret = register_trace_sys_exit(ftrace_syscall_exit, NULL); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 396 | if (!ret) { |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 397 | set_bit(num, enabled_exit_syscalls); |
| 398 | sys_refcount_exit++; |
| 399 | } |
| 400 | mutex_unlock(&syscall_trace_lock); |
| 401 | return ret; |
| 402 | } |
| 403 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 404 | void unreg_event_syscall_exit(struct ftrace_event_call *call) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 405 | { |
| 406 | int num; |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 407 | |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 408 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | 57421db | 2009-08-24 17:40:22 -0400 | [diff] [blame] | 409 | if (num < 0 || num >= NR_syscalls) |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 410 | return; |
| 411 | mutex_lock(&syscall_trace_lock); |
| 412 | sys_refcount_exit--; |
| 413 | clear_bit(num, enabled_exit_syscalls); |
| 414 | if (!sys_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 415 | unregister_trace_sys_exit(ftrace_syscall_exit, NULL); |
Jason Baron | fb34a08 | 2009-08-10 16:52:47 -0400 | [diff] [blame] | 416 | mutex_unlock(&syscall_trace_lock); |
| 417 | } |
| 418 | |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 419 | int init_syscall_trace(struct ftrace_event_call *call) |
| 420 | { |
| 421 | int id; |
| 422 | |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 423 | if (set_syscall_print_fmt(call) < 0) |
| 424 | return -ENOMEM; |
| 425 | |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 426 | id = trace_event_raw_init(call); |
| 427 | |
| 428 | if (id < 0) { |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 429 | free_syscall_print_fmt(call); |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 430 | return id; |
Lai Jiangshan | 50307a4 | 2009-12-15 15:39:45 +0800 | [diff] [blame] | 431 | } |
Steven Rostedt | c7ef3a9 | 2009-12-28 21:13:59 -0500 | [diff] [blame] | 432 | |
| 433 | return id; |
Lai Jiangshan | a1301da | 2009-12-01 16:23:55 +0800 | [diff] [blame] | 434 | } |
| 435 | |
Mike Frysinger | e7b8e67 | 2010-01-26 04:40:03 -0500 | [diff] [blame] | 436 | unsigned long __init arch_syscall_addr(int nr) |
| 437 | { |
| 438 | return (unsigned long)sys_call_table[nr]; |
| 439 | } |
| 440 | |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 441 | int __init init_ftrace_syscalls(void) |
| 442 | { |
| 443 | struct syscall_metadata *meta; |
| 444 | unsigned long addr; |
| 445 | int i; |
| 446 | |
| 447 | syscalls_metadata = kzalloc(sizeof(*syscalls_metadata) * |
| 448 | NR_syscalls, GFP_KERNEL); |
| 449 | if (!syscalls_metadata) { |
| 450 | WARN_ON(1); |
| 451 | return -ENOMEM; |
| 452 | } |
| 453 | |
| 454 | for (i = 0; i < NR_syscalls; i++) { |
| 455 | addr = arch_syscall_addr(i); |
| 456 | meta = find_syscall_meta(addr); |
Lai Jiangshan | c252f65 | 2009-12-01 16:23:47 +0800 | [diff] [blame] | 457 | if (!meta) |
| 458 | continue; |
| 459 | |
| 460 | meta->syscall_nr = i; |
Frederic Weisbecker | c44fc77 | 2009-09-19 06:50:42 +0200 | [diff] [blame] | 461 | syscalls_metadata[i] = meta; |
| 462 | } |
| 463 | |
| 464 | return 0; |
| 465 | } |
| 466 | core_initcall(init_ftrace_syscalls); |
| 467 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 468 | #ifdef CONFIG_PERF_EVENTS |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 469 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 470 | static DECLARE_BITMAP(enabled_perf_enter_syscalls, NR_syscalls); |
| 471 | static DECLARE_BITMAP(enabled_perf_exit_syscalls, NR_syscalls); |
| 472 | static int sys_perf_refcount_enter; |
| 473 | static int sys_perf_refcount_exit; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 474 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 475 | static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 476 | { |
| 477 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 478 | struct syscall_trace_enter *rec; |
| 479 | unsigned long flags; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 480 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 481 | int rctx; |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 482 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 483 | |
| 484 | syscall_nr = syscall_get_nr(current, regs); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 485 | if (!test_bit(syscall_nr, enabled_perf_enter_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 486 | return; |
| 487 | |
| 488 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 489 | if (!sys_data) |
| 490 | return; |
| 491 | |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 492 | /* get the size after alignment with the u32 buffer size field */ |
| 493 | size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); |
| 494 | size = ALIGN(size + sizeof(u32), sizeof(u64)); |
| 495 | size -= sizeof(u32); |
| 496 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 497 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
| 498 | "perf buffer not large enough")) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 499 | return; |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 500 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 501 | rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 502 | sys_data->enter_event->id, &rctx, &flags); |
| 503 | if (!rec) |
| 504 | return; |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 505 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 506 | rec->nr = syscall_nr; |
| 507 | syscall_get_arguments(current, regs, 0, sys_data->nb_args, |
| 508 | (unsigned long *)&rec->args); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 509 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 510 | } |
| 511 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 512 | int perf_sysenter_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 513 | { |
| 514 | int ret = 0; |
| 515 | int num; |
| 516 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 517 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 518 | |
| 519 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 520 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 521 | ret = register_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 522 | if (ret) { |
| 523 | pr_info("event trace: Could not activate" |
| 524 | "syscall entry trace point"); |
| 525 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 526 | set_bit(num, enabled_perf_enter_syscalls); |
| 527 | sys_perf_refcount_enter++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 528 | } |
| 529 | mutex_unlock(&syscall_trace_lock); |
| 530 | return ret; |
| 531 | } |
| 532 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 533 | void perf_sysenter_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 534 | { |
| 535 | int num; |
| 536 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 537 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 538 | |
| 539 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 540 | sys_perf_refcount_enter--; |
| 541 | clear_bit(num, enabled_perf_enter_syscalls); |
| 542 | if (!sys_perf_refcount_enter) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 543 | unregister_trace_sys_enter(perf_syscall_enter, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 544 | mutex_unlock(&syscall_trace_lock); |
| 545 | } |
| 546 | |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 547 | static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 548 | { |
| 549 | struct syscall_metadata *sys_data; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 550 | struct syscall_trace_exit *rec; |
| 551 | unsigned long flags; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 552 | int syscall_nr; |
Peter Zijlstra | 4ed7c92 | 2009-11-23 11:37:29 +0100 | [diff] [blame] | 553 | int rctx; |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 554 | int size; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 555 | |
| 556 | syscall_nr = syscall_get_nr(current, regs); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 557 | if (!test_bit(syscall_nr, enabled_perf_exit_syscalls)) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 558 | return; |
| 559 | |
| 560 | sys_data = syscall_nr_to_meta(syscall_nr); |
| 561 | if (!sys_data) |
| 562 | return; |
| 563 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 564 | /* We can probably do that at build time */ |
| 565 | size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); |
| 566 | size -= sizeof(u32); |
Frederic Weisbecker | 19007a67 | 2009-08-11 20:22:53 +0200 | [diff] [blame] | 567 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 568 | /* |
| 569 | * Impossible, but be paranoid with the future |
| 570 | * How to put this check outside runtime? |
| 571 | */ |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 572 | if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, |
| 573 | "exit event has grown above perf buffer size")) |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 574 | return; |
| 575 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 576 | rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, |
Xiao Guangrong | 430ad5a | 2010-01-28 09:32:29 +0800 | [diff] [blame] | 577 | sys_data->exit_event->id, &rctx, &flags); |
| 578 | if (!rec) |
| 579 | return; |
Frederic Weisbecker | ce71b9d | 2009-11-22 05:26:55 +0100 | [diff] [blame] | 580 | |
Frederic Weisbecker | 20ab4425 | 2009-09-18 06:10:28 +0200 | [diff] [blame] | 581 | rec->nr = syscall_nr; |
| 582 | rec->ret = syscall_get_return_value(current, regs); |
| 583 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 584 | perf_trace_buf_submit(rec, size, rctx, 0, 1, flags, regs); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 585 | } |
| 586 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 587 | int perf_sysexit_enable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 588 | { |
| 589 | int ret = 0; |
| 590 | int num; |
| 591 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 592 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 593 | |
| 594 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 595 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 596 | ret = register_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 597 | if (ret) { |
| 598 | pr_info("event trace: Could not activate" |
Wenji Huang | 6574658 | 2010-02-24 15:40:22 +0800 | [diff] [blame] | 599 | "syscall exit trace point"); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 600 | } else { |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 601 | set_bit(num, enabled_perf_exit_syscalls); |
| 602 | sys_perf_refcount_exit++; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 603 | } |
| 604 | mutex_unlock(&syscall_trace_lock); |
| 605 | return ret; |
| 606 | } |
| 607 | |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 608 | void perf_sysexit_disable(struct ftrace_event_call *call) |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 609 | { |
| 610 | int num; |
| 611 | |
Lai Jiangshan | 3bbe84e | 2009-12-01 16:24:01 +0800 | [diff] [blame] | 612 | num = ((struct syscall_metadata *)call->data)->syscall_nr; |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 613 | |
| 614 | mutex_lock(&syscall_trace_lock); |
Frederic Weisbecker | 97d5a22 | 2010-03-05 05:35:37 +0100 | [diff] [blame] | 615 | sys_perf_refcount_exit--; |
| 616 | clear_bit(num, enabled_perf_exit_syscalls); |
| 617 | if (!sys_perf_refcount_exit) |
Steven Rostedt | 38516ab | 2010-04-20 17:04:50 -0400 | [diff] [blame] | 618 | unregister_trace_sys_exit(perf_syscall_exit, NULL); |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 619 | mutex_unlock(&syscall_trace_lock); |
| 620 | } |
| 621 | |
Li Zefan | 07b139c | 2009-12-21 14:27:35 +0800 | [diff] [blame] | 622 | #endif /* CONFIG_PERF_EVENTS */ |
Jason Baron | f4b5ffc | 2009-08-10 16:53:02 -0400 | [diff] [blame] | 623 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 624 | static int syscall_enter_register(struct ftrace_event_call *event, |
| 625 | enum trace_reg type) |
| 626 | { |
| 627 | switch (type) { |
| 628 | case TRACE_REG_REGISTER: |
| 629 | return reg_event_syscall_enter(event); |
| 630 | case TRACE_REG_UNREGISTER: |
| 631 | unreg_event_syscall_enter(event); |
| 632 | return 0; |
| 633 | |
| 634 | #ifdef CONFIG_PERF_EVENTS |
| 635 | case TRACE_REG_PERF_REGISTER: |
| 636 | return perf_sysenter_enable(event); |
| 637 | case TRACE_REG_PERF_UNREGISTER: |
| 638 | perf_sysenter_disable(event); |
| 639 | return 0; |
| 640 | #endif |
| 641 | } |
| 642 | return 0; |
| 643 | } |
| 644 | |
| 645 | static int syscall_exit_register(struct ftrace_event_call *event, |
| 646 | enum trace_reg type) |
| 647 | { |
| 648 | switch (type) { |
| 649 | case TRACE_REG_REGISTER: |
| 650 | return reg_event_syscall_exit(event); |
| 651 | case TRACE_REG_UNREGISTER: |
| 652 | unreg_event_syscall_exit(event); |
| 653 | return 0; |
| 654 | |
| 655 | #ifdef CONFIG_PERF_EVENTS |
| 656 | case TRACE_REG_PERF_REGISTER: |
| 657 | return perf_sysexit_enable(event); |
| 658 | case TRACE_REG_PERF_UNREGISTER: |
| 659 | perf_sysexit_disable(event); |
| 660 | return 0; |
| 661 | #endif |
| 662 | } |
| 663 | return 0; |
| 664 | } |