Migrate syscall instrumentation to TP_FIELDS
[lttng-modules.git] / lttng-syscalls.c
1 /*
2 * lttng-syscalls.c
3 *
4 * LTTng syscall probes.
5 *
6 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; only
11 * version 2.1 of the License.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <linux/module.h>
24 #include <linux/slab.h>
25 #include <linux/compat.h>
26 #include <linux/err.h>
27 #include <linux/bitmap.h>
28 #include <linux/in.h>
29 #include <linux/in6.h>
30 #include <linux/seq_file.h>
31 #include <linux/stringify.h>
32 #include <linux/file.h>
33 #include <linux/anon_inodes.h>
34 #include <asm/ptrace.h>
35 #include <asm/syscall.h>
36
37 #include "lib/bitfield.h"
38 #include "wrapper/tracepoint.h"
39 #include "wrapper/file.h"
40 #include "lttng-events.h"
41
42 #ifndef CONFIG_COMPAT
43 # ifndef is_compat_task
44 # define is_compat_task() (0)
45 # endif
46 #endif
47
48 enum sc_type {
49 SC_TYPE_ENTRY,
50 SC_TYPE_EXIT,
51 SC_TYPE_COMPAT_ENTRY,
52 SC_TYPE_COMPAT_EXIT,
53 };
54
55 #define SYSCALL_ENTRY_TOK syscall_entry_
56 #define COMPAT_SYSCALL_ENTRY_TOK compat_syscall_entry_
57 #define SYSCALL_EXIT_TOK syscall_exit_
58 #define COMPAT_SYSCALL_EXIT_TOK compat_syscall_exit_
59
60 #define SYSCALL_ENTRY_STR __stringify(SYSCALL_ENTRY_TOK)
61 #define COMPAT_SYSCALL_ENTRY_STR __stringify(COMPAT_SYSCALL_ENTRY_TOK)
62 #define SYSCALL_EXIT_STR __stringify(SYSCALL_EXIT_TOK)
63 #define COMPAT_SYSCALL_EXIT_STR __stringify(COMPAT_SYSCALL_EXIT_TOK)
64
65 static
66 void syscall_entry_probe(void *__data, struct pt_regs *regs, long id);
67 static
68 void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret);
69
70 /*
71 * Forward declarations for old kernels.
72 */
73 struct mmsghdr;
74 struct rlimit64;
75 struct oldold_utsname;
76 struct old_utsname;
77 struct sel_arg_struct;
78 struct mmap_arg_struct;
79
80 #ifdef IA32_NR_syscalls
81 #define NR_compat_syscalls IA32_NR_syscalls
82 #else
83 #define NR_compat_syscalls NR_syscalls
84 #endif
85
86 /*
87 * Create LTTng tracepoint probes.
88 */
89 #define LTTNG_PACKAGE_BUILD
90 #define CREATE_TRACE_POINTS
91 #define TP_MODULE_NOINIT
92 #define TRACE_INCLUDE_PATH ../instrumentation/syscalls/headers
93
94 #define PARAMS(args...) args
95
96 /* Handle unknown syscalls */
97 #undef TRACE_SYSTEM
98 #define TRACE_SYSTEM syscalls_unknown
99 #include "instrumentation/syscalls/headers/syscalls_unknown.h"
100 #undef TRACE_SYSTEM
101
102 #define SC_ENTER
103
104 #undef sc_exit
105 #define sc_exit(...)
106 #undef sc_in
107 #define sc_in(...) __VA_ARGS__
108 #undef sc_out
109 #define sc_out(...)
110 #undef sc_inout
111 #define sc_inout(...) __VA_ARGS__
112
113 /* Hijack probe callback for system call enter */
114 #undef TP_PROBE_CB
115 #define TP_PROBE_CB(_template) &syscall_entry_probe
116 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
117 LTTNG_TRACEPOINT_EVENT(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
118 PARAMS(_fields))
119 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
120 LTTNG_TRACEPOINT_EVENT_CODE(syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
121 PARAMS(_locvar), PARAMS(_code), \
122 PARAMS(_fields))
123 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
124 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_entry_##_name, PARAMS(_fields))
125 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
126 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_entry_##_template, syscall_entry_##_name)
127 #undef TRACE_SYSTEM
128 #define TRACE_SYSTEM syscall_entry_integers
129 #define TRACE_INCLUDE_FILE syscalls_integers
130 #include "instrumentation/syscalls/headers/syscalls_integers.h"
131 #undef TRACE_INCLUDE_FILE
132 #undef TRACE_SYSTEM
133 #define TRACE_SYSTEM syscall_entry_pointers
134 #define TRACE_INCLUDE_FILE syscalls_pointers
135 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
136 #undef TRACE_INCLUDE_FILE
137 #undef TRACE_SYSTEM
138 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
139 #undef SC_LTTNG_TRACEPOINT_EVENT
140 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
141 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
142 #undef TP_PROBE_CB
143 #undef _TRACE_SYSCALLS_INTEGERS_H
144 #undef _TRACE_SYSCALLS_POINTERS_H
145
146 /* Hijack probe callback for compat system call enter */
147 #define TP_PROBE_CB(_template) &syscall_entry_probe
148 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
149 LTTNG_TRACEPOINT_EVENT(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
150 PARAMS(_fields))
151 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
152 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_entry_##_name, PARAMS(_proto), PARAMS(_args), \
153 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
154 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
155 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_entry_##_name, PARAMS(_fields))
156 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
157 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_entry_##_template, \
158 compat_syscall_entry_##_name)
159 #define TRACE_SYSTEM compat_syscall_entry_integers
160 #define TRACE_INCLUDE_FILE compat_syscalls_integers
161 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
162 #undef TRACE_INCLUDE_FILE
163 #undef TRACE_SYSTEM
164 #define TRACE_SYSTEM compat_syscall_entry_pointers
165 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
166 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
167 #undef TRACE_INCLUDE_FILE
168 #undef TRACE_SYSTEM
169 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
170 #undef SC_LTTNG_TRACEPOINT_EVENT
171 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
172 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
173 #undef TP_PROBE_CB
174 #undef _TRACE_SYSCALLS_INTEGERS_H
175 #undef _TRACE_SYSCALLS_POINTERS_H
176
177 #undef SC_ENTER
178
179 #define SC_EXIT
180
181 #undef sc_exit
182 #define sc_exit(...) __VA_ARGS__
183 #undef sc_in
184 #define sc_in(...)
185 #undef sc_out
186 #define sc_out(...) __VA_ARGS__
187 #undef sc_inout
188 #define sc_inout(...) __VA_ARGS__
189
190 /* Hijack probe callback for system call exit */
191 #define TP_PROBE_CB(_template) &syscall_exit_probe
192 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
193 LTTNG_TRACEPOINT_EVENT(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
194 PARAMS(_fields))
195 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
196 LTTNG_TRACEPOINT_EVENT_CODE(syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
197 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
198 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
199 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(syscall_exit_##_name, PARAMS(_fields))
200 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
201 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(syscall_exit_##_template, \
202 syscall_exit_##_name)
203 #define TRACE_SYSTEM syscall_exit_integers
204 #define TRACE_INCLUDE_FILE syscalls_integers
205 #include "instrumentation/syscalls/headers/syscalls_integers.h"
206 #undef TRACE_INCLUDE_FILE
207 #undef TRACE_SYSTEM
208 #define TRACE_SYSTEM syscall_exit_pointers
209 #define TRACE_INCLUDE_FILE syscalls_pointers
210 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
211 #undef TRACE_INCLUDE_FILE
212 #undef TRACE_SYSTEM
213 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
214 #undef SC_LTTNG_TRACEPOINT_EVENT
215 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
216 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
217 #undef TP_PROBE_CB
218 #undef _TRACE_SYSCALLS_INTEGERS_H
219 #undef _TRACE_SYSCALLS_POINTERS_H
220
221
222 /* Hijack probe callback for compat system call exit */
223 #define TP_PROBE_CB(_template) &syscall_exit_probe
224 #define SC_LTTNG_TRACEPOINT_EVENT(_name, _proto, _args, _fields) \
225 LTTNG_TRACEPOINT_EVENT(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
226 PARAMS(_fields))
227 #define SC_LTTNG_TRACEPOINT_EVENT_CODE(_name, _proto, _args, _locvar, _code, _fields) \
228 LTTNG_TRACEPOINT_EVENT_CODE(compat_syscall_exit_##_name, PARAMS(_proto), PARAMS(_args), \
229 PARAMS(_locvar), PARAMS(_code), PARAMS(_fields))
230 #define SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(_name, _fields) \
231 LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS(compat_syscall_exit_##_name, PARAMS(_fields))
232 #define SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(_template, _name) \
233 LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS(compat_syscall_exit_##_template, \
234 compat_syscall_exit_##_name)
235 #define TRACE_SYSTEM compat_syscall_exit_integers
236 #define TRACE_INCLUDE_FILE compat_syscalls_integers
237 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
238 #undef TRACE_INCLUDE_FILE
239 #undef TRACE_SYSTEM
240 #define TRACE_SYSTEM compat_syscall_exit_pointers
241 #define TRACE_INCLUDE_FILE compat_syscalls_pointers
242 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
243 #undef TRACE_INCLUDE_FILE
244 #undef TRACE_SYSTEM
245 #undef SC_LTTNG_TRACEPOINT_EVENT_CODE
246 #undef SC_LTTNG_TRACEPOINT_EVENT
247 #undef SC_LTTNG_TRACEPOINT_EVENT_CLASS_NOARGS
248 #undef SC_LTTNG_TRACEPOINT_EVENT_INSTANCE_NOARGS
249 #undef TP_PROBE_CB
250 #undef _TRACE_SYSCALLS_INTEGERS_H
251 #undef _TRACE_SYSCALLS_POINTERS_H
252
253 #undef SC_EXIT
254
255 #undef TP_MODULE_NOINIT
256 #undef LTTNG_PACKAGE_BUILD
257 #undef CREATE_TRACE_POINTS
258
259 struct trace_syscall_entry {
260 void *func;
261 const struct lttng_event_desc *desc;
262 const struct lttng_event_field *fields;
263 unsigned int nrargs;
264 };
265
266 #define CREATE_SYSCALL_TABLE
267
268 #define SC_ENTER
269
270 #undef sc_exit
271 #define sc_exit(...)
272
273 #undef TRACE_SYSCALL_TABLE
274 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
275 [ _nr ] = { \
276 .func = __event_probe__syscall_entry_##_template, \
277 .nrargs = (_nrargs), \
278 .fields = __event_fields___syscall_entry_##_template, \
279 .desc = &__event_desc___syscall_entry_##_name, \
280 },
281
282 /* Syscall enter tracing table */
283 static const struct trace_syscall_entry sc_table[] = {
284 #include "instrumentation/syscalls/headers/syscalls_integers.h"
285 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
286 };
287
288 #undef TRACE_SYSCALL_TABLE
289 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
290 [ _nr ] = { \
291 .func = __event_probe__compat_syscall_entry_##_template, \
292 .nrargs = (_nrargs), \
293 .fields = __event_fields___compat_syscall_entry_##_template, \
294 .desc = &__event_desc___compat_syscall_entry_##_name, \
295 },
296
297 /* Compat syscall enter table */
298 const struct trace_syscall_entry compat_sc_table[] = {
299 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
300 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
301 };
302
303 #undef SC_ENTER
304
305 #define SC_EXIT
306
307 #undef sc_exit
308 #define sc_exit(...) __VA_ARGS__
309
310 #undef TRACE_SYSCALL_TABLE
311 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
312 [ _nr ] = { \
313 .func = __event_probe__syscall_exit_##_template, \
314 .nrargs = (_nrargs), \
315 .fields = __event_fields___syscall_exit_##_template, \
316 .desc = &__event_desc___syscall_exit_##_name, \
317 },
318
319 /* Syscall exit table */
320 static const struct trace_syscall_entry sc_exit_table[] = {
321 #include "instrumentation/syscalls/headers/syscalls_integers.h"
322 #include "instrumentation/syscalls/headers/syscalls_pointers.h"
323 };
324
325 #undef TRACE_SYSCALL_TABLE
326 #define TRACE_SYSCALL_TABLE(_template, _name, _nr, _nrargs) \
327 [ _nr ] = { \
328 .func = __event_probe__compat_syscall_exit_##_template, \
329 .nrargs = (_nrargs), \
330 .fields = __event_fields___compat_syscall_exit_##_template, \
331 .desc = &__event_desc___compat_syscall_exit_##_name, \
332 },
333
334 /* Compat syscall exit table */
335 const struct trace_syscall_entry compat_sc_exit_table[] = {
336 #include "instrumentation/syscalls/headers/compat_syscalls_integers.h"
337 #include "instrumentation/syscalls/headers/compat_syscalls_pointers.h"
338 };
339
340 #undef SC_EXIT
341
342 #undef CREATE_SYSCALL_TABLE
343
344 struct lttng_syscall_filter {
345 DECLARE_BITMAP(sc, NR_syscalls);
346 DECLARE_BITMAP(sc_compat, NR_compat_syscalls);
347 };
348
349 static void syscall_entry_unknown(struct lttng_event *event,
350 struct pt_regs *regs, unsigned int id)
351 {
352 unsigned long args[UNKNOWN_SYSCALL_NRARGS];
353
354 syscall_get_arguments(current, regs, 0, UNKNOWN_SYSCALL_NRARGS, args);
355 if (unlikely(is_compat_task()))
356 __event_probe__compat_syscall_entry_unknown(event, id, args);
357 else
358 __event_probe__syscall_entry_unknown(event, id, args);
359 }
360
361 void syscall_entry_probe(void *__data, struct pt_regs *regs, long id)
362 {
363 struct lttng_channel *chan = __data;
364 struct lttng_event *event, *unknown_event;
365 const struct trace_syscall_entry *table, *entry;
366 size_t table_len;
367
368 if (unlikely(is_compat_task())) {
369 struct lttng_syscall_filter *filter;
370
371 filter = rcu_dereference(chan->sc_filter);
372 if (filter) {
373 if (id < 0 || id >= NR_compat_syscalls
374 || !test_bit(id, filter->sc_compat)) {
375 /* System call filtered out. */
376 return;
377 }
378 }
379 table = compat_sc_table;
380 table_len = ARRAY_SIZE(compat_sc_table);
381 unknown_event = chan->sc_compat_unknown;
382 } else {
383 struct lttng_syscall_filter *filter;
384
385 filter = rcu_dereference(chan->sc_filter);
386 if (filter) {
387 if (id < 0 || id >= NR_syscalls
388 || !test_bit(id, filter->sc)) {
389 /* System call filtered out. */
390 return;
391 }
392 }
393 table = sc_table;
394 table_len = ARRAY_SIZE(sc_table);
395 unknown_event = chan->sc_unknown;
396 }
397 if (unlikely(id < 0 || id >= table_len)) {
398 syscall_entry_unknown(unknown_event, regs, id);
399 return;
400 }
401 if (unlikely(is_compat_task()))
402 event = chan->compat_sc_table[id];
403 else
404 event = chan->sc_table[id];
405 if (unlikely(!event)) {
406 syscall_entry_unknown(unknown_event, regs, id);
407 return;
408 }
409 entry = &table[id];
410 WARN_ON_ONCE(!entry);
411
412 switch (entry->nrargs) {
413 case 0:
414 {
415 void (*fptr)(void *__data) = entry->func;
416
417 fptr(event);
418 break;
419 }
420 case 1:
421 {
422 void (*fptr)(void *__data, unsigned long arg0) = entry->func;
423 unsigned long args[1];
424
425 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
426 fptr(event, args[0]);
427 break;
428 }
429 case 2:
430 {
431 void (*fptr)(void *__data,
432 unsigned long arg0,
433 unsigned long arg1) = entry->func;
434 unsigned long args[2];
435
436 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
437 fptr(event, args[0], args[1]);
438 break;
439 }
440 case 3:
441 {
442 void (*fptr)(void *__data,
443 unsigned long arg0,
444 unsigned long arg1,
445 unsigned long arg2) = entry->func;
446 unsigned long args[3];
447
448 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
449 fptr(event, args[0], args[1], args[2]);
450 break;
451 }
452 case 4:
453 {
454 void (*fptr)(void *__data,
455 unsigned long arg0,
456 unsigned long arg1,
457 unsigned long arg2,
458 unsigned long arg3) = entry->func;
459 unsigned long args[4];
460
461 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
462 fptr(event, args[0], args[1], args[2], args[3]);
463 break;
464 }
465 case 5:
466 {
467 void (*fptr)(void *__data,
468 unsigned long arg0,
469 unsigned long arg1,
470 unsigned long arg2,
471 unsigned long arg3,
472 unsigned long arg4) = entry->func;
473 unsigned long args[5];
474
475 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
476 fptr(event, args[0], args[1], args[2], args[3], args[4]);
477 break;
478 }
479 case 6:
480 {
481 void (*fptr)(void *__data,
482 unsigned long arg0,
483 unsigned long arg1,
484 unsigned long arg2,
485 unsigned long arg3,
486 unsigned long arg4,
487 unsigned long arg5) = entry->func;
488 unsigned long args[6];
489
490 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
491 fptr(event, args[0], args[1], args[2],
492 args[3], args[4], args[5]);
493 break;
494 }
495 default:
496 break;
497 }
498 }
499
500 static void syscall_exit_unknown(struct lttng_event *event,
501 struct pt_regs *regs, int id, long ret)
502 {
503 unsigned long args[UNKNOWN_SYSCALL_NRARGS];
504
505 syscall_get_arguments(current, regs, 0, UNKNOWN_SYSCALL_NRARGS, args);
506 if (unlikely(is_compat_task()))
507 __event_probe__compat_syscall_exit_unknown(event, id, ret,
508 args);
509 else
510 __event_probe__syscall_exit_unknown(event, id, ret, args);
511 }
512
513 void syscall_exit_probe(void *__data, struct pt_regs *regs, long ret)
514 {
515 struct lttng_channel *chan = __data;
516 struct lttng_event *event, *unknown_event;
517 const struct trace_syscall_entry *table, *entry;
518 size_t table_len;
519 long id;
520
521 id = syscall_get_nr(current, regs);
522 if (unlikely(is_compat_task())) {
523 struct lttng_syscall_filter *filter;
524
525 filter = rcu_dereference(chan->sc_filter);
526 if (filter) {
527 if (id < 0 || id >= NR_compat_syscalls
528 || !test_bit(id, filter->sc_compat)) {
529 /* System call filtered out. */
530 return;
531 }
532 }
533 table = compat_sc_exit_table;
534 table_len = ARRAY_SIZE(compat_sc_exit_table);
535 unknown_event = chan->compat_sc_exit_unknown;
536 } else {
537 struct lttng_syscall_filter *filter;
538
539 filter = rcu_dereference(chan->sc_filter);
540 if (filter) {
541 if (id < 0 || id >= NR_syscalls
542 || !test_bit(id, filter->sc)) {
543 /* System call filtered out. */
544 return;
545 }
546 }
547 table = sc_exit_table;
548 table_len = ARRAY_SIZE(sc_exit_table);
549 unknown_event = chan->sc_exit_unknown;
550 }
551 if (unlikely(id < 0 || id >= table_len)) {
552 syscall_exit_unknown(unknown_event, regs, id, ret);
553 return;
554 }
555 if (unlikely(is_compat_task()))
556 event = chan->compat_sc_exit_table[id];
557 else
558 event = chan->sc_exit_table[id];
559 if (unlikely(!event)) {
560 syscall_exit_unknown(unknown_event, regs, id, ret);
561 return;
562 }
563 entry = &table[id];
564 WARN_ON_ONCE(!entry);
565
566 switch (entry->nrargs) {
567 case 0:
568 {
569 void (*fptr)(void *__data, long ret) = entry->func;
570
571 fptr(event, ret);
572 break;
573 }
574 case 1:
575 {
576 void (*fptr)(void *__data,
577 long ret,
578 unsigned long arg0) = entry->func;
579 unsigned long args[1];
580
581 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
582 fptr(event, ret, args[0]);
583 break;
584 }
585 case 2:
586 {
587 void (*fptr)(void *__data,
588 long ret,
589 unsigned long arg0,
590 unsigned long arg1) = entry->func;
591 unsigned long args[2];
592
593 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
594 fptr(event, ret, args[0], args[1]);
595 break;
596 }
597 case 3:
598 {
599 void (*fptr)(void *__data,
600 long ret,
601 unsigned long arg0,
602 unsigned long arg1,
603 unsigned long arg2) = entry->func;
604 unsigned long args[3];
605
606 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
607 fptr(event, ret, args[0], args[1], args[2]);
608 break;
609 }
610 case 4:
611 {
612 void (*fptr)(void *__data,
613 long ret,
614 unsigned long arg0,
615 unsigned long arg1,
616 unsigned long arg2,
617 unsigned long arg3) = entry->func;
618 unsigned long args[4];
619
620 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
621 fptr(event, ret, args[0], args[1], args[2], args[3]);
622 break;
623 }
624 case 5:
625 {
626 void (*fptr)(void *__data,
627 long ret,
628 unsigned long arg0,
629 unsigned long arg1,
630 unsigned long arg2,
631 unsigned long arg3,
632 unsigned long arg4) = entry->func;
633 unsigned long args[5];
634
635 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
636 fptr(event, ret, args[0], args[1], args[2], args[3], args[4]);
637 break;
638 }
639 case 6:
640 {
641 void (*fptr)(void *__data,
642 long ret,
643 unsigned long arg0,
644 unsigned long arg1,
645 unsigned long arg2,
646 unsigned long arg3,
647 unsigned long arg4,
648 unsigned long arg5) = entry->func;
649 unsigned long args[6];
650
651 syscall_get_arguments(current, regs, 0, entry->nrargs, args);
652 fptr(event, ret, args[0], args[1], args[2],
653 args[3], args[4], args[5]);
654 break;
655 }
656 default:
657 break;
658 }
659 }
660
661 /*
662 * noinline to diminish caller stack size.
663 * Should be called with sessions lock held.
664 */
665 static
666 int fill_table(const struct trace_syscall_entry *table, size_t table_len,
667 struct lttng_event **chan_table, struct lttng_channel *chan,
668 void *filter, enum sc_type type)
669 {
670 const struct lttng_event_desc *desc;
671 unsigned int i;
672
673 /* Allocate events for each syscall, insert into table */
674 for (i = 0; i < table_len; i++) {
675 struct lttng_kernel_event ev;
676 desc = table[i].desc;
677
678 if (!desc) {
679 /* Unknown syscall */
680 continue;
681 }
682 /*
683 * Skip those already populated by previous failed
684 * register for this channel.
685 */
686 if (chan_table[i])
687 continue;
688 memset(&ev, 0, sizeof(ev));
689 switch (type) {
690 case SC_TYPE_ENTRY:
691 strncpy(ev.name, SYSCALL_ENTRY_STR,
692 LTTNG_KERNEL_SYM_NAME_LEN);
693 break;
694 case SC_TYPE_EXIT:
695 strncpy(ev.name, SYSCALL_EXIT_STR,
696 LTTNG_KERNEL_SYM_NAME_LEN);
697 break;
698 case SC_TYPE_COMPAT_ENTRY:
699 strncpy(ev.name, COMPAT_SYSCALL_ENTRY_STR,
700 LTTNG_KERNEL_SYM_NAME_LEN);
701 break;
702 case SC_TYPE_COMPAT_EXIT:
703 strncpy(ev.name, COMPAT_SYSCALL_EXIT_STR,
704 LTTNG_KERNEL_SYM_NAME_LEN);
705 break;
706 default:
707 BUG_ON(1);
708 break;
709 }
710 strncat(ev.name, desc->name,
711 LTTNG_KERNEL_SYM_NAME_LEN - strlen(ev.name) - 1);
712 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
713 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
714 chan_table[i] = _lttng_event_create(chan, &ev, filter,
715 desc, ev.instrumentation);
716 WARN_ON_ONCE(!chan_table[i]);
717 if (IS_ERR(chan_table[i])) {
718 /*
719 * If something goes wrong in event registration
720 * after the first one, we have no choice but to
721 * leave the previous events in there, until
722 * deleted by session teardown.
723 */
724 return PTR_ERR(chan_table[i]);
725 }
726 }
727 return 0;
728 }
729
730 /*
731 * Should be called with sessions lock held.
732 */
733 int lttng_syscalls_register(struct lttng_channel *chan, void *filter)
734 {
735 struct lttng_kernel_event ev;
736 int ret;
737
738 wrapper_vmalloc_sync_all();
739
740 if (!chan->sc_table) {
741 /* create syscall table mapping syscall to events */
742 chan->sc_table = kzalloc(sizeof(struct lttng_event *)
743 * ARRAY_SIZE(sc_table), GFP_KERNEL);
744 if (!chan->sc_table)
745 return -ENOMEM;
746 }
747 if (!chan->sc_exit_table) {
748 /* create syscall table mapping syscall to events */
749 chan->sc_exit_table = kzalloc(sizeof(struct lttng_event *)
750 * ARRAY_SIZE(sc_exit_table), GFP_KERNEL);
751 if (!chan->sc_exit_table)
752 return -ENOMEM;
753 }
754
755
756 #ifdef CONFIG_COMPAT
757 if (!chan->compat_sc_table) {
758 /* create syscall table mapping compat syscall to events */
759 chan->compat_sc_table = kzalloc(sizeof(struct lttng_event *)
760 * ARRAY_SIZE(compat_sc_table), GFP_KERNEL);
761 if (!chan->compat_sc_table)
762 return -ENOMEM;
763 }
764
765 if (!chan->compat_sc_exit_table) {
766 /* create syscall table mapping compat syscall to events */
767 chan->compat_sc_exit_table = kzalloc(sizeof(struct lttng_event *)
768 * ARRAY_SIZE(compat_sc_exit_table), GFP_KERNEL);
769 if (!chan->compat_sc_exit_table)
770 return -ENOMEM;
771 }
772 #endif
773 if (!chan->sc_unknown) {
774 const struct lttng_event_desc *desc =
775 &__event_desc___syscall_entry_unknown;
776
777 memset(&ev, 0, sizeof(ev));
778 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
779 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
780 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
781 chan->sc_unknown = _lttng_event_create(chan, &ev, filter,
782 desc,
783 ev.instrumentation);
784 WARN_ON_ONCE(!chan->sc_unknown);
785 if (IS_ERR(chan->sc_unknown)) {
786 return PTR_ERR(chan->sc_unknown);
787 }
788 }
789
790 if (!chan->sc_compat_unknown) {
791 const struct lttng_event_desc *desc =
792 &__event_desc___compat_syscall_entry_unknown;
793
794 memset(&ev, 0, sizeof(ev));
795 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
796 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
797 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
798 chan->sc_compat_unknown = _lttng_event_create(chan, &ev, filter,
799 desc,
800 ev.instrumentation);
801 WARN_ON_ONCE(!chan->sc_unknown);
802 if (IS_ERR(chan->sc_compat_unknown)) {
803 return PTR_ERR(chan->sc_compat_unknown);
804 }
805 }
806
807 if (!chan->compat_sc_exit_unknown) {
808 const struct lttng_event_desc *desc =
809 &__event_desc___compat_syscall_exit_unknown;
810
811 memset(&ev, 0, sizeof(ev));
812 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
813 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
814 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
815 chan->compat_sc_exit_unknown = _lttng_event_create(chan, &ev,
816 filter, desc,
817 ev.instrumentation);
818 WARN_ON_ONCE(!chan->compat_sc_exit_unknown);
819 if (IS_ERR(chan->compat_sc_exit_unknown)) {
820 return PTR_ERR(chan->compat_sc_exit_unknown);
821 }
822 }
823
824 if (!chan->sc_exit_unknown) {
825 const struct lttng_event_desc *desc =
826 &__event_desc___syscall_exit_unknown;
827
828 memset(&ev, 0, sizeof(ev));
829 strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
830 ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
831 ev.instrumentation = LTTNG_KERNEL_SYSCALL;
832 chan->sc_exit_unknown = _lttng_event_create(chan, &ev, filter,
833 desc, ev.instrumentation);
834 WARN_ON_ONCE(!chan->sc_exit_unknown);
835 if (IS_ERR(chan->sc_exit_unknown)) {
836 return PTR_ERR(chan->sc_exit_unknown);
837 }
838 }
839
840 ret = fill_table(sc_table, ARRAY_SIZE(sc_table),
841 chan->sc_table, chan, filter, SC_TYPE_ENTRY);
842 if (ret)
843 return ret;
844 ret = fill_table(sc_exit_table, ARRAY_SIZE(sc_exit_table),
845 chan->sc_exit_table, chan, filter, SC_TYPE_EXIT);
846 if (ret)
847 return ret;
848
849 #ifdef CONFIG_COMPAT
850 ret = fill_table(compat_sc_table, ARRAY_SIZE(compat_sc_table),
851 chan->compat_sc_table, chan, filter,
852 SC_TYPE_COMPAT_ENTRY);
853 if (ret)
854 return ret;
855 ret = fill_table(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table),
856 chan->compat_sc_exit_table, chan, filter,
857 SC_TYPE_COMPAT_EXIT);
858 if (ret)
859 return ret;
860 #endif
861 if (!chan->sys_enter_registered) {
862 ret = lttng_wrapper_tracepoint_probe_register("sys_enter",
863 (void *) syscall_entry_probe, chan);
864 if (ret)
865 return ret;
866 chan->sys_enter_registered = 1;
867 }
868 /*
869 * We change the name of sys_exit tracepoint due to namespace
870 * conflict with sys_exit syscall entry.
871 */
872 if (!chan->sys_exit_registered) {
873 ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
874 (void *) syscall_exit_probe, chan);
875 if (ret) {
876 WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
877 (void *) syscall_entry_probe, chan));
878 return ret;
879 }
880 chan->sys_exit_registered = 1;
881 }
882 return ret;
883 }
884
885 /*
886 * Only called at session destruction.
887 */
888 int lttng_syscalls_unregister(struct lttng_channel *chan)
889 {
890 int ret;
891
892 if (!chan->sc_table)
893 return 0;
894 if (chan->sys_enter_registered) {
895 ret = lttng_wrapper_tracepoint_probe_unregister("sys_exit",
896 (void *) syscall_exit_probe, chan);
897 if (ret)
898 return ret;
899 chan->sys_enter_registered = 0;
900 }
901 if (chan->sys_exit_registered) {
902 ret = lttng_wrapper_tracepoint_probe_unregister("sys_enter",
903 (void *) syscall_entry_probe, chan);
904 if (ret)
905 return ret;
906 chan->sys_exit_registered = 0;
907 }
908 /* lttng_event destroy will be performed by lttng_session_destroy() */
909 kfree(chan->sc_table);
910 kfree(chan->sc_exit_table);
911 #ifdef CONFIG_COMPAT
912 kfree(chan->compat_sc_table);
913 kfree(chan->compat_sc_exit_table);
914 #endif
915 kfree(chan->sc_filter);
916 return 0;
917 }
918
919 static
920 int get_syscall_nr(const char *syscall_name)
921 {
922 int syscall_nr = -1;
923 int i;
924
925 for (i = 0; i < ARRAY_SIZE(sc_table); i++) {
926 const struct trace_syscall_entry *entry;
927 const char *it_name;
928
929 entry = &sc_table[i];
930 if (!entry->desc)
931 continue;
932 it_name = entry->desc->name;
933 it_name += strlen(SYSCALL_ENTRY_STR);
934 if (!strcmp(syscall_name, it_name)) {
935 syscall_nr = i;
936 break;
937 }
938 }
939 return syscall_nr;
940 }
941
942 static
943 int get_compat_syscall_nr(const char *syscall_name)
944 {
945 int syscall_nr = -1;
946 int i;
947
948 for (i = 0; i < ARRAY_SIZE(compat_sc_table); i++) {
949 const struct trace_syscall_entry *entry;
950 const char *it_name;
951
952 entry = &compat_sc_table[i];
953 if (!entry->desc)
954 continue;
955 it_name = entry->desc->name;
956 it_name += strlen(COMPAT_SYSCALL_ENTRY_STR);
957 if (!strcmp(syscall_name, it_name)) {
958 syscall_nr = i;
959 break;
960 }
961 }
962 return syscall_nr;
963 }
964
965 static
966 uint32_t get_sc_tables_len(void)
967 {
968 return ARRAY_SIZE(sc_table) + ARRAY_SIZE(compat_sc_table);
969 }
970
971 int lttng_syscall_filter_enable(struct lttng_channel *chan,
972 const char *name)
973 {
974 int syscall_nr, compat_syscall_nr, ret;
975 struct lttng_syscall_filter *filter;
976
977 WARN_ON_ONCE(!chan->sc_table);
978
979 if (!name) {
980 /* Enable all system calls by removing filter */
981 if (chan->sc_filter) {
982 filter = chan->sc_filter;
983 rcu_assign_pointer(chan->sc_filter, NULL);
984 synchronize_trace();
985 kfree(filter);
986 }
987 chan->syscall_all = 1;
988 return 0;
989 }
990
991 if (!chan->sc_filter) {
992 if (chan->syscall_all) {
993 /*
994 * All syscalls are already enabled.
995 */
996 return -EEXIST;
997 }
998 filter = kzalloc(sizeof(struct lttng_syscall_filter),
999 GFP_KERNEL);
1000 if (!filter)
1001 return -ENOMEM;
1002 } else {
1003 filter = chan->sc_filter;
1004 }
1005 syscall_nr = get_syscall_nr(name);
1006 compat_syscall_nr = get_compat_syscall_nr(name);
1007 if (syscall_nr < 0 && compat_syscall_nr < 0) {
1008 ret = -ENOENT;
1009 goto error;
1010 }
1011 if (syscall_nr >= 0) {
1012 if (test_bit(syscall_nr, filter->sc)) {
1013 ret = -EEXIST;
1014 goto error;
1015 }
1016 bitmap_set(filter->sc, syscall_nr, 1);
1017 }
1018 if (compat_syscall_nr >= 0) {
1019 if (test_bit(compat_syscall_nr, filter->sc_compat)) {
1020 ret = -EEXIST;
1021 goto error;
1022 }
1023 bitmap_set(filter->sc_compat, compat_syscall_nr, 1);
1024 }
1025 if (!chan->sc_filter)
1026 rcu_assign_pointer(chan->sc_filter, filter);
1027 return 0;
1028
1029 error:
1030 if (!chan->sc_filter)
1031 kfree(filter);
1032 return ret;
1033 }
1034
1035 int lttng_syscall_filter_disable(struct lttng_channel *chan,
1036 const char *name)
1037 {
1038 int syscall_nr, compat_syscall_nr, ret;
1039 struct lttng_syscall_filter *filter;
1040
1041 WARN_ON_ONCE(!chan->sc_table);
1042
1043 if (!chan->sc_filter) {
1044 if (!chan->syscall_all)
1045 return -EEXIST;
1046 filter = kzalloc(sizeof(struct lttng_syscall_filter),
1047 GFP_KERNEL);
1048 if (!filter)
1049 return -ENOMEM;
1050 /* Trace all system calls, then apply disable. */
1051 bitmap_set(filter->sc, 0, NR_syscalls);
1052 bitmap_set(filter->sc_compat, 0, NR_compat_syscalls);
1053 } else {
1054 filter = chan->sc_filter;
1055 }
1056
1057 if (!name) {
1058 /* Fail if all syscalls are already disabled. */
1059 if (bitmap_empty(filter->sc, NR_syscalls)
1060 && bitmap_empty(filter->sc_compat,
1061 NR_compat_syscalls)) {
1062 ret = -EEXIST;
1063 goto error;
1064 }
1065
1066 /* Disable all system calls */
1067 bitmap_clear(filter->sc, 0, NR_syscalls);
1068 bitmap_clear(filter->sc_compat, 0, NR_compat_syscalls);
1069 goto apply_filter;
1070 }
1071 syscall_nr = get_syscall_nr(name);
1072 compat_syscall_nr = get_compat_syscall_nr(name);
1073 if (syscall_nr < 0 && compat_syscall_nr < 0) {
1074 ret = -ENOENT;
1075 goto error;
1076 }
1077 if (syscall_nr >= 0) {
1078 if (!test_bit(syscall_nr, filter->sc)) {
1079 ret = -EEXIST;
1080 goto error;
1081 }
1082 bitmap_clear(filter->sc, syscall_nr, 1);
1083 }
1084 if (compat_syscall_nr >= 0) {
1085 if (!test_bit(compat_syscall_nr, filter->sc_compat)) {
1086 ret = -EEXIST;
1087 goto error;
1088 }
1089 bitmap_clear(filter->sc_compat, compat_syscall_nr, 1);
1090 }
1091 apply_filter:
1092 if (!chan->sc_filter)
1093 rcu_assign_pointer(chan->sc_filter, filter);
1094 chan->syscall_all = 0;
1095 return 0;
1096
1097 error:
1098 if (!chan->sc_filter)
1099 kfree(filter);
1100 return ret;
1101 }
1102
1103 static
1104 const struct trace_syscall_entry *syscall_list_get_entry(loff_t *pos)
1105 {
1106 const struct trace_syscall_entry *entry;
1107 int iter = 0;
1108
1109 for (entry = sc_table;
1110 entry < sc_table + ARRAY_SIZE(sc_table);
1111 entry++) {
1112 if (iter++ >= *pos)
1113 return entry;
1114 }
1115 for (entry = compat_sc_table;
1116 entry < compat_sc_table + ARRAY_SIZE(compat_sc_table);
1117 entry++) {
1118 if (iter++ >= *pos)
1119 return entry;
1120 }
1121 /* End of list */
1122 return NULL;
1123 }
1124
1125 static
1126 void *syscall_list_start(struct seq_file *m, loff_t *pos)
1127 {
1128 return (void *) syscall_list_get_entry(pos);
1129 }
1130
1131 static
1132 void *syscall_list_next(struct seq_file *m, void *p, loff_t *ppos)
1133 {
1134 (*ppos)++;
1135 return (void *) syscall_list_get_entry(ppos);
1136 }
1137
1138 static
1139 void syscall_list_stop(struct seq_file *m, void *p)
1140 {
1141 }
1142
1143 static
1144 int get_sc_table(const struct trace_syscall_entry *entry,
1145 const struct trace_syscall_entry **table,
1146 unsigned int *bitness)
1147 {
1148 if (entry >= sc_table && entry < sc_table + ARRAY_SIZE(sc_table)) {
1149 if (bitness)
1150 *bitness = BITS_PER_LONG;
1151 if (table)
1152 *table = sc_table;
1153 return 0;
1154 }
1155 if (!(entry >= compat_sc_table
1156 && entry < compat_sc_table + ARRAY_SIZE(compat_sc_table))) {
1157 return -EINVAL;
1158 }
1159 if (bitness)
1160 *bitness = 32;
1161 if (table)
1162 *table = compat_sc_table;
1163 return 0;
1164 }
1165
1166 static
1167 int syscall_list_show(struct seq_file *m, void *p)
1168 {
1169 const struct trace_syscall_entry *table, *entry = p;
1170 unsigned int bitness;
1171 unsigned long index;
1172 int ret;
1173 const char *name;
1174
1175 ret = get_sc_table(entry, &table, &bitness);
1176 if (ret)
1177 return ret;
1178 if (!entry->desc)
1179 return 0;
1180 if (table == sc_table) {
1181 index = entry - table;
1182 name = &entry->desc->name[strlen(SYSCALL_ENTRY_STR)];
1183 } else {
1184 index = (entry - table) + ARRAY_SIZE(sc_table);
1185 name = &entry->desc->name[strlen(COMPAT_SYSCALL_ENTRY_STR)];
1186 }
1187 seq_printf(m, "syscall { index = %lu; name = %s; bitness = %u; };\n",
1188 index, name, bitness);
1189 return 0;
1190 }
1191
1192 static
1193 const struct seq_operations lttng_syscall_list_seq_ops = {
1194 .start = syscall_list_start,
1195 .next = syscall_list_next,
1196 .stop = syscall_list_stop,
1197 .show = syscall_list_show,
1198 };
1199
1200 static
1201 int lttng_syscall_list_open(struct inode *inode, struct file *file)
1202 {
1203 return seq_open(file, &lttng_syscall_list_seq_ops);
1204 }
1205
1206 const struct file_operations lttng_syscall_list_fops = {
1207 .owner = THIS_MODULE,
1208 .open = lttng_syscall_list_open,
1209 .read = seq_read,
1210 .llseek = seq_lseek,
1211 .release = seq_release,
1212 };
1213
1214 long lttng_channel_syscall_mask(struct lttng_channel *channel,
1215 struct lttng_kernel_syscall_mask __user *usyscall_mask)
1216 {
1217 uint32_t len, sc_tables_len, bitmask_len;
1218 int ret = 0, bit;
1219 char *tmp_mask;
1220 struct lttng_syscall_filter *filter;
1221
1222 ret = get_user(len, &usyscall_mask->len);
1223 if (ret)
1224 return ret;
1225 sc_tables_len = get_sc_tables_len();
1226 bitmask_len = ALIGN(sc_tables_len, 8) >> 3;
1227 if (len < sc_tables_len) {
1228 return put_user(sc_tables_len, &usyscall_mask->len);
1229 }
1230 /* Array is large enough, we can copy array to user-space. */
1231 tmp_mask = kzalloc(bitmask_len, GFP_KERNEL);
1232 if (!tmp_mask)
1233 return -ENOMEM;
1234 filter = channel->sc_filter;
1235
1236 for (bit = 0; bit < ARRAY_SIZE(sc_table); bit++) {
1237 bool state;
1238
1239 if (channel->sc_table) {
1240 if (filter)
1241 state = test_bit(bit, filter->sc);
1242 else
1243 state = 1;
1244 } else {
1245 state = 0;
1246 }
1247 bt_bitfield_write_be(tmp_mask, char, bit, 1, state);
1248 }
1249 for (; bit < sc_tables_len; bit++) {
1250 bool state;
1251
1252 if (channel->compat_sc_table) {
1253 if (filter)
1254 state = test_bit(bit - ARRAY_SIZE(sc_table),
1255 filter->sc_compat);
1256 else
1257 state = 1;
1258 } else {
1259 state = 0;
1260 }
1261 bt_bitfield_write_be(tmp_mask, char, bit, 1, state);
1262 }
1263 if (copy_to_user(usyscall_mask->mask, tmp_mask, bitmask_len))
1264 ret = -EFAULT;
1265 kfree(tmp_mask);
1266 return ret;
1267 }
1268
1269 int lttng_abi_syscall_list(void)
1270 {
1271 struct file *syscall_list_file;
1272 int file_fd, ret;
1273
1274 file_fd = lttng_get_unused_fd();
1275 if (file_fd < 0) {
1276 ret = file_fd;
1277 goto fd_error;
1278 }
1279
1280 syscall_list_file = anon_inode_getfile("[lttng_syscall_list]",
1281 &lttng_syscall_list_fops,
1282 NULL, O_RDWR);
1283 if (IS_ERR(syscall_list_file)) {
1284 ret = PTR_ERR(syscall_list_file);
1285 goto file_error;
1286 }
1287 ret = lttng_syscall_list_fops.open(NULL, syscall_list_file);
1288 if (ret < 0)
1289 goto open_error;
1290 fd_install(file_fd, syscall_list_file);
1291 if (file_fd < 0) {
1292 ret = file_fd;
1293 goto fd_error;
1294 }
1295 return file_fd;
1296
1297 open_error:
1298 fput(syscall_list_file);
1299 file_error:
1300 put_unused_fd(file_fd);
1301 fd_error:
1302 return ret;
1303 }
This page took 0.070163 seconds and 5 git commands to generate.