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