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